-static int _convert_signal_name_str_to_enum (const char *name_str, mm_sound_signal_name_t *name_enum) {
- int ret = MM_ERROR_NONE;
-
- if (!name_str || !name_enum)
- return MM_ERROR_INVALID_ARGUMENT;
-
- if (!strncmp(name_str, "ReleaseInternalFocus", strlen("ReleaseInternalFocus"))) {
- *name_enum = MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS;
- } else {
- ret = MM_ERROR_INVALID_ARGUMENT;
- LOGE("not supported signal name(%s), err(0x%08x)", name_str, ret);
- }
- return ret;
-}
-
-static void _dbus_signal_callback (const char *signal_name, int value, void *user_data)
-{
- int ret = MM_ERROR_NONE;
- mm_sound_signal_name_t signal;
- subscribe_cb_t *subscribe_cb = (subscribe_cb_t*)user_data;
-
- debug_fenter();
-
- if (!subscribe_cb)
- return;
-
- ret = _convert_signal_name_str_to_enum(signal_name, &signal);
- if (ret)
- return;
-
- debug_msg("signal: name[%s], value[0x%08x], user_data[%p], type[%d]",
- signal_name, value, user_data, subscribe_cb->signal_type);
-
- if (subscribe_cb->signal_type == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS) {
- /* Trigger the signal callback when it comes from the same process.
- * In this case, the second integer argument is consist of
- * |<-- pid (16bits) -->|<-- value (16bits) -->|,
- * FYI, #define PID_MAX_DEFAULT (CONFIG_BASE_SMALL ? 0x1000 : 0x8000).
- * In case of daemon usage, it uses the client_pid of subscribe_cb. */
- debug_msg ("client_pid[%d], getpid[%d], value>>16[%d], callback[%p]",
- subscribe_cb->client_pid, getpid(), (value >> 16), subscribe_cb);
- if ((subscribe_cb->client_pid ? subscribe_cb->client_pid : getpid()) == (value >> 16))
- subscribe_cb->callback(signal, (value & 0x0000FFFF), subscribe_cb->user_data);
- } else {
- debug_warning("not supported type[%d]", subscribe_cb->signal_type);
- }
-
- debug_fleave();
-
- return;
-}
-
-static void signal_callback(GDBusConnection *conn,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- int value=0;
- const GVariantType* value_type;
-
- debug_msg ("sender : %s, object : %s, interface : %s, signal : %s",
- sender_name, object_path, interface_name, signal_name);
- if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(i)"))) {
- g_variant_get(parameters, "(i)",&value);
- debug_msg(" - value : 0x08%x", value);
- _dbus_signal_callback(signal_name, value, user_data);
- } else {
- value_type = g_variant_get_type(parameters);
- debug_warning("signal type is %s", value_type);
- }
-}
-
-EXPORT_API
-int mm_sound_subscribe_signal(mm_sound_signal_name_t signal_type, unsigned int *subscribe_id,
- mm_sound_signal_callback callback, void *user_data)
-{
- int ret = MM_ERROR_NONE;
- GError *err = NULL;
- guint subs_id;
- subscribe_cb_t *subscribe_cb = NULL;
-
- debug_fenter();
-
- MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
-
- if (signal_type < 0 || signal_type >= MM_SOUND_SIGNAL_MAX || !subscribe_id) {
- debug_error ("invalid argument, signal(%d), subscribe_id(%p)", signal_type, subscribe_id);
- ret = MM_ERROR_INVALID_ARGUMENT;
- goto error;
- }
-
- subscribe_cb = malloc(sizeof(subscribe_cb_t));
- if (!subscribe_cb) {
- ret = MM_ERROR_SOUND_INTERNAL;
- goto error;
- }
- memset(subscribe_cb, 0, sizeof(subscribe_cb_t));
- subscribe_cb->signal_type = signal_type;
- subscribe_cb->callback = callback;
- subscribe_cb->user_data = user_data;
-
- g_dbus_conn_mmsound = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!g_dbus_conn_mmsound && err) {
- debug_error ("g_bus_get_sync() error (%s) ", err->message);
- g_error_free (err);
- ret = MM_ERROR_SOUND_INTERNAL;
- goto error;
- }
- subs_id = g_dbus_connection_signal_subscribe(g_dbus_conn_mmsound, NULL, MM_SOUND_DBUS_INTERFACE,
- dbus_signal_name_str[signal_type], MM_SOUND_DBUS_OBJECT_PATH,
- NULL, G_DBUS_SIGNAL_FLAGS_NONE, signal_callback,
- subscribe_cb, free);
- if (subs_id == 0) {
- debug_error ("g_dbus_connection_signal_subscribe() error (%d)", subs_id);
- ret = MM_ERROR_SOUND_INTERNAL;
- g_object_unref(g_dbus_conn_mmsound);
- goto error;
- }
- subscribe_cb->id = subs_id;
- *subscribe_id = subs_id;
-
- MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
-
- debug_fleave();
-
- return ret;
-
-error:
- if (subscribe_cb)
- free(subscribe_cb);
-
- MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
-
- return ret;
-}
-
-/* ToDo : Almost same as mm_sound_subscribe_signal, need to be merged */