[maemo-commits] [maemo-commits] r8607 - projects/haf/trunk/libosso/src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Dec 4 17:36:28 EET 2006
Author: kihamala
Date: 2006-12-04 17:36:27 +0200 (Mon, 04 Dec 2006)
New Revision: 8607

Modified:
   projects/haf/trunk/libosso/src/osso-hw.c
   projects/haf/trunk/libosso/src/osso-init.c
   projects/haf/trunk/libosso/src/osso-internal.h
Log:
implemented handler_id code


Modified: projects/haf/trunk/libosso/src/osso-hw.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-hw.c	2006-12-04 15:32:45 UTC (rev 8606)
+++ projects/haf/trunk/libosso/src/osso-hw.c	2006-12-04 15:36:27 UTC (rev 8607)
@@ -732,7 +732,8 @@
                                          _osso_handler_f *event_cb,
                                          int event_type,
                                          muali_handler_t *user_handler,
-                                         void *user_data)
+                                         void *user_data,
+                                         int handler_id)
 {
         DBusError error;
         _osso_callback_data_t *cb_data;
@@ -788,15 +789,12 @@
                 return MUALI_ERROR;
         }
 
-        _msg_handler_set_cb_f((osso_context_t*)context,
-                              service,
-                              object_path,
-                              interface,
-                              event_cb,
-                              cb_data, FALSE);
+        if (_muali_set_handler(context, event_cb, cb_data, handler_id)) {
+                return MUALI_ERROR_SUCCESS;
+        } else {
+                return MUALI_ERROR;
+        }
 
-        return MUALI_ERROR_SUCCESS;
-
 _set_handler_oom1:
         free(cb_data->interface);
 _set_handler_oom2:
@@ -866,6 +864,7 @@
         const char *service = NULL, *object_path = NULL,
                    *interface = NULL;
         char *match = NULL;
+        int new_handler_id;
 
         ULOG_DEBUG_F("entered");
 
@@ -879,6 +878,8 @@
                 return MUALI_ERROR_INVALID;
         }
 
+        new_handler_id = context->next_handler_id++;
+
         if (info != NULL) {
                 muali_error_t ret;
 
@@ -897,11 +898,12 @@
                                      event_cb,
                                      0, /* event_type ignored */
                                      handler,
-                                     user_data);
+                                     user_data,
+                                     new_handler_id);
                 } else {
                         error = ret;
                 }
-                *handler_id = 0;  /* TODO */
+                *handler_id = new_handler_id;
                 return error;
         }
 
@@ -925,15 +927,28 @@
                                              event_cb,
                                              event_type,
                                              handler,
-                                             user_data);
+                                             user_data,
+                                             new_handler_id);
+
                         if (event_type == MUALI_EVENT_LOWMEM_BOTH
                             && error == MUALI_ERROR_SUCCESS) {
-                                error = muali_set_event_handler(context,
-                                                NULL,
-                                                MUALI_EVENT_LOWMEM_ON,
-                                                handler,
-                                                user_data,
-                                                handler_id);
+                                /* set lowmem_on handler with the same
+                                 * handler id */
+                                object_path = USER_LOWMEM_ON_SIGNAL_OP;
+                                interface = USER_LOWMEM_ON_SIGNAL_IF;
+                                match = "type='signal',interface='"
+                                        USER_LOWMEM_ON_SIGNAL_IF "'";
+                                error = _set_handler(context,
+                                                     service,
+                                                     object_path,
+                                                     interface,
+                                                     NULL,
+                                                     match,
+                                                     event_cb,
+                                                     event_type,
+                                                     handler,
+                                                     user_data,
+                                                     new_handler_id);
                         }
                         break;
                 case MUALI_EVENT_LOWMEM_ON:
@@ -952,12 +967,13 @@
                                              event_cb,
                                              event_type,
                                              handler,
-                                             user_data);
+                                             user_data,
+                                             new_handler_id);
                         break;
                 default:
                         ULOG_ERR_F("unknown event type %d", event_type);
                         error = MUALI_ERROR_INVALID;
         }
-        *handler_id = 0;  /* TODO */
+        *handler_id = new_handler_id;
         return error;
 }

Modified: projects/haf/trunk/libosso/src/osso-init.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-init.c	2006-12-04 15:32:45 UTC (rev 8606)
+++ projects/haf/trunk/libosso/src/osso-init.c	2006-12-04 15:36:27 UTC (rev 8607)
@@ -302,6 +302,7 @@
     }
     osso->cp_plugins = g_array_new(FALSE, FALSE, sizeof(_osso_cp_plugin_t));
     osso->rpc_timeout = -1;
+    osso->next_handler_id = 1;
     return osso;
 }
 
@@ -731,7 +732,7 @@
     return TRUE;
 }
 
-static gboolean set_handler_helper(osso_context_t *osso,
+static int set_handler_helper(osso_context_t *osso,
                                    const char *service,
                                    const char *object_path,
                                    const char *interface,
@@ -749,13 +750,14 @@
     handler = calloc(1, sizeof(_osso_handler_t));
     if (handler == NULL) {
         ULOG_ERR_F("calloc() failed");
-        return FALSE;
+        return 0;
     }
 
     handler->handler = cb;
     handler->data = data;
     handler->method = method;
     handler->can_free_data = can_free_data;
+    handler->handler_id = osso->next_handler_id++;
 
     /* warn about the old element if it exists */
     old = g_hash_table_lookup(osso->uniq_hash, uniq_key);
@@ -783,7 +785,7 @@
         if (new_elem == NULL) {
             ULOG_ERR_F("calloc() failed");
             free(handler);
-            return FALSE;
+            return 0;
         }
 
         new_key = strdup(uniq_key);
@@ -791,14 +793,19 @@
             ULOG_ERR_F("strdup() failed");
             free(handler);
             free(new_elem);
-            return FALSE;
+            return 0;
         }
 
         new_elem->handlers = g_list_append(NULL, handler);
 
         g_hash_table_insert(osso->uniq_hash, new_key, new_elem);
     }
-    return add_to_if_hash(osso, handler, interface);
+
+    if (add_to_if_hash(osso, handler, interface)) {
+        return handler->handler_id;
+    } else {
+        return 0;
+    }
 }
 
 void __attribute__ ((visibility("hidden")))

Modified: projects/haf/trunk/libosso/src/osso-internal.h
===================================================================
--- projects/haf/trunk/libosso/src/osso-internal.h	2006-12-04 15:32:45 UTC (rev 8606)
+++ projects/haf/trunk/libosso/src/osso-internal.h	2006-12-04 15:36:27 UTC (rev 8607)
@@ -159,6 +159,8 @@
     osso_hw_state_t hw_state;
     guint rpc_timeout;
     GArray *cp_plugins;
+    int next_handler_id;    /* next available handler id, unique in this
+                               context */
 } _osso_af_context_t, _muali_context_t;
 
 typedef struct _muali_context_t {
@@ -184,6 +186,8 @@
     osso_hw_state_t hw_state;
     guint rpc_timeout;
     GArray *cp_plugins;
+    int next_handler_id;    /* next available handler id, unique in this
+                               context */
 } _muali_this_type_is_not_used_t;
 
 # ifdef LIBOSSO_DEBUG


More information about the maemo-commits mailing list