home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / smxdemo / smxpp / smxspec.doc < prev    next >
Encoding:
Text File  |  1993-02-06  |  40.0 KB  |  1,418 lines

  1.  
  2.  
  3.  
  4.                                                                1-31-93
  5.  
  6.  
  7.  
  8.                          smx++ Design Specification
  9.  
  10.  
  11.      1.0 Introduction
  12.  
  13.      smx++ is a C++ class library which sits on top of smx. The smx++
  14.      API is designed to mirror smx yet be simpler and easier to use. 
  15.      In most cases, smx++ methods call their smx counterparts for
  16.      system services.  A chief objective of smx++ is to provide a
  17.      simpler API which meets most user requirements.  As a
  18.      consequence, several smx features and functions have been left
  19.      out or are accessible only in a restricted manner (see Limitation
  20.      section).  Where this becomes a problem, the user can make smx
  21.      calls directly.  (He also, of course, can create his own system
  22.      objects.)
  23.  
  24.      The smx++ classes contain pointers to the control blocks they
  25.      use.  This is to remove the burden of declaring control blocks
  26.      from the user. With smx++ the user will use the names of objects
  27.      instead of the names of control block handles (pointers).  Since
  28.      classes do not incorporate control blocks, the same control block
  29.      management scheme can be used for smx and smx++.  This has the
  30.      benefit that the user can both use smx++ objects and make smx
  31.      calls directly (but not for the same object).
  32.  
  33.      Because of the close relationship of smx++ to smx, method
  34.      descriptions herein are intentionally brief.  Refer to the smx
  35.      Reference Manual for detailed information.
  36.  
  37.      NOTE:  Certain enhancements to smx (e.g. fully dynamic objects)
  38.      are necessary to implement this specification.  It has been
  39.      decided to allow these to go forward independently of the current
  40.      version (v2.x) of smx.  The underlying version of smx will be
  41.      identified as V3.0.  Versions will be merged at a later time in
  42.      V3.x.
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.                                      1
  60.  
  61.  
  62.      2.0 Classes
  63.  
  64.      smx++ is made up of nine base classes. The following is a list of
  65.      the base classes:  Counter, Event, Exchange, SIOBus, Message,
  66.      Block Pool, Semaphore, Task, and Process.
  67.  
  68.  
  69.      2.1 Class hierarchy
  70.  
  71.      Base Class     1st Derived Class        2nd Derived Class
  72.  
  73.      Counter
  74.  
  75.      SIOBus         Bucket              block device drivers
  76.                     Pipe                character device drivers
  77.  
  78.      Exchange       Normal Exch
  79.                     Pass Exch
  80.                     Resource Exch
  81.  
  82.      Message
  83.  
  84.      Block Pool     FarHeap Pool
  85.                     NearHeap Pool
  86.  
  87.      Semaphore
  88.  
  89.      Task
  90.  
  91.      Event
  92.  
  93.      Process
  94.  
  95.  
  96.  
  97.      3.0 Counter Class
  98.  
  99.      The Counter class is used to count the number of times an event
  100.      happens. See smx manual on event queues.
  101.  
  102.  
  103.      3.1 Counter Data Members
  104.  
  105.      The Counter class has only one data member, the counter control
  106.      block pointer. It is a private data member and is only used by
  107.      the Counter methods.
  108.  
  109.                ECB_PTR   CounterCBP;
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.                                      2
  119.  
  120.  
  121.      3.2 Constructors 
  122.  
  123.      The Counter class has only one constructor and it takes no
  124.      parameters. It will call the create_eq smx function and store the
  125.      ECB_PTR as its private data member. 
  126.  
  127.                void      Counter();
  128.                void      Counter(ECB_PTR p);
  129.  
  130.  
  131.      3.3 Methods 
  132.  
  133.      The Counter class has five methods: Signal, Count, CountStop,
  134.      ClearQ, and QSize.  They perform the same function as their smx
  135.      counterparts.
  136.  
  137.      Method declarations:
  138.  
  139.                BOOLEAN   Signal();
  140.                BOOLEAN   Count( word count, word TimeOut=INF );
  141.                BOOLEAN   CountStop( word count, word TimeOut=INF );
  142.                BOOLEAN   ClearQ();
  143.                int       Qsize();
  144.  
  145.  
  146.      3.3.1 Signal
  147.  
  148.      Signal will signal the system that an event has just occurred. It
  149.      takes no parameters and calls its smx counterpart passing it the
  150.      handle in counterCBP.
  151.  
  152.  
  153.      3.3.2 Count
  154.  
  155.      Count suspends the current task for a specified number of
  156.      signals. Count takes two parameters: count and timeout. The count
  157.      parameter is the number of signals before the task will resume.
  158.      Timeout, which is usually not required because it has a default
  159.      value of infinite, will resume the task at the end of the timeout
  160.      period if it has not already been resumed.
  161.  
  162.  
  163.      3.3.3 CountStop
  164.  
  165.      CountStop works like Count except that the task is first stopped.
  166.  
  167.  
  168.      3.3.4 ClearQ
  169.  
  170.      This method works like its smx counterpart.
  171.  
  172.  
  173.      3.3.5 Qsize
  174.  
  175.      This method works like its smx counterpart.
  176.  
  177.                                      3
  178.  
  179.  
  180.  
  181.      3.4 Destructor 
  182.  
  183.      The Counter destructor deletes the event instance and sends any
  184.      system resource back.  This includes the ECB_PTR that was
  185.      obtained by the constructor and the event control block.
  186.  
  187.  
  188.  
  189.      4.0 SIOBus Class
  190.  
  191.      The SIOBus (Software Input/Output Bus) is an abstract base class. 
  192.      It is used for system communication with block and character
  193.      devices.  The intent of the SIOBus is to provide a uniform data
  194.      interface for all device drivers.  (A uniform control interface
  195.      will be added in the future.)  The SIOBus class has two methods
  196.      which are pure virtual methods.  This reduces the number of
  197.      methods that other classes must implement.  Two classes derived
  198.      from the SIOBus are generic drivers:
  199.  
  200.           (1)  bucket for block-oriented devices
  201.           (2)  byte pipe for character-oriented devices
  202.  
  203.      A word pipe may be implemented in the future.  Actual device
  204.      drivers will be derived by users from the generic device drivers
  205.      (bucket and pipe).  Note that a device driver is uni-directional. 
  206.      Hence, two are required for a bi-directional device.
  207.  
  208.  
  209.      4.1 Data Members 
  210.  
  211.                VOID_PTR  SIOXCBP;
  212.  
  213.  
  214.      4.2 Constructors 
  215.  
  216.      The SIOBus class is an abstract class and does not use a
  217.      constructor.
  218.  
  219.  
  220.      4.3 Methods 
  221.  
  222.      The SIOBus class has two methods, GetChar and PutChar. They are
  223.      pure virtual methods which must be defined in the derived
  224.      classes.
  225.  
  226.      Method Declarations:
  227.  
  228.                int       GetChar()=0;
  229.                BOOLEAN   PutChar( char achar )=0;
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.                                      4
  237.  
  238.  
  239.      4.3.1 GetChar
  240.  
  241.      GetChar is a pure virtual method which is used to get a character
  242.      from an SIOBus object.  The derived classes will have their own
  243.      interpretations of it.
  244.  
  245.  
  246.      4.3.2 PutChar
  247.  
  248.      PutChar is a pure virtual method which is used to put a character
  249.      on a SIOBus.  The derived classes will have their own
  250.      interpretations of it.  PutChar accepts the character to be put
  251.      as its parameters.
  252.  
  253.  
  254.      4.4 Destructor 
  255.  
  256.      Since the SIOBus is an abstract class, it does not require a
  257.      destructor.
  258.  
  259.  
  260.      4.5 Bucket Class
  261.  
  262.      The bucket class is used in the same manner as an smx bucket.  It
  263.      is derived from the SIOBus class. In smx++ it is intended that
  264.      the user take the bucket class one step further. The user should
  265.      derive his particular class from the bucket class to communicate
  266.      with his custom hardware. He will do this by creating his own
  267.      constructor that will initialize his hardware and a destructor
  268.      that will shutdown his hardware. Also, the two methods PutChar
  269.      and Getchar should be overloaded to interface with his hardware.
  270.  
  271.  
  272.      4.5.1 Data Members
  273.  
  274.                None
  275.  
  276.  
  277.      4.5.2 Constructors 
  278.  
  279.      The bucket class has two constructors.  The first takes no
  280.      parameters; it calls the smx function create_cx(BUCKET).  The
  281.      second constructor takes a size parameter.  It creates a bucket
  282.      and a message of the specified size, from the near heap and sends
  283.      the message to the bucket.
  284.  
  285.                void      Bucket();
  286.                void      Bucket( word size);
  287.                void      Bucket( CXB_PTR p);
  288.  
  289.  
  290.      4.5.3 Methods
  291.  
  292.      The bucket class defines the two virtual methods GetChar and
  293.      PutChar which it inherits from the SIOBus class.  Theses methods
  294.  
  295.                                      5
  296.  
  297.  
  298.      are protected so they can be used only in device drivers.
  299.  
  300.      Method Definitions:
  301.                int       GetChar();
  302.                BOOLEAN   PutChar( char achar );
  303.  
  304.  
  305.      4.5.3.1 GetChar
  306.  
  307.      GetChar is used to get a character from a bucket.  smx implements
  308.      this as a C macro.  The GetChar method will be implemented as an
  309.      inline method.  It takes no parameters and returns an int which
  310.      is the next character.  This method is used only within device
  311.      drivers.  It is not used for system communication via the SIOBus
  312.      (see the Message class for this).
  313.  
  314.  
  315.      4.5.3.2 PutChar
  316.  
  317.      PutChar is used to put a character into a bucket.  It is
  318.      implemented in smx as a C macro and will be an inline method in
  319.      smx++.  It takes a character parameter and returns a BOOLEAN. 
  320.      This method is used only within device drivers and is not used
  321.      for system communication.
  322.  
  323.  
  324.      4.5.4 Destructor 
  325.  
  326.      The bucket class destructor releases BucketCBP and the control
  327.      block for the bucket.  If the Bucket is holding a message, a pool
  328.      message is returned to its pool and a non-pool message is
  329.      deleted.
  330.  
  331.  
  332.      4.6 Pipe Class
  333.  
  334.      The pipe class is used in the same manner as an smx pipe.  It is
  335.      derived from the SIOBus class. In smx++ the pipe class is
  336.      intended to be used by the user in the same manner that the
  337.      bucket class was. The user should derive his own class reflecting
  338.      the personality of his hardware. Again all functions will be
  339.      overloaded and the constructor and destructor will do the
  340.      initializing and closing of the device.
  341.  
  342.  
  343.      4.6.1 Data Members
  344.  
  345.                None
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.                                      6
  355.  
  356.  
  357.      4.6.2 Constructors 
  358.  
  359.      The constructor creates a pipe and a message of the specified
  360.      size from the near heap.  It attaches the message to the pipe for
  361.      use as its buffer.
  362.  
  363.                void Pipe( word size );
  364.                void Pipe( CXP_PTR p );
  365.  
  366.  
  367.      4.6.3 Methods 
  368.  
  369.      In addition to GetChar, and PutChar, which it inherits from the
  370.      base class, the pipe class defines four more methods. GetChar and
  371.      PutChar are protected methods.  The others are public.
  372.  
  373.      Method Declaration:
  374.  
  375.                int       GetChar();
  376.                BOOLEAN   PutChar( char achar );
  377.  
  378.                int       PGetChar( word TimeOut=INF );
  379.                int       PGetCharStop( word TimeOut=INF );
  380.  
  381.                BOOLEAN   PPutChar( char achar, word TimeOut=INF );
  382.                BOOLEAN   PPutCharStop( char achar, word TimeOut=INF );
  383.  
  384.  
  385.      4.6.3.1 GetChar
  386.  
  387.      smx++ implements this in the same way smx implements PGET_CHAR.
  388.      This is the fast version for smx. It will be an inline method in
  389.      smx++.  Like its smx counterpart it takes no parameters and
  390.      returns an int.  This is a protected method for use by device
  391.      drivers, only.
  392.  
  393.  
  394.      4.6.3.2 PutChar
  395.  
  396.      smx++ implements this in the same way smx implements PPUT_CHAR.
  397.      This is the fast version for smx. It will be an inline method in
  398.      smx++.  This method accepts a character to be put into the pipe.
  399.      It will return a BOOLEAN to indicate if the operation was
  400.      successful.  This is a protected method for use by device
  401.      drivers, only.  The return value works like the bucket GET_CHAR
  402.      in the smx Reference Manual. 
  403.  
  404.  
  405.      4.6.3.3  PGetChar
  406.  
  407.      This method calls the smx function, pget_char. It takes a timeout
  408.      parameter which has a default value of infinite. It returns an
  409.      int, which contains the character.
  410.  
  411.  
  412.  
  413.                                      7
  414.  
  415.  
  416.      4.6.3.4  PGetCharStop
  417.  
  418.      GetCharStop works just like the PGetChar method. The only
  419.      difference is that it stops the task first.
  420.  
  421.  
  422.      4.6.3.5  PPutChar
  423.  
  424.      This method calls the smx function, pput_char. It accepts
  425.      character and timeout parameters.  The timeout parameter has a
  426.      default value of infinite.
  427.  
  428.  
  429.      4.6.3.6  PPutCharStop
  430.  
  431.      The putcharstop method works just like the putchar method except
  432.      that it stops the task first.
  433.  
  434.  
  435.      4.6.4 Destructor 
  436.  
  437.      The pipe class destructor releases PipeCBP and the pipe control
  438.      block.  It also deletes the pipe's buffer.  (Pipe buffers are
  439.      always non-pool near messages).  A task waiting at the pipe is
  440.      resumed.
  441.  
  442.  
  443.  
  444.      5.0 Exchange Class
  445.  
  446.      The exchange class is the base class for the normal, pass and
  447.      resource exchange classes. It defines the basic methods for them. 
  448.      There should not be an instance of the exchange class since it is
  449.      intended to be just a base class. The methods are defined here to
  450.      centralize code location and reduce coding effort.
  451.  
  452.  
  453.      5.1 Data Members
  454.  
  455.      The exchange has one data member which is the exchange control
  456.      block pointer. It is a private member and is only used by member
  457.      functions.
  458.  
  459.                XCB_PTR   XchgCBP;
  460.  
  461.  
  462.      5.2 Constructors 
  463.  
  464.      Since the exchange is a base class and not intended to have an
  465.      instances there is no constructor.
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.                                      8
  473.  
  474.  
  475.      5.3 Methods 
  476.  
  477.      The exchange class has two methods: ClearQ and QSize.
  478.  
  479.      Method Declaration
  480.  
  481.                BOOLEAN   ClearQ();
  482.                int       QSize();
  483.  
  484.  
  485.      5.3.1 ClearQ
  486.  
  487.      This method works like its smx counterpart.
  488.  
  489.  
  490.      5.3.2 QSize
  491.  
  492.      This method also works like its smx counterpart.
  493.  
  494.  
  495.      5.4 Destructor 
  496.  
  497.      The exchange class does not define a destructor. Since it is a
  498.      base class and it is intended that no instances of it should
  499.      exist.                            
  500.  
  501.  
  502.      5.5  Normal Exchange Class
  503.  
  504.      The normal exchange class is derived from the exchange class. It
  505.      serves the same function as its smx counterpart. 
  506.  
  507.  
  508.      5.5.1 Data Members
  509.  
  510.      There are no data members. They are all defined in the base
  511.      class.
  512.  
  513.  
  514.      5.5.2 Constructors 
  515.  
  516.      There are two constructors for the normal exchange class. The
  517.      normal constructor takes two variable length parameters: the task
  518.      priority limits and the message priority limits. The larger
  519.      number of limits dictates the number of queue control blocks
  520.      required.  The other constructor is the copy constructor. It is
  521.      used to create a twin exchange. The new exchange will have the
  522.      same limits as the old exchange.
  523.  
  524.                void NrmXchg( word tplimN, ... );
  525.                void NrmXchg( XCB_PTR p );
  526.  
  527.  
  528.  
  529.  
  530.  
  531.                                      9
  532.  
  533.  
  534.      5.5.3 Methods 
  535.  
  536.      No additional methods are defined for this class.
  537.  
  538.  
  539.      5.5.4 Destructor
  540.  
  541.      The destructor releases the XchgCBP and the queue control blocks.
  542.  
  543.  
  544.      5.6 Pass Exchange
  545.  
  546.      The pass exchange is built like the normal exchange. It also
  547.      functions like its smx counterpart.
  548.  
  549.  
  550.      5.7 Resource Exchange 
  551.  
  552.      The resource exchange is built like the normal exchange. 
  553.      Resource exchanges function as the centers of message pools. 
  554.      When a message is sent to a resource exchange, it is stamped with
  555.      the resource exchange i.d. and thereafter is a "pool" message. 
  556.      The advantage of pool messages is that they are fast to obtain
  557.      and release.  ClearQ will resume waiting tasks, but it cannot
  558.      remove messages.
  559.  
  560.  
  561.  
  562.      6.0 Message Class
  563.  
  564.      The message class is used to hold a message that is in use by the
  565.      application code. It has the methods to send, receive, create,
  566.      and delete messages. It should be noted that an instance of the
  567.      class can exist without holding a message.  A message consists of
  568.      a mcb and a data block.  The mcb contains a pointer to the data
  569.      block. 
  570.  
  571.      The message class is a friend class to the exchange and SIOBus
  572.      classes.  It needs this friendship to have access to the control
  573.      block pointers of each class.
  574.  
  575.      The message class is a general class that can hold any type of
  576.      message. It is designed this way because there is no way to know
  577.      what type of message you will be holding. This is due to the fact
  578.      that a resource exchange can contain messages from both heaps and
  579.      a pool at the same time.
  580.  
  581.  
  582.      6.1 Data Members
  583.  
  584.      The message class has one private data members, the message
  585.      control block pointer, which is used by smx. Message objects are
  586.      said to be either "holding" or "not holding" a message.  This
  587.      complexity arises from the fact that messages transcend the
  588.      scopes of the code threads (i.e. "tasks") which use them. 
  589.  
  590.                                      10
  591.  
  592.  
  593.      Messages are sent from one thread to another.
  594.  
  595.                MCB_PTR        MsgCBP;
  596.                Boolean        Holding;
  597.  
  598.  
  599.      6.2 Constructors 
  600.  
  601.      The message class has three constructors. The first, creates only
  602.      an instance.  The second creates an instance and a message. (i.e.
  603.      it creates an mcb and gets a data block from the smx near or far
  604.      heap). The third constructor is the copy constructor.  It will
  605.      create a new instance and, if the old one is holding, create a
  606.      new message and copy over data.
  607.  
  608.                void      Message();
  609.                void      Message( word Blksize, HEAPTYPE near Heap );
  610.                void      Message( MCB_PTR p );
  611.  
  612.      The first constructor creates a non-holding message object which
  613.      is ready to receive from an exchange.  The second constructor can
  614.      be used to initially create messages.  If one of these messages
  615.      is sent to a resource exchange, it becomes a member of the
  616.      message pool defined by that resource exchange.
  617.  
  618.  
  619.      6.3 Methods
  620.  
  621.      Method Descriptions:
  622.  
  623.                BOOLEAN   BumpMsg( word priority );
  624.  
  625.                BOOLEAN   Send( const Xchg& xchg );
  626.  
  627.                BOOLEAN   Receive( const Xchg& xchg, word TimeOut=INF);
  628.  
  629.                BOOLEAN   ReceiveStop( const Xchg& xchg, word
  630.                                                         TimeOut=INF );
  631.  
  632.                void far* Contents();
  633.  
  634.                BOOLEAN   Put( const SIOBus& xchg );
  635.  
  636.                BOOLEAN   Get( const SIOBus& xchg );
  637.  
  638.                BOOLEAN   Holding();
  639.  
  640.                BOOLEAN   Create( word size, BOOLEAN ht=NEAR );
  641.  
  642.                BOOLEAN   Create( word size, const ResExch& rxchg
  643.                                        HeapType ht=NEAR, word num=1 );
  644.  
  645.                BOOLEAN   Delete();
  646.  
  647.  
  648.  
  649.                                      11
  650.  
  651.  
  652.      6.3.1  Send
  653.  
  654.      The send method is used to send the message to an exchange and
  655.      takes a message exchange its parameter.  If the message object is
  656.      not holding, the send method aborts and returns a NOT_HOLDING
  657.      error.
  658.  
  659.      The second type of send takes an additional parameter which is
  660.      the priority of the message.  (This send replaces the smx
  661.      function bump_msg).  If the message is already at the specified
  662.      destination, it is merely requeued.
  663.  
  664.  
  665.      6.3.2  Receive
  666.  
  667.      The receive method is used to get a message from an exchange and
  668.      takes an exchange reference and a timeout as parameters.  The
  669.      timeout parameter has a default value of infinite.  If the
  670.      message object is already holding a message, receive is aborted
  671.      and a HOLDING error is reported.
  672.  
  673.  
  674.      6.3.3  Receive Stop
  675.  
  676.      Receive stop works just like the receive method except that the
  677.      task is first stopped.
  678.  
  679.  
  680.      6.3.4 Contents
  681.  
  682.      This method is used to get the contents of the message. It
  683.      returns a void far pointer to the data blocks. Its smx
  684.      counterpart is msg->mv.  If the message instance is not holding,
  685.      the method will return NULL.  The contents method assume the
  686.      worst case return type of far pointer. It is necessary to do this
  687.      since it is impossible to predict what type of message we will be
  688.      holding at any given time.
  689.  
  690.  
  691.      6.3.5 Put
  692.  
  693.      Put is used to send a message to a SIOBus. It Takes a SIOBus
  694.      reference as a parameter. If you try to use a message that is not
  695.      from the near heap as a SIOBus buffer you will receive a
  696.      WRONG_MCB_TYPE error and return a false condition. This is due to
  697.      the fact that SIOBus's can only accept a near messages as a
  698.      buffer. See the smx manual for further details.
  699.  
  700.  
  701.      6.3.6 Get
  702.  
  703.      Get is used to get a message from a SIOBus. It Takes a SIOBus
  704.      reference as a parameter. See the smx manual for further details.
  705.  
  706.  
  707.  
  708.                                      12
  709.  
  710.  
  711.      6.3.7 Holding
  712.  
  713.      This method is used to indicate if a class instance is holding a
  714.      message. It tests the MCB_PTR for NULL and if it is NULL, Holding
  715.      will return a false condition indicating that the class instance
  716.      is not holding a message. A true response indicates the class
  717.      instance is holding a message.
  718.  
  719.  
  720.      6.3.8 Create
  721.  
  722.      The create message method is used to create a message from the
  723.      far heap. It comes in two types. The first one takes a size and
  724.      the heaptype as parameters. It just creates a message and
  725.      prepares it for use. The second create message method, in
  726.      addition to the above parameters, takes a resource exchange
  727.      reference and number of blocks as parameters. It is used to
  728.      create multiple messages and send them to a resource exchange. It
  729.      will send the previous message to the exchange before the next
  730.      one is created. With both versions of the create message method,
  731.      if the instance is holding a message when the method is used a
  732.      HOLDING error will be reported.
  733.  
  734.  
  735.      6.3.9 Delete
  736.  
  737.      The deleted message method will delete a message that is being
  738.      held by a message instance. A heap message is freed and a pool
  739.      message is sent back to its resource exchange. If the message
  740.      instance is not holding this method has no affect.
  741.  
  742.  
  743.      6.4 Destructor 
  744.  
  745.      The message class destructor releases the MsgCBP. If the message
  746.      object is holding a message, the message is deleted (i.e. its mcb
  747.      is released and its data block is freed to the appropriate heap.)
  748.  
  749.  
  750.  
  751.      7.0 Block Pool Class
  752.  
  753.      The memory pool class is used to control access to block memory
  754.      pools. It is the base class for the near heap and far heap pools.
  755.      There should not be an instance of the memory pool class. 
  756.  
  757.  
  758.      7.1 Data Members
  759.  
  760.      The only  data member is the pointer to the pool control block. 
  761.      It is protected.
  762.  
  763.                PCB_PTR   PoolCBP;
  764.  
  765.  
  766.  
  767.                                      13
  768.  
  769.  
  770.      7.2 Constructors 
  771.  
  772.      The memory pool class does not have a constructor since it is a
  773.      base class and there should not be an instance of it.
  774.  
  775.  
  776.      7.3 Methods 
  777.  
  778.      The memory pool class defines two methods.
  779.  
  780.      Method Descriptions:
  781.  
  782.                BCB_PTR   Get();
  783.                BOOLEAN   Release( BCB_PTR bp );
  784.  
  785.  
  786.      7.3.1 Get
  787.  
  788.      The Get method works just like its smx counterpart. It takes no
  789.      parameters and returns a block control block pointer.
  790.  
  791.  
  792.      7.3.2 Release
  793.  
  794.      The Release method works just like its smx counterpart. It
  795.      accepts a block control block as a parameter and returns a
  796.      BOOLEAN for testing.
  797.  
  798.  
  799.      7.4 Destructor 
  800.  
  801.      Since the memory pool is a base class it does not have a
  802.      destructor and there will not be an instance of it.
  803.      7.5 Far Heap Memory Pool Class
  804.  
  805.      The far heap memory pool is derived from the memory pool. It has
  806.      no additional methods. As its name implies it get its memory from
  807.      the far heap.
  808.  
  809.  
  810.      7.5.1 Constructor
  811.  
  812.      The far heap memory pool has only one constructor. It accepts the
  813.      number of blocks and block size as parameters. It will create a
  814.      memory pool from the far heap.
  815.  
  816.                void      FarHeapPool( word NumBlks, word BlkSize );
  817.                void      FarHeapPool( PCB_PTR p );
  818.  
  819.  
  820.      7.5.2 Destructor
  821.  
  822.      The destructor releases all the memory used by the pool back to
  823.      the system. If any block is in use (i.e. has an owner) operation
  824.      is aborted and a OBJECT_IN_USE error is reported.
  825.  
  826.                                      14
  827.  
  828.  
  829.  
  830.      7.6 Near Heap Memory Pool Class
  831.  
  832.      The near heap memory pool works just like the far heap memory
  833.      pool except it gets its memory from the near heap.
  834.  
  835.  
  836.  
  837.      8.0 Semaphore Class
  838.  
  839.      The semaphore class is used to create a semaphore with a
  840.      specified threshold and one or more task priority levels. This
  841.      class is the base class with no other class derived from it. 
  842.  
  843.  
  844.      8.1 Data Members
  845.  
  846.      The only data member for the semaphore class is the pointer to
  847.      the semaphore control block. It is a private data member.
  848.  
  849.                SCB_PTR   SemCBP;
  850.  
  851.  
  852.      8.2 Constructors 
  853.  
  854.      The semaphore class has two constructors: a regular constructor
  855.      and a copy constructor.  The regular constructor takes the same
  856.      parameters as the create_sem() smx function. It is used to create
  857.      a semaphore from scratch. One queue control block is required per
  858.      priority level.  The copy constructor will create a new semaphore
  859.      with the same parameters as the original.
  860.  
  861.                void Sem( word thres, word tplimN, ... );
  862.                void Sem( SCB_PTR p );
  863.  
  864.  
  865.      8.3 Methods 
  866.  
  867.      The semaphore class has five methods.  These methods are similar
  868.      to their smx counterparts.
  869.  
  870.                BOOLEAN   Signal();
  871.                BOOLEAN   Test( word TimeOut=INF );
  872.                BOOLEAN   TestStop( word TimeOut=INF );
  873.                BOOLEAN   ClearQ();
  874.                int       QSize();
  875.  
  876.  
  877.      8.3.1 Signal
  878.  
  879.      The signal method is used to increment a semaphore's internal
  880.      counter. It takes no parameters and return a BOOLEAN. 
  881.  
  882.  
  883.  
  884.  
  885.                                      15
  886.  
  887.  
  888.      8.3.2 Test
  889.  
  890.      The test method is used to test if a semaphore's internal counter
  891.      has reached or exceeded its threshold.  When test passes, the
  892.      internal counter is reduced by the threshold.  Test accepts a
  893.      timeout parameter which has a default value of infinite.
  894.  
  895.  
  896.      8.3.2 TestStop
  897.  
  898.      TestStop works like Test except TestStop first stops the test.
  899.  
  900.  
  901.      8.3.3 ClearQ
  902.  
  903.      This method works like its smx counter part.
  904.  
  905.  
  906.      8.3.4 QSize
  907.  
  908.      This method works like its smx counter part.
  909.  
  910.  
  911.      8.4 Destructor 
  912.  
  913.      The semaphore class destructor releases semCBP and the queue
  914.      control blocks.  Tasks waiting on this semaphore are resumed with
  915.      FALSE return values.
  916.  
  917.  
  918.      9.0 Task Class
  919.  
  920.      The task class defines the API for working with tasks. The
  921.      methods in this class are similar to their smx counterparts.
  922.  
  923.  
  924.      9.1 Data Members
  925.  
  926.      The only data member for the task class is the task control block
  927.      pointer. It is a private member.
  928.  
  929.                TCB_PTR   TaskCBP;
  930.  
  931.  
  932.      9.2 Constructors
  933.  
  934.      The task class has two constructors: a regular constructor and a
  935.      copy constructor.  The regular constructor accepts the same
  936.      parameters as the create_task smx function. It is used to create
  937.      a task from scratch. The copy constructor creates a new task with
  938.      the same parameters as the original.
  939.  
  940.                void Task( const cdecl void(*TaskMain), byte priority,
  941.                          word StackSize=0 );
  942.                void Task( TCB_PTR p );
  943.  
  944.                                      16
  945.  
  946.  
  947.  
  948.      9.3 Methods
  949.  
  950.      The task class has 16 methods which are closely related to their
  951.      smx counterparts.
  952.  
  953.      Method Definitions:
  954.                BOOLEAN   Start();
  955.                BOOLEAN   Start( word parm )
  956.                BOOLEAN   Start( byte Priority )
  957.                BOOLEAN   Start( const void (*NewTaskMain),
  958.                                                       byte Priority );
  959.                BOOLEAN   Stop( word timeout=INF );
  960.                void      Lock();
  961.                BOOLEAN   Resume();
  962.                void      StackCheckOn();
  963.                void      StackCheckOff();            
  964.                BOOLEAN   Suspend( word timeout=INF );
  965.                void      Unlock();
  966.                BOOLEAN   IsLocked();
  967.  
  968.      NOTE:  Hook, Lock, StackCheckOn, StackCheckOff, Unlock, Sleep,
  969.      and SleepStop may be used only for the current task.  Attempting
  970.      to use them for another task results in an OP_NOT_ALLOWED error.
  971.  
  972.  
  973.      9.3.1 Hook
  974.  
  975.      The hook method works just like its smx counterpart.
  976.  
  977.  
  978.      9.3.2 Start
  979.  
  980.      There are three start methods.  They all start a task.  The first
  981.      one takes no parameters; it just starts the task. The second one
  982.      passes a parameter to the task, changes the task's priority, then
  983.      starts it.  The third does all the above, plus giving the task a
  984.      new main function pointer.  This version is similar to the
  985.      NEWSTART macro in smx.
  986.  
  987.  
  988.      9.3.3 Stop
  989.  
  990.      The stop method works just like its smx counterpart. 
  991.  
  992.  
  993.      9.3.5 Lock
  994.  
  995.      The lock method works just like its smx counterpart.
  996.  
  997.  
  998.      9.3.6 Resume
  999.  
  1000.      The resume method works just like its smx counterpart. 
  1001.  
  1002.  
  1003.                                      17
  1004.  
  1005.  
  1006.      9.3.7 StackCheckOn/StackCheckOff
  1007.  
  1008.      These two methods work like the smx function StackCheck with the
  1009.      parameters ON and OFF, respectively.
  1010.  
  1011.  
  1012.      9.3.8 Suspend
  1013.  
  1014.      The suspend method works just like its smx counterpart. 
  1015.  
  1016.  
  1017.      9.3.9 Unlock
  1018.  
  1019.      The unlock method works just like its smx counterpart. 
  1020.  
  1021.  
  1022.      9.3.10 Sleep
  1023.  
  1024.      The sleep method works just like its smx counterpart. 
  1025.  
  1026.  
  1027.      9.3.11 SleepStop
  1028.  
  1029.      The sleepstop method works just like its smx counterpart.
  1030.  
  1031.  
  1032.      9.3.12 IsLocked
  1033.  
  1034.      Works just like in smx.
  1035.  
  1036.  
  1037.      9.4 Destructor 
  1038.  
  1039.      The task class destructor releases the TaskCBP and the task
  1040.      control block back to the system.
  1041.  
  1042.  
  1043.  
  1044.      10.0 Event Class
  1045.  
  1046.      The event class functions like the smx event table object. It is
  1047.      used to allow task to wait on a specific event.
  1048.  
  1049.  
  1050.      10.1 Data Members
  1051.  
  1052.      The event class has only one data member which is the pointer to
  1053.      the event table. It is a private data member.
  1054.  
  1055.                ECT_PTR   EventTP;
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.                                      18
  1063.  
  1064.  
  1065.      10.2 Constructor
  1066.  
  1067.      The event class has only one constructor. It will create the
  1068.      event table with the specified number of slots for tasks. It uses
  1069.      the create_et function.
  1070.  
  1071.                Event( word num ); 
  1072.                Event( ECT_PTR p ); 
  1073.  
  1074.  
  1075.      10.3 Methods
  1076.  
  1077.      The event class has four member function. They perform the same
  1078.      functions as their smx counterparts.
  1079.  
  1080.  
  1081.                void ResetFlags( int mask );
  1082.                void SetFlags( int mask );
  1083.                int  TestFlags( int mask, word timeout=INF );
  1084.                int  TestFlagStop( int mask, word timeout=INF );
  1085.  
  1086.  
  1087.      10.3.1 ResetFlags
  1088.  
  1089.      This method functions like its smx counterpart.
  1090.  
  1091.  
  1092.      10.3.2 SetFlags
  1093.  
  1094.      This method functions like its smx counterpart.
  1095.  
  1096.  
  1097.      10.3.3 TestFlags
  1098.  
  1099.      This method functions like its smx counterpart.
  1100.  
  1101.  
  1102.      10.3.3 TestFlagsStop
  1103.  
  1104.      This method functions like its smx counterpart.
  1105.  
  1106.  
  1107.      10.4 Destructor
  1108.  
  1109.      The event class destructor will send the smx event table control
  1110.      block back to the system.
  1111.  
  1112.  
  1113.  
  1114.      11.0 Process Class
  1115.  
  1116.      This class is totally defined by the user. It is made up of all
  1117.      the previously defined objects. When the user defines a block of
  1118.      work i.e a process, it will take many smx++ object to preform
  1119.      that function. Since the process class will be designed to
  1120.  
  1121.                                      19
  1122.  
  1123.  
  1124.      perform a specific job there is no one way to build just one
  1125.      type.
  1126.  
  1127.      The process class provides the functions for creating and
  1128.      destroying all smx objects associated with it. This prevents
  1129.      messages and other objects from accumulating in tasks as they are
  1130.      created and deleted. The following is the process base class. It
  1131.      provides a start and shutdown method. Both the methods are pure
  1132.      virtual and are left up to the derived classes to define. 
  1133.  
  1134.      class Process
  1135.      {
  1136.      public:
  1137.           BOOLEAN   Start()=0;     // Start the process
  1138.           BOOLEAN   ShutDown()=0;  //Stop the process, does not delete
  1139.      };
  1140.  
  1141.  
  1142.      11.1 Communication Process
  1143.  
  1144.      The communication process is the communication subsystem taken
  1145.      from the smx User Guide page 5. This example shows how a
  1146.      particular system can be subdivided into subsystems by the use of
  1147.      a process.
  1148.  
  1149.      class Communication : Public Process
  1150.      {
  1151.           // smx++ objects
  1152.           NrmXchg   TxXchg;   // Transmit message
  1153.           NrmXchg   RcvXchg;  // Receive Message
  1154.  
  1155.           Bucket    TxBkt;    // Transmit bucket
  1156.           Bucket    RcvBkt;   // Receive Bucket
  1157.  
  1158.           Task      SendTsk;  // Send Task
  1159.           Task      RcvTsk;   // Receive Task
  1160.  
  1161.           // Constructor
  1162.           Communication( int port, int buf,
  1163.                        const cdecl void (*TxMain), byte Txpri,
  1164.                        const cdecl void (*RcvMain), byte Rcvpri ):
  1165.                       TxXchg(0,0). RcvXchg(0,0),
  1166.                       TxBkt(buf), RcvBkt(buf),
  1167.                       SendTsk(TxMain, Txpri),
  1168.                       RcvTsk( RcvMain, RcvTsk ) ;
  1169.  
  1170.           // Methods   Note: We inherit the start and shutdown method
  1171.           BOOLEAN   Send( const Message& msg );
  1172.           BOOLEAN   Receive( const Message& msg );
  1173.  
  1174.      };
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.                                      20
  1181.  
  1182.  
  1183.      11.1.1 Communication smx++ Objects
  1184.  
  1185.      The communication process is made up of six smx++ objects. They
  1186.      consist of the following types: Normal Exchange, Bucket and Task.
  1187.      Two of each object is needed for a full duplex system.
  1188.  
  1189.  
  1190.      11.1.2 Normal Exchange
  1191.  
  1192.      The normal exchanges are used as the message queue. They act as
  1193.      the message buffers for the process
  1194.  
  1195.  
  1196.      11.1.3 Buckets
  1197.  
  1198.      The buckets are used to interface a serial device with the
  1199.      message structure. The user will want to derive his own version
  1200.      of bucket to connect to his particular hardware.
  1201.  
  1202.  
  1203.      11.1.4 Tasks
  1204.  
  1205.      The two task perform the send and receive work for the process.
  1206.      You would want to put any headers or trailers on the messages in
  1207.      these task.
  1208.  
  1209.  
  1210.      11.2 Constructor
  1211.  
  1212.      There is only one constructor for the communication process. It
  1213.      takes all the parameters that are necessary to create all the
  1214.      objects. The user will have to determine what parameters are
  1215.      necessary for the objects. This will reduce the number of
  1216.      parameters.
  1217.  
  1218.  
  1219.      11.3  Methods
  1220.  
  1221.      The communication process has for methods. Two which it inherited
  1222.      from the base process class and two that it defines itself. The
  1223.      following is a list of the methods:
  1224.  
  1225.                BOOLEAN   Start();
  1226.                BOOLEAN   ShutDown();
  1227.                BOOLEAN   Send( const Message& msg );
  1228.                BOOLEAN   Receive( const Message& msg );
  1229.  
  1230.  
  1231.      11.3.1 Start
  1232.  
  1233.      This method is used to start the process. Since they process can
  1234.      be a very complicated class you will want to specify a start up
  1235.      sequence. Start takes no parameters and returns a BOOLEAN
  1236.      indicating that the process was started.
  1237.  
  1238.  
  1239.                                      21
  1240.  
  1241.  
  1242.      11.3.2 ShutDown
  1243.  
  1244.      This method works just the opposite of the  of the start method.
  1245.      It is used to shutdown the process in a orderly fashion. It takes
  1246.      no parameters and return a BOOLEAN indicating that the process
  1247.      was shut down correctly.
  1248.  
  1249.  
  1250.      11.3.3 Send
  1251.  
  1252.      This method is used to send a message to the process. Send will
  1253.      enqueue the message in the transmit exchange. It take a message
  1254.      reference for a parameter.
  1255.  
  1256.  
  1257.      11.3.4 Receive
  1258.  
  1259.      This method is used to receive a message to the process. Receive
  1260.      will remove the next message in the receive exchange. It take a
  1261.      message reference for a parameter.
  1262.  
  1263.  
  1264.  
  1265.      12.0 Memory Management
  1266.  
  1267.      With C++, memory management is done through new and delete. New
  1268.      and delete will use the Borland default heap for efficiency. 
  1269.      Users can overload new and delete for class specific functions. 
  1270.      smx++ supports all the memory management schemes that smx
  1271.      supports, except dynamic allocated regions.      
  1272.  
  1273.  
  1274.      12.1 Memory management schemes
  1275.  
  1276.      smx is rich with management scheme. They include the pool,
  1277.      compiler heap and the smx heap. The compiler heap will be
  1278.      accessed through new and delete. They pool through its class and
  1279.      the smx heap through its "C" functions.
  1280.  
  1281.  
  1282.  
  1283.      13.0 Error Handling
  1284.  
  1285.      smx++ error handling will be an extension of smx error handling
  1286.      and will use the smx error manager.  Since most methods utilize
  1287.      underlying smx functions, many errors will be the same for smx++
  1288.      as for smx.  However, many smx errors cannot occur when using the
  1289.      smx++ API.  For example, TaskA.Start cannot return INVALID_TCB. 
  1290.      In other cases, errors should be renamed.  For example,
  1291.      "INVALID_MCB" is not as meaningful as "NOT_HOLDING" for
  1292.      MsgX.Send().  In this example, by testing MCB_PTR for NULL in the
  1293.      smx++ class code, the send() call can be avoided.  Hence,
  1294.      INVALID_MCB will not occur. New error codes will be added to
  1295.      accommodate new errors. 
  1296.  
  1297.  
  1298.                                      22
  1299.  
  1300.  
  1301.      13.1 Constructor Error Handling
  1302.  
  1303.      When an object is constructed it will be necessary to indicate if
  1304.      it was successful. With smx++, all constructors will be
  1305.      attempting to get a control block of some kind.  If this should
  1306.      fail the instance will still be constructed, but the control
  1307.      block pointer will be set to NULL. This will be an indication to
  1308.      the methods that the smx object could not be created. They will
  1309.      not attempt to perform there desired function and just abort
  1310.      setting an error.
  1311.  
  1312.      In some cases it will be a normal occurrence to not have an smx
  1313.      object ( message class ) so the errors will have to be tailored
  1314.      for the specific case.
  1315.  
  1316.      One finial not, objects can come from three places, global
  1317.      memory, stack, and heap. In the case were there are coming from
  1318.      global and stack memory Borland will respond with an error at
  1319.      compile time if it cannot build the class. In the case of the
  1320.      heap, where the new operator is used to assign a class to a
  1321.      pointer. The new operator will return a NULL if it cannot create
  1322.      the class from the heap.
  1323.  
  1324.  
  1325.      13.2 Destructor Error Handling
  1326.  
  1327.      The destructor will have to handle the situation where a
  1328.      destructor is called and the object or a subsidiary object is
  1329.      still in use.  The system response to this will be to abort and
  1330.      report on OBJECT_IN_USE error.
  1331.  
  1332.  
  1333.  
  1334.      14.0 smx++ Error List Additions
  1335.  
  1336.  
  1337.      14.1 NOT_HOLDING
  1338.  
  1339.      A message object does not have a message to send.
  1340.  
  1341.  
  1342.      14.2 HOLDING
  1343.  
  1344.      A message object cannot receive a message.
  1345.  
  1346.  
  1347.      14.3 INVALID_PARM
  1348.  
  1349.      The constructor was not able to create the instance of the class. 
  1350.      It will signify that a parameter was bad.
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.                                      23
  1358.  
  1359.  
  1360.      14.4 OBJECT_IN_USE
  1361.  
  1362.      This error occurs when the destructor is called and the object is
  1363.      still in use.  See 13.2 for a detailed explanation.
  1364.  
  1365.  
  1366.      14.5 WRONG_MCB_TYPE
  1367.  
  1368.      This error occurs when the user try's to use a message that is
  1369.      not from the near heap has a SIOBus buffer. ( See section 6.3.5
  1370.      Put )
  1371.  
  1372.  
  1373.      14.6 OBJECT_NOT_CREATED
  1374.  
  1375.      This error occurs when a class is created and it can not get a
  1376.      control block and one of its methods is used. The method will
  1377.      check the control block pointer for NULL to determine if a
  1378.      control block was obtained from the system.
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.                                      24
  1417.  
  1418.