home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / os2apipm.zip / OS2API / OS2-NPIP.ADS < prev    next >
Text File  |  1996-08-10  |  11KB  |  209 lines

  1.  
  2. -- ╔═══════════════════════════════════════════════════════════════════╗
  3. -- ║       D E S I G N   E N G I N E R I N G              ║D║S║        ║
  4. -- ║            S O F T W A R E                           ╚═╩═╝        ║
  5. -- ║                                                                   ║
  6. -- ║        Package     Os2.Npip                                       ║
  7. -- ║                                                                   ║
  8. -- ║        Author :  Leonid Dulman     1995                           ║
  9. -- ║                                                                   ║
  10. -- ║             GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS            ║
  11. -- ║                                                                   ║
  12. -- ║             Dos Named Pipes      of os/2 api functions            ║
  13. -- ║                                                                   ║
  14. -- ╚═══════════════════════════════════════════════════════════════════╝
  15.  
  16. with Interfaces.C;         use Interfaces.C;
  17. with Interfaces.C.Strings; use Interfaces.C.Strings;
  18.  
  19. package Os2.Npip is
  20. pragma Preelaborate (Npip);
  21.  
  22. --** DosNamedPipes API Support --
  23.  
  24.    --** Data ures used with named pipes **--
  25.  
  26. subtype HPIPE is LHANDLE ;     -- hp --
  27. type PHPIPE   is access all HPIPE;
  28.  
  29. type  AVAILDATA is record               -- AVAILDATA --
  30.   cbpipe       :USHORT      ;         -- bytes left in the pipe --
  31.   cbmessage    :USHORT      ;         -- bytes left in the current message --
  32. end record;  -- AVAILDATA;
  33. type PAVAILDATA is access all AVAILDATA;
  34.  
  35. type  PIPEINFO is record               -- nmpinf --
  36.   cbOut        :USHORT ;                  -- length of outgoing I/O buffer --
  37.   cbIn         :USHORT ;                   -- length of incoming I/O buffer --
  38.   cbMaxInst    :BYTE   ;              -- maximum number of instances   --
  39.   cbCurInst    :BYTE   ;              -- current number of instances   --
  40.   cbName       :BYTE   ;                 -- length of pipe name           --
  41.   szName       :string(1..1);  -- [1];   -- start of name                 --
  42. end record;  -- PIPEINFO;
  43. type PPIPEINFO  is access all PIPEINFO;
  44.  
  45. type  PIPESEMSTATE is record     -- nmpsmst --
  46.   fStatus    :BYTE   ;         -- type of record; 0 = EOI; 1 = read ok; --
  47.                               -- 2 = write ok; 3 = pipe closed         --
  48.   fFlag      :BYTE   ;           -- additional info; 01 = waiting thread  --
  49.   usKey      :USHORT ;           -- user's key value                      --
  50.   usAvail    :USHORT ;         -- available data/space if status = 1/2  --
  51. end record;  -- PIPESEMSTATE;
  52. type PPIPESEMSTATE is access all PIPESEMSTATE;
  53.  
  54.  NP_INDEFINITE_WAIT :constant Long :=     -1;
  55.  NP_DEFAULT_WAIT    :constant Long :=      0;
  56.  
  57. -- DosPeekNmPipe() pipe states --
  58.  
  59.  NP_STATE_DISCONNECTED :constant Long :=   16#0001#;
  60.  NP_STATE_LISTENING    :constant Long :=   16#0002#;
  61.  NP_STATE_CONNECTED    :constant Long :=   16#0003#;
  62.  NP_STATE_CLOSING      :constant Long :=   16#0004#;
  63.  
  64. -- DosCreateNPipe open modes --
  65.  
  66.  NP_ACCESS_INBOUND     :constant Long :=   16#0000#;
  67.  NP_ACCESS_OUTBOUND    :constant Long :=   16#0001#;
  68.  NP_ACCESS_DUPLEX      :constant Long :=   16#0002#;
  69.  NP_INHERIT            :constant Long :=   16#0000#;
  70.  NP_NOINHERIT          :constant Long :=   16#0080#;
  71.  NP_WRITEBEHIND        :constant Long :=   16#0000#;
  72.  NP_NOWRITEBEHIND      :constant Long :=   16#4000#;
  73.  
  74. -- DosCreateNPipe and DosQueryNPHState state
  75.  
  76.  NP_READMODE_BYTE      :constant Long :=   16#0000#;
  77.  NP_READMODE_MESSAGE   :constant Long :=   16#0100#;
  78.  NP_TYPE_BYTE          :constant Long :=   16#0000#;
  79.  NP_TYPE_MESSAGE       :constant Long :=   16#0400#;
  80.  NP_END_CLIENT         :constant Long :=   16#0000#;
  81.  NP_END_SERVER         :constant Long :=   16#4000#;
  82.  NP_WAIT               :constant Long :=   16#0000#;
  83.  NP_NOWAIT             :constant Long :=   16#8000#;
  84.  NP_UNLIMITED_INSTANCES:constant Long :=   16#00FF#;
  85.  
  86. function  DosCallNPipe(pszName  :PSZ    ;
  87.                        pInbuf   :PVOID  ;
  88.                        cbIn     :ULONG  ;
  89.                        pOutbuf  :PVOID  ;
  90.                        cbOut    :ULONG  ;
  91.                        pcbActual:PULONG ;
  92.                        msec     :ULONG  ) return apiret;
  93. pragma Import(c,DosCallNPipe, Link_name=>"_DosCallNPipe");
  94.  
  95. function  DosConnectNPipe(hpp:HPIPE ) return apiret;
  96. pragma Import(c,DosConnectNPipe, Link_name=>"_DosConnectNPipe");
  97.  
  98. function  DosDisConnectNPipe(hpp:HPIPE)return apiret;
  99. pragma Import(c,DosDisConnectNPipe, Link_name=>"_DosDisConnectNPipe");
  100.  
  101. function  DosCreateNPipe(pszName :PSZ    ;
  102.                           Ppipe  :PHPIPE ;
  103.                          openmode:ULONG  ;
  104.                          pipemode:ULONG  ;
  105.                          cbInbuf :ULONG  ;
  106.                          cbOutbuf:ULONG  ;
  107.                          msec    :ULONG  )return apiret;
  108. pragma Import(c,DosCreateNPipe, Link_name=>"_DosCreateNPipe");
  109.  
  110. function  DosPeekNPipe( pipe    :HPIPE      ;
  111.                        pBuf     :PVOID      ;
  112.                        cbBuf    :ULONG      ;
  113.                        pcbActual:PULONG     ;
  114.                        pAvail   :PAVAILDATA ;
  115.                        pState   :PULONG     )return apiret;
  116. pragma Import(c,DosPeekNPipe, Link_name=>"_DosPeekNPipe");
  117.  
  118. function  DosQueryNPHState( pipe :HPIPE  ;
  119.                            pState:PULONG )return apiret;
  120. pragma Import(c,DosQueryNPHState, Link_name=>"_DosQueryNPHState");
  121.  
  122. function  DosQueryNPipeInfo( pipe    :HPIPE ;
  123.                             infolevel:ULONG ;
  124.                             pBuf     :PVOID ;
  125.                             cbBuf    :ULONG )return apiret;
  126. pragma Import(c,DosQueryNPipeInfo, Link_name=>"_DosQueryNPipeInfo");
  127.  
  128. function DosQueryNPipeSemState(sem  :HSEM          ;
  129.                                pnpss:PPIPESEMSTATE ;
  130.                                cbBuf:ULONG         ) return apiret;
  131. pragma Import(c,DosQueryNPipeSemState, Link_name=>"_DosQueryNPipeSemState");
  132.  
  133. function  DosRawReadNPipe(pszName:PSZ    ;
  134.                           cb     :ULONG  ;
  135.                           pLen   :PULONG ;
  136.                           pBuf   :PVOID  )return apiret;
  137. pragma Import(c,DosRawReadNPipe, Link_name=>"_DosRawReadNPipe");
  138.  
  139. function  DosRawWriteNPipe(pszName:PSZ   ;
  140.                            cb     :ULONG )return apiret;
  141. pragma Import(c,DosRawWriteNPipe, Link_name=>"_DosRawWriteNPipe");
  142.  
  143. function  DosSetNPHState(hpp  :HPIPE ;
  144.                          state:ULONG )return apiret;
  145. pragma Import(c,DosSetNPHState, Link_name=>"_DosSetNPHState");
  146.  
  147. function  DosSetNPipeSem(hpp:HPIPE ;
  148.                          sem:HSEM  ;
  149.                          key:ULONG )return apiret;
  150. pragma Import(c,DosSetNPipeSem, Link_name=>"_DosSetNPipeSem");
  151.  
  152. function  DosTransactNPipe(hpp     :HPIPE ;
  153.                            pOutbuf :PVOID ;
  154.                            cbOut   :ULONG ;
  155.                            pInbuf  :PVOID ;
  156.                            cbIn    :ULONG ;
  157.                             pcbRead:PULONG)return apiret;
  158. pragma Import(c,DosTransactNPipe, Link_name=>"_DosTransactNPipe");
  159.  
  160. function  DosWaitNPipe(pszName:PSZ   ;
  161.                        msec   :ULONG )return apiret;
  162. pragma Import(c,DosWaitNPipe, Link_name=>"_DosWaitNPipe");
  163.  
  164.  -- values in fStatus --
  165.   NPSS_EOI     :constant Long :=    0 ;   -- End Of Information
  166.   NPSS_RDATA   :constant Long :=    1 ;   -- read data available
  167.   NPSS_WSPACE  :constant Long :=    2 ;   -- write space available
  168.   NPSS_CLOSE   :constant Long :=    3 ;   -- pipe in CLOSING state
  169.  
  170.  -- values in npss_flag --
  171.   NPSS_WAIT    :constant Long :=    16#01#;  -- waiting thread on end of pipe
  172.  
  173.  -- defined bits in pipe mode
  174.   NP_NBLK      :constant Long :=    16#8000#; -- non-blocking read/write
  175.   NP_SERVER    :constant Long :=    16#4000#; -- set if server end
  176.   NP_WMESG     :constant Long :=    16#0400#; -- write messages
  177.   NP_RMESG     :constant Long :=    16#0100#; -- read as messages
  178.   NP_ICOUNT    :constant Long :=    16#00FF#; -- instance count field
  179.  
  180.  
  181. --   ║ --Named pipes may be in one of several states depending on the actions                       ║
  182. --   ║ * that have been taken on it by the server end and client end.  The                          ║
  183. --   ║ * following state/action table summarizes the valid state transitions:                       ║
  184. --   ║ *                                                                                            ║
  185. --   ║ * Current state           Action                  Next state                                 ║
  186. --   ║ *                                                                                            ║
  187. --   ║ *  <none>             server DosMakeNmPipe        DISCONNECTED                               ║
  188. --   ║ *  DISCONNECTED       server connect              LISTENING                                  ║
  189. --   ║ *  LISTENING          client open                 CONNECTED                                  ║
  190. --   ║ *  CONNECTED          server disconn              DISCONNECTED                               ║
  191. --   ║ *  CONNECTED          client close                CLOSING                                    ║
  192. --   ║ *  CLOSING            server disconn              DISCONNECTED                               ║
  193. --   ║ *  CONNECTED          server close                CLOSING                                    ║
  194. --   ║ *  <any other>        server close                <pipe deallocated>                         ║
  195. --   ║ *                                                                                            ║
  196. --   ║ * If a server disconnects his end of the pipe; the client end will enter a                   ║
  197. --   ║ * special state in which any future operations (except close)return apiret; on the file      ║
  198. --   ║ * descriptor associated with the pipe will return an error.                                  ║
  199. --   ║ --                                                                                           ║
  200. --   ╚══════════════════════════════════════════════════════════════════════════════════════════════╝
  201.  
  202.  --     Values for named pipe state
  203.  
  204.   NP_DISCONNECTED :constant Long :=       1 ;       -- after pipe creation or Disconnect
  205.   NP_LISTENING    :constant Long :=       2 ;       -- after DosNmPipeConnect
  206.   NP_CONNECTED    :constant Long :=       3 ;       -- after Client open
  207.   NP_CLOSING      :constant Long :=       4 ;       -- after Client or Server close
  208. end Os2.Npip;
  209.