summaryrefslogtreecommitdiffstats
path: root/src/soundmanager.c
diff options
context:
space:
mode:
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,