Device: Give more explicit names (based on handlers) to the functions
authorPaul Kocialkowski <contact@paulk.fr>
Thu, 30 Aug 2012 17:06:53 +0000 (19:06 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Thu, 30 Aug 2012 17:06:53 +0000 (19:06 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
at.c
device.c
hayes-ril.c
hayes-ril.h

diff --git a/at.c b/at.c
index 541766c..b4c5018 100644 (file)
--- a/at.c
+++ b/at.c
@@ -1718,7 +1718,7 @@ int at_request_send(struct at_request *request)
        ril_send_log(request);
        RIL_LOG_UNLOCK();
 
-       ril_device_send(ril_device, string, length);
+       ril_device_transport_send(ril_device, string, length);
 
        free(string);
 
index 9265a6f..9872ab8 100644 (file)
--- a/device.c
+++ b/device.c
 
 #include <hayes-ril.h>
 
+/*
+ * Global
+ */
+
 int ril_device_init(struct ril_device *ril_device_p)
 {
        int rc;
@@ -39,13 +43,13 @@ int ril_device_init(struct ril_device *ril_device_p)
                return -1;
        }
 
-       rc = ril_device_boot(ril_device_p);
+       rc = ril_device_power_boot(ril_device_p);
        if(rc < 0) {
                LOGE("Failed to boot device!");
                return -1;
        }
 
-       rc = ril_device_open(ril_device_p);
+       rc = ril_device_transport_open(ril_device_p);
        if(rc < 0) {
                LOGE("Failed to open device!");
                return -1;
@@ -56,7 +60,7 @@ int ril_device_init(struct ril_device *ril_device_p)
 
 int ril_device_deinit(struct ril_device *ril_device_p)
 {
-       ril_device_close(ril_device_p);
+       ril_device_transport_close(ril_device_p);
 
        ril_device_power_off(ril_device_p);
 
@@ -163,7 +167,11 @@ int ril_device_data_destroy(struct ril_device *ril_device_p)
        return 0;
 }
 
-int ril_device_boot(struct ril_device *ril_device_p)
+/*
+ * Power
+ */
+
+int ril_device_power_on(struct ril_device *ril_device_p)
 {
        int rc;
 
@@ -177,18 +185,18 @@ int ril_device_boot(struct ril_device *ril_device_p)
                return -1;
        }
 
-       if(ril_device_p->handlers->power->boot == NULL) {
-               LOGE("Missing device power boot handler!");
+       if(ril_device_p->handlers->power->power_on == NULL) {
+               LOGE("Missing device power on handler!");
                return -1;
        }
 
-       LOGD("Booting modem...");
+       LOGD("Powering modem on...");
 
-       rc = ril_device_p->handlers->power->boot(ril_device_p->handlers->power->sdata);
+       rc = ril_device_p->handlers->power->power_on(ril_device_p->handlers->power->sdata);
        return rc;
 }
 
-int ril_device_power_on(struct ril_device *ril_device_p)
+int ril_device_power_off(struct ril_device *ril_device_p)
 {
        int rc;
 
@@ -202,18 +210,18 @@ int ril_device_power_on(struct ril_device *ril_device_p)
                return -1;
        }
 
-       if(ril_device_p->handlers->power->power_on == NULL) {
-               LOGE("Missing device power on handler!");
+       if(ril_device_p->handlers->power->power_off == NULL) {
+               LOGE("Missing device power off handler!");
                return -1;
        }
 
-       LOGD("Powering modem on...");
+       LOGD("Powering modem off...");
 
-       rc = ril_device_p->handlers->power->power_on(ril_device_p->handlers->power->sdata);
+       rc = ril_device_p->handlers->power->power_off(ril_device_p->handlers->power->sdata);
        return rc;
 }
 
-int ril_device_power_off(struct ril_device *ril_device_p)
+int ril_device_power_boot(struct ril_device *ril_device_p)
 {
        int rc;
 
@@ -227,18 +235,23 @@ int ril_device_power_off(struct ril_device *ril_device_p)
                return -1;
        }
 
-       if(ril_device_p->handlers->power->power_off == NULL) {
-               LOGE("Missing device power off handler!");
+       if(ril_device_p->handlers->power->boot == NULL) {
+               LOGE("Missing device power boot handler!");
                return -1;
        }
 
-       LOGD("Powering modem off...");
+       LOGD("Booting modem...");
 
-       rc = ril_device_p->handlers->power->power_off(ril_device_p->handlers->power->sdata);
+       rc = ril_device_p->handlers->power->boot(ril_device_p->handlers->power->sdata);
        return rc;
 }
 
-int ril_device_open(struct ril_device *ril_device_p)
+/*
+ * Transport
+ */
+
+
+int ril_device_transport_open(struct ril_device *ril_device_p)
 {
        int rc;
 
@@ -263,7 +276,7 @@ int ril_device_open(struct ril_device *ril_device_p)
        return rc;
 }
 
-int ril_device_close(struct ril_device *ril_device_p)
+int ril_device_transport_close(struct ril_device *ril_device_p)
 {
        int rc;
 
@@ -288,7 +301,7 @@ int ril_device_close(struct ril_device *ril_device_p)
        return rc;
 }
 
-int ril_device_send(struct ril_device *ril_device_p, void *data, int length)
+int ril_device_transport_send(struct ril_device *ril_device_p, void *data, int length)
 {
        int rc;
 
@@ -314,7 +327,7 @@ int ril_device_send(struct ril_device *ril_device_p, void *data, int length)
        return rc;
 }
 
-int ril_device_recv(struct ril_device *ril_device_p, void **data, int length)
+int ril_device_transport_recv(struct ril_device *ril_device_p, void **data, int length)
 {
        int rc;
 
@@ -340,7 +353,7 @@ int ril_device_recv(struct ril_device *ril_device_p, void **data, int length)
        return rc;
 }
 
-int ril_device_recv_poll(struct ril_device *ril_device_p)
+int ril_device_transport_recv_poll(struct ril_device *ril_device_p)
 {
        int rc;
 
@@ -363,7 +376,7 @@ int ril_device_recv_poll(struct ril_device *ril_device_p)
        return rc;
 }
 
-int ril_device_recv_loop(struct ril_device *ril_device_p)
+int ril_device_transport_recv_loop(struct ril_device *ril_device_p)
 {
        struct at_response **responses = NULL;
        int responses_count = 0;
@@ -377,7 +390,7 @@ int ril_device_recv_loop(struct ril_device *ril_device_p)
        // Return error after 5 consecutive poll/read failures
        for(i=5 ; i > 0 ; i--) {
                while(1) {
-                       rc = ril_device_recv_poll(ril_device_p);
+                       rc = ril_device_transport_recv_poll(ril_device_p);
                        if(rc < 0) {
                                LOGE("Polling from transport recv failed!");
                                break;
@@ -385,7 +398,7 @@ int ril_device_recv_loop(struct ril_device *ril_device_p)
 
                        length = rc;
 
-                       rc = ril_device_recv(ril_device_p, &data, length);
+                       rc = ril_device_transport_recv(ril_device_p, &data, length);
                        if(rc <= 0 || data == NULL) {
                                LOGE("Reading from transport recv failed!");
                                break;
@@ -433,9 +446,9 @@ int ril_device_recv_loop(struct ril_device *ril_device_p)
                }
 
                // When poll/read failed, close and reopen the device
-               ril_device_close(ril_device_p);
+               ril_device_transport_close(ril_device_p);
                usleep(500);
-               ril_device_open(ril_device_p);
+               ril_device_transport_open(ril_device_p);
 
                RIL_DEVICE_UNLOCK(ril_device_p);
        }
@@ -443,14 +456,14 @@ int ril_device_recv_loop(struct ril_device *ril_device_p)
        return -1;
 }
 
-void *ril_device_recv_thread(void *data)
+void *ril_device_transport_recv_thread(void *data)
 {
        struct ril_device *ril_device_p = (struct ril_device *) data;
        int rc;
        int i;
 
        for(i = 5 ; i > 0 ; i--) {
-               rc = ril_device_recv_loop(ril_device_p);
+               rc = ril_device_transport_recv_loop(ril_device_p);
                if(rc < 0) {
                        LOGE("Recv loop failed too many times, restarting...");
 
@@ -472,7 +485,7 @@ void *ril_device_recv_thread(void *data)
        return NULL;
 }
 
-int ril_device_recv_thread_start(struct ril_device *ril_device_p)
+int ril_device_transport_recv_thread_start(struct ril_device *ril_device_p)
 {
        pthread_attr_t attr;
        int rc;
@@ -490,7 +503,7 @@ int ril_device_recv_thread_start(struct ril_device *ril_device_p)
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
-       rc = pthread_create(&(ril_device_p->handlers->transport->recv_thread), &attr, ril_device_recv_thread, (void *) ril_device_p);
+       rc = pthread_create(&(ril_device_p->handlers->transport->recv_thread), &attr, ril_device_transport_recv_thread, (void *) ril_device_p);
        if(rc != 0) {
                LOGE("Creating transport recv thread failed!");
                return -1;
index e03a510..84ac480 100644 (file)
@@ -209,9 +209,9 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **a
                return NULL;
        }
 
-       rc = ril_device_recv_thread_start(ril_device);
+       rc = ril_device_transport_recv_thread_start(ril_device);
        if(rc < 0) {
-               LOGE("Failed to start device thread!");
+               LOGE("Failed to start device recv thread!");
                ril_device_deinit(ril_device);
 
                return NULL;
index 51f9c04..8b4a1a2 100644 (file)
@@ -124,16 +124,15 @@ int ril_device_deinit(struct ril_device *ril_device_p);
 
 int ril_device_data_create(struct ril_device *ril_device_p);
 int ril_device_data_destroy(struct ril_device *ril_device_p);
-int ril_device_boot(struct ril_device *ril_device_p);
-int ril_device_boot(struct ril_device *ril_device_p);
 int ril_device_power_on(struct ril_device *ril_device_p);
 int ril_device_power_off(struct ril_device *ril_device_p);
-int ril_device_open(struct ril_device *ril_device_p);
-int ril_device_close(struct ril_device *ril_device_p);
-int ril_device_send(struct ril_device *ril_device_p, void *data, int length);
-int ril_device_recv(struct ril_device *ril_device_p, void **data, int length);
-int ril_device_recv_poll(struct ril_device *ril_device_p);
-int ril_device_recv_thread_start(struct ril_device *ril_device_p);
+int ril_device_power_boot(struct ril_device *ril_device_p);
+int ril_device_transport_open(struct ril_device *ril_device_p);
+int ril_device_transport_close(struct ril_device *ril_device_p);
+int ril_device_transport_send(struct ril_device *ril_device_p, void *data, int length);
+int ril_device_transport_recv(struct ril_device *ril_device_p, void **data, int length);
+int ril_device_transport_recv_poll(struct ril_device *ril_device_p);
+int ril_device_transport_recv_thread_start(struct ril_device *ril_device_p);
 
 // Utils
 char *ril_status_string(int status);