diff options
author | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-02-26 17:06:16 +0900 |
---|---|---|
committer | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-02-26 17:06:16 +0900 |
commit | 21560b8ca2f7cc803e0c288a9ec96aa68e9c19c6 (patch) | |
tree | 8a3efa1c7583e21c7cabc90fdbb4713c20ed9322 | |
parent | 8ca504d9e1a94bf575b671d0492a2aff02725a2d (diff) |
clean: Use function and remove duplicated code
Change-Id: If41193db78cb290d2d4a8bac9d164df502e7393a
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r-- | src/sm-error.h | 23 | ||||
-rw-r--r-- | src/soundmanager.c | 83 |
2 files changed, 39 insertions, 67 deletions
diff --git a/src/sm-error.h b/src/sm-error.h index a963d47..bc60175 100644 --- a/src/sm-error.h +++ b/src/sm-error.h @@ -1,5 +1,11 @@ #ifndef SM_ERROR_H #define SM_ERROR_H +#include <glib.h> +#define _GNU_SOURCE +#define AFB_BINDING_VERSION 2 +#include <afb/afb-binding.h> +#define IS_SEND_ERROR(...) is_send_error(__VA_ARGS__, __FUNCTION__) +#define IS_SEND_ERROR_WITHOUT_RETURN(...) is_send_error_without_return(__VA_ARGS__, __FUNCTION__) char* get_response_audiomanager_massage_error(int am_error_code) { @@ -31,7 +37,7 @@ char* get_response_audiomanager_massage_error(int am_error_code) case 100: return "desired event doesn't exist"; default: - return "Audio Manager responsed unknown error number"; + return "Audio Manager responsed unknown error number"; } } @@ -49,4 +55,19 @@ char* get_source_state_key(int am_source_state){ return ""; } } + +void is_send_error_without_return(GError* result_of_send, const char* function){ + if(result_of_send != NULL){ + AFB_ERROR("Unable to call %s", function); + } +} + +int is_send_error(GError* result_of_send, struct afb_req req, const char* function){ + if(result_of_send != NULL) + { + afb_req_fail_f(req, "failed", "Unable to call %s", function); + return 0; + } + return -1; +} #endif diff --git a/src/soundmanager.c b/src/soundmanager.c index 916860e..e709665 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -26,7 +26,6 @@ #include "sm-error.h" #include "sm-helper.h" - const static struct afb_binding_interface *afbitf; static AudiomanagerCommandinterface *am_cmd_bus; static AudiomanagerRoutinginterface *am_route_bus; @@ -97,11 +96,7 @@ void connect (struct afb_req request) &main_connectionID, NULL, &err); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; /* ToDo Remember appname(key) and tie to sourceID(value) */ @@ -138,11 +133,7 @@ void disconnect (struct afb_req request) NULL, &err); AFB_DEBUG( "ret = %d", ret); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, @@ -178,11 +169,7 @@ void setVolume (struct afb_req request) NULL, &err); AFB_DEBUG( "ret = %d", ret); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, @@ -218,11 +205,7 @@ void volumeStep (struct afb_req request) NULL, &err); AFB_DEBUG( "ret = %d", ret); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, @@ -258,11 +241,7 @@ void setSinkMuteState(struct afb_req request) NULL, &err); AFB_DEBUG( "ret = %d", ret); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, @@ -287,11 +266,8 @@ void getListMainConnections(struct afb_req request) &err ); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; + /* create response */ struct json_object *array_res = json_object_new_array(); gsize size = g_variant_n_children(mainConnectionList); @@ -343,11 +319,7 @@ void getListMainSources(struct afb_req request) &err ); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; /* create response */ struct json_object *response = json_object_new_object(); @@ -405,11 +377,7 @@ void getListMainSinks(struct afb_req request) &err ); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; /* create response */ struct json_object *response = json_object_new_object(); @@ -492,11 +460,7 @@ void ackConnect(struct afb_req request) error, NULL, &err); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, @@ -536,11 +500,8 @@ void ackDisconnect(struct afb_req request) error, NULL, &err); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; + /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, @@ -573,11 +534,8 @@ void ackSetSourceState(struct afb_req request) error, NULL, &err); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; + /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, @@ -679,11 +637,7 @@ void registerSource(struct afb_req request) NULL, &err); g_variant_unref(input); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; /*create response json object*/ struct json_object *res = json_object_new_object(); @@ -710,11 +664,8 @@ void deregisterSource(struct afb_req request) &ret, NULL, &err ); - if(err != NULL) - { - afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__); - return; - } + if(IS_SEND_ERROR(err, request) == 0) return; + /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, |