edelib
2.1.0
|
Simple IPC server. More...
#include <edelib/Sipc.h>
Public Member Functions | |
SipcServer () | |
~SipcServer () | |
bool | request_name (const char *prefix) |
void | callback (SipcCallback cb, void *data) |
Simple IPC server.
Sipc stands for Simple IPC (Inter Process Communication) and is very lighweight communication system between two processes by exchanging character messages based on UNIX domain sockets.
Sipc main purpose is to allow quick message exchanging when messages are simple (like simple notifications for refresh or quit) and there is no need for D-BUS, as heavier alternative (see EdbusConnection). It also minimizes linkage depenedencies (in D-BUS case) and can provide some sort of IPC support in places where D-BUS libraries does not exists.
SipcServer will listen incomming messages and will report them via registered callback. Before listening starts, you have to register name via request_name() adding prefix parameter; this name will be used by clients to connects to (same like port numbers, as you concluded already ;)).
If name is already taken, request_name() will fail and you will have to try with another one.
To listen for incomming connections, make sure you call listener_wait().
Here is the short sample:
Bidirectional communication is not possible (a case when server wants to reply); for that D-BUS exists :P
SipcServer | ( | ) |
Constructor; prepares internal data
~SipcServer | ( | ) |
Cleans internal stuff, closes connections
void callback | ( | SipcCallback | cb, |
void * | data | ||
) |
Register callback, called when message arrives.
cb | is callback |
data | is optional data passet to the callback |
bool request_name | ( | const char * | prefix | ) |
Register name to be listening on. The name should be unique and not taken by other listener.
prefix | is name clients will use for connection |