Confirmed users
699
edits
| Line 127: | Line 127: | ||
=== Direction === | === Direction === | ||
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 ... | |||
protocol Direction { | |||
child: | |||
Foo(); // can be sent from-parent-to-child | |||
parent: | |||
Bar(); // can be sent from-child-to-parent | |||
both: | |||
Baz(); // can be sent both ways | |||
}; | |||
// ... generates these C++ abstract classes ... | |||
// ----- DirectionProtocolParent.h ----- | |||
class DirectionProtocolParent { | |||
protected: | |||
virtual void RecvBar() = 0; | |||
virtual void RecvBaz() = 0; | |||
public: | |||
void SendFoo() { /* boilerplate */ } | |||
void SendBaz() { /* boilerplate */ } | |||
}; | |||
// ----- DirectionProtocolChild.h ----- | |||
class DirectionProtocolChild { | |||
protected: | |||
virtual void RecvFoo() = 0; | |||
virtual void RecvBaz() = 0; | |||
public: | |||
void SendBar() { /* 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 === | ||