Vuo  2.3.2
VuoRuntimeCommunicator.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "VuoCompositionState.h"
13 #include "VuoTelemetry.h"
14 
16 struct NodeContext;
17 
22 {
23 private:
24  bool _hasZmqConnection;
25 
26  void *zmqContext;
27  void *zmqControl;
28  void *zmqSelfReceive;
29  void *zmqSelfSend;
30  void *zmqTelemetry;
31 
32  dispatch_queue_t controlQueue;
33  dispatch_queue_t telemetryQueue;
34  dispatch_source_t controlTimer;
35  dispatch_source_t telemetryTimer;
36  dispatch_semaphore_t controlCanceled;
37  dispatch_semaphore_t telemetryCanceled;
38 
39  int runnerPipe;
40 
41  set<string> compositionsSendingAllTelemetry;
42  set<string> compositionsSendingEventTelemetry;
43  map<string, set<string> > portsSendingDataTelemetry;
44 
45  VuoRuntimePersistentState *persistentState;
46 
47  void sendControlReply(enum VuoControlReply reply, zmq_msg_t *messages, unsigned int messageCount);
48  void sendTelemetry(enum VuoTelemetry type, zmq_msg_t *messages, unsigned int messageCount);
49 
50  static char * mergeEnumDetails(string type, const char *details);
51 
52  void subscribeToPortDataTelemetry(const char *compositionIdentifier, const char *portIdentifer);
53  void unsubscribeFromPortDataTelemetry(const char *compositionIdentifier, const char *portIdentifer);
54  bool isSubscribedToPortDataTelemetry(const char *compositionIdentifier, const char *portIdentifer);
55 
56  void subscribeToEventTelemetry(const char *compositionIdentifier);
57  void unsubscribeFromEventTelemetry(const char *compositionIdentifier);
58  bool isSubscribedToEventTelemetry(const char *compositionIdentifier);
59 
60  void subscribeToAllTelemetry(const char *compositionIdentifier);
61  void unsubscribeFromAllTelemetry(const char *compositionIdentifier);
62  bool isSubscribedToAllTelemetry(const char *compositionIdentifier);
63 
64  void sendHeartbeat(bool blocking = false);
65 
67 
70  typedef void (*vuoInstanceInitType)(void);
71  vuoInstanceInitType vuoInstanceInit;
72  typedef void (*vuoInstanceTriggerStartType)(void);
73  vuoInstanceTriggerStartType vuoInstanceTriggerStart;
74  typedef void (*vuoInstanceTriggerStopType)(void);
75  vuoInstanceTriggerStopType vuoInstanceTriggerStop;
76  typedef void (*vuoSetInputPortValueType)(const char *portIdentifier, char *valueAsString);
77  vuoSetInputPortValueType vuoSetInputPortValue;
78  typedef unsigned int (*getPublishedInputPortCountType)(void);
79  getPublishedInputPortCountType getPublishedInputPortCount;
80  typedef unsigned int (*getPublishedOutputPortCountType)(void);
81  getPublishedOutputPortCountType getPublishedOutputPortCount;
82  typedef char ** (*getPublishedInputPortNamesType)(void);
83  getPublishedInputPortNamesType getPublishedInputPortNames;
84  typedef char ** (*getPublishedOutputPortNamesType)(void);
85  getPublishedOutputPortNamesType getPublishedOutputPortNames;
86  typedef char ** (*getPublishedInputPortTypesType)(void);
87  getPublishedInputPortTypesType getPublishedInputPortTypes;
88  typedef char ** (*getPublishedOutputPortTypesType)(void);
89  getPublishedOutputPortTypesType getPublishedOutputPortTypes;
90  typedef char ** (*getPublishedInputPortDetailsType)(void);
91  getPublishedInputPortDetailsType getPublishedInputPortDetails;
92  typedef char ** (*getPublishedOutputPortDetailsType)(void);
93  getPublishedOutputPortDetailsType getPublishedOutputPortDetails;
94  typedef void (*firePublishedInputPortEventType)(const char *const *names, unsigned int count);
95  firePublishedInputPortEventType firePublishedInputPortEvent;
96  typedef void (*setPublishedInputPortValueType)(const char *portIdentifier, const char *valueAsString);
97  setPublishedInputPortValueType setPublishedInputPortValue;
98  typedef char * (*getPublishedInputPortValueType)(const char *portIdentifier, int shouldUseInterprocessSerialization);
99  getPublishedInputPortValueType getPublishedInputPortValue;
100  typedef char * (*getPublishedOutputPortValueType)(const char *portIdentifier, int shouldUseInterprocessSerialization);
101  getPublishedOutputPortValueType getPublishedOutputPortValue;
103 
104 public:
107  void updateCompositionSymbols(void *compositionBinaryHandle);
108  void openConnection(void *_zmqContext, const char *controlURL, const char *telemetryURL, int runnerPipe);
109  void closeConnection(void);
110 
111  bool hasZmqConnection(void);
112  dispatch_queue_t getControlQueue(void);
113 
114  void startSendingHeartbeat(void);
116  void startListeningForControl(void);
117  void stopListeningForControl(void);
118  void interruptListeningForControl(void);
119  void cleanUpControl(void);
120  void startListeningForRunnerExit(void);
121 
122  void sendNodeExecutionStarted(const char *compositionIdentifier, const char *nodeIdentifier);
123  void sendNodeExecutionFinished(const char *compositionIdentifier, const char *nodeIdentifier);
124  void sendInputPortsUpdated(const char *compositionIdentifier, const char *portIdentifier, bool receivedEvent, bool receivedData, const char *portDataSummary);
125  void sendOutputPortsUpdated(const char *compositionIdentifier, const char *portIdentifier, bool sentEvent, bool sentData, const char *portDataSummary);
126  void sendPublishedOutputPortsUpdated(const char *portIdentifier, bool sentData, const char *portDataSummary);
127  void sendEventFinished(unsigned long eventId, NodeContext *compositionContext);
128  void sendEventDropped(const char *compositionIdentifier, const char *portIdentifier);
129  void sendError(const char *message);
130  void sendStopRequested(void);
132 
133  bool shouldSendPortDataTelemetry(const char *compositionIdentifier, const char *portIdentifier);
134 };
135 
136 extern "C"
137 {
138 void vuoSendNodeExecutionStarted(VuoCompositionState *compositionState, const char *nodeIdentifier);
139 void vuoSendNodeExecutionFinished(VuoCompositionState *compositionState, const char *nodeIdentifier);
140 void vuoSendInputPortsUpdated(VuoCompositionState *compositionState, const char *portIdentifier, bool receivedEvent, bool receivedData, const char *portDataSummary);
141 void vuoSendOutputPortsUpdated(VuoCompositionState *compositionState, const char *portIdentifier, bool sentEvent, bool sentData, const char *portDataSummary);
142 void vuoSendPublishedOutputPortsUpdated(VuoCompositionState *compositionState, const char *portIdentifier, bool sentData, const char *portDataSummary);
143 void vuoSendEventFinished(VuoCompositionState *compositionState, unsigned long eventId);
144 void vuoSendEventDropped(VuoCompositionState *compositionState, const char *portIdentifier);
145 bool vuoShouldSendPortDataTelemetry(VuoCompositionState *compositionState, const char *portIdentifier);
146 char * vuoGetInputPortString(VuoCompositionState *compositionState, const char *portIdentifier, bool shouldUseInterprocessSerialization);
147 char * vuoGetOutputPortString(VuoCompositionState *compositionState, const char *portIdentifier, bool shouldUseInterprocessSerialization);
148 }