adbus is designed to be a portable C implementation of both a dbus client and bus server, and bound into higher level languages or used directly from C/C++ with ease.
It's written in the common subset of ISO C and C++ and uses only the CRT except for the optional adbus_Socket module which uses the BSD socket API and some atomic operations found in adbus/misc.h.
The API as a whole is thread-safe (ie has no global data) but most objects can only be used on a single thread. The API especially adbus_Connection is heavily callback based and thus there are some restrictions on what functions can be called in callbacks to avoid reentrancy problems. Notably:
The multithreading support is incomplete and untested. For the moment being it would be unwise to use a connection on multiple threads, but this will be addressed soon.
The linux build is built using tup available from http://gittup.org/tup/ .
To build tup:
git clone git://gittup.org/tup.git
cd tup
./bootstrap.sh
To build adbus with tup:
git clone git://github.com/jmckaskill/adbus.git
cd adbus
../tup/tup init
../tup/tup upd
Building on other platforms or manually with gcc is fairly straightforward:
gcc -o adbus.so -Iinclude/c -fPIC --std=gnu99 adbus/ *.c dmem/ *.c
For MSVC you will need the provided stdint.h in deps/msvc/stdint.h.
The adbus API is composed of a number of modules centred around the major types. These modules can be grouped into 4 groups:
Example blocking BSD sockets main loop.
static void SetupConnection(adbus_Connection* c) { // Do connection setup } static adbus_ssize_t SendMessage(void* user, adbus_Message* m) { return send(*(adbus_Socket*) user, m->data, m->size, 0); } # define RECV_SIZE 64 * 1024 int main(void) { adbus_Buffer* buffer; adbus_Connection* connection; adbus_Socket socket; adbus_ConnectionCallbacks callbacks; // Connect and authenticate buffer = adbus_buf_new(); socket = adbus_sock_connect(ADBUS_DEFAULT_BUS); if (socket == ADBUS_SOCK_INVALID || adbus_sock_cauth(socket, buffer)) return 1; // Create and setup connection memset(&callbacks, 0, sizeof(callbacks)); callbacks.send_message = &SendMessage; connection = adbus_conn_new(&callbacks, &socket); SetupConnection(connection); // Connect to bus server adbus_conn_connect(connection, NULL, NULL); while (1) { // Get the next chunk of data char* dest = adbus_buf_recvbuf(buffer, RECV_SIZE); adbus_ssize_t recvd = recv(socket, buffer, RECV_SIZE, 0); adbus_buf_recvd(buffer, RECV_SIZE, recvd); if (recvd < 0) return 2; // Dispatch received data if (adbus_conn_parse(connection, buffer)) return 3; } }
1.6.1