home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / devnews / vol2 / sample3 / os2thrd.lst < prev    next >
Encoding:
File List  |  1994-02-27  |  44.6 KB  |  389 lines

  1. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     1
  2.                                       * * * * *   P R O L O G   * * * * *
  3.  
  4.  Compiler . . . . . . . . . . . . : IBM C/C++ Tools V2.0
  5.  Command options:
  6.     Compiler mode . . . . . . . . : C
  7.     Program name. . . . . . . . . : OS2THRD.C
  8.     Assemble name . . . . . . . . : "os2thrd.asm"
  9.     Object name . . . . . . . . . : "os2thrd.obj"
  10.     Listing name. . . . . . . . . : os2thrd.lst
  11.     Compiler options. . . . . . . : /C+  /Fa+ /Fc- /Fd- /Fi- /Fl- /Fm- /Fo+ /Fw- /Gd- /Ge+ /Gf- /Gh- /Gi- /Gm- /Gn- /Gr+ /Gs-
  12.                                   : /Gt- /Gu- /Gv- /Gw- /J+  /L-  /La- /Lb- /Le- /Lf- /Li- /Lj- /Ls+ /Lx- /Ly- /O-  /Ol- /Om-
  13.                                   : /Op+ /Os- /P-  /Pc- /Pd- /Pe- /Q+  /Sd- /Sh- /Si- /Sm- /Sn- /Sr- /Ss+ /Sv- /Ti- /Tm- /Tx-
  14.                                   : /Xi-
  15.                                   : /Wcls- /Wcmp- /Wcnd- /Wcns- /Wcnv- /Wcpy- /Wdcl- /Weff- /Wenu- /Wext- /Wgen- /Wgnr- /Wgot-
  16.                                   : /Wini- /Wlan- /Wobs- /Word- /Wpar- /Wpor- /Wppc- /Wppt- /Wpro- /Wrea- /Wret- /Wtrd- /Wtru-
  17.                                   : /Wund- /Wuni- /Wuse- /Wvft-
  18.                                   : /Mp  /Rn  /Se  /Sp1  /G3  /W3  /H255  /Lp66  /Sg-  /Sq-  /N  /Oi0  /Su-  /Tl10 
  19.                                   : /DM_I386=1  
  20.                                   : /I  
  21.                                   : /Lt 
  22.                                   : /Lu 
  23.                                   : /B  
  24.                                   : /V  
  25. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     2
  26.                                           * * * * *   S O U R C E   * * * * *
  27.  
  28.  LINE  STMT                                                                                                       SEQNBR INCNO
  29.              *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9.......*
  30.     1       |/******************************************************************************/                  |      1           
  31.     2       |/* The following code fragments were published as part of                     */                  |      2           
  32.     3       |/* The Developer Connection News  Volume II                                   */                  |      3           
  33.     4       |/*                                                                            */                  |      4           
  34.     5       |/* COPYRIGHT:                                                                 */                  |      5           
  35.     6       |/* ----------                                                                 */                  |      6           
  36.     7       |/* Copyright (C) International Business Machines Corp., 1993.                 */                  |      7           
  37.     8       |/*                                                                            */                  |      8           
  38.     9       |/* DISCLAIMER OF WARRANTIES:                                                  */                  |      9           
  39.    10       |/* -------------------------                                                  */                  |     10           
  40.    11       |/* The following [enclosed] code is sample code created by IBM                */                  |     11           
  41.    12       |/* Corporation.  This sample code is not part of any standard IBM product     */                  |     12           
  42.    13       |/* and is provided to you solely for the purpose of assisting you in the      */                  |     13           
  43.    14       |/* development of your applications.  The code is provided "AS IS",           */                  |     14           
  44.    15       |/* without warranty of any kind.  IBM shall not be liable for any damages     */                  |     15           
  45.    16       |/* arising out of your use of the sample code, even if they have been         */                  |     16           
  46.    17       |/* advised of the possibility of such damages.                                */                  |     17           
  47.    18       |/*                                                                            */                  |     18           
  48.    19       |/******************************************************************************/                  |     19           
  49.    20       |                                                                                                  |     20           
  50.    21       |                                                                                                  |     21           
  51.    22       |#define INCL_DOSMVDM                                                                              |     22           
  52.    23       |#define INCL_BASE                                                                                 |     23           
  53.    24       |#include <os2.h>                                                                                  |     24           
  54.    25       |#include <stdlib.h>                                                                               |     25           
  55.    26       |#include <string.h>                                                                               |     26           
  56.    27       |#include "sty_main.h"                                                                             |     27           
  57.    28       |#include "sty_xtrn.h"                                                                             |     28           
  58.    29       |#include "sty_dlg.h"                                                                              |     29           
  59.    30       |#include "common.h"                                                                               |     30           
  60.    31       |                                                                                                  |     31           
  61.    32       |                                                                                                  |     32           
  62.    33       |/*                                                                                                |     33           
  63.    34       | *Any data types that are private to this module                                                  |     34           
  64.    35       | */                                                                                               |     35           
  65.    36       |                                                                                                  |     36           
  66.    37       |                                                                                                  |     37           
  67.    38       |/*                                                                                                |     38           
  68.    39       | *any data declarations that are private to this module                                           |     39           
  69.    40       | */                                                                                               |     40           
  70.    41       |ULONG  HandleToVDD;                                                                               |     41           
  71.    42       |MESSAGEBUFFER MessageBuffer;                                                                      |     42           
  72.    43       |                                                                                                  |     43           
  73.    44       |/****************************************************************************/                    |     44           
  74.    45       |/*The following code fragments were enclosed due to erros in The Developer  */                    |     45           
  75.    46       |/*Connection News that we were not able to correct before press time.       */                    |     46           
  76.    47       |/*The following routines will be expanded and incoporated into the final    */                    |     47           
  77.    48       |/*release of the source code that will be released in a future release of   */                    |     48           
  78.    49       |/*The Developer Connection News - David Kenner                              */                    |     49           
  79.    50       |/****************************************************************************/                    |     50           
  80.    51       |/****************************************************************************/                    |     51           
  81.    52       |/*OpenVirtQueue                                                             */                    |     52           
  82.    53       |/*                                                                          */                    |     53           
  83.    54       |/*                                                                          */                    |     54           
  84.    55       |/*A service routine that will allow us to do our initilization with the vdd */                    |     55           
  85.    56       |/****************************************************************************/                    |     56           
  86.    57       |APIRET OpenVirtQueue(VOID)                                                                        |     57           
  87.    58       |{                                                                                                 |     58           
  88.    59       |     APIRET apiRet;                                                                               |     59           
  89.    60       |                                                                                                  |     60           
  90.    61       |     /*                                                                                           |     61           
  91. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     3
  92.                                           * * * * *   S O U R C E   * * * * *
  93.  
  94.  LINE  STMT                                                                                                       SEQNBR INCNO
  95.              *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9.......*
  96.    62       |      *see if our Vdd is alive and if so get                                                      |     62           
  97.    63       |      *a handle that we may use later                                                             |     63           
  98.    64       |      */                                                                                          |     64           
  99.    65     1 |     if(apiRet = DosOpenVDD(VDDNAME,&HandleToVDD) )                                               |     65           
  100.    66       |     {                                                                                            |     66           
  101.    67     2 |          return(apiRet);                                                                         |     67           
  102.    68       |     }                                                                                            |     68           
  103.    69       |                                                                                                  |     69           
  104.    70       |     /*                                                                                           |     70           
  105.    71       |      *Call into our Vdd so we perform any initialization                                         |     71           
  106.    72       |      *we need to do at this time.                                                                |     72           
  107.    73       |      */                                                                                          |     73           
  108.    74       |     if(apiRet  = DosRequestVDD(HandleToVDD,                                                      |     74           
  109.    75       |                                0,                                                                |     75           
  110.    76       |                                INIT_COMMAND,                                                     |     76           
  111.    77       |                                0,                                                                |     77           
  112.    78       |                                NULL,                                                             |     78           
  113.    79       |                                0,                                                                |     79           
  114.    80     3 |                                NULL) )                                                           |     80           
  115.    81       |     {                                                                                            |     81           
  116.    82     4 |          return(apiRet);                                                                         |     82           
  117.    83       |     }                                                                                            |     83           
  118.    84     5 |     return(apiRet);                                                                              |     84           
  119.    85       |}                                                                                                 |     85           
  120.    86       |/****************************************************************************/                    |     86           
  121.    87       |/*WriteVirtQueue                                                            */                    |     87           
  122.    88       |/*                                                                          */                    |     88           
  123.    89       |/*                                                                          */                    |     89           
  124.    90       |/*A service routine that will allow us to send our message data to the  vdd */                    |     90           
  125.    91       |/*                                                                          */                    |     91           
  126.    92       |/*                                                                          */                    |     92           
  127.    93       |/*                                                                          */                    |     93           
  128.    94       |/****************************************************************************/                    |     94           
  129.    95       |                                                                                                  |     95           
  130.    96       |APIRET WriteVirtQueue(PVOID pvMessageToSend,                                                      |     96           
  131.    97       |                      ULONG ulCount,                                                              |     97           
  132.    98       |                      SGID  SessionId)                                                            |     98           
  133.    99       |{                                                                                                 |     99           
  134.   100       |     APIRET apiRet;                                                                               |    100           
  135.   101       |                                                                                                  |    101           
  136.   102       |     if(apiRet = DosRequestVDD(HandleToVDD,                                                       |    102           
  137.   103       |                               SessionId,                                                         |    103           
  138.   104       |                               POST_MESSAGE,                                                      |    104           
  139.   105       |                               ulCount,                                                           |    105           
  140.   106       |                               pvMessageToSend,                                                   |    106           
  141.   107       |                               0,                                                                 |    107           
  142.   108     6 |                               NULL) )                                                            |    108           
  143.   109       |     {                                                                                            |    109           
  144.   110     7 |          return(apiRet);                                                                         |    110           
  145.   111       |     }                                                                                            |    111           
  146.   112     8 |     return(apiRet);                                                                              |    112           
  147.   113       |}                                                                                                 |    113           
  148.   114       |                                                                                                  |    114           
  149.   115       |/****************************************************************************/                    |    115           
  150.   116       |/*ReadVirtQueue                                                             */                    |    116           
  151.   117       |/*                                                                          */                    |    117           
  152.   118       |/*                                                                          */                    |    118           
  153.   119       |/*This routine is set up as separate thread that will read messages,process */                    |    119           
  154.   120       |/*them,and then continue to block until additional messages come in.The     */                    |    120           
  155.   121       |/*block mechansim is accomplished through the semaphore in our VDD          */                    |    121           
  156.   122       |/*                                                                          */                    |    122           
  157. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     4
  158.                                           * * * * *   S O U R C E   * * * * *
  159.  
  160.  LINE  STMT                                                                                                       SEQNBR INCNO
  161.              *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9.......*
  162.   123       |/*Note:                                                                     */                    |    123           
  163.   124       |/*There is no error return. All error messages are handled before the       */                    |    124           
  164.   125       |/*thread terminates                                                         */                    |    125           
  165.   126       |/*                                                                          */                    |    126           
  166.   127       |/****************************************************************************/                    |    127           
  167.   128       |VOID ReadVirtQueue(VOID)                                                                          |    128           
  168.   129       |{                                                                                                 |    129           
  169.   130       |     APIRET apiRet;                                                                               |    130           
  170.   131       |     PVOID  pvMessage;                                                                            |    131           
  171.   132       |     CHAR   CommandToSend[SIZ_COMMAND_BUF];                                                       |    132           
  172.   133       |                                                                                                  |    133           
  173.   134       |                                                                                                  |    134           
  174.   135       |                                                                                                  |    135           
  175.   136     9 |     do                                                                                           |    136           
  176.   137       |     {                                                                                            |    137           
  177.   138       |          /*                                                                                      |    138           
  178.   139       |           *block until we get any message                                                        |    139           
  179.   140       |           *data                                                                                  |    140           
  180.   141       |           */                                                                                     |    141           
  181.   142       |          if(apiRet = DosRequestVDD(HandleToVDD,                                                  |    142           
  182.   143       |                                    0,                                                            |    143           
  183.   144       |                                    READ_QUEUE,                                                   |    144           
  184.   145       |                                    strlen(CommandToSend),                                        |    145           
  185.   146       |                                    CommandToSend,                                                |    146           
  186.   147       |                                    sizeof(MessageBuffer),                                        |    147           
  187.   148    10 |                                    &MessageBuffer) )                                             |    148           
  188.   149       |          {                                                                                       |    149           
  189.   150    11 |               break;                                                                             |    150           
  190.   151       |          }                                                                                       |    151           
  191.   152       |          /*                                                                                      |    152           
  192.   153       |           *do all of our message processing                                                      |    153           
  193.   154       |           */                                                                                     |    154           
  194.   155    12 |           apiRet = ProcessMessageData(MessageBuffer);                                            |    155           
  195.   156       |                                                                                                  |    156           
  196.   157    13 |     }while(!apiRet);                                                                             |    157           
  197.   158       |     /*                                                                                           |    158           
  198.   159       |      *handle any error that was  encountered                                                     |    159           
  199.   160       |      *during our polling                                                                         |    160           
  200.   161       |      */                                                                                          |    161           
  201.   162       |                                                                                                  |    162           
  202.   163       |                                                                                                  |    163           
  203.   164       |     /*                                                                                           |    164           
  204.   165       |      *do any other clean up we need to do                                                        |    165           
  205.   166       |      *and get out                                                                                |    166           
  206.   167       |      */                                                                                          |    167           
  207.   168       |                                                                                                  |    168           
  208.   169    14 |     _endthread();                                                                                |    169           
  209.   170       |}                                                                                                 |    170           
  210.   171       |                                                                                                  |    171           
  211.   172       |/****************************************************************************/                    |    172           
  212.   173       |/*Provide a stub to keep the linker from complaining                        */                    |    173           
  213.   174       |/*                                                                          */                    |    174           
  214.   175       |/*                                                                          */                    |    175           
  215.   176       |/*This is currently just a stub routine                                     */                    |    176           
  216.   177       |/****************************************************************************/                    |    177           
  217.   178       |#if 0                                                                                             |    178           
  218.   179       |INT main(void)                                                                                    |    179           
  219.   180       |{                                                                                                 |    180           
  220.   181       |     APIRET apiRet;                                                                               |    181           
  221.   182       |                                                                                                  |    182           
  222.   183       |                                                                                                  |    183           
  223. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     5
  224.                                           * * * * *   S O U R C E   * * * * *
  225.  
  226.  LINE  STMT                                                                                                       SEQNBR INCNO
  227.              *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9.......*
  228.   184       |     do                                                                                           |    184           
  229.   185       |     {                                                                                            |    185           
  230.   186       |                                                                                                  |    186           
  231.   187       |          if(OpenVirtQueue() )                                                                    |    187           
  232.   188       |          {                                                                                       |    188           
  233.   189       |               break;                                                                             |    189           
  234.   190       |          }                                                                                       |    190           
  235.   191       |          /*                                                                                      |    191           
  236.   192       |           *start off our read thread                                                             |    192           
  237.   193       |           */                                                                                     |    193           
  238.   194       |           apiRet = StartReadThread();                                                            |    194           
  239.   195       |                                                                                                  |    195           
  240.   196       |     }ONCE;                                                                                       |    196           
  241.   197       |     return(0);                                                                                   |    197           
  242.   198       |                                                                                                  |    198           
  243.   199       |}                                                                                                 |    199           
  244.   200       |#endif                                                                                            |    200           
  245.   201       |                                                                                                  |    201           
  246.   202       |/****************************************************************************/                    |    202           
  247.   203       |/*Process any message data we get from our vdd                              */                    |    203           
  248.   204       |/*                                                                          */                    |    204           
  249.   205       |/*                                                                          */                    |    205           
  250.   206       |/*This is currently just a stub routine                                     */                    |    206           
  251.   207       |/****************************************************************************/                    |    207           
  252.   208       |APIRET ProcessMessageData(MESSAGEBUFFER MessageBuffer)                                            |    208           
  253.   209       |{                                                                                                 |    209           
  254.   210       |                                                                                                  |    210           
  255.   211       |     APIRET apiRet;                                                                               |    211           
  256.   212       |                                                                                                  |    212           
  257.   213    15 |     do                                                                                           |    213           
  258.   214       |     {                                                                                            |    214           
  259.   215       |                                                                                                  |    215           
  260.   216       |                                                                                                  |    216           
  261.   217       |                                                                                                  |    217           
  262.   218    16 |     }ONCE;                                                                                       |    218           
  263.   219    17 |     return(apiRet);                                                                              |    219           
  264.   220       |}                                                                                                 |    220           
  265.   221       |/****************************************************************\                                |    221           
  266.   222       | *                                                                                                |    222           
  267.   223       | *--------------------------------------------------------------                                  |    223           
  268.   224       | *                                                                                                |    224           
  269.   225       | *  Name:                                                                                         |    225           
  270.   226       | *                                                                                                |    226           
  271.   227       | *  Purpose:                                                                                      |    227           
  272.   228       | *                                                                                                |    228           
  273.   229       | *                                                                                                |    229           
  274.   230       | *                                                                                                |    230           
  275.   231       | *  Usage:                                                                                        |    231           
  276.   232       | *                                                                                                |    232           
  277.   233       | *  Method:                                                                                       |    233           
  278.   234       | *          -                                                                                     |    234           
  279.   235       | *                                                                                                |    235           
  280.   236       | *          -                                                                                     |    236           
  281.   237       | *          -                                                                                     |    237           
  282.   238       | *                                                                                                |    238           
  283.   239       | *          -                                                                                     |    239           
  284.   240       | *          -                                                                                     |    240           
  285.   241       | *                                                                                                |    241           
  286.   242       | *  Returns:                                                                                      |    242           
  287.   243       | *          1 - if sucessful execution completed                                                  |    243           
  288.   244       | *          0 - if error                                                                          |    244           
  289. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     6
  290.                                           * * * * *   S O U R C E   * * * * *
  291.  
  292.  LINE  STMT                                                                                                       SEQNBR INCNO
  293.              *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9.......*
  294.   245       |\****************************************************************/                                |    245           
  295.   246       |APIRET StartReadThread(VOID)                                                                      |    246           
  296.   247       |{                                                                                                 |    247           
  297.   248       |    APIRET ApiRet;                                                                                |    248           
  298.   249       |                                                                                                  |    249           
  299.   250       |                                                                                                  |    250           
  300.   251       |     if( (ApiRet = _beginthread(ReadVirtQueue,                                                    |    251           
  301.   252       |                          NULL,                                                                   |    252           
  302.   253       |                          8192,                                                                   |    253           
  303.   254    18 |                          NULL)) == -1)                                                           |    254           
  304.   255       |     {                                                                                            |    255           
  305.   256    19 |          return(TRUE);                                                                           |    256           
  306.   257       |     }                                                                                            |    257           
  307.   258       |                                                                                                  |    258           
  308.   259       |                                                                                                  |    259           
  309.   260    20 |     return(FALSE);                                                                               |    260           
  310.   261       |}                                                                                                 |    261           
  311.   262       |                                                                                                  |    262           
  312.   263       |/****************************************************************************/                    |    263           
  313.   264       |/****************************************************************************/                    |    264           
  314.   265       |/*OpenVirtQueue                                                             */                    |    265           
  315.   266       |/*                                                                          */                    |    266           
  316.   267       |/*                                                                          */                    |    267           
  317.   268       |/*A service routine that will allow us to do our initilization with the vdd */                    |    268           
  318.   269       |/****************************************************************************/                    |    269           
  319.   270       |APIRET CloseVirtQueue(VOID)                                                                       |    270           
  320.   271       |{                                                                                                 |    271           
  321.   272       |     APIRET apiRet;                                                                               |    272           
  322.   273       |                                                                                                  |    273           
  323.   274       |     /*                                                                                           |    274           
  324.   275       |      *Call into our Vdd so we perform any initialization                                         |    275           
  325.   276       |      *we need to do at this time.                                                                |    276           
  326.   277       |      */                                                                                          |    277           
  327.   278       |     if(apiRet  = DosRequestVDD(HandleToVDD,                                                      |    278           
  328.   279       |                                0,                                                                |    279           
  329.   280       |                                TERMINATE_COMMAND,                                                |    280           
  330.   281       |                                0,                                                                |    281           
  331.   282       |                                NULL,                                                             |    282           
  332.   283       |                                0,                                                                |    283           
  333.   284    21 |                                NULL) )                                                           |    284           
  334.   285       |     {                                                                                            |    285           
  335.   286    22 |          return(apiRet);                                                                         |    286           
  336.   287       |     }                                                                                            |    287           
  337.   288    23 |     return(apiRet);                                                                              |    288           
  338.   289       |}                                                                                                 |    289           
  339.   290       |                                                                                                  |    290           
  340.   291       |                                                                                                  |    291           
  341.   292       |                                                                                                  |    292           
  342.   293       |                                                                                                  |    293           
  343.   294       |                                                                                                  |    294           
  344.   295       |                                                                                                  |    295           
  345.   296       |                                                                                                  |    296           
  346.   297       |                                                                                                  |    297           
  347.   298       |                                                                                                  |    298           
  348.   299       |                                                                                                  |    299           
  349.                                     * * * * *   E N D   O F   S O U R C E   * * * * *
  350. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     7
  351.                         * * * * *   I N C L U D E S   * * * * *
  352.  
  353. INCLUDE FILES  ---  FILE#   NAME
  354.                       1       F:\TOOLKT21\C\OS2H\OS2.H
  355.                       2       F:\TOOLKT21\C\OS2H\OS2DEF.H
  356.                       3       F:\TOOLKT21\C\OS2H\BSE.H
  357.                       4       F:\TOOLKT21\C\OS2H\BSEDOS.H
  358.                       5       F:\TOOLKT21\C\OS2H\BSETIB.H
  359.                       6       F:\TOOLKT21\C\OS2H\BSEMEMF.H
  360.                       7       F:\TOOLKT21\C\OS2H\BSEXCPT.H
  361.                       8       F:\TOOLKT21\C\OS2H\BSESUB.H
  362.                       9       F:\TOOLKT21\C\OS2H\BSEERR.H
  363.                      10       F:\TOOLKT21\C\OS2H\PM.H
  364.                      11       F:\TOOLKT21\C\OS2H\PMWIN.H
  365.                      12       F:\TOOLKT21\C\OS2H\PMSHL.H
  366.                      13       F:\TOOLKT21\C\OS2H\PMGPI.H
  367.                      14       F:\TOOLKT21\C\OS2H\PMDEV.H
  368.                      15       F:\TOOLKT21\C\OS2H\PMWP.H
  369.                      16       F:\TOOLKT21\C\OS2H\PMERR.H
  370.                      17       F:\TOOLKT21\C\OS2H\PMSTDDLG.H
  371.                      18       G:\IBMCPP\INCLUDE\STDLIB.H
  372.                      19       G:\IBMCPP\INCLUDE\STRING.H
  373.                      20       G:\IBMCPP\SRC\STY_MAIN.H
  374.                      21       G:\IBMCPP\SRC\STY_XTRN.H
  375.                      22       G:\IBMCPP\SRC\STY_DLG.H
  376.                      23       G:\IBMCPP\SRC\COMMON.H
  377.  
  378.                         * * * * *   E N D   O F   I N C L U D E S   * * * * *
  379. OS2THRD.C                                                                                      02/27/94 14:56:07     Page     8
  380.                              * * * * *   M E S S A G E   S U M M A R Y   * * * * *
  381.  
  382.         Total            Informational(00)          Warning(10)          Error(30)            Severe Error(40)
  383.  
  384.           0                    0                        0                   0                        0
  385.  
  386.                         * * * * *   E N D   O F   M E S S A G E   S U M M A R Y   * * * * *
  387.  
  388.                              * * * * *   E N D   O F   C O M P I L A T I O N   * * * * *
  389.