diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-09-28 18:50:19 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-09-29 14:56:22 -0500 |
commit | 2fca5c7f0838194683d9dd69c7773a4693114876 (patch) | |
tree | d0e736014fc1a040eb512379f205ae84bdb354a0 /src/call-volume.c | |
parent | b8bc7a4c619554f74caa76557da18c9fdc37d205 (diff) | |
download | ofono-2fca5c7f0838194683d9dd69c7773a4693114876.tar.bz2 |
Refactor: Call Volume set_property handling
Diffstat (limited to 'src/call-volume.c')
-rw-r--r-- | src/call-volume.c | 130 |
1 files changed, 59 insertions, 71 deletions
diff --git a/src/call-volume.c b/src/call-volume.c index 3a022fcd..a19a0222 100644 --- a/src/call-volume.c +++ b/src/call-volume.c @@ -115,90 +115,48 @@ static DBusMessage *cv_get_properties(DBusConnection *conn, return reply; } -static void generic_callback(const struct ofono_error *error, void *data) +static void sv_set_callback(const struct ofono_error *error, void *data) { struct ofono_call_volume *cv = data; DBusConnection *conn = ofono_dbus_get_connection(); - DBusMessage *reply; + const char *path = __ofono_atom_get_path(cv->atom); - if (!cv->pending) + if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { + __ofono_dbus_pending_reply(&cv->pending, + __ofono_error_failed(cv->pending)); return; + } - if (error->type == OFONO_ERROR_TYPE_NO_ERROR) - reply = dbus_message_new_method_return(cv->pending); - else - reply = __ofono_error_failed(cv->pending); - - g_dbus_send_message(conn, reply); - - dbus_message_unref(cv->pending); - cv->pending = NULL; -} + cv->speaker_volume = cv->pending_volume; -static void sv_set_callback(const struct ofono_error *error, void *data) -{ - struct ofono_call_volume *cv = data; + __ofono_dbus_pending_reply(&cv->pending, + dbus_message_new_method_return(cv->pending)); - if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { - ofono_error("Error occurred during Speaker Volume set: %s", - telephony_error_to_str(error)); - } else { - cv->speaker_volume = cv->pending_volume; - } - - generic_callback(error, data); + ofono_dbus_signal_property_changed(conn, path, CALL_VOLUME_INTERFACE, + "SpeakerVolume", + DBUS_TYPE_BYTE, &cv->speaker_volume); } static void mv_set_callback(const struct ofono_error *error, void *data) { struct ofono_call_volume *cv = data; + DBusConnection *conn = ofono_dbus_get_connection(); + const char *path = __ofono_atom_get_path(cv->atom); if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { - ofono_error("Error occurred during Microphone Volume set: %s", - telephony_error_to_str(error)); - } else { - cv->microphone_volume = cv->pending_volume; + __ofono_dbus_pending_reply(&cv->pending, + __ofono_error_failed(cv->pending)); + return; } - generic_callback(error, data); -} - -static DBusMessage *cv_set_call_volume(DBusMessage *msg, - struct ofono_call_volume *cv, - const char *property, - unsigned char percent) -{ - if (percent > 100) - return __ofono_error_invalid_format(msg); + cv->microphone_volume = cv->pending_volume; - DBG("set %s volume to %d percent", property, percent); + __ofono_dbus_pending_reply(&cv->pending, + dbus_message_new_method_return(cv->pending)); - cv->pending_volume = percent; - - if (msg) - cv->pending = dbus_message_ref(msg); - - if (!strcmp(property, "SpeakerVolume")) { - if (!cv->driver->speaker_volume) { - if (msg != NULL) - return __ofono_error_not_implemented(msg); - else - return NULL; - } - cv->driver->speaker_volume(cv, percent, sv_set_callback, cv); - } - - if (!strcmp(property, "MicrophoneVolume")) { - if (!cv->driver->microphone_volume) { - if (msg != NULL) - return __ofono_error_not_implemented(msg); - else - return NULL; - } - cv->driver->microphone_volume(cv, percent, mv_set_callback, cv); - } - - return NULL; + ofono_dbus_signal_property_changed(conn, path, CALL_VOLUME_INTERFACE, + "MicrophoneVolume", + DBUS_TYPE_BYTE, &cv->microphone_volume); } static DBusMessage *cv_set_property(DBusConnection *conn, DBusMessage *msg, @@ -208,7 +166,6 @@ static DBusMessage *cv_set_property(DBusConnection *conn, DBusMessage *msg, DBusMessageIter iter; DBusMessageIter var; const char *property; - unsigned char percent; if (cv->pending) return __ofono_error_busy(msg); @@ -227,18 +184,49 @@ static DBusMessage *cv_set_property(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_recurse(&iter, &var); - if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BYTE) - return __ofono_error_invalid_args(msg); + if (g_str_equal(property, "SpeakerVolume") == TRUE) { + unsigned char percent; + + if (!cv->driver->speaker_volume) + return __ofono_error_not_supported(msg); + + if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BYTE) + return __ofono_error_invalid_args(msg); - dbus_message_iter_get_basic(&var, &percent); + dbus_message_iter_get_basic(&var, &percent); + + if (percent > 100) + return __ofono_error_invalid_format(msg); + + cv->pending_volume = percent; + cv->pending = dbus_message_ref(msg); + cv->driver->speaker_volume(cv, percent, sv_set_callback, cv); + } else if (g_str_equal(property, "MicrophoneVolume") == TRUE) { + unsigned char percent; + + if (!cv->driver->microphone_volume) + return __ofono_error_not_supported(msg); + + if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BYTE) + return __ofono_error_invalid_args(msg); + + dbus_message_iter_get_basic(&var, &percent); + + if (percent > 100) + return __ofono_error_invalid_format(msg); + + cv->pending_volume = percent; + cv->pending = dbus_message_ref(msg); + cv->driver->speaker_volume(cv, percent, mv_set_callback, cv); + } - return cv_set_call_volume(msg, cv, property, percent); + return __ofono_error_invalid_args(msg); } static GDBusMethodTable cv_methods[] = { { "GetProperties", "", "a{sv}", cv_get_properties }, { "SetProperty", "sv", "", cv_set_property, - G_DBUS_METHOD_FLAG_ASYNC }, + G_DBUS_METHOD_FLAG_ASYNC }, { } }; |