[FIX] include paths (capi-system-runtime-info)
[platform/core/system/swap-probe.git] / custom_chart / da_chart.c
index ad8140f..801e0fc 100755 (executable)
@@ -3,18 +3,18 @@
  *
  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: 
+ * Contact:
  *
  * Jaewon Lim <jaewon81.lim@samsung.com>
  * Woojin Jung <woojin2.jung@samsung.com>
  * Juyoung Kim <j0.kim@samsung.com>
  * Anastasia Lyupa <a.lyupa@samsung.com>
- * 
+ *
  * This library is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the
  * Free Software Foundation; either version 2.1 of the License, or (at your option)
  * any later version.
- * 
+ *
  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
@@ -27,7 +27,7 @@
  * Contributors:
  * - S-Core Co., Ltd
  * - Samsung RnD Institute Russia
- * 
+ *
  */
 
 #include <pthread.h>
@@ -137,7 +137,7 @@ void* _chart_timerThread(void* data)
                        PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM,
                                          API_ID__chart_timerThread,
                                          "", 0);
-                       PACK_COMMON_END(0, 0, 2);
+                       PACK_COMMON_END('p', 0, 0, 2);
                        PACK_CUSTOM(cur->series_handle, 0, "", 0, value);
                        FLUSH_LOCAL_BUF();
 
@@ -196,17 +196,21 @@ static int start_callback_thread(chart_interval interval)
                return ERR_WRONG_PARAMETER;
        }
 
-       if(*timerfd != -1 || *thread_handle != -1)
+       /**
+        * FIXME: Type of pthread_t is undefined.
+        * Comparing it with -1 is *very* bad
+        */
+       if (*timerfd != -1 || *thread_handle != (pthread_t) -1)
                return 0;               // already thread exist
 
        *timerfd = timerfd_create(CLOCK_REALTIME, 0);
-       if(*timerfd == -1)
+       if (*timerfd == -1)
                return errno;
 
-       if(timerfd_settime(*timerfd, 0, &timevalue, NULL) == -1)
+       if (timerfd_settime(*timerfd, 0, &timevalue, NULL) == -1)
                return errno;
 
-       if(pthread_create(thread_handle, NULL, _chart_timerThread, pman) < 0)
+       if (pthread_create(thread_handle, NULL, _chart_timerThread, pman) < 0)
                return ERR_THREAD_CREATE_FAIL;
 
        return 0;
