From: Yunmi Ha Date: Mon, 6 Jul 2020 07:47:19 +0000 (+0900) Subject: Remove duplicated code X-Git-Tag: submit/tizen/20200707.064531~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F237865%2F1;p=platform%2Fcore%2Fsystem%2Ffeedbackd.git Remove duplicated code Change-Id: I934f6cf3efc9194333e303cfab156863ae746b89 Signed-off-by: Yunmi Ha --- diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index c8ec2a8..dbf5872 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -27,7 +27,7 @@ #define METHOD_HAPTIC_SHOWHANDLELIST "ShowHandleList" #define METHOD_HAPTIC_ISSUPPORTED "IsSupported" -static bool request_haptic_method(const char *method, GVariant *param) +static bool request_haptic_method(const char *method, GVariant *param, int *return_val) { GVariant *msg; int val; @@ -60,180 +60,108 @@ static bool request_haptic_method(const char *method, GVariant *param) } g_variant_unref(msg); + + if (return_val) + *return_val = val; + return ret; } static bool haptic_getcount() { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_GETCOUNT, NULL); + return request_haptic_method(METHOD_HAPTIC_GETCOUNT, NULL, NULL); } static bool haptic_opendevice(int index) { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", index)); + return request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", index), NULL); } static bool haptic_closedevice() { - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (dh_get_param_from_var(msg, "(i)", &handle)) - ret = request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle)); + if (request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) + ret = request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); - return ret; } static bool haptic_vibratemonotone(int duration, int level, int priority) { - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (dh_get_param_from_var(msg, "(i)", &handle)) - ret = request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority)); - else + if (request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) { + ret = request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority), NULL); + usleep(duration*1000); + request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); + } else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); - return ret; } static bool haptic_vibratepattern(char *pattern, int level, int priority) { - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (dh_get_param_from_var(msg, "(i)", &handle)) - ret = request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority)); - else + if (request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) { + ret = request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority), NULL); + usleep(1000*1000); // 1 sec + request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); + } else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); - return ret; } static bool haptic_stopdevice() { - struct timespec time = {0,}; - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (!dh_get_param_from_var(msg, "(i)", &handle)) { + if (!request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) { _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); return ret; } - g_variant_unref(msg); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_VIBRATEMONOTONE, - g_variant_new("(uiii)", handle, 1000, 100, 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_VIBRATEMONOTONE); - return ret; + if (request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, 1000, 2, 0), NULL)) { + _D("Sleep 300ms."); + usleep(300*1000); + _D("Wakeup."); + ret = request_haptic_method(METHOD_HAPTIC_STOPDEVICE, g_variant_new("(u)", handle), NULL); } - g_variant_unref(msg); - - _D("Sleep 300ms."); - time.tv_nsec = 300 * NANO_SECOND_MULTIPLIER; - nanosleep(&time, NULL); - _D("Wakeup."); - - return request_haptic_method(METHOD_HAPTIC_STOPDEVICE, g_variant_new("(u)", handle)); + request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); + return ret; } static bool haptic_getstate(int index) { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_GETSTATE, g_variant_new("(i)", index)); + return request_haptic_method(METHOD_HAPTIC_GETSTATE, g_variant_new("(i)", index), NULL); } static bool haptic_showhandlelist() { - GVariant *msg; - _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_SHOWHANDLELIST, - NULL); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return FALSE; - } - g_variant_unref(msg); - return TRUE; + return request_haptic_method(METHOD_HAPTIC_SHOWHANDLELIST, NULL, NULL); } static bool haptic_issupported(char *pattern) { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_ISSUPPORTED, g_variant_new("(s)", pattern)); + return request_haptic_method(METHOD_HAPTIC_ISSUPPORTED, g_variant_new("(s)", pattern), NULL); } void haptic_test_all(int *success, int *fail) @@ -249,10 +177,10 @@ void haptic_test_all(int *success, int *fail) (haptic_closedevice()) ? s++ : f++; (haptic_stopdevice()) ? s++ : f++; nanosleep(&time, NULL); - (haptic_vibratemonotone(300, 100, 0)) ? s++ : f++; - nanosleep(&time, NULL); + (haptic_vibratemonotone(300, 2, 0)) ? s++ : f++; + //nanosleep(&time, NULL); (haptic_vibratepattern("FEEDBACK_PATTERN_SIP", 2, 0)) ? s++ : f++; - nanosleep(&time, NULL); + //nanosleep(&time, NULL); (haptic_getstate(0)) ? s++ : f++; (haptic_showhandlelist()) ? s++ : f++; (haptic_issupported("FEEDBACK_PATTERN_SIP")) ? s++ : f++;