summaryrefslogtreecommitdiffstats
path: root/src/soundmanager.c
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-03-28 21:03:23 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-05-16 18:38:27 +0900
commitcbf280b545bbb3a879c55913564796f944b217c4 (patch)
tree0fa8345f5d396bca5d4049783fb914d1bb527880 /src/soundmanager.c
parent975d5e70b89481c90df30365c660b3f5043c3150 (diff)
Clean: divide soundmanager.c into interface part and proxy part
* interface part ... soundmanager This receives request and send event to clients * proxy part ... am_proxy_audiomanager This is the proxy to call and receive audiomanager API Change-Id: If29643ba3356ec1d7ec87468b023cf8809aa4eb3 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src/soundmanager.c')
-rw-r--r--src/soundmanager.c618
1 files changed, 165 insertions, 453 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c
index cb33854..6acf2a0 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,11 +84,9 @@ 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;
req_err1 = get_value_uint16(request, KEY_SOURCE_ID, &source_id);
/* ToDo: Hardware abstraction for application user is needed.
@@ -120,24 +112,18 @@ 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, sink_id, &main_connectionID);
- if(!SEND_RESULT(err, request)) return;
+ if(!SEND_RESULT(ec, request)) return;
/* ToDo Remember appname(key) and tie to sourceID(value) */
/*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);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res, info);
}
@@ -145,32 +131,26 @@ 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;
+ 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, ret);
- char *info = get_response_audiomanager_massage_error(ret);
+ KEY_ERROR, ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res_obj, info); /* return error num as status */
}
@@ -180,9 +160,7 @@ 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;
req_err1 = get_value_uint16(request, KEY_SINK_ID, &sink_id);
req_err2 = get_value_int16(request, KEY_VOLUME, &vol);
@@ -193,20 +171,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;
+ 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", ret);
- char *info = get_response_audiomanager_massage_error(ret);
+ "error", ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res_obj, info); /* return error num as status */
}
@@ -216,9 +189,7 @@ 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;
req_err1 = get_value_uint16(request, KEY_SINK_ID, &sink_id);
req_err2 = get_value_int16(request, KEY_VOLUME_STEP, &vol);
@@ -229,20 +200,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;
+ 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", ret);
- char *info = get_response_audiomanager_massage_error(ret);
+ "error", ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res_obj, info); /* return error num as status */
}
@@ -252,9 +218,7 @@ 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;
req_err1 = get_value_uint16(request, KEY_SINK_ID, &sink_id);
req_err2 = get_value_int16(request, KEY_MUTE_STATE, &mute);
@@ -266,20 +230,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;
+ 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", ret);
- char *info = get_response_audiomanager_massage_error(ret);
+ "error", ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res_obj, info); /* return error num as status */
}
@@ -287,19 +246,12 @@ 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;
+ if(!SEND_RESULT(ec, request)) return;
/* create response */
struct json_object *array_res = json_object_new_array();
@@ -340,19 +292,12 @@ 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;
+ if(!SEND_RESULT(ec, request)) return;
/* create response */
struct json_object *response = json_object_new_object();
@@ -398,19 +343,12 @@ 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;
+ if(!SEND_RESULT(ec, request)) return;
/* create response */
struct json_object *response = json_object_new_object();
@@ -469,7 +407,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);
@@ -486,20 +423,15 @@ 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;
+ 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);
}
@@ -510,7 +442,7 @@ void ackDisconnect(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);
req_err3 = get_value_uint16(request, KEY_ERROR, &error);
@@ -526,20 +458,15 @@ 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;
+ 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);
}
@@ -549,7 +476,6 @@ void ackSetSourceState(struct afb_req request)
guint16 handle, error;
guint16 ret = 0;
REQ_ERROR req_err1, req_err2;
- GError *err = NULL;
req_err1 = get_value_uint16(request, KEY_HANDLE, &handle);
req_err2 = get_value_uint16(request, KEY_ERROR, &error);
@@ -561,27 +487,21 @@ 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;
+ 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);
+ KEY_ERROR, ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res, info);
}
void registerSource(struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
- GError *err = NULL;
-
guint16 source_id; /* q 0 is for dynamic id*/
guint16 domain_id; /* q */
@@ -653,57 +573,44 @@ void registerSource(struct afb_req request)
nconf_command.parameter = 0;
/* acquire data */
- guint16 acquire_source_id;
- guint16 ret;
+ int acquire_source_id;
+
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;
+ 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, ret,
+ KEY_ERROR, ec,
KEY_SOURCE_ID, acquire_source_id);
- char *info = get_response_audiomanager_massage_error(ret);
+ const 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
- );
- if(!SEND_RESULT(err, request)) return;
+ ErrorCode ec = am_proxy_deregister_source(source_id);
+ 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);
+ KEY_ERROR, ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
afb_req_success(request, res, info);
}
@@ -741,7 +648,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);
}
@@ -778,7 +685,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);
}
@@ -795,7 +702,7 @@ void streamOpen(struct afb_req request){
AFB_DEBUG("call %s", __FUNCTION__);
// register audio role and endpoint
// get audio_role
- const gchar* audio_role = afb_req_value(request, KEY_AHL_AUDIO_ROLE);
+ const gchar* audio_role = afb_req_value(request, KEY_AHL_AUDIO_ROLE); /* s */
if(!audio_role)
{
afb_req_fail(request, "wrong request", "Please input 'audio_role' as key");
@@ -843,14 +750,21 @@ void streamOpen(struct afb_req request){
json_object *res = json_object_new_object();
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);
+ KEY_AHL_REP_STREAM_ID, sid);
+ 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
+/* 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,42 +776,31 @@ 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(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
- );
- AFB_DEBUG("json object :%s:",json_object_to_json_string(res_obj));
-
+ KEY_CONNECTION_STATE, connectionState);
afb_event_push(ev_new_connection, res_obj);
}
-static void on_removed_main_connection(
- AudiomanagerCommandinterface* interface, guint16 mainConnectionID)
+static void on_removed_main_connection(int mainConnectionID)
{
AFB_DEBUG("%s is called",__FUNCTION__);
struct json_object* res_obj = json_object_new_object();
- sm_add_object_to_json_object(res_obj, 2,
- KEY_MAIN_CONNECTION_ID, mainConnectionID);
+ json_object_object_add(res_obj, KEY_MAIN_CONNECTION_ID, json_object_new_int(mainConnectionID));
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(int connectionID, int connectionState)
{
AFB_DEBUG("%s is called",__FUNCTION__);
@@ -908,8 +811,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(int sinkID, int volume)
{
AFB_DEBUG("%s is called",__FUNCTION__);
struct json_object* res_obj = json_object_new_object();
@@ -919,8 +821,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(int sinkID, int mute)
{
AFB_DEBUG("%s is called",__FUNCTION__);
struct json_object* res_obj = json_object_new_object();
@@ -933,15 +834,28 @@ 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)
{
AFB_DEBUG("%s is called",__FUNCTION__);
+ struct domain_data ddata = {
+ .domainID = DYNAMIC_DOMAIN_ID,
+ .name = "SoundManager",
+ .busname = SOUND_MANAGER_BUS_NAME,
+ .nodename = "soundmanager",
+ .early = FALSE,
+ .complete = TRUE,
+ .state = DS_CONTROLLED
+ };
+ ErrorCode ec = am_proxy_register_domain(create_domain_data(&ddata) , &SOUNDMANAGER_DOMAIN_ID);
+ if(!SEND_RESULT_NO_RESP(ec)){
+ AFB_WARNING("Failed to re-gisterDomain when asyncAbort");
+ return;
+ }
+ AFB_NOTICE("Sound Manager re-register domain, the old infomation may be lost");
afb_event_push(ev_set_routing_ready, NULL);
}
-static void on_set_routing_rundown(
- AudiomanagerRoutinginterface* interface)
+static void on_set_routing_rundown(void)
{
AFB_DEBUG("%s is called",__FUNCTION__);
afb_event_push(ev_set_routing_ready, NULL);
@@ -956,122 +870,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(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(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 void on_async_disconnect(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 void on_async_set_sink_volume(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 void on_async_set_source_state(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);
+ const 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,140 +966,28 @@ 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 ec = initialize_proxy();
+ if(ec == NOT_INITIALIZED){
+ 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;
+ ErrorCode ec;
/*create event*/
/*ToDo Hash table is better. And event should be created in the loop
@@ -1288,78 +1025,53 @@ int sm_init()
routing_event_list[3].event = &ev_async_set_source_state;
routing_event_list[4].name = strdup(route_evlist[4]);
routing_event_list[4].event = &ev_async_disconnect;
- /*for(size_t i = 0; i < size; ++i)
- {
- struct afb_event afbev = afb_daemon_make_event(afbitf->daemon, cmd_evlist[i]));
- size_t afbev_size = sizeof afbev;
- size_t key_size = sizeof cmd_evlist[i];
-
- struct event ev = {cmd_evlist[i],afbev};
- command_event_list[i] = malloc(key_size + afbev_size);
- command_event_list[i] = ev;
- search_result = hsearch(entry, FIND);
- if(search_result)
- 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_main_connection_state_changed = on_main_connection_state_changed,
+ .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
+ };
+ ec = open_soundmanager_interface(&instruction);
+ if(ec != 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
+ };
+ ec = am_proxy_register_domain(create_domain_data(&ddata) , &SOUNDMANAGER_DOMAIN_ID);
+ if(!SEND_RESULT_NO_RESP(ec)){
+ return -1;
+ }
+ if(ec != OK){
+ AFB_ERROR("Failed to registerDomain : %s", get_response_audiomanager_massage_error(ec));
+ return -1;
}
+ AFB_DEBUG("domainID : %d", SOUNDMANAGER_DOMAIN_ID);
- AFB_INFO("Finish Initialize event receive setting");
return 0;
-
-ev_init_out:
- AFB_WARNING( "DBus connection is not created");
- return -1;
}
void onevent(const char *event, struct json_object *object)