Always use semi-colon at the end of macro to avoid missleading
[platform/core/telephony/tel-plugin-imc.git] / src / desc.c
index 52181b1..62b4065 100644 (file)
 #include <sys/utsname.h>
 #include <glib.h>
 #include <tcore.h>
+#include <server.h>
 #include <plugin.h>
 #include <core_object.h>
 #include <hal.h>
 #include <at.h>
+#include <server.h>
 
 #include "s_network.h"
 #include "s_modem.h"
 #include "s_phonebook.h"
 #include "s_gps.h"
 
-static gboolean on_load()
-{
-       dbg("i'm load!");
-
-       return TRUE;
-}
-
 static void on_confirmation_modem_message_send(TcorePending *p,
                                                gboolean result,
                                                void *user_data)
@@ -57,29 +52,43 @@ static void on_confirmation_modem_message_send(TcorePending *p,
        dbg("%s", result == FALSE ? "SEND FAIL" : "SEND OK");
 }
 
-static void on_response_bootup_subscription(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_response_bootup_subscription(TcorePending *p,
+                                                       int data_len, const void *data, void *user_data)
 {
-       TcorePlugin *plugin = user_data;
        const TcoreATResponse *resp = data;
-
        dbg("Entry");
 
        if (resp->success > 0) {
-               dbg("result OK");
+               dbg("RESULT - OK");
        } else {
-               dbg("result ERROR");
+               err("RESULT - ERROR");
        }
+}
+
+static void on_response_last_bootup_subscription(TcorePending *p,
+                                                       int data_len, const void *data, void *user_data)
+{
+       const TcoreATResponse *resp = data;
+       gboolean ret;
+       dbg("Last Subscription - COMPLETED");
 
-       if (plugin != NULL)
-               modem_power_on(plugin);
+       if (resp->success) {
+               dbg("RESULT - OK");
+       } else {
+               err("RESULT - FAIL");
+       }
+
+       dbg("Boot-up configration completed for IMC modem. %s",
+                               "Bring CP to ONLINE state based on Flightmode status");
+       ret = modem_power_on(tcore_pending_ref_plugin(p));
+       dbg("Modem Power ON: [%s]", (ret == TRUE ? "SUCCESS" : "FAIL"));
 }
 
-static void modem_subscribe_events(TcorePlugin *plugin)
+static void _modem_subscribe_events(TcorePlugin *plugin)
 {
        CoreObject *co_call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
        CoreObject *co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
        CoreObject *co_sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS);
-       CoreObject *co_modem = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM);
        CoreObject *co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
        CoreObject *co_ps = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PS);
        CoreObject *co_sap = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAP);
@@ -87,98 +96,101 @@ static void modem_subscribe_events(TcorePlugin *plugin)
 
        dbg("Entry");
 
