Working with the libeveusb shared library

 Python binding to libeveusb

 Java binding to libeveusb


Working with the libeveusb shared library


1. USB Network Gate daemon is managed via libeveusb library (libeveusb.so) which can be found in 'lib' folder under USB Network Gate installation path. 

 

2. To use the library, you will need header files which are stored in the ‹install_dir›/include/eveusb folder. 

 

There are three of them: eveusbfwd.h, eveusb.h and device.h. These files provide the API for C++ programming language. 

 

eveusbfwd.h contains forward declarations for classes and structures declared in other headers. 

 

device.h contains declaration for class Device that represents local or remote USB devices (or USB ports, if more precisely). 

 

eveusb.h contains API for daemon management. 

 

3. libeveusb does not have library dependencies (except for dependency on libstdc++) and does not use exceptions or threads. 

 

4. All declarations are placed in 'namespace electronic'. 

 

5. To get the daemon events, inherit from the pure abstract class EveusbEventHandler and implement all its virtual member functions. 

 

The typical code sample is the following (basing on Qt library usage):

class WindowMain : private electronic::EveusbEventHandler, ... 

public: 

WindowMain(); 

private: 

QLocalSocket *m_socket; 

electronic::EveusbController m_ctl; 

long writeToDaemon(const void *buf, size_t count); 

long readFromDaemon(void *buf, size_t count); 

};

WindowMain::WindowMain() 

m_ctl.setEventHandler(this); 

connect(m_socket, SIGNAL(connected()), 

SLOT(socket_connected())); connect(m_socket, 

SIGNAL(readyRead()), SLOT(socket_readyRead())); 

m_socket->connectToServer(electronic::EveusbController::getSocketPath()) ; // now you can call any members of m_ctl 

void WindowMain::socket_connected() 

m_ctl.clearDataAvailable(); 

void WindowMain::socket_readyRead() 

while (qint64 cnt = m_socket->bytesAvailable()) { 

if (int err = m_ctl.onDataAvailable(cnt)) { 

m_socket->close(); 

// strerror(err) 

break; 

long WindowMain::writeToDaemon(const void *buf, size_t count) { 

return m_socket->write(buf, count); 

long WindowMain::readFromDaemon(void *buf, size_t count) 

return m_socket->read(data, count); 

}

 

6. As far as the sample shows, the library does not manage the local socket. The socket should be created and managed by you, including data writing/reading and errors management.

 

To get the socket, call the following function: 

 

int EveusbController::connect() 

 

The command returns open file descriptor. If the error occurs, -1 is returned. 

 

7. The following function returns the path to Unix socket

 

std::string EveusbController::getSocketPath() 

 

It can be used instead of EveusbController::connect(). 

 

Anyway, the socket should be closed by you, not the library. 

 

8. When a user manages the socket operations themselves, they can use third-party APIs, e.g. select() and poll() system calls, boost::asio, QLocalSocket from Qt library, and so on. 

 

9. The encoding format for all strings is UTF-8 

 

10. All EveusbController members are asynchronous

 

Each member sends a request to the daemon and returns the error code. 

 

If the request is sent successfully (that is, error code is zero), the 

corresponding EveusbEventHandler virtual function is called once the daemon reply is 

received.


Python binding to libeveusb


Python extension module is provided with the library. That makes it possible to use libeveusb API in applications written in Python. 

 

‹install_dir›/redistr/eveusb_python.tar.gz archive contains the source distribution of Python extension module. 

 

eveusbsh is the interpreter written in Python for daemon management from the console. It is installed into /usr/local/bin or /usr/bin and uses the Python extension module itself. 

 

If C++ compiler is present in the system, and python-dev package is installed, the post installation script will install the Python extension module and eveusbsh automatically. Also, you can install the Python extension module and eveusbsh file manually at any moment - just unpack eveusb_python.tar.gz and execute 'sudo ./setup.py install' command. To see the example of libeveusb API usage, refer to eveusbsh.


Java binding to libeveusb


Java binding is provided with the library. That makes it possible to use libeveusb API in applications written in Java. 

 

Java binding is generated by swig, similar to Python binding. 

 

‹install_dir›/redistr/eveusb_java.tar.gz archive contains the source distribution of Java binding. 

 

Moreover, it contains an “example” directory with simple examples of API usage for Oracle Java and Android. 

 

‹install_dir›/ElectronicTeam/eveusb/lib/eveusb.jar is a precompiled Java binding built from eveusb_java.tar.gz sources. You must append it to -classpath when you invoke Java compiler. 

 

If you use Oracle Java, you must append to -classpath 

 

$(JAVA_HOME)/jre/lib/deploy.jar Our UNG application on Android uses Java binding for libeveusb API itself.