@@ -221,7 +225,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle,
                da_user_data_2_chart_data callback, void* user_data)
 {
        chart_interval_callback* newelem;
-       
+
        newelem = (chart_interval_callback*)malloc(sizeof(chart_interval_callback));
        newelem->chart_handle = charthandle;
        newelem->series_handle = series_handle;
@@ -229,7 +233,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle,
        newelem->user_data = user_data;
 
        chm.interval_for_series[charthandle][series_handle % 10] = interval;
-       
+
        switch(interval)
        {
        case CHART_INTERVAL_10MSEC:
@@ -262,7 +266,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle,
 static void remove_all_callback_list()
 {
        chart_interval_callback* cur;
-       
+
        pthread_mutex_lock(&chm.interval_10ms.list_mutex);
        while(chm.interval_10ms.callback_list != NULL)
        {
@@ -389,9 +393,6 @@ static void remove_from_callback_list(da_handle charthandle, da_handle series_ha
 // constructor and destructor functions
 // =====================================================================
 
-void memory_initialize_hook(void);
-void (*__malloc_initialize_hook) (void) = memory_initialize_hook;
-
 void __attribute__((constructor)) _init_lib()
 {
        probeBlockStart();
@@ -415,25 +416,19 @@ void __attribute__((destructor)) _fini_lib()
        probeBlockStart();
 
        remove_all_callback_list();
-       if(chm.interval_10ms.timerfd != -1)
+       if (chm.interval_10ms.timerfd != -1)
                close(chm.interval_10ms.timerfd);
-       if(chm.interval_100ms.timerfd != -1)
+       if (chm.interval_100ms.timerfd != -1)
                close(chm.interval_100ms.timerfd);
-       if(chm.interval_1s.timerfd != -1)
+       if (chm.interval_1s.timerfd != -1)
                close(chm.interval_1s.timerfd);
-
-       if(chm.interval_10ms.thread_handle != -1)
-       {
+       /*! Bad. Ugly. Unportable */
+       if (chm.interval_10ms.thread_handle != (pthread_t) -1)
                pthread_join(chm.interval_10ms.thread_handle, NULL);
-       }
-       if(chm.interval_100ms.thread_handle != -1)
-       {
+       if (chm.interval_100ms.thread_handle != (pthread_t) -1)
                pthread_join(chm.interval_100ms.thread_handle, NULL);
-       }
-       if(chm.interval_1s.thread_handle != -1)
-       {
+       if (chm.interval_1s.thread_handle != (pthread_t) -1)
                pthread_join(chm.interval_1s.thread_handle, NULL);
-       }
 
        probeBlockEnd();
 }
@@ -446,16 +441,16 @@ void __attribute__((destructor)) _fini_lib()
 void da_mark(chart_color color, char* mark_text)
 {
        DECLARE_CHART_VARIABLE;
-       
+
        probeBlockStart();
-       
+
        setProbePoint(&probeInfo);
 
        PREPARE_LOCAL_BUF();
        PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM,
                          API_ID_da_mark,
-                         "dp", color, mark_text);
-       PACK_COMMON_END(0, 0, 2);
+                         "dp", color, voidp_to_uint64(mark_text));
+       PACK_COMMON_END('v', 0, 0, 2);
        PACK_CUSTOM(0, 0, mark_text, color, 0.0f);
        FLUSH_LOCAL_BUF();
 
@@ -469,11 +464,11 @@ da_handle da_create_chart(char* chart_name)
        // check if there is available chart handle slot
        if(chm.chart_handle_index + 1 >= MAX_CHART_HANDLE)
                return ERR_MAX_CHART_NUMBER;
-               
+
        // check if chart_name is null
        if(chart_name == NULL)
                return ERR_WRONG_PARAMETER;
-               
+
        probeBlockStart();
        ret = ++(chm.chart_handle_index);
 
@@ -482,13 +477,13 @@ da_handle da_create_chart(char* chart_name)
        PREPARE_LOCAL_BUF();
        PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM,
                          API_ID_da_create_chart,
-                         "p", chart_name);
-       PACK_COMMON_END(ret, 0, 2);
+                         "p", voidp_to_uint64(chart_name));
+       PACK_COMMON_END('d', ret, 0, 2);
        PACK_CUSTOM(0, 0, chart_name, 0, 0.0f);
        FLUSH_LOCAL_BUF();
-       
+
        probeBlockEnd();
-       
+
        return ret;
 }
 
@@ -496,11 +491,11 @@ da_handle da_create_series(da_handle charthandle, char* seriesname,
                series_type type, chart_color color)
 {
        DECLARE_CHART_VARIABLE;
-       
+
        // check if charthandle is valid handle or not
        if(charthandle <= 0 || charthandle > chm.chart_handle_index)
                return ERR_WRONG_HANDLE;
-               
+
        // chech if extra parameter is valid
        if(seriesname == NULL)
                return ERR_WRONG_PARAMETER;
@@ -508,26 +503,27 @@ da_handle da_create_series(da_handle charthandle, char* seriesname,
        // check if there is available series spot
        if(chm.series_handle_index[(int)charthandle] + 1 >= MAX_SERIES_PER_CHART)
                return ERR_MAX_CHART_NUMBER;
-       
+
        probeBlockStart();
        ret = ++(chm.series_handle_index[charthandle]);
        ret += (10 * charthandle);
-       
+
        setProbePoint(&probeInfo);
 
        PREPARE_LOCAL_BUF();
        PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM,
                          API_ID_da_create_series,
-                         "dpdd",  charthandle, seriesname, type, color);
-       PACK_COMMON_END(ret, 0, 2);
+                         "dpdd",  charthandle, voidp_to_uint64(seriesname),
+                         type, color);
+       PACK_COMMON_END('d', ret, 0, 2);
        PACK_CUSTOM(charthandle, type, seriesname, color, 0.0f);
        FLUSH_LOCAL_BUF();
 
        probeBlockEnd();
-       
+
        return ret;
 }
-               
+
 da_handle da_create_default_series(da_handle charthandle, char* seriesname)
 {
        return da_create_series(charthandle, seriesname,
@@ -540,14 +536,14 @@ int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback,
        int cindex, sindex;
        cindex = (int)(series_handle / 10);
        sindex = series_handle % 10;
-       
+
        // check series handle
        if(cindex <= 0 || cindex > chm.chart_handle_index)
                return ERR_WRONG_HANDLE;
-       
+
        if(sindex > chm.series_handle_index[(int)cindex])
                return ERR_WRONG_HANDLE;
-       
+
        // check rest parameters
        if(interval == CHART_NO_CYCLE && callback != NULL)
                return ERR_WRONG_PARAMETER;
@@ -560,8 +556,10 @@ int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback,
        // register new callback
        if(callback != NULL)
        {
+               int re;
                add_to_callback_list(interval, cindex, series_handle, callback, data_addr);
-               start_callback_thread(interval);
+               re = start_callback_thread(interval);
+               LOG("start callback thread return %d\n", re);
        }
        probeBlockEnd();
 
@@ -571,29 +569,29 @@ int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback,
 void da_log(da_handle series_handle, float uservalue)
 {
        DECLARE_CHART_VARIABLE;
-       
+
        // chech if series handle is valid
        int cindex, sindex;
        cindex = (int)(series_handle / 10);
        sindex = series_handle % 10;
-       
+
        if(cindex <= 0 || cindex > chm.chart_handle_index)
                return;
-       
+
        if(sindex > chm.series_handle_index[(int)cindex])
                return;
-       
+
        probeBlockStart();
-       
+
        setProbePoint(&probeInfo);
 
        PREPARE_LOCAL_BUF();
        PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM,
                          API_ID_da_log,
-                         "dw", series_handle, uservalue);
-       PACK_COMMON_END(0, 0, 2);
+                         "df", series_handle, uservalue);
+       PACK_COMMON_END('v', 0, 0, 2);
        PACK_CUSTOM(series_handle, 0, "", 0, uservalue);
        FLUSH_LOCAL_BUF();
-       
+
        probeBlockEnd();
 }