Initial refactoring merge 95/19095/1 accepted/tizen_3.0.2014.q3_common accepted/tizen_3.0.m14.3_ivi accepted/tizen_generic accepted/tizen_ivi_panda tizen_3.0.2014.q3_common tizen_3.0.2014.q4_common tizen_3.0.2015.q1_common tizen_3.0.m14.2_ivi tizen_3.0.m14.3_ivi tizen_3.0_ivi accepted/tizen/generic/20140408.094833 accepted/tizen/ivi/20140410.192339 accepted/tizen/ivi/panda/20140408.203158 accepted/tizen/mobile/20140409.082611 submit/tizen/20140408.080522 submit/tizen_mobile/20141120.000000 tizen_3.0.2014.q3_common_release tizen_3.0.m14.2_ivi_release tizen_3.0.m14.3_ivi_release tizen_3.0_ivi_release
authorDongchul Lim <dc7.lim@samsung.com>
Mon, 7 Apr 2014 10:51:38 +0000 (19:51 +0900)
committerDongchul Lim <dc7.lim@samsung.com>
Mon, 7 Apr 2014 10:51:55 +0000 (19:51 +0900)
Change-Id: I68ddef83fb976f5df38434bfafa1b152d67b7c2c

AUTHORS [deleted file]
packaging/tel-plugin-indicator.spec
src/desc-indicator.c [changed mode: 0644->0755]

diff --git a/AUTHORS b/AUTHORS
deleted file mode 100644 (file)
index 0e9faa9..0000000
--- a/AUTHORS
+++ /dev/null
@@ -1,6 +0,0 @@
-Jongman Park <jman.park@samsung.com>
-Ja-young Gu <jygu@samsung.com>
-Kyeongchul Kim <kyeongchul.kim@samsung.com>
-DongHoo Park <donghoo.park@samsung.>
-Youngman Park <youngman.park@samsung.com>
-Inho Oh <inho48.oh@samsung.com>
index b0a85e6..fe33031 100644 (file)
@@ -1,7 +1,11 @@
+%define major 3
+%define minor 0
+%define patchlevel 1
+
 Name:       tel-plugin-indicator
 Summary:    Telephony Indicator plugin
