Missing dbus signals

Kaustubh Atrawalkar kaustubh.ra at gmail.com
Thu Feb 26 01:10:31 PST 2009


Actually there is little mix up of codes. We have g_main_loop running which
i guess works for listening to dbus socket also. And to catch the signal
dbus_bus_add_match & add_filter is used. So there is mix of dbus-glib
bindings and some native code also. Does that might be causing the issue?

========== Sender Code ===========
DBusMessageIter iter, array_iter;
gchar           array_sig[2];
gint            i;
DBusError       error;
array_sig[0] = DBUS_TYPE_STRING;
array_sig[1] = '\0';

gchar *app_interface = g_strconcat (APP_MGR_DBUS_INTERFACE,".", application,
NULL);
gchar *app_objectpath = g_strconcat (APP_MGR_DBUS_OBJECT, "/", application,
NULL);

while (value) {
                    params[no_of_params] = g_strdup(value);
                        no_of_params++;
                        value = va_arg (args, char*);
                }

                dbus_error_init (&error);

                DBusConnection *bus_conn = dbus_bus_get (DBUS_BUS_SYSTEM,
&error);

                DBusMessage *msg = dbus_message_new_signal (app_objectpath,
app_interface, APP_MGR_DBUS_SIGNAL_EXEC);
                if(msg == NULL)
                {
                        g_critical(Not Enough Memory to create new dbus
Message");
                        return -2;
                }

                dbus_message_iter_init_append(msg, &iter);
                dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32,
&no_of_params);
                dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
array_sig, &array_iter);
                dbus_message_iter_append_basic (&array_iter,
DBUS_TYPE_STRING, &application);

                for(i=1; i<no_of_params; i++) {
                        dbus_message_iter_append_basic(&array_iter,
DBUS_TYPE_STRING, &params[i]);
                }
                dbus_message_iter_close_container(&iter, &array_iter);

                if (!dbus_connection_send(bus_conn, msg, 0))
                {
                        g_critical("Out Of Memory!");
                        return -3
                }

======================= Receiver code ==============

DBusConnection *connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
        if(!connection)
        {
                g_critical("Failed to connect to D-Bus Daemon: !");
                return -1;
        }
gchar match_str1[MAX_SIZE] =  "type='signal',interface='";
g_strlcat(match_str1, APP_MGR_DBUS_INTERFACE, MAX_SIZE);
g_strlcat(match_str1, "'", MAX_SIZE);
dbus_bus_add_match (appclient_context.bus_conn, match_str1, NULL);

dbus_connection_add_filter (appclient_context.bus_conn, message_func, NULL,
NULL);

---------------------------- message_func ---------

static DBusHandlerResult
message_func (DBusConnection *bus_conn, DBusMessage *msg, gpointer
user_data)
{
    if (dbus_message_is_signal (msg, dbus_interface,
APP_MGR_DBUS_SIGNAL_EXEC))
        {
                if(appclient_context.exec_callback!=NULL) {
                        DBusMessageIter iter, array_iter;
                        guint no_of_param,i;
                        gchar *temp=NULL;
                        gchar **params_list=NULL;

                        dbus_message_iter_init(msg, &iter);
                        dbus_message_iter_get_basic(&iter, &no_of_param);
                        dbus_message_iter_next(&iter);

                        if(((params_list = (gchar
**)g_malloc0(((sizeof(gchar *))* no_of_param))) == NULL)) {
                                 ("Out Of Memory!");
                                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
                        }
                        if(no_of_param != 0)
                        {
                                dbus_message_iter_recurse(&iter,
&array_iter);
                                for(i=0; i<no_of_param;i++)
                                {


dbus_message_iter_get_basic(&array_iter, &temp);
                                        if(((params_list[i] = (gchar
*)g_malloc0(strlen(temp) + 1 )) == NULL)) {
                                                CLP_APPMGR_WARN("Out Of
Memory!");
                                                CLP_APPMGR_EXIT_FUNCTION();
                                                return
DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
                                        }

                                        g_stpcpy (params_list[i], temp);
                                        CLP_APPMGR_INFO_V("Restore ( Param
%u : %s )",i, params_list[i] );
                                        dbus_message_iter_next(&array_iter);
                                }
                        }
                        (appclient_context.exec_callback)(no_of_param,
params_list);

                        for(i=0;i<no_of_param;i++)
                                g_free(params_list[i]);
                        g_free(params_list);
                }
        }





Cheers,
- Kaustubh



On Thu, Feb 26, 2009 at 2:21 PM, Thiago Macieira <thiago at kde.org> wrote:

> Em Quinta-feira 26 Fevereiro 2009, às 08:24:34, Kaustubh Atrawalkar
> escreveu:
> > I am using normal g_mail_loop for events integration in receiver side.
> And
> > the regular method of add_match & add_filter to poll on signals and read
> > them. I was too suspecting on the socket getting full but I added some
> > prints in - _dbus_connection_get_dispatch_status_unlocked . But can see
> > number "6" most of the time as number of incoming connections.
> > How can i avoid though if socket is getting full sometimes?
>
> Sorry, I didn't understand one thing: are you using the dbus-glib binding
> or
> not?
>
> You mentioned integrating to g_main_loop, but you also said you were doing
> the
> integration work yourself. If that's the case, why are you integrating with
> glib yourself instead of using the binding?
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>   Senior Product Manager - Nokia, Qt Software
>       PGP/GPG: 0x6EF45358; fingerprint:
>      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090226/9d8b4767/attachment-0001.htm 


More information about the dbus mailing list