libnick 2024.12.0
A cross-platform base for native Nickvision applications.
|
An inter process communicator (server/client). More...
#include <interprocesscommunicator.h>
Public Member Functions | |
InterProcessCommunicator (const std::string &id) | |
Constructs an InterProcessCommunicator. | |
~InterProcessCommunicator () | |
Destructs an InterProcessCommunicator. | |
Events::Event< Events::ParamEventArgs< std::vector< std::string > > > & | commandReceived () |
Gets the event for when a command is received. | |
bool | isServer () const |
Gets whether or not this instance is an IPC server. | |
bool | isClient () const |
Gets whether or not this instance is an IPC client. | |
bool | communicate (const std::vector< std::string > &args, bool exitIfClient=false) |
Communicates to the IPC server instance. | |
An inter process communicator (server/client).
Nickvision::App::InterProcessCommunicator::InterProcessCommunicator | ( | const std::string & | id | ) |
Constructs an InterProcessCommunicator.
If this is the first IPC instance for all processes, this instance will become an IPC server. Else, this instance will become an IPC client.
id | The id of the process (Must be the same amongst all IPCs that must talk to each other) |
std::runtime_error | Thrown if the client or server IPC cannot be created |
Nickvision::App::InterProcessCommunicator::~InterProcessCommunicator | ( | ) |
Destructs an InterProcessCommunicator.
Events::Event< Events::ParamEventArgs< std::vector< std::string > > > & Nickvision::App::InterProcessCommunicator::commandReceived | ( | ) |
Gets the event for when a command is received.
This event is only triggered on IPC server instances.
bool Nickvision::App::InterProcessCommunicator::communicate | ( | const std::vector< std::string > & | args, |
bool | exitIfClient = false ) |
Communicates to the IPC server instance.
If this instance is the running server, commandReceived will be triggered with the passed arguments.
args | The command-line arguments |
exitIfClient | Whether or not to exit this process if it is an IPC client |
bool Nickvision::App::InterProcessCommunicator::isClient | ( | ) | const |
Gets whether or not this instance is an IPC client.
bool Nickvision::App::InterProcessCommunicator::isServer | ( | ) | const |
Gets whether or not this instance is an IPC server.