-Version:    0.1.8
-Release:    2
+Version:        %{major}.%{minor}.%{patchlevel}
+Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    tel-plugin-indicator-%{version}.tar.gz
old mode 100644 (file)
new mode 100755 (executable)
index 51abbf3..b57771f
@@ -1,9 +1,7 @@
 /*
  * tel-plugin-indicator
  *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: DongHoo Park <donghoo.park@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,7 +14,6 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
 
 #include <stdio.h>
@@ -52,90 +49,100 @@ typedef enum _indicator_state {
        INDICATOR_RXTX = 0x03,
 } indicator_state;
 
-struct indicator_device_state {
+typedef struct _indicator_device_state {
        gchar *devname;
        gboolean active;
        guint64 prev_rx;
        guint64 prev_tx;
        guint64 curr_rx;
        guint64 curr_tx;
-};
+}indicator_device_state;
 
-//global variable
-static struct  indicator_device_state indicator_info = {
-       NULL,FALSE,0,0,0,0
-};
+typedef struct _indicator_data {
+       indicator_device_state indicator_info;
+       GSource* src;
+}indicator_data;
 
-static GSource* src;
 static gboolean _indicator_update_callback(gpointer user_data);
 
-static void _indicator_initialize(Server *s)
+static void _indicator_initialize(indicator_data *data)
 {
-       indicator_info.prev_rx = 0;
-       indicator_info.prev_tx = 0;
-       indicator_info.curr_rx = 0;
-       indicator_info.curr_tx = 0;
+       if (data) {
+               data->indicator_info.prev_rx = 0;
+               data->indicator_info.prev_tx = 0;
+               data->indicator_info.curr_rx = 0;
+               data->indicator_info.curr_tx = 0;
+       } else {
+               err("user data is NULL");
+       }
 }
 
-static gboolean _indicator_start_updater(Server *s)
+
+static gboolean _indicator_start_updater(Server *s, TcorePlugin *plugin)
 {
-       Storage *strg_vconf;
-       gpointer vconf_handle;
+       TcoreStorage *strg_vconf;
+       indicator_data *data = NULL;
 
        dbg("indicator is started");
-
        strg_vconf = tcore_server_find_storage(s, "vconf");
-       vconf_handle = tcore_storage_create_handle(strg_vconf, "vconf");
-       if (!vconf_handle)
-               err("fail to create vconf db_handle");
+
+       data = tcore_plugin_ref_user_data(plugin);
+       if(!data) {
+               err("user data is NULL");
+               return FALSE;
+       }
 
        tcore_storage_set_int(strg_vconf, STORAGE_KEY_PACKET_SERVICE_STATE, CELLULAR_NORMAL_CONNECTED);
        tcore_storage_set_int(strg_vconf, STORAGE_KEY_PACKET_INDICATOR_STATE, INDICATOR_NORMAL);
 
-       if(src != 0)
+       if(data->src != 0) {
                return FALSE;
+       }
 
-       _indicator_initialize(s);
+       _indicator_initialize(data);
 
-       src = g_timeout_source_new_seconds(INDICATOR_UPDATE_INTERVAL);
-       g_source_set_callback(src, _indicator_update_callback, s, NULL);
-       g_source_set_priority(src, G_PRIORITY_HIGH);
-       g_source_attach(src, NULL);
-       g_source_unref(src);
+       data->src = g_timeout_source_new_seconds(INDICATOR_UPDATE_INTERVAL);
+       g_source_set_callback(data->src, _indicator_update_callback, plugin, NULL);
+       g_source_set_priority(data->src, G_PRIORITY_HIGH);
+       g_source_attach(data->src, NULL);
+       g_source_unref(data->src);
 
        return TRUE;
 }
 
-static gboolean _indicator_stop_updater(Server *s)
+static gboolean _indicator_stop_updater(Server *s, TcorePlugin *plugin)
 {
-       Storage *strg_vconf;
-       gpointer vconf_handle;
+       TcoreStorage *strg_vconf;
        int t_rx = 0, t_tx = 0;
+       indicator_data *data = NULL;
 
        dbg("indicator is stopped");
+       data = tcore_plugin_ref_user_data(plugin);
+       if (!data) {
+               err("user data is NULL");
+               return FALSE;
+       }
        strg_vconf = tcore_server_find_storage(s, "vconf");
-       vconf_handle = tcore_storage_create_handle(strg_vconf, "vconf");
-       if (!vconf_handle)
-               err("fail to create vconf db_handle");
 
        tcore_storage_set_int(strg_vconf, STORAGE_KEY_PACKET_SERVICE_STATE, CELLULAR_OFF);
        tcore_storage_set_int(strg_vconf, STORAGE_KEY_PACKET_INDICATOR_STATE, INDICATOR_NORMAL);
 
        t_rx = tcore_storage_get_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_TOTAL_RCV);
        t_tx = tcore_storage_get_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_TOTAL_SNT);
-       t_rx += (int)indicator_info.curr_rx;
-       t_tx += (int)indicator_info.curr_tx;
+       t_rx += (int)data->indicator_info.curr_rx;
+       t_tx += (int)data->indicator_info.curr_tx;
 
        tcore_storage_set_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_TOTAL_RCV, t_rx);
        tcore_storage_set_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_TOTAL_SNT, t_tx);
-       tcore_storage_set_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_LAST_RCV, (int)indicator_info.curr_rx);
-       tcore_storage_set_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_LAST_SNT, (int)indicator_info.curr_tx);
+       tcore_storage_set_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_LAST_RCV, (int)data->indicator_info.curr_rx);
+       tcore_storage_set_int(strg_vconf, STORAGE_KEY_CELLULAR_PKT_LAST_SNT, (int)data->indicator_info.curr_tx);
 
-       if(src == 0)
+       if(data->src == 0){
                return TRUE;
+       }
 
-       g_source_destroy(src);
-       src = 0;
+       g_source_destroy(data->src);
+       data->src = 0;
 
        return TRUE;
 }
@@ -186,13 +193,18 @@ static gint _indicator_get_pkt(gchar *buff, gint proc_ver, guint64 *rx_pkt, guin
        return result;
 }
 
-static gboolean _indicator_get_pktcnt(gpointer user_data)
+static gboolean _indicator_get_pktcnt(indicator_data *data)
 {
        FILE *pf = NULL;
        gint proc_ver = 0;
        char *res;
        gchar buff[INDICATOR_BUFF_SIZE];
 
+       if (!data) {
+               err("user data is NULL");
+               return FALSE;
+       }
+
        pf = fopen(INDICATOR_PROCFILE, "r");
        if (pf == NULL) {
                err("indicator fail to open file(%s), errno(%d)", INDICATOR_PROCFILE, errno);
@@ -226,11 +238,11 @@ static gboolean _indicator_get_pktcnt(gpointer user_data)
                        return FALSE;
                }
 
-               if ( g_strcmp0(ifname, indicator_info.devname) == 0 ){
-                       indicator_info.prev_rx = indicator_info.curr_rx;
-                       indicator_info.prev_tx = indicator_info.curr_tx;
-                       indicator_info.curr_rx = rx_pkt;
-                       indicator_info.curr_tx = tx_pkt;
+               if ( g_strcmp0(ifname, data->indicator_info.devname) == 0 ){
+                       data->indicator_info.prev_rx = data->indicator_info.curr_rx;
+                       data->indicator_info.prev_tx = data->indicator_info.curr_tx;
+                       data->indicator_info.curr_rx = rx_pkt;
+                       data->indicator_info.curr_tx = tx_pkt;
                        break;
                }
        }
@@ -239,22 +251,18 @@ static gboolean _indicator_get_pktcnt(gpointer user_data)
        return TRUE;
 }
 
-static gboolean _indicator_update(Server *s)
+static gboolean _indicator_update(Server *s, indicator_data *data)
 {
        guint64 rx_changes = 0;
        guint64 tx_changes = 0;
-       Storage *strg_vconf;
-       gpointer vconf_handle;
+       TcoreStorage *strg_vconf;
 
        strg_vconf = tcore_server_find_storage(s, "vconf");
-       vconf_handle = tcore_storage_create_handle(strg_vconf, "vconf");
-       if (!vconf_handle)
-               err("fail to create vconf db_handle");
+       if(!data) return FALSE;
+       if(!data->indicator_info.active) return FALSE;
 
-       if(!indicator_info.active) return FALSE;
-
-       rx_changes = indicator_info.curr_rx - indicator_info.prev_rx;
-       tx_changes = indicator_info.curr_tx - indicator_info.prev_tx;
+       rx_changes = data->indicator_info.curr_rx - data->indicator_info.prev_rx;
+       tx_changes = data->indicator_info.curr_tx - data->indicator_info.prev_tx;
 
        if (rx_changes != 0 || tx_changes != 0)
                tcore_storage_set_int(strg_vconf, STORAGE_KEY_PACKET_SERVICE_STATE, CELLULAR_USING);
@@ -276,83 +284,157 @@ static gboolean _indicator_update(Server *s)
 static gboolean _indicator_update_callback(gpointer user_data)
 {
        gboolean rv = FALSE;
+       TcorePlugin *indicator_plugin = NULL;
        Server *s = NULL;
+       indicator_data *data = NULL;
 
-       s = (Server *)user_data;
+       indicator_plugin = (TcorePlugin *)user_data;
+       s = tcore_plugin_ref_server(indicator_plugin);
+       data = tcore_plugin_ref_user_data(indicator_plugin);
+       if(!data){
+               err("user data is NULL");
+               return FALSE;
+       }
 
-       rv = _indicator_get_pktcnt(NULL);
+       rv = _indicator_get_pktcnt(data);
        if(!rv){
-               src = 0;
+               data->src = 0;
                return FALSE;
        }
 
-       rv = _indicator_update(s);
+       rv = _indicator_update(s, data);
        if(!rv){
-               src = 0;
+               data->src = 0;
                return FALSE;
        }
 
        return TRUE;
 }
 
-static enum tcore_hook_return __on_hook_powered(Server *s, CoreObject *source,
-               enum tcore_notification_command command, unsigned int data_len, void *data, void *user_data)
+static TcoreHookReturn __on_hook_modem_powered(TcorePlugin *source,
+       TcoreNotification command, guint data_len, void *data, void *user_data)
 {
-       struct tnoti_modem_power *modem_power = NULL;
+       TelModemPowerStatus *power_status = NULL;
 
        dbg("powered event called");
-       g_return_val_if_fail(data != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
-
-       modem_power = (struct tnoti_modem_power *)data;
-       if ( modem_power->state == MODEM_STATE_ERROR ){
-               indicator_info.active = FALSE;
-               g_free(indicator_info.devname);
-               indicator_info.devname = NULL;
-               _indicator_stop_updater(s);
+       tcore_check_return_value(data != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+
+       power_status = (TelModemPowerStatus *)data;
+       if (*power_status == TEL_MODEM_POWER_ERROR) {
+               Server *s = NULL;
+               indicator_data *data = NULL;
+               TcorePlugin *plugin = (TcorePlugin *)user_data;
+
+               data = tcore_plugin_ref_user_data(plugin);
+               if (data) {
+                       data->indicator_info.active = FALSE;
+                       g_free(data->indicator_info.devname);
+                       data->indicator_info.devname = NULL;
+                       s = tcore_plugin_ref_server(source);
+                       if (s) {
+                               _indicator_stop_updater(s, plugin);
+                       }
+               }else {
+                       err("user data is NULL");
+               }
        }
 
        return TCORE_HOOK_RETURN_CONTINUE;
 }
 
-static enum tcore_hook_return __on_hook_callstatus(Server *s, CoreObject *source,
-               enum tcore_notification_command command, unsigned int data_len, void *data,
-               void *user_data)
+static TcoreHookReturn __on_hook_ps_callstatus(TcorePlugin *source,
+       TcoreNotification command, guint data_len, void *data, void *user_data)
 {
        unsigned int con_id = 0;
        CoreObject *co_ps = NULL, *co_context = NULL;
-       struct tnoti_ps_call_status *cstatus = NULL;
+       TcorePsCallStatusInfo *cstatus = NULL;
+       TcorePlugin *plugin = NULL;
+       indicator_data *indata = NULL;
+       Server *s = NULL;
+       gboolean res = FALSE;
 
        dbg("call status event");
-       g_return_val_if_fail(data != NULL, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+       tcore_check_return_value((data != NULL) || (user_data != NULL), TCORE_HOOK_RETURN_STOP_PROPAGATION);
+
+       plugin = (TcorePlugin *)user_data;
+       indata = tcore_plugin_ref_user_data(plugin);
+       tcore_check_return_value((indata != NULL) , TCORE_HOOK_RETURN_STOP_PROPAGATION);
 
-       co_ps = source;
+       s = tcore_plugin_ref_server(source);
+       co_ps = tcore_plugin_ref_core_object(source, CORE_OBJECT_TYPE_PS);
        dbg("ps object(%p)", co_ps);
-       co_context = tcore_ps_ref_context_by_role(co_ps, CONTEXT_ROLE_INTERNET);
-       con_id = tcore_context_get_id(co_context);
+       co_context = tcore_ps_ref_context_by_role(co_ps, TCORE_CONTEXT_ROLE_INTERNET);
+       res = tcore_context_get_id(co_context, &con_id);
+       if (res == FALSE) {
+               err("get context id failed");
+               return TCORE_HOOK_RETURN_CONTINUE;
+       }
        dbg("context(%p) con_id(%d)", co_context, con_id);
 
-       cstatus = (struct tnoti_ps_call_status *) data;
+       cstatus = (TcorePsCallStatusInfo *) data;
+       if (!cstatus) {
+               err("PS status is NULL");
+               return TCORE_HOOK_RETURN_CONTINUE;
+       }
        dbg("call status event cid(%d) state(%d)", cstatus->context_id, cstatus->state);
 
        if(con_id != cstatus->context_id)
                return TCORE_HOOK_RETURN_CONTINUE;
 
-       if (cstatus->state == PS_DATA_CALL_CTX_DEFINED) {
+       if (cstatus->state == TCORE_PS_CALL_STATE_CTX_DEFINED) {
                /* do nothing. */
                dbg("Just noti for PDP define complete, do nothing.");
                return TCORE_HOOK_RETURN_CONTINUE;
        }
