Skip to content

Commit

Permalink
Implement external receiver registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhroth committed Jul 25, 2011
1 parent bc9821d commit 34045e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
23 changes: 18 additions & 5 deletions src/MessageSendController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ int MessageSendController::getNameIndex(char *receiverName) {
}

void MessageSendController::receiveMessage(char *name, PdMessage *message) {
processMessage(getNameIndex(name), message);
}

void MessageSendController::processMessage(int inletIndex, PdMessage *message) {
sendMessage(inletIndex, message);
sendMessage(getNameIndex(name), message);
if (externalReceiverSet.find(string(name)) != externalReceiverSet.end()) {
std::pair<char *, PdMessage *> pair = make_pair(name, message);
context->callbackFunction(ZG_RECEIVER_MESSAGE, context->callbackUserData, &pair);
}
}

void MessageSendController::sendMessage(int outletIndex, PdMessage *message) {
Expand Down Expand Up @@ -102,3 +102,16 @@ void MessageSendController::removeReceiver(RemoteMessageReceiver *receiver) {
// receiver set.
}
}

void MessageSendController::registerExternalReceiver(const char *receiverName) {
string str = string(receiverName);
// check to make sure that the same receiver name is not entered more than once
if (externalReceiverSet.find(str) != externalReceiverSet.end()) {
externalReceiverSet.insert(str);
}
}

void MessageSendController::unregisterExternalReceiver(const char *receiverName) {
string str = string(receiverName);
externalReceiverSet.erase(str);
}
6 changes: 5 additions & 1 deletion src/MessageSendController.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ class MessageSendController : public MessageObject {

void removeReceiver(RemoteMessageReceiver *receiver);

void registerExternalReceiver(const char *receiverName);
void unregisterExternalReceiver(const char *receiverName);

private:
void processMessage(int inletIndex, PdMessage *message);

PdContext *context;

vector<std::pair<string, set<RemoteMessageReceiver *> > > sendStack;

set<string> externalReceiverSet;
};

#endif // _MESSAGE_SEND_CONTROLLER_H_
4 changes: 2 additions & 2 deletions src/PdContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,11 @@ float PdContext::getValueForName(char *name) {
}

void PdContext::registerExternalReceiver(const char *receiverName) {

sendController->registerExternalReceiver(receiverName);
}

void PdContext::unregisterExternalReceiver(const char *receiverName) {

sendController->unregisterExternalReceiver(receiverName);
}


Expand Down
6 changes: 3 additions & 3 deletions src/PdContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class PdContext {
/** User-provided data associated with the callback function. */
void *callbackUserData;

/** The registered callback function for sending data outside of the graph. */
void (*callbackFunction)(ZGCallbackFunction, void *, void *);

private:
/** Returns <code>true</code> if the graph was successfully configured. <code>false</code> otherwise. */
bool configureEmptyGraphWithParser(PdGraph *graph, PdFileParser *fileParser);
Expand Down Expand Up @@ -245,9 +248,6 @@ class PdContext {

/** A global list of all table receivers (e.g., [tabread4~] and [tabplay~]) */
list<TableReceiverInterface *> tableReceiverList;

/** The registered callback function for sending data outside of the graph. */
void (*callbackFunction)(ZGCallbackFunction, void *, void *);
};

#endif // _PD_CONTEXT_H_
9 changes: 9 additions & 0 deletions src/ZenGarden.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ typedef enum ZGMessageElementType {
ZG_MESSAGE_ELEMENT_BANG
} ZGMessageElementType;

/**
* A pointer to this structure is supplied in the callback function with ZG_RECEIVER_MESSAGE.
* The structure will not persister after the function returns and the pointer will become invalid.
*/
typedef struct ZGReceiverMessagePair {
const char *receiverName;
ZGMessage *message;
} ZGReceiverMessagePair;


#pragma mark - New Context/Graph/Object

Expand Down

0 comments on commit 34045e7

Please sign in to comment.