RIL: Added ril_globals structure (currently holds dispatch variables)
authorPaul Kocialkowski <contact@paulk.fr>
Wed, 25 Jul 2012 17:15:08 +0000 (19:15 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Wed, 25 Jul 2012 18:08:15 +0000 (20:08 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
hayes-ril.c
hayes-ril.h

index d37ea47..262fa28 100644 (file)
 #define RIL_VERSION_STRING "Hayes RIL"
 
 struct ril_device *ril_device;
-pthread_t ril_dispatch_thread;
+struct ril_globals ril_globals;
 
 struct ril_dispatch_unsol ril_dispatch_unsol[] = {};
 
-int ril_dispatch_unsol_count = sizeof(ril_dispatch_unsol) / sizeof(struct ril_dispatch_unsol);
-
 const char *ril_get_version(void)
 {
        return RIL_VERSION_STRING;
@@ -68,9 +66,9 @@ void *ril_dispatch(void *data)
 
                        rc = at_response_expect_to_func(response);
                        if(rc < 0) {
-                               for(j=0 ; j < ril_dispatch_unsol_count ; j++) {
-                                       if(at_commands_compare(response->command, ril_dispatch_unsol[j].command) && ril_dispatch_unsol[j].func != NULL) {
-                                               ril_dispatch_unsol[j].func(response);
+                               for(j=0 ; j < ril_globals.dispatch_unsol_count ; j++) {
+                                       if(at_commands_compare(response->command, ril_globals.dispatch_unsol[j].command) && ril_globals.dispatch_unsol[j].func != NULL) {
+                                               ril_globals.dispatch_unsol[j].func(response);
                                        }
                                }
                        }
@@ -94,7 +92,7 @@ int ril_dispatch_thread_start(void)
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
-       rc = pthread_create(&ril_dispatch_thread, &attr, ril_dispatch, NULL);
+       rc = pthread_create(&ril_globals.dispatch_thread, &attr, ril_dispatch, NULL);
        if(rc != 0) {
                LOGE("Creating dispatch thread failed!");
                return -1;
@@ -105,6 +103,12 @@ int ril_dispatch_thread_start(void)
 
 void ril_globals_init(void)
 {
+       memset(&ril_globals, 0, sizeof(struct ril_globals));
+       ril_globals.dispatch_unsol = &ril_dispatch_unsol;
+       ril_globals.dispatch_unsol_count = sizeof(ril_dispatch_unsol) / sizeof(struct ril_dispatch_unsol);
+
+       LOGE("Registered %d unsol requests handlers", ril_globals.dispatch_unsol_count);
+
        at_responses_handling_init();
 }
 
index 09471b8..04b99d2 100644 (file)
 #ifndef _HAYES_RIL_H_
 #define _HAYES_RIL_H_
 
+/*
+ * Defines
+ */
+
 #define RIL_DEVICE_LOCK(ril_device_p) pthread_mutex_lock(&(ril_device_p->handlers->transport->mutex));
 #define RIL_DEVICE_UNLOCK(ril_device_p) pthread_mutex_unlock(&(ril_device_p->handlers->transport->mutex));
 
 #define DEV_GSM                RIL_DEVICE_TYPE_GSM
 #define DEV_CDMA       RIL_DEVICE_TYPE_CDMA
 
-extern struct ril_device *ril_device;
+/*
+ * Variables structures
+ */
 
+// Device
 enum ril_device_type {
        RIL_DEVICE_TYPE_GSM,
        RIL_DEVICE_TYPE_CDMA
@@ -79,11 +86,25 @@ struct ril_device {
        struct ril_device_handlers *handlers;
 };
 
+extern struct ril_device *ril_device;
+
+// RIL
 struct ril_dispatch_unsol {
        char *command;
        void (*func)(struct at_response *response);
 };
 
+struct ril_globals {
+       // Dispatch
+       pthread_t dispatch_thread;
+       struct ril_dispatch_unsol *dispatch_unsol;
+       int dispatch_unsol_count;
+};
+
+/*
+ * Functions
+ */
+
 // Device
 void ril_device_register(struct ril_device **ril_device_p);
 int ril_device_init(struct ril_device *ril_device_p);