-       else if (cstatus->state == PS_DATA_CALL_CONNECTED) {
-               indicator_info.active = TRUE;
-               indicator_info.devname = tcore_context_get_ipv4_devname(co_context);
-               _indicator_start_updater(s);
+       else if (cstatus->state == TCORE_PS_CALL_STATE_CONNECTED) {
+               indata->indicator_info.active = TRUE;
+               res = tcore_context_get_ipv4_devname(co_context, &indata->indicator_info.devname);
+               if (res == FALSE) {
+                       err("get context ipv4 failed");
+                       return TCORE_HOOK_RETURN_CONTINUE;
+               }
+               _indicator_start_updater(s, plugin);
                return TCORE_HOOK_RETURN_CONTINUE;
        }
 
-       indicator_info.active = FALSE;
-       g_free(indicator_info.devname);
-       indicator_info.devname = NULL;
-       _indicator_stop_updater(s);
+       indata->indicator_info.active = FALSE;
+       g_free(indata->indicator_info.devname);
+       indata->indicator_info.devname = NULL;
+       _indicator_stop_updater(s, plugin);
+       return TCORE_HOOK_RETURN_CONTINUE;
+}
+
+static TcoreHookReturn __on_hook_modem_plugin_added(Server *s,
+                       TcoreServerNotification command,
+                       guint data_len, void *data, void *user_data)
+{
+       TcorePlugin *modem_plugin;
+       TcorePlugin *indicator_plugin = (TcorePlugin *)user_data;
+
+       modem_plugin = (TcorePlugin *)data;
+       tcore_check_return_value_assert(NULL != modem_plugin, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+
+       tcore_plugin_add_notification_hook(modem_plugin, TCORE_NOTIFICATION_MODEM_POWER,
+                                                                               __on_hook_modem_powered, indicator_plugin);
+       tcore_plugin_add_notification_hook(modem_plugin, TCORE_NOTIFICATION_PS_CALL_STATUS,
+                                                                               __on_hook_ps_callstatus, indicator_plugin);
+
+       return TCORE_HOOK_RETURN_CONTINUE;
+}
+
+static TcoreHookReturn __on_hook_modem_plugin_removed(Server *s,
+                       TcoreServerNotification command,
+                       guint data_len, void *data, void *user_data)
+{
+       TcorePlugin *modem_plugin;
+
+       modem_plugin = (TcorePlugin *)data;
+       tcore_check_return_value_assert(NULL != modem_plugin, TCORE_HOOK_RETURN_STOP_PROPAGATION);
+
+       tcore_plugin_remove_notification_hook(modem_plugin, TCORE_NOTIFICATION_MODEM_POWER,
+                                       __on_hook_modem_powered);
+       tcore_plugin_remove_notification_hook(modem_plugin, TCORE_NOTIFICATION_PS_CALL_STATUS,
+                                       __on_hook_ps_callstatus);
 
        return TCORE_HOOK_RETURN_CONTINUE;
 }
@@ -366,16 +448,59 @@ static gboolean on_load()
 static gboolean on_init(TcorePlugin *p)
 {
        Server *s = NULL;
+       GSList *list = NULL;
+       indicator_data *data = NULL;
+       TelReturn ret = TEL_RETURN_FAILURE;
+
+       data = tcore_malloc0(sizeof(indicator_data));
+       if (!data) {
+               err("Failed to allocate memory");
+               return FALSE;
+       }
+       ret = tcore_plugin_link_user_data(p, data);
+       if (ret != TEL_RETURN_SUCCESS) {
+               err("Unable to link user data");
+               free(data);
+               return FALSE;
+       }
+
        s = tcore_plugin_ref_server(p);
-       tcore_server_add_notification_hook(s, TNOTI_MODEM_POWER, __on_hook_powered, NULL);
-       tcore_server_add_notification_hook(s, TNOTI_PS_CALL_STATUS, __on_hook_callstatus, NULL);
+       list = tcore_server_get_modem_plugin_list(s);
+       while (list) {  /* Process for pre-loaded Modem Plug-in */
+               TcorePlugin *modem_plugin;
+
+               modem_plugin = list->data;
+               if ( NULL != modem_plugin) {
+                       tcore_plugin_add_notification_hook(modem_plugin, TCORE_NOTIFICATION_MODEM_POWER,
+                                                                                               __on_hook_modem_powered, p);
+                       tcore_plugin_add_notification_hook(modem_plugin, TCORE_NOTIFICATION_PS_CALL_STATUS,
+                                                                                               __on_hook_ps_callstatus, p);
+               }
+               list = g_slist_next(list);
+       }
+       g_slist_free(list);
+
+       /* Register for post-loaded Modem Plug-ins */
+       tcore_server_add_notification_hook(s, TCORE_SERVER_NOTIFICATION_ADDED_MODEM_PLUGIN,
+                                       __on_hook_modem_plugin_added, p);
+       tcore_server_add_notification_hook(s, TCORE_SERVER_NOTIFICATION_REMOVED_MODEM_PLUGIN,
+                                       __on_hook_modem_plugin_removed, p);
        dbg("initialized Indicator plugin!");
        return TRUE;
 }
 
 static void on_unload(TcorePlugin *p)
 {
+       indicator_data *data = NULL;
        dbg("i'm unload!");
+
+       data = tcore_plugin_ref_user_data(p);
+       if (data->src) {
+               g_source_destroy(data->src);
+               data->src = NULL;
+       }
+       tcore_free(data);
+       data = NULL;
        return;
 }