diff options
author | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-03-29 18:41:25 +0900 |
---|---|---|
committer | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-03-29 21:39:59 +0900 |
commit | f12c118f08b77d3bcfd0330961d7b90d11d9dd1a (patch) | |
tree | 61c616d16386b1114b44b582833cb6bc6bcc4ceb | |
parent | dbaa852ae76e592c5ab60eca4967c9952e681ef6 (diff) |
Add Error check with ErrorCode instead of GError
Change-Id: I56d12f2a2d1787e09e149b4931a1305925c44412
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r-- | src/audiomanager_proxy.c | 1 | ||||
-rw-r--r-- | src/sm-helper.c | 17 | ||||
-rw-r--r-- | src/sm-helper.h | 4 | ||||
-rw-r--r-- | src/soundmanager.c | 71 |
4 files changed, 44 insertions, 49 deletions
diff --git a/src/audiomanager_proxy.c b/src/audiomanager_proxy.c index cdf5b4c..b62ee8b 100644 --- a/src/audiomanager_proxy.c +++ b/src/audiomanager_proxy.c @@ -454,7 +454,6 @@ ErrorCode am_proxy_register_domain(GVariant* domain_data, int *domain){ domain, &ret, NULL, &err); - SEND_RESULT_NO_RESP(err); g_variant_unref(domain_data); ec = check_send_error(err, ret); return ec; diff --git a/src/sm-helper.c b/src/sm-helper.c index 0ccd1c7..c55eefb 100644 --- a/src/sm-helper.c +++ b/src/sm-helper.c @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "sm-helper.h" -#include "sm-def.h" #include <stdlib.h> #include <string.h> #include <limits.h> @@ -187,20 +185,21 @@ int sm_search_routing_event_name_index(const char* value) return ret; } -bool send_result(const GError* result_of_send, struct afb_req req, const char* function){ +bool send_result(ErrorCode ec, struct afb_req req, const char* function){ /* GError = NULL means success in case of gdbus request */ - if(result_of_send != NULL) + if(ec == UNABLE_SEND) { - AFB_ERROR("Unable to call %s", function); - afb_req_fail_f(req, "failed", "Unable to call %s", function); + AFB_ERROR("Unable to call : %s", function); + afb_req_fail_f(req, "failed", "%s : %s", + get_response_audiomanager_massage_error(ec), function); return false; } return true; } -bool send_result_no_resp(const GError* result_of_send, const char* function){ - if(result_of_send != NULL){ - AFB_ERROR("Unable to call %s", function); +bool send_result_no_resp(ErrorCode ec, const char* function){ + if(ec == UNABLE_SEND){ + AFB_ERROR("Unable to call : %s", function); return false; } return true; diff --git a/src/sm-helper.h b/src/sm-helper.h index 412551d..0eb57a7 100644 --- a/src/sm-helper.h +++ b/src/sm-helper.h @@ -51,8 +51,8 @@ void sm_add_object_to_json_object(struct json_object* j_obj, int count, ...); void sm_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...); int sm_search_event_name_index(const char* value); int sm_search_routing_event_name_index(const char* value); -bool send_result_no_resp(const GError* result_of_send, const char* function); -bool send_result(const GError* result_of_send, struct afb_req req, const char* function); +bool send_result_no_resp(ErrorCode ec, const char* function); +bool send_result(ErrorCode ec, struct afb_req req, const char* function); ErrorCode is_range_over_guint16(int source); ErrorCode is_range_over_gint16(int source); #endif /*AM_HELPER_H*/
\ No newline at end of file diff --git a/src/soundmanager.c b/src/soundmanager.c index 2ad3c08..7b929a2 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -115,7 +115,7 @@ void connect (struct afb_req request) ErrorCode ec = am_proxy_connect(source_id, source_id, &main_connectionID); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /* ToDo Remember appname(key) and tie to sourceID(value) */ @@ -124,7 +124,7 @@ void connect (struct afb_req request) sm_add_object_to_json_object_func(res, __FUNCTION__, 4, "error", ec, KEY_MAIN_CONNECTION_ID, main_connectionID); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -147,12 +147,12 @@ void disconnect (struct afb_req request) ErrorCode ec = am_proxy_disconnect(main_connection_id); AFB_DEBUG( "ret = %d", ec); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, KEY_ERROR, ec); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -177,12 +177,12 @@ void setVolume (struct afb_req request) ErrorCode ec = am_proxy_set_volume(sink_id, vol); AFB_DEBUG( "ret = %d", ec); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, "error", ec); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -207,12 +207,12 @@ void volumeStep (struct afb_req request) ErrorCode ec = am_proxy_volume_step(sink_id, vol); AFB_DEBUG( "ret = %d", ec); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, "error", ec); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -238,12 +238,12 @@ void setSinkMuteState(struct afb_req request) ErrorCode ec = am_proxy_set_sink_mute_state(sink_id, mute); AFB_DEBUG( "ret = %d", ec); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, "error", ec); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -257,7 +257,7 @@ void getListMainConnections(struct afb_req request) ErrorCode ec = am_proxy_get_list_main_connections(mainConnectionList); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /* create response */ struct json_object *array_res = json_object_new_array(); @@ -304,7 +304,7 @@ void getListMainSources(struct afb_req request) ErrorCode ec = am_proxy_get_list_main_sources(mainSourceList); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /* create response */ struct json_object *response = json_object_new_object(); @@ -356,7 +356,7 @@ void getListMainSinks(struct afb_req request) ErrorCode ec = am_proxy_get_list_main_sinks(mainSinkList); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /* create response */ struct json_object *response = json_object_new_object(); @@ -415,7 +415,6 @@ void ackConnect(struct afb_req request) guint16 handle, connection_id, error; guint16 ret = 0; REQ_ERROR req_err1, req_err2 , req_err3; - GError *err = NULL; req_err1 = get_value_uint16(request, KEY_HANDLE, &handle); req_err2 = get_value_uint16(request, KEY_CONNECTION_ID, &connection_id); @@ -434,13 +433,13 @@ void ackConnect(struct afb_req request) ErrorCode ec = am_proxy_ack_connect(handle, connection_id, error); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, KEY_ERROR, ret); - char *info = get_response_audiomanager_massage_error(ret); + const char* info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -469,13 +468,13 @@ void ackDisconnect(struct afb_req request) ErrorCode ec = am_proxy_ack_disconnect(handle, connection_id, error); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, KEY_ERROR, ret); - char *info = get_response_audiomanager_massage_error(ret); + const char* info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -499,13 +498,13 @@ void ackSetSourceState(struct afb_req request) ErrorCode ec = am_proxy_ack_set_source_state(handle, error); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, KEY_ERROR, ec); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -595,14 +594,14 @@ void registerSource(struct afb_req request) ErrorCode ec = am_proxy_register_source(sourceData, &acquire_source_id); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 4, KEY_ERROR, ec, KEY_SOURCE_ID, acquire_source_id); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -616,13 +615,13 @@ void deregisterSource(struct afb_req request) afb_req_fail(request, "wrong-request", NULL); } ErrorCode ec = am_proxy_deregister_source(source_id); - if(!SEND_RESULT(err, request)) return; + if(!SEND_RESULT(ec, request)) return; /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, KEY_ERROR, ec); - char *info = get_response_audiomanager_massage_error(ec); + const char* info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -660,7 +659,7 @@ void subscribe(struct afb_req request) struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, KEY_ERROR, ret); - char *info = get_response_audiomanager_massage_error(ret); + const char* info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -697,7 +696,7 @@ void unsubscribe(struct afb_req request) struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, KEY_ERROR, ret); - char *info = get_response_audiomanager_massage_error(ret); + const char* info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -763,16 +762,14 @@ void streamOpen(struct afb_req request){ sm_add_object_to_json_object_func(res, __FUNCTION__, 4, KEY_ERROR, ret, KEY_CONNECTION_ID, sid); - char *info = get_response_audiomanager_massage_error(ret); + const char* info = get_response_audiomanager_massage_error(ret); create_client_context(request, sid, endpoint_id, endpoint_type); afb_req_success(request, res, info); } void streamClose(struct afb_req request){ // TODO : wtite function - // unpack request - /* json_object* response = json_object_new_object(); - smClientCtxt* ctxt = afb_req_context_get(request); +/* smClientCtxt* ctxt = afb_req_context_get(request); if(ctxt->source.mainConnectionID > 0){ json_object* jreq = json_object_new_object(); json_object_object_add(jreq, KEY_MAIN_CONNECTION_ID, ctxt->source.mainConnectionID); @@ -913,7 +910,7 @@ static void on_async_set_source_state(void *closure, int handle, int sourceID, i { AFB_DEBUG( "%s called", __FUNCTION__); struct json_object* ev_obj = json_object_new_object(); - char* ss_key = get_source_state_key(sourceState); + const char* ss_key = get_source_state_key(sourceState); sm_add_object_to_json_object(ev_obj, 4, KEY_HANDLE, handle, KEY_SOURCE_ID, sourceID); @@ -1058,8 +1055,8 @@ int sm_init() .on_async_set_sink_volume = on_async_set_sink_volume, .on_async_set_source_state = on_async_set_source_state }; - ErrorCode ret = open_soundmanager_interface(&instruction); - if(ret != OK){ + ErrorCode ec = open_soundmanager_interface(&instruction); + if(ec != OK){ AFB_ERROR("Failed to create sound manager interface"); return -1; } @@ -1074,12 +1071,12 @@ int sm_init() .complete = TRUE, .state = DS_CONTROLLED }; - ret = am_proxy_register_domain( create_domain_data(&ddata), &SOUNDMANAGER_DOMAIN_ID); - if(!SEND_RESULT_NO_RESP(err)){ + ec = am_proxy_register_domain( create_domain_data(&ddata), &SOUNDMANAGER_DOMAIN_ID); + if(!SEND_RESULT_NO_RESP(ec)){ return -1; } - if(ret != OK){ - AFB_ERROR("Failed to registerDomain : %s", get_response_audiomanager_massage_error(ret)); + if(ec != OK){ + AFB_ERROR("Failed to registerDomain : %s", get_response_audiomanager_massage_error(ec)); return -1; } AFB_DEBUG("domainID : %d", SOUNDMANAGER_DOMAIN_ID); |