Skip to content

Instantly share code, notes, and snippets.

@omo
Created April 8, 2012 11:35
Show Gist options
  • Save omo/2336759 to your computer and use it in GitHub Desktop.
Save omo/2336759 to your computer and use it in GitHub Desktop.
process.hpp
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