ScEventSubscription API
Note
This is correct for only versions of sc-machine that >= 0.10.0.
This API provides functionality to subscribe to sc-events on C++.
Note
To include this API provide #include <sc-memory/sc_event_subscription.hpp>
in your hpp source.
ScEventSubscription
ScElementaryEventSubscription
is base class for all sc-event subscription, it can be used to catch all sc-events for specified sc-element.
Each sc-event subscription constructor, besides ScElementaryEventSubscription
constructor, takes 3 parameters:
context
is an object ofScMemoryContext
that will be used to work with sc-event;subscriptionElementAddr
is an object ofScAddr
of sc-element that need to be listened for a specified sc-event;delegateFunc
is a delegate to a callback function, that will be called on each event emit (void delegateFunc(TScEvent const &)
), whereTScEvent
is corresponding sc-event class.
Note
Callback function will be called in another thread!
Warning
Subscription sc-element must be valid sc-element.
Constructor of ScElementaryEventSubscription
class takes 4 parameters:
context
is an object ofScMemoryContext
that will be used to work with sc-event;eventClassAddr
is an object ofScAddr
of sc-event class;subscriptionElementAddr
is an object ofScAddr
of sc-element that need to be listened for a specified sc-event;delegateFunc
is a delegate to a callback function, that will be called on each event emit (void delegateFunc(ScElementaryEvent const &)
).
All these constructors are private, you can't call these. We provide more safe API to generate subscription. Use C++ Agent Context API to generate sc-event subscriptions.
All sc-event classes are in core keynodes:
ScKeynodes::sc_event_after_generate_connector
;ScKeynodes::sc_event_after_generate_outgoing_arc
;ScKeynodes::sc_event_after_generate_incoming_arc
;ScKeynodes::sc_event_after_generate_edge
;ScKeynodes::sc_event_before_erase_connector
;ScKeynodes::sc_event_before_erase_outgoing_arc
;ScKeynodes::sc_event_before_erase_incoming_arc
;ScKeynodes::sc_event_before_erase_edge
;ScKeynodes::sc_event_before_erase_element
;ScKeynodes::sc_event_before_change_link_content
.
Use them as eventClassAddr
for CreateElementaryEventSubscription
.
The table of description (parameters of callback function named on pictures, if there are no parameter name on picture, then it's would have an empty value):
Note
Here context
is pointer to object of ScAgentContext
class.
Class | Description |
---|---|
ScElementaryEventSubscription |
Example C++ code:
|
ScEventAfterGenerateConnector |
|
ScEventAfterGenerateOutgoingArc |
|
ScEventAfterGenerateIncomingArc |
|
ScEventAfterGenerateEdge |
|
ScEventBeforeEraseConnector |
|
ScEventBeforeEraseOutgoingArc |
|
ScEventBeforeEraseIncomingArc |
|
ScEventBeforeEraseEdge |
|
ScEventBeforeEraseElement |
Example C++ code:
|
ScEventBeforeChangeLinkContent |
|
Frequently Asked Questions
- Whether a function is considered an agent if this function is subscribed to a sc-event and which is called after that sc-event occurs?
- Why can't you call the constructor of a subscription class to sc-event?
- Are
ScEventAfterGenerateIncomingArc
orScEventAfterGenerateOutgoingArc
events trigger whenScEventAfterGenerateEdge
event is triggered?
Whether a function is considered an agent if this function is subscribed to a sc-event and which is called after that sc-event occurs?
No, such functions are not agents. Agents have a strict specification. See C++ Agents API.
Why can't I call the constructor of a subscription class to sc-event?
First of all, it's not safe. We need more checks on input arguments because there are more of them. Secondly, it is correct from the OOP point of view. Constructors should not throw exceptions. Third, it is correct from the point of view of the architecture we use in the sc-machine. The ScAgentContext
is a facade over all possible objects used by agents.
Are ScEventAfterGenerateIncomingArc
or ScEventAfterGenerateOutgoingArc
events trigger when ScEventAfterGenerateEdge
event is triggered?
No, the ScEventAfterGenerateEdge
event only occurs when sc-edges are generated.