#define INM_PROC_DEV "/proc/net/dev"
typedef struct {
- gboolean is_initialized;
gboolean is_enabled;
guint timer_source_id;
inm_statistics_callback cb;
gpointer cb_user_data;
} statistics_mon_s;
-statistics_mon_s stat_mon = {0,};
-
+static statistics_mon_s *g_p_stat_mon = NULL;
static gboolean __get_statistics(gpointer user_data)
{
__INM_FUNC_ENTER__;
- if (!stat_mon.cb) {
+ if (!g_p_stat_mon || !g_p_stat_mon->cb) {
__INM_FUNC_EXIT__;
return TRUE;
}
&stats.tx_carrier, /* tx carrier errors */
&stats.tx_compressed /* tx compressed */
);
- stat_mon.cb(&stats, user_data);
+ g_p_stat_mon->cb(&stats, user_data);
} else {
INM_LOGI("No matched Iface name in proc file");
}
int inm_statistics_start_monitor(inm_statistics_callback cb, void *user_data)
{
gint ret = INM_STATISTICS_ERROR_NONE;
- guint source_id = 0;
- __INM_FUNC_ENTER__;
+ __INM_FUNC_ENTER__;
if (!cb) {
__INM_FUNC_ENTER__;
return INM_STATISTICS_ERROR_INVALID_PARAM;
}
- source_id = g_timeout_add(STAT_POLLING_TIME,
- __get_statistics, NULL);
+ if (g_p_stat_mon) {
+ __INM_FUNC_ENTER__;
+ return INM_STATISTICS_ERROR_OPERATION_FAILED;
+ }
+
+ g_p_stat_mon = g_try_malloc0(sizeof(statistics_mon_s));
+ if (!g_p_stat_mon) {
+ __INM_FUNC_ENTER__;
+ return INM_STATISTICS_ERROR_OPERATION_FAILED;
+ }
- if (stat_mon.timer_source_id > 0)
- g_source_remove(stat_mon.timer_source_id);
+ g_p_stat_mon->timer_source_id = g_timeout_add(STAT_POLLING_TIME,
+ __get_statistics, NULL);
- stat_mon.timer_source_id = source_id;
- stat_mon.cb = cb;
- stat_mon.cb_user_data = user_data;
+ g_p_stat_mon->cb = cb;
+ g_p_stat_mon->cb_user_data = user_data;
+ g_p_stat_mon->is_enabled = TRUE;
__INM_FUNC_EXIT__;
return ret;
int ret = INM_STATISTICS_ERROR_NONE;
__INM_FUNC_ENTER__;
- if (!stat_mon.is_enabled) {
+ if (!g_p_stat_mon) {
__INM_FUNC_ENTER__;
return INM_STATISTICS_ERROR_NONE;
}
- if (stat_mon.timer_source_id > 0) {
- g_source_remove(stat_mon.timer_source_id);
- stat_mon.timer_source_id = 0;
- }
+ if (g_p_stat_mon->timer_source_id > 0)
+ g_source_remove(g_p_stat_mon->timer_source_id);
- stat_mon.cb = NULL;
- stat_mon.cb_user_data = NULL;
+ g_free(g_p_stat_mon);
+ g_p_stat_mon = NULL;
__INM_FUNC_EXIT__;
return ret;
int ret = INM_STATISTICS_ERROR_NONE;
__INM_FUNC_ENTER__;
- if (!enabled) {
+ if (!g_p_stat_mon || !enabled) {
__INM_FUNC_ENTER__;
return INM_STATISTICS_ERROR_INVALID_PARAM;
}
- *enabled = stat_mon.is_enabled;
-
- __INM_FUNC_EXIT__;
- return ret;
-}
-
-int inm_statistics_init()
-{
- int ret = INM_STATISTICS_ERROR_NONE;
- __INM_FUNC_ENTER__;
-
- __INM_FUNC_EXIT__;
- return ret;
-}
-
-int inm_statistics_deinit()
-{
- int ret = INM_STATISTICS_ERROR_NONE;
- __INM_FUNC_ENTER__;
+ *enabled = g_p_stat_mon->is_enabled;
__INM_FUNC_EXIT__;
return ret;