From: taemin.yeom Date: Thu, 1 Jul 2021 02:00:28 +0000 (+0900) Subject: Prevent a corner case and add static keywords X-Git-Tag: accepted/tizen/unified/20210727.124557^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F73%2F260673%2F1;p=platform%2Fcore%2Fapi%2Fsensor.git Prevent a corner case and add static keywords Change-Id: I3a5652879b446aa03e09ab935b065411d82f3fa0 Signed-off-by: taemin.yeom --- diff --git a/test/main.c b/test/main.c index ca498c8..97683ab 100644 --- a/test/main.c +++ b/test/main.c @@ -5,7 +5,7 @@ #include #include -const sensor_type_e sensor_type[] = +static const sensor_type_e sensor_type[] = { SENSOR_ACCELEROMETER, SENSOR_GRAVITY, @@ -36,7 +36,7 @@ const sensor_type_e sensor_type[] = SENSOR_HUMAN_SLEEP_DETECTOR }; -const char *sensor_name[] = { +static const char *sensor_name[] = { "Accelerometer", "Gravity sensor", "Linear acceleration sensor", @@ -67,18 +67,18 @@ const char *sensor_name[] = { }; // the number of value to be verified of the sensor -const int value_num[] = {3, 3, 3, 3, 4, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 4, 4, 1, 1, 1, 3, 1}; - -GMainLoop *loop; -bool turned_on[SENSOR_NUM]; -int min_range[SENSOR_NUM]; -int max_range[SENSOR_NUM]; -int called_num[SENSOR_NUM]; -int miss[SENSOR_NUM]; -int callback_count; -bool running; - -void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) +static const int value_num[] = {3, 3, 3, 3, 4, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 4, 4, 1, 1, 1, 3, 1}; + +static GMainLoop *loop; +static bool turned_on[SENSOR_NUM]; +static int min_range[SENSOR_NUM]; +static int max_range[SENSOR_NUM]; +static int called_num[SENSOR_NUM]; +static int miss[SENSOR_NUM]; +static int callback_count; +static bool running; + +static void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) { const char *name; sensor_type_e type; @@ -139,7 +139,7 @@ void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, } } -int create_sensor_listener(int num, sensor_h *sensor, sensor_listener_h *listener) +static int create_sensor_listener(int num, sensor_h *sensor, sensor_listener_h *listener) { bool supported; int ret; @@ -183,16 +183,24 @@ int main() sensor_h sensor[29]; sensor_listener_h listener[29]; + int usable = 0; for (int i = 0; i < SENSOR_NUM; ++i) { called_num[i] = 0; miss[i] = 0; - if (create_sensor_listener(i, &sensor[i], &listener[i])) + if (create_sensor_listener(i, &sensor[i], &listener[i])) { turned_on[i] = false; - else + } + else { turned_on[i] = true; + ++usable; + } } + if (usable == 0) { + g_print("There is no supported sensor.\n"); + return -1; + } g_print("testing... ");