diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/soundmanager.c | 190 |
1 files changed, 96 insertions, 94 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c index 030b1ab..0ce2f68 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -83,33 +83,35 @@ static struct afb_event ev_async_connect; static struct afb_event ev_async_disconnect; static struct afb_event ev_async_set_source_state; -static const char _source_id[] = "sourceID"; -static const char _sink_id[] = "sinkID" ; -static const char _sink_name[] = "sinkName" ; -static const char _main_connection_id[] = "mainConnectionID"; -static const char _delay[] = "delay"; -static const char _connection_state[] = "connectionState"; -static const char _connection_id[] = "connectionID"; -static const char _volume[] = "volume"; -static const char _volume_step[] = "volumeStep"; -static const char _mute_state[] = "muteState"; - -static const char _domain_id[] = "domainID"; -static const char _handle[] = "handle"; -static const char _appname[] = "appname"; -static const char _ramp[] = "ramp"; -static const char _time[] = "time"; -static const char _source_state[] = "sourceState"; -static const char _source_class_id[] = "sourceClassID"; -static const char _sink_class_id[] = "sinkClassID"; -static const char _error[] = "error"; -static const char _sink_data[] = "sinkData"; -static const char _source_data[] = "sourceData"; -static const char _interrupt_state[] = "interruptState"; -static const char _availability[] = "availability"; -static const char _list_volumes[] = "listVolumes"; -static const char _payload[] = "payload"; -static const char _connection_format[] = "connectionFormat"; +#define _SOURCE_ID "sourceID" +#define _SINK_ID "sinkID" +#define _SINK_NAME "sinkName" +#define _MAIN_CONNECTION_ID "mainConnectionID" +#define _DELAY "delay" +#define _CONNECTION_STATE "connectionState" +#define _CONNECTION_ID "connectionID" +#define _VOLUME "volume" +#define _VOLUME_STEP "volumeStep" +#define _INTERRUPT "interrupt" +#define _MUTE_STATE "muteState" + +#define _DOMAIN_ID "domainID" +#define _HANDLE "handle" +#define _APPNAME "appname" +#define _RAMP "ramp" +#define _TIME "time" +#define _SOURCE_STATE "sourceState" +#define _SOURCE_CLASS_ID "sourceClassID" +#define _SINK_CLASS_ID "sinkClassID" +#define _ERROR "error" +#define _SINK_DATA "sinkData" +#define _SOURCE_DATA "sourceData" +#define _INTERRUPT_STATE "interruptState" +#define _AVAILABILITY "availability" +#define _AVAILABILITY_REASON "availabilityReason" +#define _LIST_VOLUMES "listVolumes" +#define _PAYLOAD "payload" +#define _CONNECTION_FORMAT "connectionFormat" /* ********** Method of Sound Manager (API) ********** */ @@ -153,11 +155,11 @@ static void connect (struct afb_req request) REQ_ERROR req_err2 = REQ_FAIL; GError *err = NULL; - req_err1 = get_value_uint16(request, _source_id, &source_id); + req_err1 = get_value_uint16(request, _SOURCE_ID, &source_id); /* ToDo: Hardware abstraction for application user is needed. select appname(speaker) or sourceID(sinkID). If appname is desired, it changes to sourceID(sinkID) */ - const char* default_sink = afb_req_value (request, _sink_id); + const char* default_sink = afb_req_value (request, _SINK_ID); if(default_sink != NULL){ if((strlen("default") == strlen(default_sink)) && (0 == strncmp("default", default_sink, strlen("default")))){ @@ -165,7 +167,7 @@ static void connect (struct afb_req request) req_err2 = REQ_OK; } else{ - req_err2 = get_value_uint16(request, _sink_id, &sink_id); + req_err2 = get_value_uint16(request, _SINK_ID, &sink_id); } } @@ -197,7 +199,7 @@ static void connect (struct afb_req request) struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 4, "error", ret, - _main_connection_id, main_connectionID); + _MAIN_CONNECTION_ID, main_connectionID); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -227,12 +229,12 @@ static void disconnect (struct afb_req request) REQ_ERROR req_err; GError *err = NULL; - req_err = get_value_uint16(request, _main_connection_id, &id); - AFB_DEBUG( "requested %s = %d", _main_connection_id, id); + req_err = get_value_uint16(request, _MAIN_CONNECTION_ID, &id); + AFB_DEBUG( "requested %s = %d", _MAIN_CONNECTION_ID, id); if(req_err != REQ_OK) { - afb_req_fail(request,"wrong-request",afb_req_value (request, _main_connection_id)); + afb_req_fail(request,"wrong-request",afb_req_value (request, _MAIN_CONNECTION_ID)); return; } audiomanager_commandinterface_call_disconnect_sync( @@ -250,7 +252,7 @@ static void disconnect (struct afb_req request) struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res_obj, info); /* return error num as status */ @@ -280,9 +282,9 @@ static void setVolume (struct afb_req request) REQ_ERROR req_err1, req_err2; GError *err = NULL; - req_err1 = get_value_uint16(request, _sink_id, &sink_id); - req_err2 = get_value_int16(request, _volume, &vol); - AFB_DEBUG( "requested %s = %d, %s = %d",_sink_id, sink_id, _volume, vol); + req_err1 = get_value_uint16(request, _SINK_ID, &sink_id); + req_err2 = get_value_int16(request, _VOLUME, &vol); + AFB_DEBUG( "requested %s = %d, %s = %d",_SINK_ID, sink_id, _VOLUME, vol); if((req_err1 != REQ_OK) || (req_err2 != REQ_OK)) { afb_req_fail(request,"wrong-request", NULL); @@ -336,9 +338,9 @@ static void volumeStep (struct afb_req request) REQ_ERROR req_err1, req_err2; GError *err = NULL; - req_err1 = get_value_uint16(request, _sink_id, &sink_id); - req_err2 = get_value_int16(request, _volume_step, &vol); - AFB_DEBUG( "requested %s = %d, %s = %d",_sink_id, sink_id, _volume_step, vol); + req_err1 = get_value_uint16(request, _SINK_ID, &sink_id); + req_err2 = get_value_int16(request, _VOLUME_STEP, &vol); + AFB_DEBUG( "requested %s = %d, %s = %d",_SINK_ID, sink_id, _VOLUME_STEP, vol); if((req_err1 != REQ_OK) || (req_err2 != REQ_OK)) { afb_req_fail(request,"wrong-request", NULL); @@ -392,9 +394,9 @@ static void setSinkMuteState(struct afb_req request) REQ_ERROR req_err1, req_err2; GError *err = NULL; - req_err1 = get_value_uint16(request, _sink_id, &sink_id); - req_err2 = get_value_int16(request, _mute_state, &mute); - AFB_DEBUG( "requested %s = %d, %s = %d",_sink_id, sink_id, _mute_state, mute); + req_err1 = get_value_uint16(request, _SINK_ID, &sink_id); + req_err2 = get_value_int16(request, _MUTE_STATE, &mute); + AFB_DEBUG( "requested %s = %d, %s = %d",_SINK_ID, sink_id, _MUTE_STATE, mute); if((req_err1 != REQ_OK) || (req_err2 != REQ_OK)) { afb_req_fail(request,"wrong-request", NULL); @@ -483,11 +485,11 @@ static void getListMainConnections(struct afb_req request) struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj,10, - _main_connection_id, mcid, - _source_id, srcid, - _sink_id, sinkid, - _delay, delay, - _connection_state, constate + _MAIN_CONNECTION_ID, mcid, + _SOURCE_ID, srcid, + _SINK_ID, sinkid, + _DELAY, delay, + _CONNECTION_STATE, constate ); json_object_array_add(array_res,res_obj); } @@ -602,9 +604,9 @@ static void ackConnect(struct afb_req request) REQ_ERROR req_err1, req_err2 , req_err3; GError *err = NULL; - req_err1 = get_value_uint16(request, _handle, &handle); - req_err2 = get_value_uint16(request, _connection_id, &connection_id); - req_err3 = get_value_uint16(request, _error, &error); + req_err1 = get_value_uint16(request, _HANDLE, &handle); + req_err2 = get_value_uint16(request, _CONNECTION_ID, &connection_id); + req_err3 = get_value_uint16(request, _ERROR, &error); if((req_err1 != REQ_OK) || (req_err2 != REQ_OK) || (req_err3 != REQ_OK)) { @@ -632,7 +634,7 @@ static void ackConnect(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -664,9 +666,9 @@ static void ackDisconnect(struct afb_req request) REQ_ERROR req_err1, req_err2 , req_err3; GError *err = NULL; - req_err1 = get_value_uint16(request, _handle, &handle); - req_err2 = get_value_uint16(request, _connection_id, &connection_id); - req_err3 = get_value_uint16(request, _error, &error); + req_err1 = get_value_uint16(request, _HANDLE, &handle); + req_err2 = get_value_uint16(request, _CONNECTION_ID, &connection_id); + req_err3 = get_value_uint16(request, _ERROR, &error); if((req_err1 != REQ_OK) || (req_err2 != REQ_OK) || (req_err3 != REQ_OK)) { @@ -694,7 +696,7 @@ static void ackDisconnect(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -724,8 +726,8 @@ static void ackSetSourceState(struct afb_req request) REQ_ERROR req_err1, req_err2; GError *err = NULL; - req_err1 = get_value_uint16(request, _handle, &handle); - req_err2 = get_value_uint16(request, _error, &error); + req_err1 = get_value_uint16(request, _HANDLE, &handle); + req_err2 = get_value_uint16(request, _ERROR, &error); if((req_err1 != REQ_OK) || (req_err2 != REQ_OK)) { @@ -748,7 +750,7 @@ static void ackSetSourceState(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -784,10 +786,10 @@ static void registerSource(struct afb_req request) gint32 source_state; /* i */ gint16 volume; /* n */ - if(REQ_OK != get_value_uint16(request, _source_id, &source_id)){ + if(REQ_OK != get_value_uint16(request, _SOURCE_ID, &source_id)){ source_id = DYNAMIC_SOURCE_ID; /* if 0, dynamic source id will be applied */ } - REQ_ERROR req_err = get_value_uint16(request, _domain_id, &domain_id); + REQ_ERROR req_err = get_value_uint16(request, _DOMAIN_ID, &domain_id); if( req_err != REQ_OK){ if(req_err == REQ_FAIL) { @@ -803,20 +805,20 @@ static void registerSource(struct afb_req request) afb_req_fail(request,"wrong-request", "domainID should be more than 0"); return; } - const gchar* name = afb_req_value(request, _appname); /* s */ + const gchar* name = afb_req_value(request, _APPNAME); /* s */ if(!name) { char* info = "Must specify the name. Please input json arg such as {\"appname\":\"radio\"}"; afb_req_fail(request, NULL, info); return; } - if(REQ_OK != get_value_uint16(request, _source_class_id, &source_class_id)){ + if(REQ_OK != get_value_uint16(request, _SOURCE_CLASS_ID, &source_class_id)){ source_class_id = DEFAULT_SOURCE_CLASS_ID; /* BASE */ } - if(REQ_OK != get_value_int32(request, _source_state, &source_state)){ + if(REQ_OK != get_value_int32(request, _SOURCE_STATE, &source_state)){ source_state = DEFAULT_SOURCE_STATE; /* SS_OFF */ } - if(REQ_OK != get_value_int16(request, _volume, &volume)){ + if(REQ_OK != get_value_int16(request, _VOLUME, &volume)){ volume = DEFAULT_VOLUME; } gboolean visible = TRUE; /* b */ @@ -871,8 +873,8 @@ static void registerSource(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 4, - _error, ret, - _source_id, acquire_source_id); + _ERROR, ret, + _SOURCE_ID, acquire_source_id); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -897,7 +899,7 @@ static void deregisterSource(struct afb_req request) GError *err = NULL; - if(REQ_OK != get_value_uint16(request, _source_id, &source_id)){ + if(REQ_OK != get_value_uint16(request, _SOURCE_ID, &source_id)){ afb_req_fail(request, "wrong-request", NULL); } audiomanager_routinginterface_call_deregister_source_sync( @@ -914,7 +916,7 @@ static void deregisterSource(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); @@ -964,7 +966,7 @@ static void subscribe(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -1013,7 +1015,7 @@ static void unsubscribe(struct afb_req request) /*create response json object*/ struct json_object *res = json_object_new_object(); sm_add_object_to_json_object_func(res, __FUNCTION__, 2, - _error, ret); + _ERROR, ret); char *info = get_response_audiomanager_massage_error(ret); afb_req_success(request, res, info); } @@ -1034,11 +1036,11 @@ static void on_new_main_connection(AudiomanagerCommandinterface* interface, struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj,10, - _main_connection_id, mcid, - _source_id, srcid, - _sink_id, sinkid, - _delay, delay, - _connection_state, constate + _MAIN_CONNECTION_ID, mcid, + _SOURCE_ID, srcid, + _SINK_ID, sinkid, + _DELAY, delay, + _CONNECTION_STATE, constate ); AFB_DEBUG("json object :%s:",json_object_to_json_string(res_obj)); @@ -1052,7 +1054,7 @@ static void on_removed_main_connection( struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj, 2, - _main_connection_id, mainConnectionID); + _MAIN_CONNECTION_ID, mainConnectionID); afb_event_push(ev_removed_main_connection, res_obj); } @@ -1063,8 +1065,8 @@ static void on_main_connection_state_changed( struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj, 4, - _connection_id, connectionID, - _connection_state, connectionState); + _CONNECTION_ID, connectionID, + _CONNECTION_STATE, connectionState); afb_event_push(ev_main_connection_state_changed, res_obj); } @@ -1074,8 +1076,8 @@ static void on_volume_changed( AFB_DEBUG("%s is called",__FUNCTION__); struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj, 4, - _sink_id, sinkID, - _volume, volume); + _SINK_ID, sinkID, + _VOLUME, volume); afb_event_push(ev_volume_changed, res_obj); } @@ -1085,8 +1087,8 @@ static void on_sink_mute_state_changed( AFB_DEBUG("%s is called",__FUNCTION__); struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj, 4, - _sink_id, sinkID, - _mute_state, mute); + _SINK_ID, sinkID, + _MUTE_STATE, mute); afb_event_push(ev_sink_mute_state_changed, res_obj); } @@ -1139,11 +1141,11 @@ static gboolean on_async_connect( struct json_object* ev_obj = json_object_new_object(); sm_add_object_to_json_object(ev_obj, 10, - _handle, arg_handle, - _connection_id, arg_connectionID, - _source_id, arg_sourceID, - _sink_id, arg_sinkID, - _connection_format, arg_connectionFormat); + _HANDLE, arg_handle, + _CONNECTION_ID, arg_connectionID, + _SOURCE_ID, arg_sourceID, + _SINK_ID, arg_sinkID, + _CONNECTION_FORMAT, arg_connectionFormat); afb_event_push(ev_async_connect, ev_obj); /* GError must be initialized here because it is same as grobal errno, @@ -1172,8 +1174,8 @@ static gboolean on_async_disconnect( AFB_DEBUG( "%s called", __FUNCTION__); struct json_object* ev_obj = json_object_new_object(); sm_add_object_to_json_object(ev_obj, 4, - _handle, arg_handle, - _connection_id, arg_connectionID); + _HANDLE, arg_handle, + _CONNECTION_ID, arg_connectionID); afb_event_push(ev_async_disconnect, ev_obj); GError* err = NULL; audiomanager_routinginterface_call_ack_disconnect_sync( @@ -1241,9 +1243,9 @@ static gboolean on_async_set_source_state( struct json_object* ev_obj = json_object_new_object(); char* ss_key = get_source_state_key(arg_sourceState); sm_add_object_to_json_object(ev_obj, 4, - _handle, arg_handle, - _source_id, arg_sourceID); - json_object_object_add(ev_obj, _source_state, json_object_new_string(ss_key)); + _HANDLE, arg_handle, + _SOURCE_ID, arg_sourceID); + json_object_object_add(ev_obj, _SOURCE_STATE, json_object_new_string(ss_key)); afb_event_push(ev_async_set_source_state, ev_obj); /* Applications must return ackSetSourceState to look sourceID, then Sound Manager doen't return ackSetSourceState */ /*audiomanager_routinginterface_call_ack_set_source_state_sync( |