summaryrefslogtreecommitdiffstats
path: root/src/soundmanager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/soundmanager.c')
-rw-r--r--src/soundmanager.c598
1 files changed, 81 insertions, 517 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c
index 0ac116f..2c67f83 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-#define _GNU_SOURCE
-#define AFB_BINDING_VERSION 2
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -23,35 +21,15 @@
#include <unistd.h>
#include <json-c/json.h>
#include <glib.h>
-#include <pthread.h>
-#include <afb/afb-binding.h>
+#include "soundmanager.h"
+#include "sm-def.h"
#include "sm-error.h"
#include "sm-helper.h"
-#include "dbus/audio_manager_interface.h"
-
-#define AM_NAME "org.genivi.audiomanager"
-#define AM_CMD_PATH "/org/genivi/audiomanager/commandinterface"
-#define AM_ROUTE_PATH "/org/genivi/audiomanager/routinginterface"
-#define AM_ROUTE_NAME "org.genivi.audiomanager.routinginterface"
-#define SOUND_MANAGER_RETURN_INTERFACE "org.genivi.audiomanager.routing.soundmanager"
-#define SOUND_MANAGER_BUS_NAME "org.genivi.audiomanager.routing.soundmanager"
-#define SOUND_MANAGER_PATH "/org/genivi/audiomanager/routing/soundmanager"
-
-#define COMMAND_EVENT_NUM 10
-#define ROUTING_EVENT_NUM 10
-#define DEFAULT_SINK 1
-#define DEFAULT_SOURCE_CLASS_ID 100
-#define DYNAMIC_DOMAIN_ID 100
-#define DEFAULT_DOMAIN_ID 0
-#define DYNAMIC_SOURCE_ID 0
-#define DEFAULT_VOLUME 100
-#define DEFAULT_AVAILABLES 1
-#define DEFAULT_CONNECTION_FORMAT 2
-#define DEFAULT_INTERRUPT 0
-#define DEFAULT_SOURCE_STATE 2
-#define DS_CONTROLLED 1
-
-#define EVENT_SUBSCRIBE_ERROR_CODE 100
+
+struct event{
+ char* name;
+ struct afb_event* event;
+ };
const static struct afb_binding_interface *afbitf;
static AudiomanagerCommandinterface *am_cmd_bus;
@@ -60,13 +38,7 @@ static AudiomanagerRoutingSoundmanager *sm_adapter;
static AudiomanagerRoutingSoundmanagerIface* sm_itf;
static GDBusConnection* system_conn = NULL;
-static GMainLoop *loop = NULL;
static guint16 SOUNDMANAGER_DOMAIN_ID;
-/* To Do hash table is better */
-struct event{
- char* name;
- struct afb_event* event;
- };
static struct event command_event_list[COMMAND_EVENT_NUM];
static struct event routing_event_list[ROUTING_EVENT_NUM];
@@ -83,69 +55,11 @@ static struct afb_event ev_async_connect;
static struct afb_event ev_async_disconnect;
static struct afb_event ev_async_set_source_state;
-#define KEY_SOURCE_ID "sourceID"
-#define KEY_SINK_ID "sinkID"
-#define KEY_SINK_NAME "sinkName"
-#define KEY_MAIN_CONNECTION_ID "mainConnectionID"
-#define KEY_DELAY "delay"
-#define KEY_CONNECTION_STATE "connectionState"
-#define KEY_CONNECTION_ID "connectionID"
-#define KEY_VOLUME "volume"
-#define KEY_VOLUME_STEP "volumeStep"
-#define KEY_INTERRUPT "interrupt"
-#define KEY_MUTE_STATE "muteState"
-
-#define KEY_DOMAIN_ID "domainID"
-#define KEY_HANDLE "handle"
-#define KEY_APPNAME "appname"
-#define KEY_RAMP "ramp"
-#define KEY_TIME "time"
-#define KEY_SOURCE_STATE "sourceState"
-#define KEY_SOURCE_CLASS_ID "sourceClassID"
-#define KEY_SINK_CLASS_ID "sinkClassID"
-#define KEY_ERROR "error"
-#define KEY_SINK_DATA "sinkData"
-#define KEY_SOURCE_DATA "sourceData"
-#define KEY_INTERRUPT_STATE "interruptState"
-#define KEY_AVAILABILITY "availability"
-#define KEY_AVAILABILITY_REASON "availabilityReason"
-#define KEY_LIST_VOLUMES "listVolumes"
-#define KEY_PAYLOAD "payload"
-#define KEY_CONNECTION_FORMAT "connectionFormat"
/*
********** Method of Sound Manager (API) **********
*/
-/**
- * Call "connect" function of Audio Manager.
- * Getting resource right to output audio stream.
- * Please input following keys with value into json string object in argument.
- * In case of using libsoundmanager,
- * json_object *jobj = json_object_new_object();
- * json_object_object_add(jobj, "sourceID", json_object_new_int(100));
- * json_object_object_add(jobj, "sinkID", json_object_new_int(100));
- * call("connect", jobj);
- *
- * The order of arguments is not important.
- *
- * #### Parameters
- * Request key
- * - sourceID : Source ID getting in return value in registerSource or appname.
- * - sinkID : Sink ID. This should be more than 0. If no request, defalut value is set by sound manager
- *
- * This will be changed in near future because these arguments should be aliased like
- * sinkID:100 -> sinkID:"speaker"
- *
- * This will be modified after integrating
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- * sourceID and sinkID should be more than 0
- *
- */
-static void connect (struct afb_req request)
+void connect (struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
guint16 source_id = 0, sink_id = 0;
@@ -204,23 +118,7 @@ static void connect (struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Call "disconnect" function of Audio Manager.
- * Release resource right to output audio stream.
- *
- * #### Parameters
- * Request key
- * - sourceID : Source ID getting in return value in registerSource or appname.
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- * sourceID should be more than 0
- *
- */
-static void disconnect (struct afb_req request)
+void disconnect (struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
@@ -258,22 +156,7 @@ static void disconnect (struct afb_req request)
afb_req_success(request, res_obj, info); /* return error num as status */
}
-/**
- * Call "setVolume" function of Audio Manager.
- * Set sink volume.
- *
- * #### Parameters
- * Request key
- * - volume : volume value. The range of value should be [0-100]
- * - sinkID : sinkID you would like to change volume at
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void setVolume (struct afb_req request)
+void setVolume (struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
@@ -313,23 +196,7 @@ static void setVolume (struct afb_req request)
afb_req_success(request, res_obj, info); /* return error num as status */
}
-/**
- * Call "volumeStep" function of Audio Manager.
- * Change volume step of sink
- *
- * #### Parameters
- * Request key
- * - sinkID : sinkID you would to change volume step
- * - volumeStep : Step size of volume
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void volumeStep (struct afb_req request)
+void volumeStep (struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
@@ -369,23 +236,7 @@ static void volumeStep (struct afb_req request)
afb_req_success(request, res_obj, info); /* return error num as status */
}
-/**
- * Call "volumeStep" function of Audio Manager.
- * Change volume step of sink
- *
- * #### Parameters
- * Request key
- * - sinkID : sinkID you would like to change mute state
- * - muteState : muteState, 1 means mute, 2 means unmute. Or you can designate as "mute" or "unmute"
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void setSinkMuteState(struct afb_req request)
+void setSinkMuteState(struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
@@ -426,23 +277,7 @@ static void setSinkMuteState(struct afb_req request)
afb_req_success(request, res_obj, info); /* return error num as status */
}
-/**
- * Call "getListMainConnections" function of Audio Manager.
- * Get mainc connection list
- *
- * #### Parameters
- * Request key
- * None
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
- * Sound Manager return success.
- *
- * #### Note
- *
- */
-static void getListMainConnections(struct afb_req request)
+void getListMainConnections(struct afb_req request)
{
AFB_DEBUG("call getListMainConnections");
guint16 ret;
@@ -499,23 +334,7 @@ static void getListMainConnections(struct afb_req request)
afb_req_success(request, array_res, "Success to get main connection list");
}
-/**
- * Call "getListMainSources" function of Audio Manager.
- * Get main source list
- *
- * #### Parameters
- * Request key
- * None
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- * Even if there is no connection list, Sound Manager return success.
- *
- * #### Note
- *
- */
-static void getListMainSources(struct afb_req request)
+void getListMainSources(struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
guint16 ret;
@@ -577,23 +396,7 @@ static void getListMainSources(struct afb_req request)
g_variant_unref(mainSourceList);
}
-/**
- * Call "getListMainSinks" function of Audio Manager.
- * Get main sink list
- *
- * #### Parameters
- * Request key
- * None
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
- * Sound Manager return success.
- *
- * #### Note
- *
- */
-static void getListMainSinks(struct afb_req request)
+void getListMainSinks(struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
guint16 ret;
@@ -664,26 +467,7 @@ static void getListMainSinks(struct afb_req request)
*
*/
-/**
- * Call "ackConnect" function of Audio Manager.
- * Return acknowledge of connect against asyncConnect
- *
- * #### Parameters
- * - handle : Handle id when you get on asyncConnect
- * - connectionID : connection id when you got on connect return value
- * - error : Error Number you would like to send. If error is 0, it means OK.
- * If an application has some error, send error number in function then AM release
- * resources the application got in connect.
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
- * Sound Manager return success. So you should check the contents size of return json object
- *
- * #### Note
- *
- */
-static void ackConnect(struct afb_req request)
+void ackConnect(struct afb_req request)
{
/* This function will be deprecated */
AFB_DEBUG("call %s", __FUNCTION__);
@@ -727,25 +511,7 @@ static void ackConnect(struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Call "ackDisconnect" function of Audio Manager.
- * Return acknowledge of disconnect against asyncDisconnect
- *
- * #### Parameters
- * - handle : Handle id when you get on asyncDisconnect
- * - connectionID : connection id when you got on connect return value
- * - error : Error Number you would like to send. If error is 0, it means OK.
- * If an application has some error, send error number in function then AM
- *
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message. Even if there is no connection list,
- * Sound Manager return success. So you should check the contents size of return json object
- *
- * #### Note
- *
- */
-static void ackDisconnect(struct afb_req request)
+void ackDisconnect(struct afb_req request)
{
/* This function will be deprecated */
AFB_DEBUG("call %s", __FUNCTION__);
@@ -757,7 +523,6 @@ static void ackDisconnect(struct afb_req request)
req_err2 = get_value_uint16(request, KEY_CONNECTION_ID, &connection_id);
req_err3 = get_value_uint16(request, KEY_ERROR, &error);
-
if((req_err1 != REQ_OK) || (req_err2 != REQ_OK) || (req_err3 != REQ_OK))
{
afb_req_fail(request,"wrong-request", "connectionID is more than 0");
@@ -789,34 +554,17 @@ static void ackDisconnect(struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Call "ackSetSourceState" function of Audio Manager.
- * Return acknowledge of setSourceState against asyncSetSourceState.
- *
- * #### Parameters
- * - handle : Handle id when you get on asyncSetSourceState
- * - error : Error Number you would like to send. If error is 0, it means OK.
- * If an application has some errors, send error number in function
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- * This function is very important for applications to realise the sequence of Audio Management.
- * An Application which matches with sourceID in the parameter of asyncSetSourceState has to return ack to use this function
- *
- */
-static void ackSetSourceState(struct afb_req request)
+void ackSetSourceState(struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
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);
-
if((req_err1 != REQ_OK) || (req_err2 != REQ_OK))
{
AFB_DEBUG("wrong request");
@@ -843,26 +591,7 @@ static void ackSetSourceState(struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Call "registerSource" function of Audio Manager.
- * Register source(application) to Audio Manager Policy Management
- * Application must call this function on its initialization
- *
- * #### Parameters
- * - appname : Application unieque name
- * [Option]
- * It is not necessary to designate following argument, because these are default value is selected y soundmanager
- * If you would like to set value, please input the following key and value
- * - sourceClassID :
- * - sourceState :
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void registerSource(struct afb_req request)
+void registerSource(struct afb_req request)
{
AFB_DEBUG("call %s", __FUNCTION__);
GError *err = NULL;
@@ -970,20 +699,7 @@ static void registerSource(struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Call "deregisterSource" function of Audio Manager.
- * Deregister source(application) to Audio Manager Policy Management
- *
- * #### Parameters
- * - sourceID : sourceID returned in resisterSource
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void deregisterSource(struct afb_req request)
+void deregisterSource(struct afb_req request)
{
guint16 source_id;
guint16 ret;
@@ -1013,22 +729,10 @@ static void deregisterSource(struct afb_req request)
}
-/**
- * Subscribe event
- *
- * #### Parameters
- * - event : Event name. Event list is written in libsoundmanager.hpp
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void subscribe(struct afb_req request)
+void subscribe(struct afb_req request)
{
- const char *value = afb_req_value(request, "event");
- AFB_DEBUG( "value is %s", value);
+ const char *value = afb_req_value(request, KEY_EVENT);
+ AFB_DEBUG( "%s %s", __FUNCTION__, value);
int ret = 0;
if(value) {
int index = sm_search_event_name_index(value);
@@ -1062,22 +766,10 @@ static void subscribe(struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Unsubscribe event
- *
- * #### Parameters
- * - event : Event name. Event list is written in libsoundmanager.hpp
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- *
- * #### Note
- *
- */
-static void unsubscribe(struct afb_req request)
+void unsubscribe(struct afb_req request)
{
- const char *value = afb_req_value(request, "event");
- AFB_DEBUG( "value is %s", value);
+ const char *value = afb_req_value(request, KEY_EVENT);
+ AFB_DEBUG( "%s %s", __FUNCTION__, value);
int ret = 0;
if(value) {
int index = sm_search_event_name_index(value);
@@ -1111,65 +803,26 @@ static void unsubscribe(struct afb_req request)
afb_req_success(request, res, info);
}
-/**
- * Application High Level API for AGL
- * This function opens "stream".
- * "stream" means the routing from source to sink.
- * This function calls registerSource and register the endpoint.
- * If the endpoint is not registered in AudioManager, Sound Manager uses default value.
- * audio_role will be translated to "sourceID", and "endpoint_id" will be translated to "sinkID".
- *
- * #### Parameters
- * - audio_role : audio role such like entertainment, emergency.
- * This name is depends on the system architect.
- * The name will be application name or will be the group(role) of application.
- * - endpoint_id : Same as sinkID in Sound Manager.
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- * - stream_id : Same as sourceID but the key is different. This is for AHL.
- * #### Note
- * TODO : write note
- */
-static void streamOpen(struct afb_req req){
+/*
+*
+****** High Level API ***********
+*
+*/
+
+
+#ifdef ENABLE_AGL_AHL
+void streamOpen(struct afb_req request){
// TODO : wtite function
}
-/**
- * Application High Level API for AGL
- * This function closes "stream".
- * This function calls disconnect with registered connectionID translated with requested connection_id.
- * If the connection is not created in Sound Manager, Sound Manager just returns with error message.
- *
- * #### Parameters
- * - stream_id : Stream id which is returned in stream_open.
- *
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- * #### Note
- * TODO : write note
- */
-static void streamClose(struct afb_req req){
+void streamClose(struct afb_req request){
// TODO : wtite function
}
-/**
- * Application High Level API for AGL
- * This function set stream state.
- * This function set the availability and calls connect function of Audio Manager
- * and returns the result of policy check.
- *
- * #### Parameters
- * - stream_id : Stream id which is returned in stream_open.
- * - mute : Stream state as int
- * #### Return
- * - error : Error status number. If error is 0, it means the request is accepted, otherwise error message is attached with error code in reply message.
- * #### Note
- * TODO : write note
- */
-static void setStreamState(struct afb_req req){
+void setStreamState(struct afb_req request){
// TODO : wtite function
}
+#endif
/*
********** Callback Function invoked by Audio Manager **********
@@ -1366,23 +1019,6 @@ static gboolean on_async_set_sink_volume(
return TRUE;
}
-/**
- * Event "asyncSetSourceState"
- * This event is one of the result of Audio Management for connect/disconnect.
- *
- * #### Parameters
- * Request key
- * - sourceID : sourceID to be commanded by Audio Manager. The contents of command is sourceState
- * - handle : handle is the dynamic number managed by Audio Manager. Please return this parameter to input ackSetSourceState as is
- * - sourceState : "on" is the instruction that application can output sound
- * "off" is the instruction that application sound right will be removed_main_connection
- * "pause" is the instruction that application must stop output sound because other applications temporaly got sound right and will output sound
- *
- * #### Note
- * This function is very important for applications to realise the sequence of Audio Management.
- * An Application which matches with sourceID in the parameter of asyncSetSourceState has to return ack to use this function
- *
- */
static gboolean on_async_set_source_state(
AudiomanagerRoutingSoundmanager *object,
GDBusMethodInvocation *invocation,
@@ -1406,59 +1042,6 @@ static gboolean on_async_set_source_state(
NULL, &err);*/
}
-
-/*
- * array of the verbs exported to afb-daemon
- */
-static const struct afb_verb_v2 binding_verbs[]= {
-#ifdef ENABLE_AGL_AHL
-// High level API of AGL
-{ .verb = "stream_open", .callback = streamOpen, .auth = NULL,
- .info = "Open stream." , .session = AFB_SESSION_NONE},
-{ .verb = "stream_close", .callback = streamClose, .auth = NULL,
- .info = "Close stream" , .session = AFB_SESSION_NONE},
-{ .verb = "set_stream_state", .callback = setStreamState, .auth = NULL,
- .info = "Set stream state" , .session = AFB_SESSION_NONE},
-#endif
-// Adaption API of Audio Manager
-{ .verb = "connect", .callback = connect, .auth = NULL,
- .info = "Connect source id and sink id" , .session = AFB_SESSION_NONE},
-{ .verb = "disconnect", .callback = disconnect, .auth = NULL,
- .info = "Disconnect source id and sink id" , .session = AFB_SESSION_NONE},
-{ .verb = "setVolume", .callback = setVolume, .auth = NULL,
- .info = "Set volume value" , .session = AFB_SESSION_NONE}, /* it is better to show the range*/
-{ .verb = "volumeStep", .callback = volumeStep, .auth = NULL,
- .info = "Set volume step range" , .session = AFB_SESSION_NONE},
-{ .verb = "setSinkMuteState", .callback = setSinkMuteState, .auth = NULL,
- .info = "Set Mute state: 1 means mute, 2 means umute. Others are invalid" ,.session = AFB_SESSION_NONE},
-{ .verb = "getListMainConnections", .callback = getListMainConnections, .auth = NULL,
- .info = "Get MainConnection List" , .session = AFB_SESSION_NONE},
-{ .verb = "getListMainSinks", .callback = getListMainSinks, .auth = NULL,
- .info = "Get MainSink List" , .session = AFB_SESSION_NONE},
-{ .verb = "getListMainSources", .callback = getListMainSources, .auth = NULL,
- .info = "Get MainSource List" , .session = AFB_SESSION_NONE},
-{ .verb = "registerSource", .callback = registerSource, .auth = NULL,
- .info = "Register audio role" , .session = AFB_SESSION_NONE},
-{ .verb = "deregisterSource", .callback = deregisterSource, .auth = NULL,
- .info = "Deregister audio role" , .session = AFB_SESSION_NONE},
-{ .verb = "ackConnect", .callback = ackConnect, .auth = NULL,
- .info = "Acknowledge of asyncConnect" , .session = AFB_SESSION_NONE},
-{ .verb = "ackDisconnect", .callback = ackDisconnect, .auth = NULL,
- .info = "Acknowledge of asyncConnect" , .session = AFB_SESSION_NONE},
-{ .verb = "ackSetSourceState", .callback = ackSetSourceState, .auth = NULL,
- .info = "Acknowledge of asyncSetSourceState" , .session = AFB_SESSION_NONE},
-{ .verb = "subscribe", .callback = subscribe, .auth = NULL,
- .info = "Subscribe event" , .session = AFB_SESSION_NONE},
-{ .verb = "unsubscribe", .callback = unsubscribe, .auth = NULL,
- .info = "Unsubscribe event" , .session = AFB_SESSION_NONE},
-{ .verb = NULL } /* marker for end of the array */};
-
-static void *dbus_event_loop_run(void *args)
-{
- loop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(loop);
-}
-
/*
*
********** Internal Function used by Sound Manager **********
@@ -1507,45 +1090,6 @@ static int registerDomain()
return 0;
}
-static 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;
- }
-
- AFB_NOTICE( "Finish Initialize");
- return 0;
-out:
- AFB_ERROR("Failed to initialize");
- return -1;
-}
-
static int create_adapter()
{
GError *error = NULL;
@@ -1588,11 +1132,50 @@ static int create_adapter()
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;
+ }
+
+ AFB_NOTICE( "Finish Initialize");
+ return 0;
+out:
+ AFB_ERROR("Failed to initialize");
+ return -1;
+}
-static int sm_event_init()
+int sm_init()
{
AFB_NOTICE("Initialize event receive setting");
printf("Initialize event receive setting");
@@ -1655,12 +1238,6 @@ static int sm_event_init()
{
goto ev_init_out;
}
- pthread_t thread_id;
- ret = pthread_create(&thread_id, NULL, dbus_event_loop_run, NULL);
- if(ret != 0)
- {
- goto ev_init_out;
- }
/* initialize signal from audio manager command interface */
g_signal_connect(am_cmd_bus,
"volume_changed",
@@ -1712,24 +1289,11 @@ static int sm_event_init()
return 0;
ev_init_out:
- if(loop != NULL)
- {
- g_main_loop_unref(loop);
- }
AFB_WARNING( "DBus connection is not created");
return -1;
}
-static void onevent(const char *event, struct json_object *object)
+void onevent(const char *event, struct json_object *object)
{
AFB_NOTICE("on_event %s", event);
-}
-
-const struct afb_binding_v2 afbBindingV2 = {
- .api = "soundmanager",
- .specification = NULL,
- .verbs = binding_verbs,
- .preinit = preinit,
- .init = sm_event_init,
- .onevent = onevent
-};
+} \ No newline at end of file