#include <cascade/interprocess/CascadeWormhole.h>
Inheritance diagram for CascadeWormhole:
Public Types | |
typedef bool() | WormholeEnumProc (const char *pWormholeURL, void *pClientData) |
enum | { kMaxName = 96, kMaxNameLen = kMaxName - 1 } |
Public Member Functions | |
CascadeWormhole () | |
virtual | ~CascadeWormhole () |
bool | Create (const char *pWormholeURL) |
void | Destroy () |
CascadeMessage * | WaitForMessage (u32 nTimeoutMilliseconds=0) |
bool | PostMessage (const char *pWormholeURL, u32 nMessageID, void *pMessageData=NULL, u32 nDataSize=0) |
bool | BroadcastMessage (const char *pBroadcastURL, u32 nMessageID, void *pMessageData=NULL, u32 nDataSize=0) |
bool | SendMessage (const char *pWormholeURL, u32 nMessageID, void *pMessageData, u32 nDataSize, CascadeMessage *&pReplyMessageToSet) |
bool | SendReply (u32 nReplyMessageID, void *pMessageData=NULL, u32 nDataSize=0) |
Static Public Member Functions | |
static bool | EnumerateWormholes (const char *pWormholeURL, WormholeEnumProc *pEnumProc, void *pClientData) |
static bool | DoesWormholeExist (const char *pWormholeURL) |
CascadeWormhole is the Cascade mechanism for inter-process communication. Wormholes provide the ability to transfer anything from small messages to huge media streams in a super-duper-high- performance manner between threads of a same process, threads of different processes, even threads of different processes on different machines.
Wormhole (n) 1 : a hole or passage burrowed by a worm 2 : a hypothetical structure of space-time envisioned as a long thin tunnel connecting points that are separated in space and time 3 : a Cascade data-structure and run-time facility envisioned as a long thin tunnel connecting threads within and across processes and machines with multiple entry points for parcels of data sent through the Wormhole
Wormholes are identified by their URLs. All wormholes on the same host have unique names and are referred to as "wormhole://localhost/" based URLs. "wormhole://localhost/" based URLs are the only URLs supported in the 1.0 implementation of this interface. The unique part of the wormhole name is the part to the right of the "wormhole://localhost/". This name is limited to a length of kMaxNameLen characters. kMaxName refers to the size of buffer needed to store string of kMaxNameLen.
"wormhole://localhost/"
and must be unique. Both sender and receiver wormholes must have been created with unique URLs. Sending a wormhole message to yourself is illegal (send is synchronous), but posting a message to yourself is permitted. In order to minimize collisions in the namespace of wormhole URLs it is recommended that you create wormhole urls that contain your internet domain in them, as is the style in java class naming."wormhole://localhost/org.woodward.dons_application" "wormhole://localhost/com.ficticiouscompany.special.daemonwormhole" "wormhole://localhost/com.roku.cascade.cascadeprivate.internalwormhole"
"wormhole://localhost/"
. To broadcast a message to all wormholes created by processes written by ficticious company, one would use the broadcast URL" "wormhole://localhost/com.ficticiouscompany"
. "_outputonly:"
WormholesCascadeWormhole wormhole; CascadeMessage * pMessage = NULL; if (wormhole.Create("wormhole://localhost/com.yourcompany.here.yourwormholename")) { while (1) { pMessage = WaitForMessage(); if (NULL == pMessage) { // receive failure - probable SIGINT sent to my process // I can break or continue as is my preference break; } /* Do something with pMessage */ /* break out of the loop when I've decided I'm done with this wormhole */ } wormhole.Destroy(); }
If you are receiving a message that was sent to you (check this with pMessage->IsReplyRequired()) then the sender is waiting on your reply. It is very important to reply in a timely fashion so as not to make the sender wait too long. Reply to a message with a call to SendReply(). If you start waiting for another message without sending a reply a default (empty) reply will be sent on your behalf.
"_outputonly:"
WormholesCascadeMessage::WaitForMessage()
"_outputonly"
to your wormhole name. For example "wormhole://localhost/_outputonly:com.ficticiouscompany.wormhole"
is a URL for an output only wormhole. Output only wormholes may only call Send(), Post(), and Broadcast(). No wormhole messages will ever be received by an output only wormhole. Therefore, you never need to call WaitForMessage() on an output only wormhole.
|
Callback function for enumerating wormholes on the local system Clients provide their own WormholeEnumProc to the EnumerateWormholes() function. Your custom WormholeEnumProc will get called back by the EnumerateWormholes() function, one for each wormhole that matches the matching criteria.
|
|
|
|
the default constructor - lightweight This default constructor is lightweight. |
|
destructor This destructor will Destroy() the wormhole if necessary.
|
|
broadcasts a wormhole message asynchronously BroadcastMessage() will asynchronously broadcast the message identified by nMessageID to the wormhole destinations identified by pBroadcastURL. Each recipient receives a copy of the pMessageData. Each wormhole where pBroadcastURL is a substring of the wormhole's URL will receive the broadcasted message.
|
|
creates a wormhole Create() creates the wormhole identified by pWormholeURL returning true if successful, false otherwise. pWormholeURL must refer to a local URL starting with "wormhole://localhost/" whose unique part of the URL has a string length of not more than kMaxNameLen.
|
|
destroys the wormhole Destroy() destroys a previously created wormhole.
|
|
determines whether or not a wormhole exists DoesWormholeExist() returns true if the wormhole identified by pWormholeURL currently exists, false otherwise.
|
|
enumerates wormholes on the local system call EnumerateWormholes() to enumerate the wormholes that match on pWormholeURL. (Those wormholes where pWormholeURL is substring of their wormhole URL). If pWormholeURL is NULL or empty (""), then all local wormholes are enumerated.
|
|
posts a wormhole message asynchronously PostMessage() will asynchronously post the message identified by nMessageID to the wormhole identified by pWormholeURL returning true if successful, false otherwise.
|
|
sends a wormhole message SendMessage() delivers the message identified by nMessageID to the wormhole identified by pWormholeURL synchronously. SendMessage() returns true if successful, false otherwise. SendMessage() sets pReplyMessageToSet (on success) with the reply message. See SendReply(). pReplyMessageToSet is only valid until the next call to SendMessage().
|
|
sends a reply message SendReply() will send a reply to the most recently received synchronous message returning true if successful, false otherwise. SendReply() is only used to reply to messages sent to this wormhole with SendMessage(). That can be determined by calling pMessage->IsReplyRequired() on the message returned from WaitForMessage(). SendReply() sends a reply message with message id nMessageID, data pMessageData of size nDataSize to the wormhole that sent the message with SendMessage(). SendReply() returns true if successful, false otherwise.
|
|
waits for a wormhole message WaitForMessage() blocks the calling thread for nTimeoutMilliseconds (0 == infinite) or until a CascadeMessage is received. WaitForMessage() returns non-null if successful, NULL if there is a timeout. The returned CascadeMessage * and the data it points to is valid until the next call to WaitForMessage().
|