home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / misc / netmio.src < prev    next >
Encoding:
Text File  |  1988-05-03  |  11.4 KB  |  330 lines

  1. --::::::::::
  2. --NETMIO.DIS
  3. --::::::::::
  4. -- NETWORK_MIXED_IO Prologue and Distribution Files
  5. NETMIO.DIS
  6. NETMIO.PRO
  7. -- NETWORK_MIXED_IO Code in Compilation Order
  8. NETMIO.SPC
  9. NETMIO.BOD
  10. --::::::::::
  11. --NETMIO.PRO
  12. --::::::::::
  13. -------- SIMTEL20 Ada Software Repository Prologue ------------
  14. --                                                           -*
  15. -- Unit name    : generic package NETWORK_MIXED_IO
  16. -- Version      : 2.0
  17. -- Author       : Stanley R. Allen
  18. --              : Lockheed Engineering Management Services Company
  19. --              : Computer Systems Engineering Department  MS B08
  20. --              : Houston, TX  77258
  21. --              : (713) 333-6120
  22. -- DDN Address  : SALLEN%LOCK.SPAN@Jpl-VLSI.ARPA
  23. -- Copyright    : none
  24. -- Date created : Fri 31 Jul 87
  25. -- Release date : Mon 31 Aug 87
  26. -- Last update  : Mon 31 Aug 87
  27. -- Machine/System Compiled/Run on : VAX 11/785, VAX 8650
  28. --                                                           -*
  29. ---------------------------------------------------------------
  30. --                                                           -*
  31. -- Keywords     :  NETWORK, COMMUNICATION
  32. ----------------:
  33. --
  34. -- Abstract     :  This package provides an Ada interface to a
  35. ----------------:  communication network.  The model of the network
  36. ----------------:  is one that allows tasks on separate nodes to
  37. ----------------:  pass messages (message-passing).  The package
  38. ----------------:  is designed to be similar to the VAX-supplied
  39. ----------------:  package SEQUENTIAL_MIXED_IO, with the same basic
  40. ----------------:  operations, applicable to networks.  The
  41. ----------------:  idea of SEQUENTIAL_MIXED_IO (just as for the other
  42. ----------------:  predefined I/O packages) is machine independent
  43. ----------------:  logical operations defined in the spec, and
  44. ----------------:  machine dependencies hidden in the private
  45. ----------------:  parts and the bodies.  Currently NETWORK_MIXED_IO
  46. ----------------:  allows a link two VAX DECnet nodes to be created
  47. ----------------:  across which any type can be passed.
  48. -- Dependent Units : package SYSTEM, STARLET, CONDITION_HANDLING,
  49. --                   IO_EXCEPTIONS, TASKING_SERVICES.
  50. --                                                           -*
  51. ------------------ Revision history ---------------------------
  52. --                                                           -*
  53. -- DATE         VERSION              AUTHOR     HISTORY
  54. -- 08/31/87     2.0               Allen      First Update
  55. --
  56. --    A number of changes have been made since version 1.0:
  57. --
  58. --    1)  The name of the abstraction is no longer FILE_TYPE,
  59. --        but is LINK_TYPE instead.  This just seemed to make
  60. --        more logical sense.  The only change made to the
  61. --        source to reflect this was the text substitution
  62. --        LINK for FILE throughout.  This includes the change
  63. --        from IN_FILE, OUT_FILE, and INOUT_FILE to IN_LINK,
  64. --        OUT_LINK, and INOUT_LINK for MODE_TYPE.  In old
  65. --        programs where you used version 1.0, just make the
  66. --        same global text substitution to upgrade, and
  67. --        recompile.
  68. --
  69. --    2)  The body has been changed to use the VAX's TASK_QIOW
  70. --        instead of STARLET.QIOW.  This means that now the
  71. --        network i/o READ and WRITE operation will not suspend
  72. --        the entire VMS process while waiting for completion,
  73. --        only the individual Ada task.
  74. --
  75. --    3)  The body no longer uses the VAX-specific 'MACHINE_SIZE
  76. --        attribute to determine the size of the message to be sent.
  77. --        Now 'SIZE is used on the object (as opposed to the type)
  78. --        to be sent.
  79. --
  80. --                                                           -*
  81. ------------------ Distribution and Copyright -----------------
  82. --                                                           -*
  83. -- This prologue must be included in all copies of this software.
  84. --
  85. -- This software is released to the Ada community.
  86. -- This software is released to the Public Domain (note:
  87. --   software released to the Public Domain is not subject
  88. --   to copyright protection).
  89. -- Restrictions on use or distribution:  NONE
  90. --                                                           -*
  91. ------------------ Disclaimer ---------------------------------
  92. --                                                           -*
  93. -- This software and its documentation are provided "AS IS" and
  94. -- without any expressed or implied warranties whatsoever.
  95. -- No warranties as to performance, merchantability, or fitness
  96. -- for a particular purpose exist.
  97. --
  98. -- Because of the diversity of conditions and hardware under
  99. -- which this software may be used, no warranty of fitness for
  100. -- a particular purpose is offered.  The user is advised to
  101. -- test the software thoroughly before relying on it.  The user
  102. -- must assume the entire risk and liability of using this
  103. -- software.
  104. --
  105. -- In no event shall any person or organization of people be
  106. -- held responsible for any direct, indirect, consequential
  107. -- or inconsequential damages or lost profits.
  108. --                                                           -*
  109. -------------------END-PROLOGUE--------------------------------
  110. -------
  111. --::::::::::
  112. --NETMIO.SPC
  113. --::::::::::
  114. with STARLET;
  115. with IO_EXCEPTIONS;
  116. package NETWORK_MIXED_IO is
  117.  
  118.     type LINK_TYPE is limited private;
  119.     type LINK_MODE is (IN_LINK, INOUT_LINK, OUT_LINK);
  120.  
  121.     procedure CREATE(               --| Create a VC link to remote PE.
  122.         LINK : in out LINK_TYPE;    --| LINK: logical name.
  123.         MODE : in LINK_MODE;        --| MODE: IN_LINK, OUT_LINK, INOUT_LINK.
  124.         NAME : in STRING := "";     --| NAME: Physical name of remote PE.
  125.         FORM : in STRING := "");    --| FORM: Special local parameters.
  126.  
  127.     procedure OPEN (                --| Complete a VC link to remote PE.
  128.         LINK : in out LINK_TYPE;    --| LINK: logical name.
  129.         MODE : in LINK_MODE;        --| MODE: IN_LINK, OUT_LINK, INOUT_LINK.
  130.         NAME : in STRING := "";     --| NAME: Physical name of remote PE.
  131.         FORM : in STRING := "");    --| FORM: Special local parameters.
  132.  
  133.     procedure CLOSE (LINK : in out LINK_TYPE);  --| Disconnect VC.
  134.  
  135.     generic
  136.         type MESSAGE_TYPE is private;
  137.     procedure READ (LINK : in LINK_TYPE;
  138.             ITEM : out MESSAGE_TYPE);
  139.  
  140.     generic
  141.         type MESSAGE_TYPE is private;
  142.     procedure WRITE (LINK : in LINK_TYPE;
  143.              ITEM : in MESSAGE_TYPE);
  144.  
  145.     STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
  146.     MODE_ERROR   : exception renames IO_EXCEPTIONS.MODE_ERROR;
  147.     NAME_ERROR   : exception renames IO_EXCEPTIONS.NAME_ERROR;
  148.     USE_ERROR    : exception renames IO_EXCEPTIONS.USE_ERROR;
  149.     DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
  150.  
  151. private
  152.  
  153.     type LINK_STATUS is (OPEN, CLOSED);
  154.     type LINK_TYPE is
  155.       record
  156.         CHAN : STARLET.CHANNEL_TYPE;
  157.         MODE : LINK_MODE;
  158.         STAT : LINK_STATUS := CLOSED;
  159.       end record;
  160.  
  161. end NETWORK_MIXED_IO;
  162. --::::::::::
  163. --NETMIO.BOD
  164. --::::::::::
  165. with    SYSTEM,
  166.     STARLET,
  167.     TASKING_SERVICES,
  168.     CONDITION_HANDLING;
  169. use    SYSTEM,
  170.     STARLET;
  171. package body NETWORK_MIXED_IO is
  172.  
  173.     --|
  174.     --| CREATE creates a link to the remote task specified
  175.     --| in the string NAME.  The system service $ASSIGN is
  176.     --| used to do this.
  177.     --|
  178.  
  179.     procedure CREATE (
  180.         LINK : in out LINK_TYPE;
  181.         MODE : in LINK_MODE;
  182.         NAME : in STRING := "";
  183.         FORM : in STRING := "")
  184.     is
  185.         STAT : CONDITION_HANDLING.COND_VALUE_TYPE;
  186.     begin
  187.       if LINK.STAT = OPEN then raise STATUS_ERROR; end if;
  188.  
  189.       STARLET.ASSIGN (STAT, NAME, LINK.CHAN);
  190.  
  191.       if not CONDITION_HANDLING.SUCCESS(STAT) then 
  192.         case STAT is
  193.         when SS_CONNECFAIL | SS_DEVOFFLINE | SS_INSFMEM | SS_SHUT |
  194.                SS_NOLINKS | SS_PROTOCOL | SS_UNREACHABLE | SS_REJECT |
  195.                SS_REMRSRC | SS_THIRDPARTY | SS_LINKEXIT =>
  196.                 raise DEVICE_ERROR;
  197.         when SS_INVLOGIN | SS_IVDEVNAM | SS_NOSUCHNODE |
  198.                SS_NOSUCHUSER | SS_NOSUCHOBJ  =>
  199.                 raise NAME_ERROR;
  200.         when SS_NOPRIV |  SS_TOOMUCHDATA =>
  201.                 raise USE_ERROR;
  202.         when others => null;
  203.         end case;
  204.       end if;
  205.       LINK.STAT := OPEN;
  206.       LINK.MODE := MODE;
  207.     end CREATE;
  208.  
  209.     --|
  210.     --| OPEN completes a link to the remote task specified
  211.     --| in the string NAME.  The system service $ASSIGN is
  212.     --| used to do this.
  213.     --|
  214.  
  215.     procedure OPEN (
  216.         LINK : in out LINK_TYPE;
  217.         MODE : in LINK_MODE;
  218.         NAME : in STRING := "";
  219.         FORM : in STRING := "")
  220.     is
  221.         STAT : CONDITION_HANDLING.COND_VALUE_TYPE;
  222.     begin
  223.       if LINK.STAT = OPEN then raise STATUS_ERROR; end if;
  224.  
  225.       STARLET.ASSIGN (STAT, "SYS$NET", LINK.CHAN);
  226.  
  227.       if not CONDITION_HANDLING.SUCCESS(STAT) then 
  228.         case STAT is
  229.         when SS_CONNECFAIL | SS_DEVOFFLINE | SS_INSFMEM | SS_SHUT |
  230.                SS_NOLINKS | SS_PROTOCOL | SS_UNREACHABLE | SS_REJECT |
  231.                SS_REMRSRC | SS_THIRDPARTY | SS_LINKEXIT =>
  232.                 raise DEVICE_ERROR;
  233.         when SS_INVLOGIN | SS_IVDEVNAM | SS_NOSUCHNODE |
  234.                SS_NOSUCHUSER | SS_NOSUCHOBJ  =>
  235.                 raise NAME_ERROR;
  236.         when SS_NOPRIV |  SS_TOOMUCHDATA =>
  237.                 raise USE_ERROR;
  238.         when others => null;
  239.         end case;
  240.       end if;
  241.       LINK.STAT := OPEN;
  242.       LINK.MODE := MODE;
  243.     end OPEN;
  244.  
  245.     procedure CLOSE (LINK : in out LINK_TYPE) is
  246.         STAT : CONDITION_HANDLING.COND_VALUE_TYPE;
  247.     begin
  248.       if LINK.STAT = CLOSED then raise STATUS_ERROR; end if;
  249.       STARLET.DASSGN(STAT, LINK.CHAN);
  250.       if not CONDITION_HANDLING.SUCCESS(STAT) then
  251.         raise USE_ERROR; --| USE_ERROR for SS$_NOPRIV and SS$_IVCHAN
  252.       end if;
  253.       LINK.STAT := CLOSED;
  254.     end CLOSE;
  255.  
  256.  
  257.     procedure READ (LINK : in LINK_TYPE;
  258.             ITEM : out MESSAGE_TYPE)
  259.     is
  260.         --|
  261.         --| MSIZE is size (in bytes) of the ITEM.
  262.         --|
  263.         MSIZE : SYSTEM.UNSIGNED_LONGWORD
  264.         := ITEM'SIZE/SYSTEM.STORAGE_UNIT;
  265.         STAT : CONDITION_HANDLING.COND_VALUE_TYPE;
  266.         IOSB : STARLET.IOSB_TYPE;
  267.     begin
  268.         if LINK.STAT = CLOSED then raise STATUS_ERROR; end if;
  269.         if LINK.MODE = OUT_LINK then raise MODE_ERROR; end if;
  270.         TASKING_SERVICES.TASK_QIOW (
  271.         STATUS => STAT,
  272.         CHAN   => LINK.CHAN,
  273.         FUNC   => IO_READVBLK,
  274.         IOSB   => IOSB,
  275.         P1     => SYSTEM.TO_UNSIGNED_LONGWORD (ITEM'ADDRESS),
  276.         P2     => MSIZE);
  277.         if not CONDITION_HANDLING.SUCCESS(STAT) then
  278.           case STAT is
  279.         when SS_DATAOVERUN | SS_INSFMEM | SS_PATHLOST |
  280.              SS_LINKEXIT | SS_PROTOCOL | SS_LINKABORT |
  281.              SS_LINKDISCON | SS_THIRDPARTY =>
  282.             raise DEVICE_ERROR;
  283.         when SS_FILNOTACC =>
  284.             raise USE_ERROR;
  285.         when others => null;
  286.           end case;
  287.         end if;
  288.         if IOSB.STATUS /= SS_NORMAL then
  289.         raise DEVICE_ERROR;
  290.         end if;
  291.     end READ;
  292.  
  293.     procedure WRITE (LINK : in LINK_TYPE;
  294.              ITEM : in MESSAGE_TYPE)
  295.     is
  296.         --|
  297.         --| MSIZE is size (in bytes) of the ITEM.
  298.         --|
  299.         MSIZE : SYSTEM.UNSIGNED_LONGWORD
  300.         := ITEM'SIZE/SYSTEM.STORAGE_UNIT;
  301.         STAT : CONDITION_HANDLING.COND_VALUE_TYPE;
  302.         IOSB : STARLET.IOSB_TYPE;
  303.     begin
  304.         if LINK.STAT = CLOSED then raise STATUS_ERROR; end if;
  305.         if LINK.MODE = IN_LINK then raise MODE_ERROR; end if;
  306.         TASKING_SERVICES.TASK_QIOW (
  307.         STATUS => STAT,
  308.         CHAN   => LINK.CHAN,
  309.         FUNC   => IO_WRITEVBLK,
  310.         IOSB   => IOSB,
  311.         P1     => SYSTEM.TO_UNSIGNED_LONGWORD (ITEM'ADDRESS),
  312.         P2     => MSIZE);
  313.         if not CONDITION_HANDLING.SUCCESS(STAT) then
  314.           case STAT is
  315.         when SS_DATAOVERUN | SS_INSFMEM | SS_PATHLOST |
  316.              SS_LINKEXIT | SS_PROTOCOL | SS_LINKABORT |
  317.              SS_LINKDISCON | SS_THIRDPARTY =>
  318.             raise DEVICE_ERROR;
  319.         when SS_FILNOTACC =>
  320.             raise USE_ERROR;
  321.         when others => null;
  322.           end case;
  323.         end if;
  324.         if IOSB.STATUS /= SS_NORMAL then
  325.         raise DEVICE_ERROR;
  326.         end if;
  327.     end WRITE;
  328.  
  329. end NETWORK_MIXED_IO;
  330.