#define PA_TONE_PLAYER_METHOD_NAME_TONE_PLAY "TonePlay"
#define PA_TONE_PLAYER_METHOD_NAME_TONE_STOP "ToneStop"
-static int _convert_dbus_error(const char *error_msg)
+static int __convert_dbus_error(const char *error_msg)
{
if (error_msg && strstr(error_msg, "InvalidArgument"))
return TONE_PLAYER_ERROR_INVALID_PARAMETER;
static GDBusConnection *__get_dbus_connection(void)
{
GDBusConnection *conn = NULL;
- GError *err = NULL;
+ g_autoptr(GError) err = NULL;
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!conn) {
+ if (!(conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err))) {
+ g_assert(err);
LOGE("g_bus_get_sync() error (%s)", err->message);
- g_error_free(err);
+ return NULL;
}
return conn;
static int __dbus_method_call(const char *method, GVariant *param, GVariant **reply)
{
- GDBusConnection *conn = NULL;
- GVariant * _reply = NULL;
- GError *err = NULL;
- int ret;
+ g_autoptr(GDBusConnection) conn = NULL;
+ g_autoptr(GVariant) _reply = NULL;
+ g_autoptr(GError) err = NULL;
if (!method || !param) {
- LOGE("invalid parameter");
- ret = TONE_PLAYER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
- goto error;
- }
-
- if (!(conn = __get_dbus_connection())) {
- ret = TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
- goto error;
+ LOGE("invalid parameter"); //LCOV_EXCL_LINE
+ return TONE_PLAYER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- _reply = g_dbus_connection_call_sync(conn, PA_BUS_NAME,
- PA_TONE_PLAYER_OBJECT_PATH,
- PA_TONE_PLAYER_INTERFACE,
- method, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-
- g_object_unref(conn);
+ if (!(conn = __get_dbus_connection()))
+ return TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
- if (!_reply) {
+ if (!(_reply = g_dbus_connection_call_sync(conn, PA_BUS_NAME,
+ PA_TONE_PLAYER_OBJECT_PATH,
+ PA_TONE_PLAYER_INTERFACE,
+ method, param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+ &err))) {
+ g_assert(err);
LOGE("g_dbus_connection_call_sync() method(%s), err-msg(%s)", method, err->message);
- ret = _convert_dbus_error(err->message);
- g_error_free(err);
- return ret;
+
+ return __convert_dbus_error(err->message);
}
if (reply)
- *reply = _reply;
- else
- g_variant_unref(_reply);
+ *reply = g_steal_pointer(&_reply);
return TONE_PLAYER_ERROR_NONE;
-
-error:
- if (param)
- g_variant_unref(param);
-
- return ret;
}
-
-int tone_player_start_new(tone_type_e tone, sound_stream_info_h stream_info, int duration_ms, int *id)
+static int __get_sound_manager_stream_properties(sound_stream_info_h stream_info, char **stream_type, int *stream_id)
{
- int ret;
- char *stream_type = NULL;
- int stream_id;
+ int ret = SOUND_MANAGER_ERROR_NONE;
bool result = false;
- GVariant *reply = NULL;
- int handle;
-
- LOGI("tone(%d), duration_ms(%d)", tone, duration_ms);
-
- if (tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE || !stream_info) {
- LOGE("invalid parameter.");
+ if (!stream_info) {
+ LOGE("invalid stream_info!!");
return TONE_PLAYER_ERROR_INVALID_PARAMETER;
}
return TONE_PLAYER_ERROR_NOT_SUPPORTED_TYPE;
}
- ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
- if (ret) {
+ if ((ret = sound_manager_get_type_from_stream_information(stream_info, stream_type))) {
LOGE("can't get stream type. ret(0x%x)", ret);
return TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
}
- ret = sound_manager_get_index_from_stream_information(stream_info, &stream_id);
- if (ret) {
+ if ((ret = sound_manager_get_index_from_stream_information(stream_info, stream_id))) {
LOGE("can't get stream index. ret(0x%x)", ret);
return TONE_PLAYER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
}
- ret = __dbus_method_call(PA_TONE_PLAYER_METHOD_NAME_TONE_PLAY,
- g_variant_new("(uiisi)", tone, duration_ms, getpid(), stream_type, stream_id), &reply);
- if (ret) {
+ return TONE_PLAYER_ERROR_NONE;
+}
+
+int tone_player_start_new(tone_type_e tone, sound_stream_info_h stream_info, int duration_ms, int *id)
+{
+ int ret = TONE_PLAYER_ERROR_NONE;
+ char *stream_type = NULL;
+ int stream_id = -1;
+ g_autoptr(GVariant) reply = NULL;
+ unsigned int handle_id = 0;
+
+ LOGI("tone(%d), duration_ms(%d)", tone, duration_ms);
+
+ if (tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE) {
+ LOGE("invalid tone type (%d)", tone);
+ return TONE_PLAYER_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((ret = __get_sound_manager_stream_properties(stream_info, &stream_type, &stream_id)))
+ return ret;
+
+ if ((ret = __dbus_method_call(PA_TONE_PLAYER_METHOD_NAME_TONE_PLAY,
+ g_variant_new("(uiisi)", tone, duration_ms, getpid(), stream_type, stream_id),
+ &reply))) {
LOGE("__dbus_method_call ret(0x%x)", ret);
return ret;
}
- g_variant_get(reply, "(u)", &handle);
- g_variant_unref(reply);
- if (id)
- *id = handle;
+ g_assert(reply);
+ g_variant_get(reply, "(u)", &handle_id);
+ LOGI("handle id(%u)", handle_id);
- LOGI("handle : %d", handle);
+ if (id)
+ *id = (int)handle_id;
return TONE_PLAYER_ERROR_NONE;
}
int tone_player_stop(int id)
{
- int ret;
+ int ret = TONE_PLAYER_ERROR_NONE;
- LOGI("handle(%d)", id);
+ LOGI("handle id(%d)", id);
- ret = __dbus_method_call(PA_TONE_PLAYER_METHOD_NAME_TONE_STOP, g_variant_new("(u)", id), NULL);
- if (ret) {
+ if ((ret = __dbus_method_call(PA_TONE_PLAYER_METHOD_NAME_TONE_STOP,
+ g_variant_new("(u)", id),
+ NULL))) {
LOGE("__dbus_method_call ret(0x%x)", ret);
return ret;
}
return TONE_PLAYER_ERROR_NONE;
}
-