The daemon management API.

 

All member functions are asynchronous. The function sends a 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 connection with daemon via local socket. You have to manage the socket yourself. You should organize read loop (see onDataAvailable) and error handling.

 

EveusbEventHandler::writeToDaemon/readFromDaemon is called if EveusbController requests read/write operations on a socket that you manage.

 

Members return zero if command is sent to the daemon, otherwise error code. 


Methods:


 static int connect();
 static std::string getSocketPath();
 void setEventHandler(EveusbEventHandler *obj);

 int onDataAvailable(long bytes = -1);
 void clearDataAvailable();
 int reloadDaemon();

 int stopDaemon();
 int getLoglevel();
 int setLoglevel(int level);

 int getLicense();
 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 getVersion();

 int getCompression();
 int setCompression(const std::string &compr);
 int enumLocalDeviceTree();

 int enumSharedDevices();

 int enumRemoteDevices();
 int findServers();
 int findServerDevices(const std::string &host);

 int localShare(const Device &dev);
 int localUnshare(const Device &dev);
 int localUnshareAll();

 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 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, et


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 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, it calls EveusbEventHandler::readFromDaemon().

If a complete message is received from daemon, it calls onMessage() and 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 onDataAvailable calling.


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 the 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 the daemon.

 

Parameters:

 

key - activation key given to you on license purchase

 

Return:

 

errno error code


int ActivateOffline(const std::string &data);


Sends offline activation data to the 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 daemon for its version

 

Note: See onVersion()


int getCompression();


Requests default compression from daemon

 

Return:

 

errno error code

 

Note: See onCompress()


int setCompression(const std::string &compr);


Sets default compression to daemon

 

Parameters:

 

compr - type of compression: none, best or fast

 

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.

 

Return:

 

errno error code


int localShare(const Device &dev);


Local devices management. Shares USB port.

 

Parameters:

 

dev - device that needs to be shared

 

Return:

 

errno error code


int localUnshare(const Device &dev);


Local devices management. Unshares USB port. 

 

Parameters: 

 

dev - device that needs to be unshared 

 

Return: 

 

errno error code


int localUnshareAll();


Local devices management. Unshares all shared ports.

 

Return:

 

errno error code


int localDisconnectClient(const Device &dev);


Local devices 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 devices 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 devices management. Connects to the remote device.

 

Parameters:

 

dev - device to which you need to connect

 

bool persistent - true if it’s required to restore connection in case of failure

 

Return:

 

errno error code


int remoteDisconnect(const Device &dev);


Remote devices management. Disconnects from the remote device.

 

Parameters:

 

dev - device that needs to be disconnected

 

Return:

 

errno error code


int remoteBreakConnection(const Device &dev);


Remote devices 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 devices management. Removes device from the list.

 

Parameters:

 

dev - device that needs to be removed from the list

 

Return:

 

errno error code


const char *getLoglevelStr(int level);


Returns loglevel name.

 

Parameters:

 

level - loglevel value - LOG_DEBUG, LOG_ERR, etc.

 

Return:

 

Return NULL if argument is invalid, otherwise 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 loglevel value - LOG_DEBUG, LOG_ERR, etc.

 

Parameters:

 

level - log level name

 

Return:

 

Return -1 if argument is invalid

 

Note:

 

See getLoglevelStr()

See syslog()