libnick 2024.12.0
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::App::InterProcessCommunicator Class Reference

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.
 

Detailed Description

An inter process communicator (server/client).

Constructor & Destructor Documentation

◆ InterProcessCommunicator()

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.

Parameters
idThe id of the process (Must be the same amongst all IPCs that must talk to each other)
Exceptions
std::runtime_errorThrown if the client or server IPC cannot be created

◆ ~InterProcessCommunicator()

Nickvision::App::InterProcessCommunicator::~InterProcessCommunicator ( )

Destructs an InterProcessCommunicator.

Member Function Documentation

◆ commandReceived()

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.

Returns
The command received event

◆ communicate()

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.

Parameters
argsThe command-line arguments
exitIfClientWhether or not to exit this process if it is an IPC client
Returns
True if command-line arguments were sent to a server instance

◆ isClient()

bool Nickvision::App::InterProcessCommunicator::isClient ( ) const

Gets whether or not this instance is an IPC client.

Returns
True if this instance is an IPC client, else false.

◆ isServer()

bool Nickvision::App::InterProcessCommunicator::isServer ( ) const

Gets whether or not this instance is an IPC server.

Returns
True if this instance is an IPC server, else false.

The documentation for this class was generated from the following file: