diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sm-def.h | 13 | ||||
-rw-r--r-- | src/sm-helper.c | 35 | ||||
-rw-r--r-- | src/soundmanager.c | 105 | ||||
-rw-r--r-- | src/soundmanager.h | 7 |
4 files changed, 154 insertions, 6 deletions
diff --git a/src/sm-def.h b/src/sm-def.h index 0c4a5e3..a735cdd 100644 --- a/src/sm-def.h +++ b/src/sm-def.h @@ -55,4 +55,17 @@ #define KEY_CONNECTION_FORMAT "connectionFormat" #define KEY_EVENT "event" +#ifdef ENABLE_AGL_AHL +#define KEY_AHL_AUDIO_ROLE "audio_role" +#define KEY_AHL_ENDPOINT_ID "endpoint_id" +#define KEY_AHL_ENDPOINT_TYPE "endpoint_type" + +typedef enum { + ENDPOINT_SINK, + ENDPOINT_SOURCE, +} EndPointType; +#endif + +#define MAX_LENGTH_STRING 256 + #endif // SOUNDMANAGER_DEFINE_H
\ No newline at end of file diff --git a/src/sm-helper.c b/src/sm-helper.c index 3300d67..02de95a 100644 --- a/src/sm-helper.c +++ b/src/sm-helper.c @@ -15,6 +15,7 @@ */ #include "sm-helper.h" +#include "sm-def.h" #include <stdlib.h> #include <string.h> #include <limits.h> @@ -111,7 +112,7 @@ void sm_add_object_to_json_object_func(struct json_object* j_obj, const char* ve { va_list args; va_start(args, count); - + json_object_object_add(j_obj,"verb", json_object_new_string(verb_name)); for(int i = 0; i < count; ++i ) @@ -157,9 +158,9 @@ int sm_search_routing_event_name_index(const char* value) } GVariant* create_source_data(guint16 sourceID, guint16 domainID, const char* appname, guint16 sourceClassID, - gint32 sourceState, gint16 volume, gboolean visible, struct availability_s availables, - guint16 interrupt, struct sound_property_s soundPropertyList, gint32 connectionFormatList, - struct main_sound_property_s mainPropertyList, struct notification_config_s NConfRouting, + gint32 sourceState, gint16 volume, gboolean visible, struct availability_s availables, + guint16 interrupt, struct sound_property_s soundPropertyList, gint32 connectionFormatList, + struct main_sound_property_s mainPropertyList, struct notification_config_s NConfRouting, struct notification_config_s NConfCommand) { GVariantBuilder builder; @@ -229,3 +230,29 @@ GVariant* create_domain_data(struct domain_data* data) AFB_DEBUG("created domainData %d", __LINE__); return g_variant_builder_end (&builder); } + +int get_sink_id(struct afb_req req, const char* key){ + const char* default_sink = afb_req_value (req, key); + int sink_id; + REQ_ERROR result = REQ_FAIL; + if(default_sink == NULL) { + afb_req_fail(req, "wrong request", NULL); + return -1; + } + else{ + if((strlen("default") == strlen(default_sink)) && + (0 == strncmp("default", default_sink, strlen("default")))){ + sink_id = DEFAULT_SINK; + result = REQ_OK; + } + else{ + result = get_value_uint16(req, key, &sink_id); + } + } + if(REQ_OK != result){ + AFB_INFO("can't parse %s, result %d", key, result); + afb_req_fail_f(req,"wrong-request","can't parse %s, result: %d", result); + return -1 + } + return sink_id; +}
\ No newline at end of file diff --git a/src/soundmanager.c b/src/soundmanager.c index e709665..689c358 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -754,8 +754,59 @@ void unsubscribe(struct afb_req request) ****** High Level API *********** * */ +#ifdef ENABLE_AGL_AHL void streamOpen(struct afb_req req){ -// TODO : wtite function + AFB_DEBUG("call %s", __FUNCTION__); + // register audio role and endpoint + 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"); + return; + } + guint16 endpoint_type = 0, endpoint_id = 0; + + endpoint_id = get_sink_id(request, KEY_AHL_ENDPOINT_ID); + if(-1 == endpoint_id) return; + + get_value_uint16(request, KEY_AHL_ENDPOINT_TYPE, &endpoint_type); + if(endpoint_type == ENDPOINT_SINK){ + AFB_WARNING("register sink from application is not supported"); + afb_req_fail(request,"wrong-request", "register sink from application is not supported"); + return; + } + // call registerSource + json_object *jreq = afb_req_json(req); + json_object *response = json_object_new_object(); + json_object_object_add(jreq, KEY_SOURCE_ID, json_object_new_string(audio_role)); + afb_service_call_sync("soundmanager", "registerSource", jreq, &response); + + json_object j_sid = NULL; + if(!json_object_object_get_ex(response, KEY_ERROR, &j_sid) { + afb_req_fail(request, NULL, "Failed streamOpen"); + return; + } + int sid = json_object_get_int(j_sid); + + // create client context + smClientCtxt* ctxt = (smClientCtxt*)malloc(sizeof smClientCtxt); + char* appid = afb_req_get_application_id((req); + ctxt->appname = malloc(MAX_LENGTH_STRING * sizeof(char)); + strcpy(ctxt->appname, appid, MAX_LENGTH_STRING); + ctxt->source->sourceID = sid; + ctxt->sink->sinkID = endpoint_id; + ctxt->type = endpoint_type; + ctxt->event->asyncSetSourceState = afb_daemon_make_event("asyncSetSourceState"); + afb_req_context_set(req, ctxt, on_client_context_terminated); + + // response + json_object *res = json_object_new_object(); + sm_add_object_to_json_object_func(res, __FUNCTION__, 4, + KEY_ERROR, ret, + KEY_CONNECTION_ID); + char *info = get_response_audiomanager_massage_error(ret); + afb_req_success(request, res, info); + } void streamClose(struct afb_req req){ @@ -769,6 +820,58 @@ void setStreamState(struct afb_req req){ /* ********** Callback Function invoked by Audio Manager ********** */ +#endif + +typedef struct source { + struct source* next; + int sourceID; + int mainConnectionID; +} source; + +typedef struct sink { + struct sink* next; + int sinkID; +} sink; + +typedef struct events { + struct afb_event asyncSetSourceState; +} + +typedef struct smClientCtxt{ + char* appname; + struct source source; + struct sink sink; + struct events events; +} + +static void on_client_context_terminated(void *data){ + smClientCtxt ctxt = (smClientCtxt*)data; + source* source_deleted; + if(ctxt == NULL){ + return; + } + AFB_DEBUG("Client %s session is closed", ctxt->appname); + while(ctxt->source->next != NULL){ + gint16 ret; + GError *err = NULL; + audiomanager_routinginterface_call_deregister_source_sync( + am_route_bus, + ctxt->source->sourceID, + &ret, NULL, &err + ); + source = ctxt->source->next; + free(ctxt->source->source); + if(err != NULL){ + AFB_ERROR("failed to call deregisterSource"); + } + else if(ret != NULL) + ++(ctxt->source); + AFB_DEBUG("ret = %d", ret); + } + free(ctxt->appname); + free(ctxt->event); + free(ctxt); +} static void on_new_main_connection(AudiomanagerCommandinterface* interface, GVariant* mainConnection) diff --git a/src/soundmanager.h b/src/soundmanager.h index 34d82fd..8f068c4 100644 --- a/src/soundmanager.h +++ b/src/soundmanager.h @@ -310,10 +310,12 @@ void subscribe(struct afb_req request); */ void unsubscribe(struct afb_req request); +#ifdef ENABLE_AGL_AHL + /** * Application High Level API for AGL * This function opens "stream". - * "strem" means the routing from source to sink. + * "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". @@ -322,6 +324,8 @@ void unsubscribe(struct afb_req request); * - 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_type: The type of endpoint which means source/sink. As default, Sound Manager uses it as source. + * sink is not supported for now. * - endpoint_id : Same as sinkID in Sound Manager. * * #### Return @@ -368,6 +372,7 @@ void setStreamState(struct afb_req req); ********** Event list from Sound Manager ********** */ +#endif /* |