GDBUS使用框架
(141条消息) GDBUS使用框架_gdbus教程_玩意儿他爸的博客-CSDN博客
服务端生成文件:gdbus-codegen --generate-c-code=libtunerservice interface-S-A.xml
客户端生成文件:gdbus-codegen --generate-c-code=libservice-c --c-generate-object-manager interface-S-A.xml
CLIENT:
**************添加客户端的生成的文件****************
(1)获取总线代理者:
com_company_tunerservice_dbus_s_proxy_new_for_bus_sync
(2)信号与回调函数的绑定:
g_signal_connect(poxy, "seek_status", G_CALLBACK(on_sig_seek_status), NULL);
***seek_status======================>根据生成的.c文件
(3)回调函数的实现
***on_sig_seek_status================>根据生成的.c文件
(4)事件的轮回上报
loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(loop);
g_object_unref(poxy);
SERVER:
**************添加服务端的生成的文件****************
(1)创建一个总线
guint ownName = g_bus_own_name (G_BUS_TYPE_SYSTEM ,
"com.company.tunerservice.dbus.s",
G_BUS_NAME_OWNER_FLAGS_NONE,
bus_acquired_handler,
name_acquired_handler,
name_lost_handler,
NULL,
NULL);
***bus_acquired_handler、name_acquired_handler、name_lost_handler实现这3个回调函数
***bus_acquired_handler中需要
***g_Skeleton = com_company_tunerservice_dbus_s_skeleton_new();***建立一个骨架
***g_signal_connect(g_Skeleton, "handle-set-tuner-station", G_CALLBACK(handle_set_tuner_station), NULL);
***handle-set-tuner-station====================>根据服务端生成的.c文件
***handle_set_tuner_station===================>参数根据服务端生成的.c文件,实现这个回调函数
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(g_Skeleton),========>骨架输出
connection,
"/",
&pError);
(2)运行总线服务代理
loop = g_main_loop_new(NULL, FALSE);
g_print("g_main_loop_new\n");
if(loop!=NULL)
{
g_main_loop_run(loop);
g_print("g_main_loop_run\n");
}
g_bus_unown_name(ownName);
g_print("g_bus_unown_name\n");
————————————————
版权声明:本文为CSDN博主「玩意儿他爸」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_16810885/article/details/93976267