Created
April 8, 2012 11:35
-
-
Save omo/2336759 to your computer and use it in GitHub Desktop.
process.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProcessBase : public EventVisitor | |
{ | |
public: | |
ProcessBase(const std::string& id = ""); | |
virtual ~ProcessBase(); | |
UPID self() const { return pid; } | |
protected: | |
// Invoked when an event is serviced. | |
virtual void serve(const Event& event) | |
{ | |
event.visit(this); | |
} | |
.... | |
// Invoked when a linked process has exited (see link). | |
virtual void exited(const UPID& pid) {} | |
// Invoked when a linked process can no longer be monitored (see link). | |
virtual void lost(const UPID& pid) {} | |
.... | |
// Sends a message with data to PID. | |
void send( | |
const UPID& to, | |
const std::string& name, | |
const char* data = NULL, | |
size_t length = 0); | |
// Links with the specified PID. Linking with a process from within | |
// the same "operating system process" is gauranteed to give you | |
// perfect monitoring of that process. However, linking with a | |
// process on another machine might result in receiving lost | |
// callbacks due to the nature of a distributed environment. | |
UPID link(const UPID& pid); | |
.... | |
// Active references. | |
int refs; | |
// Process PID. | |
UPID pid; | |
}; | |
.... | |
/** | |
* Spawn a new process. | |
* | |
* @param process process to be spawned | |
* @param manage boolean whether process should get garbage collected | |
*/ | |
UPID spawn(ProcessBase* process, bool manage = false); | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment