The daemon management API.
All member functions are asynchronous. The function sends request to the daemon and returns
control. Once the response from the daemon is received via onDataAvailable(), the
corresponding function of the class instance, set via setEventHandler(), is called.
setEventHandler must be called before any other non-static member.
Use either connect() or getSocketPath() static member functions to establish a connection with
the daemon via local socket. You have to manage the socket yourself. You should organize a
read loop (see onDataAvailable) and error handling.
EveusbEventHandler::writeToDaemon/readFromDaemon is called if EveusbController requests
read/write operations on socket that you manage.
Members return zero if command is sent to the daemon, otherwise error code.
Methods:
● static std::string getSocketPath();
● void setEventHandler(EveusbEventHandler *obj);
● int onDataAvailable(long bytes = -1);
● int Register(const std::string &name, const std::string code);
● int Activate(const std::string &key);
● int ActivateOffline(const std::string &data);
● int getOfflineRequest(const std::string &key);
● int setCompressionHint(bool size_or_speed);
● int findServerDevices(const std::string &host);
● int localShare(const Device &dev);
● int localUnshare(const Device &dev);
● int localDisconnectClient(const Device &dev);
● int remoteAdd(const Device &dev);
● int remoteConnect(const Device &dev, bool persistent);
● int remoteDisconnect(const Device &dev);
● int remoteBreakConnection(const Device &dev);
● int remoteDelete(const Device &dev);
● const char *getLoglevelStr(int level);
● int getLoglevelValue(const std::string &level);
static int connect();
Establishes connection with daemon via local socket
Return:
Socket is ready to read/write, you should close it yourself
Remarks:
Use either of these static member functions to establish a connection with the daemon via
the local socket. You have to manage the socket yourself. You should organize a read loop
(see onDataAvailable) and error handling.
static std::string getSocketPath();
Returns path to local socket to establish connection with daemon
Return:
Path to socket if you use QLocalSocket, CFSocket, libdispatch, etc.
void setEventHandler(EveusbEventHandler *obj);
Must be called before any other non-static member.
Parameters:
obj - must be not null. The instance of the class inherited from EveusbEventHandler
int onDataAvailable(long bytes = -1);
Call onDataAvailable when there are incoming data available on socket opened via connect() or
in another way (QLocalSocket, etc.).
Parameters:
bytes - number of bytes available to read from socket, -1 if the number of bytes is unknown
Return:
errno error code:
* EINVAL if EveusbEventHandler was not set via setEventHandler or in case of some other
errors
* E2BIG if message from the daemon exceeds MSG_LEN_MAX bytes *
EIO if underlying call to readFromDaemon() returned -1
* ENODATA if readFromDaemon() returned zero (connection was closed by remote side)
Note:
See poll/select, QLocalSocket::onDataAvailable, etc.
Remarks:
To perform read on socket, this method calls EveusbEventHandler::readFromDaemon(). If a
complete message is received from the daemon, it calls onMessage() and the corresponding
member of EveusbEventHandler.
You should close the socket if an error is returned.
void clearDataAvailable();
Clears incomplete messages received from daemon.
Is used if socket connection was reestablished before calling onDataAvailable.
int reloadDaemon();
The same as kill -SIGHUP the daemon.
Return:
errno error code
int stopDaemon();
Terminates the daemon.
Return:
errno error code
int getLoglevel();
Requests current log level from daemon
Return:
errno error code
Note: See onLoglevel()
int setLoglevel(int level);
Sets log level to daemon
Parameters:
level - Severity level (see constants from syslog.h: LOG_ERR, LOG_WARNING, etc.)
Return:
errno error code
int getLicense();
Requests information about license from daemon
Return:
errno error code
Note: See onLicense()
int Register(const std::string &name, const std::string code);
Sends registration information to daemon.
Parameters:
name - registration name given to you on license purchase
code - registration code given to you on license purchase
Return:
errno error code
int Activate(const std::string &key);
Sends activation key to daemon.
Parameters:
key - activation key given to you on license purchase
int ActivateOffline(const std::string &data);
Sends offline activation data to daemon.
Parameters:
data - answer on offline request from activation server (base64 encoded)
int getOfflineRequest(const std::string &key);
Requests data from daemon for offline activation.
Note: see onOfflineRequest()
int getVersion();
Requests the daemon for its version
Note: See onVersion()
int getCompressionHint();
Requests default compression from daemon
Return:
errno error code
Note: See onCompressionHint()
int setCompressionHint(bool size_or_speed);
This option affects the settings of network traffic compression.
Parameters:
size_or_speed - true for best size compression, false for best speed compression.
Return:
errno error code
int enumLocalDeviceTree();
Reports all available USB devices via onLocalAddedRemoved (including USB hubs),
onLocalDeviceInfo (except USB hubs), followed by onLocalDeviceTreeEnumerated.
Return:
errno error code
int enumSharedDevices();
Reports the state of every shared device via onLocalSharedUnshared,
onLocalAcquiredReleased followed by onSharedDevicesEnumerated.
Return:
errno error code
int enumRemoteDevices();
Reports the state of every remote device via onRemoteConnecting, onRemoteConnected,
onRemoteReconnecting, onRemoteDisconnecting, onRemoteDisconnected.
The sequence finishes with onRemoteDevicesEnumerated.
Return:
errno error code
int findServers();
Triggers onServerFound for every found server.
Return:
errno error code
int findServerDevices(const std::string &host);
Triggers onServerDeviceFound for every device shared on server, followed by onServerDevicesEnumerated.
Parameters:
host - address of server with devices shared
Return:
errno error code
int localShare(const Device &dev);
Local device management. Shares USB port.
Parameters:
dev - device that needs to be shared
Return:
errno error code
int localUnshare(const Device &dev);
Local device management. Unshares USB port.
Parameters:
dev - device that needs to be unshared
Return:
errno error code
int localUnshareAll();
Local device management. Unshares all shared ports.
Return:
errno error code
int localDisconnectClient(const Device &dev);
Local device management. Disconnects client from the shared device.
Parameters:
dev - device that needs to be disconnected from client
Return:
errno error code
int remoteAdd(const Device &dev);
Remote device management. Adds remote device to the list.
Parameters:
dev - device that needs to be added to the list
Return:
errno error code
int remoteConnect(const Device &dev, bool persistent);
Remote device management. Connects to the remote device.
Parameters:
dev - device you need to connect to
bool persistent - true if it’s required to restore connection in case of failure
Return:
errno error code
int remoteDisconnect(const Device &dev);
Remote device management. Disconnects from the remote device.
Parameters:
dev - device that needs to be disconnected
Return:
errno error code
int remoteBreakConnection(const Device &dev);
Remote device management. Stops connection of the remote USB device to the remote server.
Parameters:
dev - device that needs to be disconnected
Return:
errno error code
int remoteDelete(const Device &dev);
Remote device management. Removes device from the list.
Parameters:
dev - device that needs to be removed
Return:
errno error code
const char *getLoglevelStr(int level);
Returns loglevel name.
Parameters:
level - loglevel value - LOG_DEBUG, LOG_ERR, etc.
Return:
Returns NULL if the argument is invalid, otherwise returns one of the following strings, corresponding to the value of level:
"emergency", // LOG_EMERG
"alert", // LOG_ALERT
"critical", // LOG_CRIT
"error", // LOG_ERR
"warning", // LOG_WARNING
"notice", // LOG_NOTICE
"info", // LOG_INFO
"debug" // LOG_DEBUG
Note:
See getLoglevelValue()
See syslog()
int getLoglevelValue(const std::string &level);
Returns log level value - LOG_DEBUG, LOG_ERR, etc.
Parameters:
level - log level name
Return:
Returns -1 if the argument is invalid
Note:
See getLoglevelStr()
See syslog()
int saveDevices();
Saves information about shared ports and remote devices into the devices file. The daemon
reads this file during startup and restores trees of shared and remote devices.
Normally the daemon saves their states at exit. The daemon does not confirm execution of this
request.