diff options
-rw-r--r-- | src/soundmanager.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c index 0ce2f68..41bd271 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -536,40 +536,49 @@ static void getListMainSinks(struct afb_req request) } /* create response */ - struct json_object *array_res = json_object_new_array(); + struct json_object *response = json_object_new_object(); gsize size = g_variant_n_children(mainSinkList); AFB_DEBUG( "%s size is %u",__FUNCTION__, (uint16_t)size); - struct json_object *verb_obj = json_object_new_object(); - sm_add_object_to_json_object_func(verb_obj, __FUNCTION__, 0); - json_object_array_add(array_res, verb_obj); + sm_add_object_to_json_object_func(response, __FUNCTION__, 0); if(size <= 0) { AFB_NOTICE("%s size is 0", __FUNCTION__); } else{ - /*for(int i = 0; i < size; ++i) + struct json_object *array_res = json_object_new_array(); + for(int i = 0; i < size; ++i) { guint16 sinkid, sinkclassid; gchar* sinkname; - GVariant* available = g_variant_new("(nn)", -1, -1); + + gint16 av; + gint16 avr; gint16 volume, mutestate; - g_variant_get_child( - mainSinkList,i,"(qs(nn)nnq)", - &sinkid, sinkname, &volume, &mutestate, &sinkclassid); + GVariant* child = g_variant_get_child_value(mainSinkList, i); + g_variant_get( + child,"(qs(nn)nnq)", + &sinkid, &sinkname, &av, &avr, &volume, &mutestate, &sinkclassid); + AFB_DEBUG( "sinkID: %d, sinkName: %s, availability: %d, available_reason: %d, volume: %d, muteState: %d, sinkClassID: %d", + sinkid, sinkname, av, avr, volume, mutestate, sinkclassid); + struct json_object* res_obj = json_object_new_object(); - sm_add_object_to_json_object(res_obj,2,_sink_id, sinkid); - json_object_object_add(res_obj, _sink_name, json_object_new_string(sinkname)); - sm_add_object_to_json_object(res_obj,6, - _volume, volume, - _mute_state, mutestate, - _sink_class_id, sinkclassid); + sm_add_object_to_json_object(res_obj,2,_SINK_ID, sinkid); + json_object_object_add(res_obj, _SINK_NAME, json_object_new_string(sinkname)); + sm_add_object_to_json_object(res_obj,10, + _AVAILABILITY, av, + _AVAILABILITY_REASON, avr, + _VOLUME, volume, + _MUTE_STATE, mutestate, + _SINK_CLASS_ID, sinkclassid); json_object_array_add(array_res,res_obj); - }*/ + g_variant_unref(child); + } + json_object_object_add(response, "sinks", array_res); } - AFB_DEBUG("json object :%s:",json_object_to_json_string(array_res)); - //afb_req_success(request, array_res, "Success to get main sink list"); - afb_req_success(request, array_res, "This is not implemented yet"); + afb_req_success(request, response, "Success to get main sink list"); + g_variant_unref(mainSinkList); } + /* * ****** Routing Interface method(API) *********** |