summaryrefslogtreecommitdiffstats
path: root/src/soundmanager.c
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-02-02 16:08:20 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-02-26 08:58:48 +0000
commit3112266f448e582b06d46034748fc80d71e4d7b1 (patch)
tree409410adc01ca838e5479250cf07cc68ff817215 /src/soundmanager.c
parenta8c147ecdb6f0aa2a65c7501537bf28b9e28644e (diff)
Add getListMainSources function
This function gets the source list registered in AudioManager. Change-Id: I630200b8aaba1f6049773d183904086277624121 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src/soundmanager.c')
-rw-r--r--src/soundmanager.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c
index 3677830..0ac116f 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -500,6 +500,84 @@ static void getListMainConnections(struct afb_req request)
}
/**
+ * 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)
+{
+ 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
+ );
+
+ if(err != NULL)
+ {
+ afb_req_fail_f(request, "failed", "Unable to call %s", __FUNCTION__);
+ return;
+ }
+
+ /* create response */
+ struct json_object *response = json_object_new_object();
+ gsize size = g_variant_n_children(mainSourceList);
+ AFB_DEBUG( "%s size is %u",__FUNCTION__, (uint16_t)size);
+ sm_add_object_to_json_object_func(response, __FUNCTION__, 0);
+ if(size <= 0)
+ {
+ AFB_NOTICE("%s size is 0", __FUNCTION__);
+ }
+ else{
+ struct json_object *array_res = json_object_new_array();
+ for(int i = 0; i < size; ++i)
+ {
+ guint16 sourceid, sourceclassid;
+ gchar* sourcename;
+
+ gint16 av;
+ gint16 avr;
+ GVariant* child = g_variant_get_child_value(mainSourceList, i);
+ g_variant_get(
+ child,"(qs(nn)q)",
+ &sourceid, &sourcename, &av, &avr, &sourceclassid);
+ AFB_DEBUG( "sourceID: %d, sourceName: %s, availability: %d, availableReason: %d, sourceClassID: %d",
+ sourceid, sourcename, av, avr, sourceclassid);
+
+ struct json_object* res_obj = json_object_new_object();
+ sm_add_object_to_json_object(res_obj, 2, KEY_SOURCE_ID, sourceid);
+ json_object_object_add(res_obj, KEY_SINK_NAME, json_object_new_string(sourcename));
+ sm_add_object_to_json_object(res_obj,6,
+ KEY_AVAILABILITY, av,
+ KEY_AVAILABILITY_REASON, avr,
+ KEY_SOURCE_CLASS_ID, sourceclassid);
+ json_object_array_add(array_res,res_obj);
+ g_variant_unref(child);
+ }
+ json_object_object_add(response, "sinks", array_res);
+ }
+ afb_req_success(request, response, "Success to get main source list");
+ g_variant_unref(mainSourceList);
+}
+
+/**
* Call "getListMainSinks" function of Audio Manager.
* Get main sink list
*
@@ -1357,6 +1435,8 @@ static const struct afb_verb_v2 binding_verbs[]= {
.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,