home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s038 / 11.ddi / SSCOPE.LIF / PMAIN.P38 < prev    next >
Encoding:
Text File  |  1992-07-02  |  5.5 KB  |  187 lines

  1. $title ('psamp')
  2. $optimize(0) word16
  3. $large( -CONST IN CODE- EXPORTS process_task,
  4. $                               count_task)
  5. $debug
  6.  
  7. pmain: do;
  8. $include(/rmx386/inc/common.lit)
  9. $include(/rmx386/inc/rmxplm.ext)
  10. $include(putils.ext)
  11.  
  12. declare UINT_8        literally 'byte';
  13. declare UINT_16        literally 'dword';
  14. declare UINT_32        literally 'word';
  15. declare NIL_SEL        literally 'selectorof(NIL)';
  16.  
  17. declare        COUNT_PRIORITY        literally '200';  /* Priority of count task  */
  18. declare        PROCESS_PRIORITY    literally '200';  /* Priority of process task*/
  19. declare        BUFF_LEN            literally '125';  /* Buffer len in MSG_STRUC */
  20. declare        DATA_MBOX            literally '20h';  /* Data mailbox code.      */
  21. declare        MAX_COUNT            literally '65535';/* UI16_MAX                */
  22.  
  23. declare MSG_STRUC literally 'structure (
  24.     count                byte,
  25.     fillchar            byte,
  26.     buffer(BUFF_LEN)     byte)';
  27.  
  28. declare    proc_msg    MSG_STRUC public;     /* Message processed by process task */
  29.  
  30. declare counter            word public;    /* Counter used by count task.       */
  31. declare    count_token     TOKEN public;     /* Token for count task.             */
  32. declare    process_token    TOKEN public;     /* Token for process task.           */
  33.  
  34.  
  35. declare module_data    UINT_32;          /* Used in the create task system call */
  36.                                          /* Identifies the data segment         */
  37.  
  38. process_task: procedure public reentrant;
  39.  
  40.     declare exception    WORD;          /* Status returned from system calls     */
  41.     declare    main_mbox    TOKEN;         /* Token for main task's mailbox         */
  42.     declare    proc_mbox    TOKEN;        /* Process task's mailbox token          */
  43.     declare    msg_length    UINT_32;     /* Actual length of received message     */
  44.     declare i            byte;
  45.     
  46.     /*
  47.      *  Lookup the process task mailbox token from the object
  48.      *  directory.
  49.      */
  50.     proc_mbox = rqlookupobject (NIL_SEL, @(11,'Process Box'), 0ffffh, @exception);
  51.     /*
  52.      *  Lookup the main task mailbox token from the object
  53.      *  directory.
  54.      */
  55.     main_mbox = rqlookupobject (NIL_SEL, @(8,'Main Box'), 0ffffh, @exception);
  56.  
  57.     /*
  58.      *  Loop forever responding to requests.
  59.      */    
  60.     do FOREVER;
  61.         /*
  62.          *  Receive the next request 
  63.          */
  64.         msg_length = rqreceivedata (main_mbox,
  65.                                       @proc_msg,
  66.                                       0ffffh,
  67.                                       @exception);
  68.  
  69.         /*
  70.          *  Take action on the received message (fill msg.buffer)
  71.          */
  72.         do i = 0 to (BUFF_LEN - 1);
  73.             msg.buffer(i) = msg.fillchar;
  74.         end;        
  75.  
  76.         /*
  77.          *  Send response
  78.          */
  79.         call rqsenddata (proc_mbox, 
  80.                            @proc_msg, 
  81.                             size (proc_msg), 
  82.                             @exception);    
  83.  
  84.         call delay (1000);        /*  Sleep for about 1 sec. so others can run.*/
  85.            end;
  86.     end process_task;
  87.  
  88. count_task: procedure public reentrant;
  89.  
  90.     declare    exception    WORD;     /* Status returned from system calls */
  91.  
  92.     counter = 0;
  93.  
  94.     do FOREVER;
  95.  
  96.         counter = counter + 1;
  97.         call delay(1000);                   /* Approx. 1 second. */
  98.         call plm_data;
  99.  
  100.         end;
  101.     end count_task;
  102.  
  103. /**********************************************************************/
  104. /*  Entry point for Soft-Scope demo program                           */
  105. /**********************************************************************/
  106.     declare actual            WORD;
  107.     declare co_conn            TOKEN;
  108.     declare    exception        WORD;      /* Status returned from system calls.    */
  109.     declare    main_mbox        TOKEN;     /* Token for main task's mailbox.        */
  110.     declare    proc_mbox        TOKEN;     /* Process task's mailbox token.         */
  111.     declare    msg_length        UINT_32;/* Actual length of received message.    */
  112.     declare    msg                MSG_STRUC;/* Message to be sent/received.        */
  113.     declare    msg_count        UINT_16;
  114.     declare    i                UINT_16;
  115.     
  116.     co_conn = rqsattachfile(@(4,':CO:'),@exception);
  117.     call rqsopen(co_conn,3,0,@exception);
  118.     actual = rqswritemove(co_conn,
  119.                           @('Soft-Scope III PLM Sample Program',0dh,0ah), 35,
  120.                           @exception);
  121.  
  122.     /*
  123.      *  Create the mailbox for main task
  124.      */
  125.     main_mbox = rqcreatemailbox (DATA_MBOX, @exception);
  126.     /*
  127.      *  Catalog the mailbox token in the object directory
  128.      */
  129.     call rqcatalogobject (NIL_SEL, main_mbox, @(8,'Main Box'), @exception);
  130.  
  131.     /*
  132.      *  Create the process mailbox 
  133.      */
  134.     proc_mbox = rqcreatemailbox (DATA_MBOX, @exception);
  135.     /*
  136.      *  Catalog the mailbox token in the object directory
  137.      */
  138.     call rqcatalogobject (NIL_SEL, proc_mbox, @(11,'Process Box'),@exception);
  139.  
  140.     /*
  141.      *  Create tasks...
  142.      */
  143.     count_token = rqcreatetask (
  144.                 COUNT_PRIORITY,                    /* priority.         */
  145.                 @count_task,                    /* start address.    */
  146.                 selectorof (@module_data),        /* data segment.     */
  147.                 NIL,                            /* stack pointer.    */
  148.                 4096,                            /* stack size.       */
  149.                 0,                                /* flags (no NPX).   */
  150.                 @exception);                    /* exception ptr.    */
  151.  
  152.     process_token = rqcreatetask (
  153.                 COUNT_PRIORITY,                    /* priority.         */
  154.                 @process_task,                    /* start address.    */
  155.                 selectorof (@module_data),        /* data segment.     */
  156.                 NIL,                            /* stack pointer.    */
  157.                 4096,                            /* stack size.       */
  158.                 0,                                /* flags (no NPX).   */
  159.                 @exception);                    /* exception ptr.    */
  160.  
  161.     msg_count = 0;
  162.     do FOREVER;
  163.         msg.fillchar = '*';
  164.         if (msg_count >= MAX_COUNT) then
  165.             msg_count = 0;
  166.         else
  167.             msg.count = msg_count + 1;
  168.         call setb (0, @msg.buffer, size (msg.buffer));
  169.         /*
  170.          *  Send data to process task to fill msg.buffer with fillchar
  171.          */
  172.         call rqsenddata (main_mbox, 
  173.                                @msg, 
  174.                               size (msg), 
  175.                               @exception);    
  176.  
  177.         /*
  178.          *  Receive data back from process task 
  179.          */
  180.         msg_length = rqreceivedata (proc_mbox,
  181.                                       @msg,
  182.                                       0ffffh,
  183.                                       @exception);
  184.            end;
  185.  
  186. end pmain;
  187.