-       /* XCALLSTAT subscription */
+       /* URC Subscriptions per Module */
+
+       /****** SIM subscriptions ******/
+       /* XSIMSTATE  */
+       tcore_prepare_and_send_at_request(co_sim, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
+                                               on_response_bootup_subscription, NULL,
+                                               on_confirmation_modem_message_send, NULL);
+
+       /****** CALL subscriptions ******/
+       /* XCALLSTAT */
        tcore_prepare_and_send_at_request(co_call, "at+xcallstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* XSIMSTATE subscription */
-       tcore_prepare_and_send_at_request(co_sim, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
+       /* CSSN */
+       tcore_prepare_and_send_at_request(co_call, "at+cssn=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       tcore_prepare_and_send_at_request(co_sms, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
+       /* CUSD */
+       tcore_prepare_and_send_at_request(co_call, "at+cusd=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
-       tcore_prepare_and_send_at_request(co_modem, "at+xsimstate=1", NULL, TCORE_AT_NO_RESULT, NULL,
+
+       /* CLIP */
+       tcore_prepare_and_send_at_request(co_call, "at+clip=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* CREG subscription */
+       /****** NETWORK subscriptions ******/
+       /* CREG */
        tcore_prepare_and_send_at_request(co_network, "at+creg=2", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* CGREG subscription */
+       /* CGREG */
        tcore_prepare_and_send_at_request(co_network, "at+cgreg=2", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* Allow automatic time Zone updation via NITZ */
+       /* Allow Automatic Time Zone updation via NITZ */
        tcore_prepare_and_send_at_request(co_network, "at+ctzu=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* TZ, time & daylight changing event reporting subscription */
+       /* TZ, Time & Daylight changing event reporting Subscription */
        tcore_prepare_and_send_at_request(co_network, "at+ctzr=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* XMER subscription */
+       /* XMER */
        tcore_prepare_and_send_at_request(co_network, "at+xmer=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* CGEREP subscription */
+       /****** PS subscriptions ******/
+       /* CGEREP */
        tcore_prepare_and_send_at_request(co_ps, "at+cgerep=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* XDATASTAT subscription */
+       /* XDATASTAT */
        tcore_prepare_and_send_at_request(co_ps, "at+xdatastat=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* CSSN subscription */
-       tcore_prepare_and_send_at_request(co_call, "at+cssn=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
-                                               on_response_bootup_subscription, NULL,
-                                               on_confirmation_modem_message_send, NULL);
-
-       /* CUSD subscription */
-       tcore_prepare_and_send_at_request(co_call, "at+cusd=1", NULL, TCORE_AT_NO_RESULT, NULL,
-                                               on_response_bootup_subscription, NULL,
-                                               on_confirmation_modem_message_send, NULL);
 
-       /* XDNS subscription */
+       /* XDNS */
        tcore_prepare_and_send_at_request(co_ps, "at+xdns=1,1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* CLIP subscription */
-       tcore_prepare_and_send_at_request(co_call, "at+clip=1", NULL, TCORE_AT_NO_RESULT, NULL,
-                                               on_response_bootup_subscription, NULL,
-                                               on_confirmation_modem_message_send, NULL);
-
-       /*CMEE subscription for ps*/
+       /* CMEE */
        tcore_prepare_and_send_at_request(co_ps, "at+cmee=2", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /*CMEE subscription for sms*/
+       /****** SMS subscriptions ******/
+       /* CMEE */
        tcore_prepare_and_send_at_request(co_sms, "at+cmee=2", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /*incoming sms,cb,status report subscription*/
+       /* Incoming SMS, Cell Broadcast, Status Report Subscription */
        tcore_prepare_and_send_at_request(co_sms, "at+cnmi=1,2,2,1,0", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* XBCSTAT subscription */
-       tcore_prepare_and_send_at_request(co_sap, "at+xbcstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
-                                               on_response_bootup_subscription, NULL, 
+       /* Text/PDU mode Subscription */
+       tcore_prepare_and_send_at_request(co_sms, "at+cmgf=0", NULL, TCORE_AT_NO_RESULT, NULL,
+                                               on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
-       /* AGPS- assist data and reset assist data subscription */
+
+       /****** GPS subscriptions ******/
+       /* AGPS- Assist Data and Reset Assist Data Subscription */
        tcore_prepare_and_send_at_request(co_gps, "at+cposr=1", NULL, TCORE_AT_NO_RESULT, NULL,
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
@@ -187,14 +199,16 @@ static void modem_subscribe_events(TcorePlugin *plugin)
                                                on_response_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
-       /* text/pdu mode subscription*/
-       tcore_prepare_and_send_at_request(co_sms, "at+cmgf=0", NULL, TCORE_AT_NO_RESULT, NULL,
-                                               on_response_bootup_subscription, plugin,
+       /****** SAP subscriptions ******/
+       /* XBCSTAT */
+       tcore_prepare_and_send_at_request(co_sap, "at+xbcstat=1", NULL, TCORE_AT_NO_RESULT, NULL,
+                                               on_response_last_bootup_subscription, NULL,
                                                on_confirmation_modem_message_send, NULL);
 
        dbg("Exit");
 }
 
+/* Initializer Table */
 struct object_initializer init_table = {
        .modem_init = s_modem_init,
        .sim_init = s_sim_init,
@@ -209,6 +223,7 @@ struct object_initializer init_table = {
        .gps_init = s_gps_init,
 };
 
+/* Deinitializer Table */
 struct object_deinitializer deinit_table = {
        .modem_deinit = s_modem_exit,
        .sim_deinit = s_sim_exit,
@@ -223,34 +238,45 @@ struct object_deinitializer deinit_table = {
        .gps_deinit = s_gps_exit,
 };
 
+static gboolean on_load()
+{
+       dbg("Load!!!");
+
+       return TRUE;
+}
+
 static gboolean on_init(TcorePlugin *p)
 {
-       if (!p)
+       dbg("Init!!!");
+       if (p == NULL)
                return FALSE;
 
+       /* Initialize Modules (Core Objects) */
        if (tcore_object_init_objects(p, &init_table)
                        != TCORE_RETURN_SUCCESS) {
                err("Failed to initialize Core Objects");
                return FALSE;
        }
 
-       dbg("i'm init!");
-
-       modem_subscribe_events(p);
+       /* Subscribe for the Events from CP */
+       _modem_subscribe_events(p);
 
+       dbg("Init - Successful");
        return TRUE;
 }
 
 static void on_unload(TcorePlugin *p)
 {
-       if (!p)
+       dbg("Unload!!!");
+
+       if (p == NULL)
                return;
 
+       /* Deinitialize Modules (Core Objects) */
        tcore_object_deinit_objects(p, &deinit_table);
-
-       dbg("i'm unload");
 }
 
+/* IMC - Modem Plug-in Descriptor */
 struct tcore_plugin_define_desc plugin_define_desc = {
        .name = "IMC",
        .priority = TCORE_PLUGIN_PRIORITY_MID,