diff options
author | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-03-28 21:03:23 +0900 |
---|---|---|
committer | Kazumasa Mitsunari <knimitz@witz-inc.co.jp> | 2018-03-29 13:32:55 +0900 |
commit | c89119a916c1f06a304097ad052e20a7178aadd6 (patch) | |
tree | 97e8633ca951215e8a2966ca8c47cf426b863213 /src/soundmanager.c | |
parent | bb486346dca12af4ade6388603bb832529f41746 (diff) |
Devide source code: interface part and proxy part
build success
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src/soundmanager.c')
-rw-r--r-- | src/soundmanager.c | 528 |
1 files changed, 126 insertions, 402 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c index b887f25..1b7ad6d 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -22,6 +22,7 @@ #include <json-c/json.h> #include <glib.h> #include "soundmanager.h" +#include "audiomanager_proxy.h" #include "sm-def.h" #include "sm-error.h" #include "sm-helper.h" @@ -31,14 +32,7 @@ struct event{ struct afb_event* event; }; -const static struct afb_binding_interface *afbitf; -static AudiomanagerCommandinterface *am_cmd_bus; -static AudiomanagerRoutinginterface *am_route_bus; -static AudiomanagerRoutingSoundmanager *sm_adapter; -static AudiomanagerRoutingSoundmanagerIface* sm_itf; -static GDBusConnection* system_conn = NULL; - -static guint16 SOUNDMANAGER_DOMAIN_ID; +static int SOUNDMANAGER_DOMAIN_ID; static struct event command_event_list[COMMAND_EVENT_NUM]; static struct event routing_event_list[ROUTING_EVENT_NUM]; @@ -90,8 +84,7 @@ void connect (struct afb_req request) { AFB_DEBUG("call %s", __FUNCTION__); guint16 source_id = 0, sink_id = 0; - guint16 main_connectionID = 0; - gint16 ret = -1; + int main_connectionID = 0; REQ_ERROR req_err1 = REQ_FAIL; REQ_ERROR req_err2 = REQ_FAIL; GError *err = NULL; @@ -120,13 +113,7 @@ void connect (struct afb_req request) return; } - audiomanager_commandinterface_call_connect_sync( - am_cmd_bus, - source_id, - sink_id, - &ret, - &main_connectionID, - NULL, &err); + ErrorCode ec = am_proxy_connect(source_id, source_id, &main_connectionID); if(!SEND_RESULT(err, request)) return; @@ -135,9 +122,9 @@ void connect (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, + "error", ec, KEY_MAIN_CONNECTION_ID, main_connectionID); - char *info = get_response_audiomanager_massage_error(ret); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -145,32 +132,27 @@ void disconnect (struct afb_req request) { AFB_DEBUG("call %s", __FUNCTION__); - guint16 id; - gint16 ret; + guint16 main_connection_id; REQ_ERROR req_err; GError *err = NULL; - req_err = get_value_uint16(request, KEY_MAIN_CONNECTION_ID, &id); - AFB_DEBUG( "requested %s = %d", KEY_MAIN_CONNECTION_ID, id); + req_err = get_value_uint16(request, KEY_MAIN_CONNECTION_ID, &main_connection_id); + AFB_DEBUG( "requested %s = %d", KEY_MAIN_CONNECTION_ID, main_connection_id); if(req_err != REQ_OK) { afb_req_fail(request,"wrong-request",afb_req_value (request, KEY_MAIN_CONNECTION_ID)); return; } - audiomanager_commandinterface_call_disconnect_sync( - am_cmd_bus, - id, - &ret, - NULL, &err); - AFB_DEBUG( "ret = %d", ret); + ErrorCode ec = am_proxy_disconnect(main_connection_id); + AFB_DEBUG( "ret = %d", ec); if(!SEND_RESULT(err, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, - KEY_ERROR, ret); - char *info = get_response_audiomanager_massage_error(ret); + KEY_ERROR, ec); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -180,7 +162,6 @@ void setVolume (struct afb_req request) AFB_DEBUG("call %s", __FUNCTION__); guint16 sink_id, vol; - gint16 ret; REQ_ERROR req_err1, req_err2; GError *err = NULL; @@ -193,20 +174,15 @@ void setVolume (struct afb_req request) return; } - audiomanager_commandinterface_call_set_volume_sync( - am_cmd_bus, - sink_id, - vol, - &ret, - NULL, &err); - AFB_DEBUG( "ret = %d", ret); + ErrorCode ec = am_proxy_set_volume(sink_id, vol); + AFB_DEBUG( "ret = %d", ec); if(!SEND_RESULT(err, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, - "error", ret); - char *info = get_response_audiomanager_massage_error(ret); + "error", ec); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -216,7 +192,6 @@ void volumeStep (struct afb_req request) AFB_DEBUG("call %s", __FUNCTION__); guint16 sink_id, vol; - gint16 ret; REQ_ERROR req_err1, req_err2; GError *err = NULL; @@ -229,20 +204,15 @@ void volumeStep (struct afb_req request) return; } - audiomanager_commandinterface_call_volume_step_sync( - am_cmd_bus, - sink_id, - vol, - &ret, - NULL, &err); - AFB_DEBUG( "ret = %d", ret); + ErrorCode ec = am_proxy_volume_step(sink_id, vol); + AFB_DEBUG( "ret = %d", ec); if(!SEND_RESULT(err, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, - "error", ret); - char *info = get_response_audiomanager_massage_error(ret); + "error", ec); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -252,7 +222,6 @@ void setSinkMuteState(struct afb_req request) AFB_DEBUG("call %s", __FUNCTION__); guint16 sink_id, mute; - gint16 ret; REQ_ERROR req_err1, req_err2; GError *err = NULL; @@ -266,20 +235,15 @@ void setSinkMuteState(struct afb_req request) return; } - audiomanager_commandinterface_call_set_sink_mute_state_sync( - am_cmd_bus, - sink_id, - mute, - &ret, - NULL, &err); - AFB_DEBUG( "ret = %d", ret); + ErrorCode ec = am_proxy_set_sink_mute_state(sink_id, mute); + AFB_DEBUG( "ret = %d", ec); if(!SEND_RESULT(err, request)) return; struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object_func(res_obj, __FUNCTION__, 2, - "error", ret); - char *info = get_response_audiomanager_massage_error(ret); + "error", ec); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res_obj, info); /* return error num as status */ } @@ -287,17 +251,11 @@ void setSinkMuteState(struct afb_req request) void getListMainConnections(struct afb_req request) { AFB_DEBUG("call getListMainConnections"); - guint16 ret; + GVariant* mainConnectionList; GError *err = NULL; - audiomanager_commandinterface_call_get_list_main_connections_sync( - am_cmd_bus, - &ret, - &mainConnectionList, - NULL, - &err - ); + ErrorCode ec = am_proxy_get_list_main_connections(mainConnectionList); if(!SEND_RESULT(err, request)) return; @@ -340,17 +298,11 @@ void getListMainConnections(struct afb_req request) void getListMainSources(struct afb_req request) { AFB_DEBUG("call %s", __FUNCTION__); - guint16 ret; + GVariant* mainSourceList; GError *err = NULL; - audiomanager_commandinterface_call_get_list_main_sources_sync( - am_cmd_bus, - &ret, - &mainSourceList, - NULL, - &err - ); + ErrorCode ec = am_proxy_get_list_main_sources(mainSourceList); if(!SEND_RESULT(err, request)) return; @@ -398,17 +350,11 @@ void getListMainSources(struct afb_req request) void getListMainSinks(struct afb_req request) { AFB_DEBUG("call %s", __FUNCTION__); - guint16 ret; + GVariant* mainSinkList; GError *err = NULL; - audiomanager_commandinterface_call_get_list_main_sinks_sync( - am_cmd_bus, - &ret, - &mainSinkList, - NULL, - &err - ); + ErrorCode ec = am_proxy_get_list_main_sinks(mainSinkList); if(!SEND_RESULT(err, request)) return; @@ -486,12 +432,7 @@ void ackConnect(struct afb_req request) return; } - audiomanager_routinginterface_call_ack_connect_sync( - am_route_bus, - handle, - connection_id, - error, - NULL, &err); + ErrorCode ec = am_proxy_ack_connect(handle, connection_id, error); if(!SEND_RESULT(err, request)) return; @@ -526,12 +467,7 @@ void ackDisconnect(struct afb_req request) return; } - audiomanager_routinginterface_call_ack_disconnect_sync( - am_route_bus, - handle, - connection_id, - error, - NULL, &err); + ErrorCode ec = am_proxy_ack_disconnect(handle, connection_id, error); if(!SEND_RESULT(err, request)) return; @@ -561,19 +497,15 @@ void ackSetSourceState(struct afb_req request) return; } - audiomanager_routinginterface_call_ack_set_source_state_sync( - am_route_bus, - handle, - error, - NULL, &err); + ErrorCode ec = am_proxy_ack_set_source_state(handle, error); if(!SEND_RESULT(err, 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); + KEY_ERROR, ec); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -654,56 +586,43 @@ void registerSource(struct afb_req request) /* acquire data */ guint16 acquire_source_id; - guint16 ret; + GVariant* sourceData = create_source_data (source_id, domain_id, name, source_class_id, source_state, volume, visible, available, interrupt, sound_property_list, connection_format_list, main_property_list, nconf_routing, nconf_command); - GVariant* input = g_variant_ref_sink(sourceData); - audiomanager_routinginterface_call_register_source_sync( - am_route_bus, - input, - &acquire_source_id, - &ret, - NULL, &err); - g_variant_unref(input); + ErrorCode ec = am_proxy_register_source(sourceData, acquire_source_id); if(!SEND_RESULT(err, 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, ret, + KEY_ERROR, ec, KEY_SOURCE_ID, acquire_source_id); - char *info = get_response_audiomanager_massage_error(ret); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } void deregisterSource(struct afb_req request) { guint16 source_id; - guint16 ret; GError *err = NULL; if(REQ_OK != get_value_uint16(request, KEY_SOURCE_ID, &source_id)){ afb_req_fail(request, "wrong-request", NULL); } - audiomanager_routinginterface_call_deregister_source_sync( - am_route_bus, - source_id, - &ret, - NULL, &err - ); + ErrorCode ec = am_proxy_deregister_source(source_id); if(!SEND_RESULT(err, 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); + KEY_ERROR, ec); + char *info = get_response_audiomanager_massage_error(ec); afb_req_success(request, res, info); } @@ -851,6 +770,15 @@ void streamOpen(struct afb_req request){ 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); + if(ctxt->source.mainConnectionID > 0){ + json_object* jreq = json_object_new_object(); + json_object_object_add(jreq, KEY_MAIN_CONNECTION_ID, ctxt->source.mainConnectionID); + afb_service_call_sync("soundmanager", "disconnect", jreq, &response); + json_object_object_get_ex(response, KEY_RESPONSE, &j_resp); + } */ } void setStreamState(struct afb_req request){ @@ -862,31 +790,24 @@ void setStreamState(struct afb_req request){ ********** Callback Function invoked by Audio Manager ********** */ -static void on_new_main_connection(AudiomanagerCommandinterface* interface, - GVariant* mainConnection) +static void on_new_main_connection(void* closure, int mainConnectioID, + int sourceID, int sinkID, int delay, int connectionState) { AFB_DEBUG("%s is called",__FUNCTION__); - guint16 mcid, srcid, sinkid; - gint16 delay, constate; - g_variant_get( - mainConnection,"(qqqnn)", &mcid, &srcid, &sinkid, &delay, &constate); - struct json_object* res_obj = json_object_new_object(); sm_add_object_to_json_object(res_obj,10, - KEY_MAIN_CONNECTION_ID, mcid, - KEY_SOURCE_ID, srcid, - KEY_SINK_ID, sinkid, + KEY_MAIN_CONNECTION_ID, mainConnectioID, + KEY_SOURCE_ID, sourceID, + KEY_SINK_ID, sinkID, KEY_DELAY, delay, - KEY_CONNECTION_STATE, constate - ); + KEY_CONNECTION_STATE, connectionState); AFB_DEBUG("json object :%s:",json_object_to_json_string(res_obj)); afb_event_push(ev_new_connection, res_obj); } -static void on_removed_main_connection( - AudiomanagerCommandinterface* interface, guint16 mainConnectionID) +static void on_removed_main_connection(void* closure, int mainConnectionID) { AFB_DEBUG("%s is called",__FUNCTION__); @@ -896,8 +817,7 @@ static void on_removed_main_connection( afb_event_push(ev_removed_main_connection, res_obj); } -static void on_main_connection_state_changed( - AudiomanagerCommandinterface* interface, guint16 connectionID, gint16 connectionState) +static void on_main_connection_state_changed(void* closure, int connectionID, int connectionState) { AFB_DEBUG("%s is called",__FUNCTION__); @@ -908,8 +828,7 @@ static void on_main_connection_state_changed( afb_event_push(ev_main_connection_state_changed, res_obj); } -static void on_volume_changed( - AudiomanagerCommandinterface* interface, guint16 sinkID, gint16 volume) +static void on_volume_changed(void* closure, int sinkID, int volume) { AFB_DEBUG("%s is called",__FUNCTION__); struct json_object* res_obj = json_object_new_object(); @@ -919,8 +838,7 @@ static void on_volume_changed( afb_event_push(ev_volume_changed, res_obj); } -static void on_sink_mute_state_changed( - AudiomanagerCommandinterface* interface, guint16 sinkID, gint16 mute) +static void on_sink_mute_state_changed(void* closure, int sinkID, int mute) { AFB_DEBUG("%s is called",__FUNCTION__); struct json_object* res_obj = json_object_new_object(); @@ -933,15 +851,13 @@ static void on_sink_mute_state_changed( /* ********** Callback Function invoked by Audio Manager Routing Interface********** */ -static void on_set_routing_ready( - AudiomanagerRoutinginterface* interface) +static void on_set_routing_ready(void* closure) { AFB_DEBUG("%s is called",__FUNCTION__); afb_event_push(ev_set_routing_ready, NULL); } -static void on_set_routing_rundown( - AudiomanagerRoutinginterface* interface) +static void on_set_routing_rundown(void* closure) { AFB_DEBUG("%s is called",__FUNCTION__); afb_event_push(ev_set_routing_ready, NULL); @@ -956,122 +872,57 @@ static void on_set_routing_rundown( * Sound Manager just sends ack to Audio Manager in charge of applications. * */ -static gboolean on_async_abort( - AudiomanagerRoutingSoundmanager *object, - GDBusMethodInvocation *invocation, - guint16 arg_handle) +static void on_async_abort(void *closure, int handle) { AFB_DEBUG( "%s called", __FUNCTION__); /* Nothing To Do. If it is better to implement something, I will implement */ - return TRUE; } -static gboolean on_async_connect( - AudiomanagerRoutingSoundmanager *object, - GDBusMethodInvocation *invocation, - guint16 arg_handle, - guint16 arg_connectionID, - guint16 arg_sourceID, - guint16 arg_sinkID, - gint arg_connectionFormat) +static void on_async_connect(void *closure, int handle, int connectionID, + int sourceID, int sinkID, int connectionFormat) { AFB_DEBUG( "%s called", __FUNCTION__); struct json_object* ev_obj = json_object_new_object(); sm_add_object_to_json_object(ev_obj, 10, - KEY_HANDLE, arg_handle, - KEY_CONNECTION_ID, arg_connectionID, - KEY_SOURCE_ID, arg_sourceID, - KEY_SINK_ID, arg_sinkID, - KEY_CONNECTION_FORMAT, arg_connectionFormat); + KEY_HANDLE, handle, + KEY_CONNECTION_ID, connectionID, + KEY_SOURCE_ID, sourceID, + KEY_SINK_ID, sinkID, + KEY_CONNECTION_FORMAT, connectionFormat); afb_event_push(ev_async_connect, ev_obj); - - /* GError must be initialized here because it is same as grobal errno, - so if afb_event_push is failed due to something, number will be changed */ - GError* err = NULL; - audiomanager_routinginterface_call_ack_connect_sync( - am_route_bus, - arg_handle, - arg_connectionID, - 0, - NULL, &err); - if(err != NULL) - { - AFB_ERROR( "Can't send ack to sound manager adapter %s", __FUNCTION__); - return FALSE; - } - return TRUE; } -static gboolean on_async_disconnect( - AudiomanagerRoutingSoundmanager *object, - GDBusMethodInvocation *invocation, - guint16 arg_handle, - guint16 arg_connectionID) +static gboolean on_async_disconnect(void *closure, int handle, int connectionID) { AFB_DEBUG( "%s called", __FUNCTION__); struct json_object* ev_obj = json_object_new_object(); sm_add_object_to_json_object(ev_obj, 4, - KEY_HANDLE, arg_handle, - KEY_CONNECTION_ID, arg_connectionID); + KEY_HANDLE, handle, + KEY_CONNECTION_ID, connectionID); afb_event_push(ev_async_disconnect, ev_obj); - GError* err = NULL; - audiomanager_routinginterface_call_ack_disconnect_sync( - am_route_bus, - arg_handle, - arg_connectionID, - 0, - NULL, &err); - if(err != NULL) - { - AFB_ERROR( "Can't send ack to sound manager adapter %s", __FUNCTION__); - return FALSE; - } - return TRUE; } -static gboolean on_async_set_sink_volume( - AudiomanagerRoutingSoundmanager *object, - GDBusMethodInvocation *invocation, - guint16 arg_handle, - guint16 arg_sinkID, - gint16 arg_volume, - gint16 arg_ramp, - guint16 arg_time) +static gboolean on_async_set_sink_volume(void *closure, int handle, int sinkID, + int volume, int ramp, int time) { AFB_DEBUG( "%s called", __FUNCTION__); - GError* err = NULL; - audiomanager_routinginterface_call_ack_set_sink_volume_sync( - am_route_bus, - arg_handle, - arg_volume, - 0, NULL, &err); - if(err != NULL);{ - AFB_ERROR( "Can't send ack to sound manager adapter %s", __FUNCTION__); - return FALSE; - } - return TRUE; } -static gboolean on_async_set_source_state( - AudiomanagerRoutingSoundmanager *object, - GDBusMethodInvocation *invocation, - guint16 arg_handle, - guint16 arg_sourceID, - gint arg_sourceState) +static gboolean on_async_set_source_state(void *closure, int handle, int sourceID, int sourceState) { AFB_DEBUG( "%s called", __FUNCTION__); struct json_object* ev_obj = json_object_new_object(); - char* ss_key = get_source_state_key(arg_sourceState); + char* ss_key = get_source_state_key(sourceState); sm_add_object_to_json_object(ev_obj, 4, - KEY_HANDLE, arg_handle, - KEY_SOURCE_ID, arg_sourceID); + KEY_HANDLE, handle, + KEY_SOURCE_ID, sourceID); json_object_object_add(ev_obj, KEY_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( am_route_bus, - arg_handle, + handle, NULL, NULL, &err);*/ } @@ -1117,138 +968,25 @@ static void create_client_context(afb_req request, guint16 source_id, guint16 si afb_req_context_set(request, ctxt, on_client_context_terminated); } -static int registerDomain() -{ - /* Default Setting of Sound Manager Domain */ - struct domain_data ddata = { - .domainID = DYNAMIC_DOMAIN_ID, - .name = "SoundManager", - .busname = SOUND_MANAGER_BUS_NAME, - .nodename = "soundmanager", - .early = FALSE, - .complete = TRUE, - .state = DS_CONTROLLED - }; - GVariant* domainData = create_domain_data(&ddata); - gchar* retBusName = SOUND_MANAGER_BUS_NAME; - gchar* retPath = SOUND_MANAGER_PATH; - gchar* retInterface = SOUND_MANAGER_RETURN_INTERFACE; - guint16 domain_id; - GError *err = NULL; - guint16 error; - - audiomanager_routinginterface_call_register_domain_sync( - am_route_bus, - domainData, - retBusName, - retPath, - retInterface, - &domain_id, &error, - NULL, &err); - if(err != NULL){ - AFB_ERROR( "Failed to call %s", __FUNCTION__); - return -1; - } - if(error != 0) - { - AFB_ERROR( "Failed to register domain"); - return error; - } - SOUNDMANAGER_DOMAIN_ID = domain_id; - AFB_NOTICE( "Complete registered domain id:%d",SOUNDMANAGER_DOMAIN_ID); - return 0; -} - -static int create_adapter() -{ - GError *error = NULL; - gboolean ret; - GVariant *value; - system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (error) - { - g_error_free(error); - return -1; - } - sm_adapter = audiomanager_routing_soundmanager_skeleton_new(); - sm_itf = AUDIOMANAGER_ROUTING_SOUNDMANAGER_GET_IFACE(sm_adapter); - - /* initialize sound manager adapter */ - sm_itf->handle_async_abort = on_async_abort; - sm_itf->handle_async_connect = on_async_connect; - sm_itf->handle_async_disconnect = on_async_disconnect; - sm_itf->handle_async_set_sink_volume = on_async_set_sink_volume; - sm_itf->handle_async_set_source_state = on_async_set_source_state; - - int sigret = g_signal_connect(sm_adapter, "handle-async-abort", G_CALLBACK(on_async_abort),NULL); - sigret = g_signal_connect(sm_adapter, "handle-async-connect", G_CALLBACK(on_async_connect),NULL); - sigret = g_signal_connect(sm_adapter, "handle-async-disconnect", G_CALLBACK(on_async_disconnect),NULL); - sigret = g_signal_connect(sm_adapter, "handle-async-set-sink-volume", G_CALLBACK(on_async_set_sink_volume),NULL); - sigret = g_signal_connect(sm_adapter, "handle-async-set-source-state", G_CALLBACK(on_async_set_source_state),NULL); - ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(sm_adapter), system_conn, SOUND_MANAGER_PATH, &error); - if (FALSE == ret) - { - AFB_ERROR( "failed to export"); - g_error_free(error); - g_object_unref(system_conn); - - return -1; - } - - return 0; -} - - -static void on_name_lost(GDBusServer *server, GDBusConnection *conn, gpointer data) -{ - // TODO: when the dbus name is lost, what should we do? - AFB_WARNING("%s called", __FUNCTION__); -} - int preinit() { - int ret; AFB_INFO("Initialize Dbus object"); - /* Initialize Dbus interface */ - if(am_cmd_bus || am_route_bus) - { - AFB_ERROR( "Dbus object to Audio Manager is already created"); - goto out; - } - am_cmd_bus = audiomanager_commandinterface_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - AM_NAME, - AM_CMD_PATH, - NULL, - NULL - ); - am_route_bus = audiomanager_routinginterface_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - AM_NAME, - AM_ROUTE_PATH, - NULL, - NULL - ); - if(!am_cmd_bus || !am_route_bus) - { - goto out; + /* Initialize Dbus interface */ + ErrorCode err = initialize_proxy(); + if(err != OK){ + AFB_ERROR("Failed to initialize"); + return -1; } AFB_NOTICE( "Finish Initialize"); return 0; -out: - AFB_ERROR("Failed to initialize"); - return -1; } int sm_init() { AFB_NOTICE("Initialize event receive setting"); - printf("Initialize event receive setting"); - int ret; + /* Initialize make event */ size_t size = sizeof cmd_evlist / sizeof *cmd_evlist; @@ -1302,64 +1040,50 @@ int sm_init() AFB_NOTICE( "event name is %s", search_result->key); }*/ - /* Initialize dbus event thread */ - if(!am_cmd_bus || !am_route_bus) - { - goto ev_init_out; - } - /* initialize signal from audio manager command interface */ - g_signal_connect(am_cmd_bus, - "volume_changed", - G_CALLBACK(on_volume_changed), - NULL); - g_signal_connect(am_cmd_bus, - "new_main_connection", - G_CALLBACK(on_new_main_connection), - NULL); - g_signal_connect(am_cmd_bus, - "removed_main_connection", - G_CALLBACK(on_removed_main_connection), - NULL); - g_signal_connect(am_cmd_bus, - "sink_mute_state_changed", - G_CALLBACK(on_sink_mute_state_changed), - NULL); - g_signal_connect(am_cmd_bus, - "main_connection_state_changed", - G_CALLBACK(on_main_connection_state_changed), - NULL); - g_signal_connect(am_route_bus, - "set_routing_ready", - G_CALLBACK(on_set_routing_ready), - NULL); - g_signal_connect(am_route_bus, - "set_routing_rundown", - G_CALLBACK(on_set_routing_rundown), - NULL); + am_event callback = { + .on_new_main_connection = on_new_main_connection, + .on_removed_main_connection = on_removed_main_connection, + .on_volume_changed = on_volume_changed, + .on_sink_mute_state_changed = on_sink_mute_state_changed, + .on_set_routing_ready = on_set_routing_ready, + .on_set_routing_rundown = on_set_routing_rundown + }; + set_event_callback(&callback); /* Get soundmanager adapter bus */ - ret = g_bus_own_name(G_BUS_TYPE_SYSTEM, SOUND_MANAGER_BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, - NULL,NULL, NULL, NULL, NULL); - AFB_DEBUG( "g_bus_own_name ret: %d", ret); - ret = create_adapter(); - if(ret != 0) - { - goto ev_init_out; + am_instruction instruction = { + .on_async_abort = on_async_abort, + .on_async_connect = on_async_connect, + .on_async_disconnect = on_async_disconnect, + .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){ + AFB_ERROR("Failed to create sound manager interface"); + return -1; } - ret = registerDomain(); - if(ret != 0) - { - AFB_ERROR("registerDomain error: %s",get_response_audiomanager_massage_error(ret)); - goto ev_init_out; + GError* err = NULL; + struct domain_data ddata = { + .domainID = DYNAMIC_DOMAIN_ID, + .name = "SoundManager", + .busname = SOUND_MANAGER_BUS_NAME, + .nodename = "soundmanager", + .early = FALSE, + .complete = TRUE, + .state = DS_CONTROLLED + }; + ret = am_proxy_register_domain( create_domain_data(&ddata), &SOUNDMANAGER_DOMAIN_ID); + if(!SEND_RESULT_NO_RESP(err)){ + return -1; } - - AFB_INFO("Finish Initialize event receive setting"); + if(ret != OK){ + AFB_ERROR("Failed to registerDomain : %s", get_response_audiomanager_massage_error(ret)); + return -1; + } + AFB_DEBUG("domainID : %d", SOUNDMANAGER_DOMAIN_ID); return 0; - -ev_init_out: - AFB_WARNING( "DBus connection is not created"); - return -1; } void onevent(const char *event, struct json_object *object) |