#include "include/mm_sound_dbus.h"
#include "include/mm_sound_intf.h"
-#ifdef USE_SECURITY
-#include <security-server.h>
-#define COOKIE_SIZE 20
-#endif
-
-
struct callback_data {
void *user_cb;
void *user_data;
static int _notify_subscription(audio_event_t event, uint32_t subs_id, gboolean subscribe)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL;
+ GVariant *params = NULL;
const char *event_name = NULL;
debug_fenter();
static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32_t subs_id, GVariant *signal_params)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL;
+ GVariant *params = NULL;
const char *event_name = NULL;
debug_fenter();
return ret;
}
+static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
+ const char **device_name, int *stream_id, int *stream_num)
+{
+ const char *v_type;
+ GVariant *array_v;
+ GVariantIter iter, array_iter;
+ int i = 0;
+ int ret = MM_ERROR_NONE;
+
+ if (v == NULL) {
+ debug_error("Variant NULL");
+ return MM_ERROR_NONE;
+ }
+
+ v_type = g_variant_get_type_string(v);
+ if (g_variant_type_equal(v_type, "(isiisai)") == FALSE) {
+ debug_error("device variant type not matching '%s'", v_type);
+ return MM_ERROR_NONE;
+ }
+
+ g_variant_iter_init(&iter, v);
+ g_variant_iter_next(&iter, "i", device_id);
+ g_variant_iter_next(&iter, "&s", device_type);
+ g_variant_iter_next(&iter, "i", direction);
+ g_variant_iter_next(&iter, "i", state);
+ g_variant_iter_next(&iter, "&s", device_name);
+
+ array_v = g_variant_iter_next_value(&iter);
+ *stream_num = g_variant_iter_init(&array_iter, array_v);
+ if (*stream_num > MAX_STREAM_ON_DEVICE) {
+ debug_error("too many streams on device %d", *stream_num);
+ ret = MM_ERROR_SOUND_INTERNAL;
+ goto finish;
+ }
+
+ while (g_variant_iter_loop(&array_iter, "i", &stream_id[i++])) ;
+finish:
+ g_variant_unref(array_v);
+
+ return ret;
+}
+
/* This callback unmarshall general-formed paramters to subject specific parameters,
* and call proper callback */
static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
{
struct callback_data *cb_data = (struct callback_data*) userdata;
uint32_t event_id;
+ const char *name = NULL, *device_type = NULL;
+ int device_id, direction, state;
+ const gchar *v_type;
+ GVariantIter iter;
+ GVariant *device_v;
+ int stream_id[MAX_STREAM_ON_DEVICE];
+ int stream_num;
+
+ v_type = g_variant_get_type_string(params);
if (event == AUDIO_EVENT_VOLUME_CHANGED) {
char *volume_type_str = NULL, *direction = NULL;
g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
} else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
- const char *name = NULL, *device_type = NULL;
gboolean is_connected = FALSE;
- int device_id, io_direction, state;
- g_variant_get(params, "(u(i&sii&s)b)", &event_id, &device_id, &device_type, &io_direction,
- &state, &name, &is_connected);
- ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction, state, name, is_connected, cb_data->user_data);
+ if (g_variant_type_equal(v_type, "(u(isiisai)b)") == FALSE) {
+ debug_error("Device connection changed signature not matching : %s", v_type);
+ return ;
+ }
+ g_variant_iter_init(&iter, params);
+ g_variant_iter_next(&iter, "u", &event_id);
+ device_v = g_variant_iter_next_value(&iter);
+ if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
+ &name, stream_id, &stream_num) < 0) {
+ debug_error("Failed to parse device variant");
+ return ;
+ }
+ g_variant_iter_next(&iter, "b", &is_connected);
+
+ ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
+ state, name, stream_id, stream_num, is_connected, cb_data->user_data);
_notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
} else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
- const char *name = NULL, *device_type = NULL;
int changed_device_info_type = 0;
- int device_id, io_direction, state;
- g_variant_get(params, "(u(i&sii&s)i)", &event_id, &device_id, &device_type, &io_direction,
- &state, &name, &changed_device_info_type);
- ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, io_direction, state, name, changed_device_info_type, cb_data->user_data);
+ if (g_variant_type_equal(v_type, "(u(isiisai)i)") == FALSE) {
+ debug_error("Device information changed signature not matching : %s", v_type);
+ return ;
+ }
+
+ g_variant_iter_init(&iter, params);
+ g_variant_iter_next(&iter, "u", &event_id);
+ device_v = g_variant_iter_next_value(&iter);
+ if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
+ &name, stream_id, &stream_num) < 0) {
+ debug_error("Failed to parse device variant");
+ return ;
+ }
+ g_variant_iter_next(&iter, "i", &changed_device_info_type);
+
+ ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
+ state, name, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
+ } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
+
+ if (g_variant_type_equal(v_type, "(u(isiisai))") == FALSE) {
+ debug_error("Device state changed signature not matching : %s", v_type);
+ return ;
+ }
+
+ g_variant_iter_init(&iter, params);
+ g_variant_iter_next(&iter, "u", &event_id);
+ device_v = g_variant_iter_next_value(&iter);
+ if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
+ &name, stream_id, &stream_num) < 0) {
+ debug_error("Failed to parse device variant");
+ return ;
+ }
+
+ ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
+ state, name, stream_id, stream_num, cb_data->user_data);
} else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
} else if (event == AUDIO_EVENT_FOCUS_WATCH) {
} else if (event == AUDIO_EVENT_TEST) {
return ret;
}
+int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on)
+{
+ int ret = MM_ERROR_NONE;
+ GVariant *params, *result;
+ gboolean _is_on;
+
+ debug_fenter();
+
+ if (!is_on) {
+ debug_error("Invalid Parameter, is_on null");
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+
+ if ((params = g_variant_new("(ii)", stream_id, device_id)) == NULL) {
+ debug_error("Construct Param for query is stream on device failed");
+ return MM_ERROR_SOUND_INTERNAL;
+ }
+
+ if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_IS_STREAM_ON_DEVICE, params, &result)) != MM_ERROR_NONE) {
+ debug_error("is stream on device failed");
+ goto cleanup;
+ }
+
+ if (result) {
+ g_variant_get(result, "(b)", &_is_on);
+ debug_log("is_on : %d", _is_on);
+ *is_on = (bool)_is_on;
+ } else {
+ debug_error("reply null");
+ ret = MM_ERROR_SOUND_INTERNAL;
+ }
+
+cleanup:
+ if (params)
+ g_variant_unref(params);
+ if (result)
+ g_variant_unref(result);
+
+ debug_fleave();
+ return ret;
+}
+
int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list)
{
int ret = MM_ERROR_NONE;
GVariant *result = NULL, *child = NULL;
- GVariant *params;
+ GVariant *params = NULL;
GVariantIter iter;
mm_sound_device_t* device_item;
const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
g_variant_iter_init(&iter, child);
while (1) {
device_item = g_malloc0(sizeof(mm_sound_device_t));
- if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)", &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state, &device_name_tmp)) {
+ if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)",
+ &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
+ &device_name_tmp)) {
MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
*device_list = g_list_append(*device_list, device_item);
- debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)", device_item->id, device_item->type,device_item->io_direction, device_item->state, device_item->name);
+ debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)",
+ device_item->id, device_item->type,device_item->io_direction, device_item->state,
+ device_item->name);
+ device_item->stream_num = -1;
} else {
if (device_item)
g_free(device_item);
return ret;
}
+int mm_sound_proxy_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
+{
+ int ret = MM_ERROR_NONE;
+ struct callback_data *cb_data;
+
+ debug_fenter();
+
+ CB_DATA_NEW(cb_data, func, userdata, freefunc);
+
+ if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_STATE_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
+ debug_error("Add device state changed callback failed");
+ else
+ *subs_id = cb_data->subs_id;
+
+ debug_fleave();
+ return ret;
+}
+
+int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
+{
+ int ret = MM_ERROR_NONE;
+ debug_fenter();
+
+ if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE) {
+ debug_error("remove device state changed callback failed");
+ }
+
+ debug_fleave();
+ return ret;
+}
+
int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
{
int ret = MM_ERROR_NONE;
{
int ret = MM_ERROR_NONE;
int handle = 0;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
gboolean _enable_session = enable_session;
if (!codechandle) {
debug_fenter();
- params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume,
- volume_config, session_type, session_options, client_pid , _enable_session, stream_type, stream_index);
+ params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume, volume_config, session_type,
+ session_options, client_pid , _enable_session, stream_type, stream_index);
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus play tone failed");
debug_fleave();
return ret;
-
-
}
int mm_sound_proxy_play_tone_with_stream_info(int client_pid, int tone, char *stream_type, int stream_index, int volume, int repeat, int *codechandle)
{
int ret = MM_ERROR_NONE;
int handle = 0;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
debug_fleave();
return ret;
-
-
}
int mm_sound_proxy_play_sound(const char* filename, int tone, int repeat, int volume, int volume_config,
- int priority, int session_type, int session_options, int client_pid, int handle_route,
- bool enable_session, int *codechandle, char *stream_type, int stream_index)
+ int session_type, int session_options, int client_pid, bool enable_session, int *codechandle,
+ char *stream_type, int stream_index)
{
int ret = MM_ERROR_NONE;
int handle = 0;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
gboolean _enable_session = enable_session;
if (!filename || !codechandle) {
debug_fenter();
- params = g_variant_new("(siiiiiiiiibsi)", filename, tone, repeat, volume,
- volume_config, priority, session_type, session_options, client_pid, handle_route, _enable_session, stream_type, stream_index);
+ params = g_variant_new("(siiiiiiibsi)", filename, tone, repeat, volume,
+ volume_config, session_type, session_options, client_pid, _enable_session, stream_type, stream_index);
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus play file failed");
}
int mm_sound_proxy_play_sound_with_stream_info(const char* filename, int repeat, int volume,
- int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index)
+ int client_pid, int *codechandle, char *stream_type, int stream_index)
{
int ret = MM_ERROR_NONE;
int handle = 0;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
if (!filename || !codechandle) {
debug_error("Param for play is null");
debug_fenter();
- params = g_variant_new("(siiiiisi)", filename, repeat, volume,
- priority, client_pid, handle_route, stream_type, stream_index);
+ params = g_variant_new("(siiisi)", filename, repeat, volume, client_pid, stream_type, stream_index);
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_SOUND_SERVER, AUDIO_METHOD_PLAY_FILE_START_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus play file failed");
}
-
int mm_sound_proxy_stop_sound(int handle)
{
int ret = MM_ERROR_NONE;
int mm_sound_proxy_emergent_exit(int exit_pid)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL;
+ GVariant *params = NULL;
debug_fenter();
/*------------------------------------------ FOCUS --------------------------------------------------*/
#ifdef USE_FOCUS
-#ifdef SUPPORT_CONTAINER
-#ifdef USE_SECURITY
-char* _get_cookie(int cookie_size)
-{
- int retval = -1;
- char* cookie = NULL;
-
- if (security_server_get_cookie_size() != cookie_size) {
- debug_error ("[Security] security_server_get_cookie_size() != COOKIE_SIZE(%d)\n", cookie_size);
- return false;
- }
-
- cookie = (char*)malloc (cookie_size);
-
- retval = security_server_request_cookie (cookie, cookie_size);
- if (retval == SECURITY_SERVER_API_SUCCESS) {
- debug_msg ("[Security] security_server_request_cookie() returns [%d]\n", retval);
- } else {
- debug_error ("[Security] security_server_request_cookie() returns [%d]\n", retval);
- }
-
- return cookie;
-}
-
-static GVariant* _get_cookie_variant ()
-{
- int i;
- GVariantBuilder builder;
- char* cookie = NULL;
-
- cookie = _get_cookie(COOKIE_SIZE);
-
- if (cookie == NULL)
- return NULL;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
- for (i = 0; i < COOKIE_SIZE; i++)
- g_variant_builder_add(&builder, "y", cookie[i]);
-
- free (cookie);
- return g_variant_builder_end(&builder);
-}
-
-#endif /* USE_SECURITY */
-#endif /* SUPPORT_CONTAINER */
-
int mm_sound_proxy_get_unique_id(int *id)
{
int ret = MM_ERROR_NONE;
int mm_sound_proxy_register_focus(int id, int instance, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* userdata)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
-#ifdef SUPPORT_CONTAINER
- char container[128];
-#endif
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
-#ifdef SUPPORT_CONTAINER
-#ifdef USE_SECURITY
- params = g_variant_new("(@ayiisb)", _get_cookie_variant(), instance, id, stream_type, is_for_session);
-#else /* USE_SECURITY */
- gethostname(container, sizeof(container));
- debug_error("container = %s", container);
- params = g_variant_new("(siisb)", container, instance, id, stream_type, is_for_session);
-#endif /* USE_SECURITY */
-
-#else /* SUPPORT_CONTAINER */
params = g_variant_new("(iisb)", instance, id, stream_type, is_for_session);
-
-#endif /* SUPPORT_CONTAINER */
-
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus register focus failed");
int mm_sound_proxy_unregister_focus(int instance, int id, bool is_for_session)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
int mm_sound_proxy_set_foucs_reacquisition(int instance, int id, bool reacquisition)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
return ret;
}
-int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, char **additional_info)
+int mm_sound_proxy_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_GET_ACQUIRED_FOCUS_STREAM_TYPE, params, &result)) == MM_ERROR_NONE) {
if (result) {
- g_variant_get(result, "(ss)", stream_type, additional_info);
+ g_variant_get(result, "(sis)", stream_type, option, ext_info);
g_variant_unref(result);
}
} else {
return ret;
}
-int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session)
+int mm_sound_proxy_acquire_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info, bool is_for_session)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
- params = g_variant_new("(iiisb)", instance, id, type, option, is_for_session);
+ params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus acquire focus failed");
return ret;
}
-int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, const char *option, bool is_for_session)
+int mm_sound_proxy_release_focus(int instance, int id, mm_sound_focus_type_e type, int option, const char *ext_info, bool is_for_session)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
- params = g_variant_new("(iiisb)", instance, id, type, option, is_for_session);
+ params = g_variant_new("(iiiisb)", instance, id, type, option, ext_info ? ext_info : "", is_for_session);
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus release focus failed");
int mm_sound_proxy_set_focus_watch_callback(int instance, int handle, mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void* userdata)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
-#ifdef SUPPORT_CONTAINER
- char container[128];
-#endif
+ GVariant *params = NULL, *result = NULL;
debug_fenter();
-#ifdef SUPPORT_CONTAINER
-#ifdef USE_SECURITY
- params = g_variant_new("(@ayiiib)", _get_cookie_variant(), instance, handle, type, is_for_session);
-#else /* USE_SECURITY */
- gethostname(container, sizeof(container));
- debug_error("container = %s", container);
- params = g_variant_new("(siiib)", container, instance, handle, type, is_for_session);
-#endif /* USE_SECURITY */
-#else /* SUPPORT_CONTAINER */
params = g_variant_new("(iiib)", instance, handle, type, is_for_session);
-#endif /* SUPPORT_CONTAINER */
-
if (params) {
if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_FOCUS_SERVER, AUDIO_METHOD_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
debug_error("dbus set watch focus failed");
int mm_sound_proxy_unset_focus_watch_callback(int focus_tid, int handle, bool is_for_session)
{
int ret = MM_ERROR_NONE;
- GVariant* params = NULL, *result = NULL;
+ GVariant *params = NULL, *result = NULL;
debug_fenter();