IPDL/Getting started: Difference between revisions

Line 127: Line 127:
=== Direction ===
=== Direction ===


As introduced above, message direction specifiers simply denote which actor sends the message and which receives it.  The following artificial example should make it clear what the '''out''', '''in''', and '''inout''' direction specifiers mean to the C++ implementors.
Each message type includes a "direction."  The message direction specifies whether the message can be sent from-parent-to-child, from-child-to-parent, or both ways.  Three keywords serve as direction specifiers; '''child''' was introduced above.  The second is '''parent''', which means that the messages declared under the '''parent''' label can only be sent from-child-to-parent.  The third is '''both''', which means that the declared messages can be sent in both directions.  The following artificial example shows how these specifiers are used and how these specifiers change the generated abstract actor classes.


  // this protocol ...
// this protocol ...
  protocol Direction {
protocol Direction {
      out Foo();
child:
      in Bar();
    Foo(); // can be sent from-parent-to-child
      inout Baz();
parent:
  };   
    Bar(); // can be sent from-child-to-parent
  // ... generates these C++ abstract classes ...
both:
    Baz(); // can be sent both ways
};   
// ... generates these C++ abstract classes ...


  // ----- DirectionProtocolParent.h -----
// ----- DirectionProtocolParent.h -----
  class DirectionProtocolParent {
class DirectionProtocolParent {
  protected:
protected:
      virtual void RecvBar() = 0;
    virtual void RecvBar() = 0;
      virtual void RecvBaz() = 0;
    virtual void RecvBaz() = 0;
 
  public:
public:
      void SendFoo() { /* boilerplate */ }
    void SendFoo() { /* boilerplate */ }
      void SendBaz() { /* boilerplate */ }
    void SendBaz() { /* boilerplate */ }
  };
};


  // ----- DirectionProtocolChild.h -----
// ----- DirectionProtocolChild.h -----
  class DirectionProtocolChild {
class DirectionProtocolChild {
  protected:
protected:
      virtual void RecvFoo() = 0;
    virtual void RecvFoo() = 0;
      virtual void RecvBaz() = 0;
    virtual void RecvBaz() = 0;
 
  public:
public:
      void SendBar() { /* boilerplate */ }
    void SendBar() { /* boilerplate */ }
      void SendBaz() { /* boilerplate */ }
    void SendBaz() { /* boilerplate */ }
  };
};
 
'''Syntax note''': you can use the '''child''', '''parent''', and '''both''' specifiers multiple times in a protocol specification.  They behave like '''public''', '''protected''', and '''private''' labels in C++.


=== Parameters ===
=== Parameters ===
Confirmed users
699

edits