使用dbus-glib编写通过dbus调用函数
1.需要的头文件:
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
函数实现及注释:
#define DBUS_FPDLINK_SERVICE "com.syberos.camerautils" //sercice名称
#define DBUS_FPDLINK_PATH "/camerautils/interface"//path
#define DBUS_FPDLINK_INTERFACE "com.syberos.camerautils.interface"//interface
#define DBUS_FPDLINK_METHOD_ENABLE "fpdlinkStateChanged"//方法名字
int dbus_set_fpdlink(gint state)
{
GError * error = NULL;
DBusGConnection * connection;
DBusGProxy * proxy;
g_type_init();GType初始化
connection = dbus_g_bus_get (DBUS_BUS_SESSION, & error);
if(connection == NULL){
g_printerr ("Failed to open connection to bus : %s/n",error->message);
g_error_free( error);
return -1;
}
proxy = dbus_g_proxy_new_for_name (connection,
DBUS_FPDLINK_SERVICE,
DBUS_FPDLINK_PATH,
DBUS_FPDLINK_INTERFACE);
error = NULL;
if( !dbus_g_proxy_call (proxy, DBUS_FPDLINK_METHOD_ENABLE, &error, G_TYPE_INT, state,
G_TYPE_INVALID, G_TYPE_INVALID) ){
g_printerr("Error : %s/n", error->message);
g_error_free(error);
return -1;
}
g_object_unref(proxy);
return 0;
}