Hi,<br><br>I wrote a sample application, included in this email, to test invoking an application on a dbus message. I can see that the application launches but the dbus message that launched the apllication never reaches the filter method. Could you guys please help me with this.<br>
<br>Thanks,<br>Pradeep<br><b><br>Listener</b><br><br>#include <stdlib.h><br>#include <unistd.h><br>#include <glib.h><br><br>#include <dbus/dbus.h><br>#include <dbus/dbus-glib-lowlevel.h><br><br>
# define TEST_SERVICE "com.tpk.test"<br># define TEST_PATH "/com/tpk/test"<br># define TEST_INTERFACE "com.tpk.test"<br><br>static GMainLoop *mainloop = 0;<br><br>static DBusConnection *server_bus;<br>
<br>static<br>DBusHandlerResult<br>server_filter(DBusConnection *conn,<br> DBusMessage *msg,<br> void *user_data)<br>{<br> DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;<br>
const char *interface = dbus_message_get_interface(msg);<br> const char *member = dbus_message_get_member(msg);<br> const char *object = dbus_message_get_path(msg);<br> int type = dbus_message_get_type(msg);<br>
DBusMessage *rsp = 0;<br><br> g_message ("member %s Object %s", member, object);<br> g_message ("=================================================");<br><br> if(dbus_message_is_method_call(msg, TEST_INTERFACE,"Test"))<br>
{<br> g_main_loop_quit(mainloop);<br> result = DBUS_HANDLER_RESULT_HANDLED;<br> }<br><br> return result;<br>}<br><br>static int<br>server_init(void)<br>{<br><br> DBusError err = DBUS_ERROR_INIT;<br><br> if( (server_bus = dbus_bus_get(DBUS_BUS_SESSION, &err)) == 0 )<br>
{<br> g_error("not able to connection session bus");<br> }<br><br> if( !dbus_connection_add_filter(server_bus, server_filter, 0, 0) )<br> {<br> g_error("add filter failed");<br> }<br><br>
int ret = dbus_bus_request_name(server_bus, TEST_SERVICE,<br> DBUS_NAME_FLAG_DO_NOT_QUEUE,<br> //DBUS_NAME_FLAG_REPLACE_EXISTING,<br> &err);<br>
<br> if( ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )<br> {<br> if( dbus_error_is_set(&err) )<br> {<br> g_error("%s: %s: %s\n", "dbus_bus_request_name", <a href="http://err.name">err.name</a>, err.message);<br>
}<br> else<br> {<br> g_error("%s: %s\n", "dbus_bus_request_name", "not primary owner of connection\n");<br> }<br> }<br><br> dbus_connection_setup_with_g_main(server_bus, NULL);<br>
dbus_connection_set_exit_on_disconnect(server_bus, 0);<br><br> dbus_error_free(&err);<br> return 0;<br>}<br><br>int main(int argc, char *argv[] )<br>{<br> mainloop = g_main_loop_new(NULL, FALSE);<br><br> server_init();<br>
<br> mainloop = g_main_loop_new(NULL, FALSE);<br> g_main_loop_run(mainloop);<br><br> return EXIT_SUCCESS;<br>}<br><br><b>Sender</b><br><br>#include <glib.h><br>#include <dbus/dbus.h><br>#include <dbus/dbus-glib.h><br>
<br># define TEST_SERVICE "com.tpk.test"<br># define TEST_PATH "/com/tpk/test"<br># define TEST_INTERFACE "com.tpk.test"<br><br>DBusGProxy* m_TCPCIRProxy;<br><br>int main(void) {<br><br> g_type_init();<br>
<br> GError* error = NULL;<br> m_TCPCIRProxy = dbus_g_proxy_new_for_name(dbus_g_bus_get(DBUS_BUS_SESSION, &error),<br> TEST_SERVICE,<br> TEST_PATH,<br>
TEST_INTERFACE);<br> if (error)<br> {<br> g_debug("TCPCIRProxy failed: %s", error->message);<br> m_TCPCIRProxy = NULL;<br> g_error_free(error);<br>
}<br> error = NULL;<br><br><br> /*dbus_g_proxy_call(m_TCPCIRProxy,<br> "Test", &error,<br> G_TYPE_INVALID,<br> G_TYPE_INVALID);<br>
*/<br><br> dbus_g_proxy_call_no_reply(m_TCPCIRProxy,<br> "Test",<br> G_TYPE_INVALID,<br> G_TYPE_INVALID);<br><br> g_message ("Success");<br>}<br><br><b>Service File</b> (/usr/share/dbus-1/services/com.tpk.test.service)<br>
<br>[D-BUS Service]<br>Name=com.tpk.test<br>Exec=/usr/bin/a.out<br><br>