#include "callmgr-util.h"
#include "callmgr-log.h"
+#define COOLDOWN_STATUS_LIMIT "limit"
+#define COOLDOWN_STATUS_RELEASE "release"
+
struct __cooldown_data {
callmgr_cooldown_event_cb event_cb;
void *user_data;
-
- GDBusConnection *dbus_conn;
callmgr_cooldown_status_e cooldown_status;
- guint cooldown_subs_id;
};
int _callmgr_cooldown_get_cooldown_status(callmgr_cooldown_h handle, callmgr_cooldown_status_e *status)
return 0;
}
-static void __callmgr_cooldown_subscribe_cooldown_signal_cb(GDBusConnection *connection,
- const gchar *sender_name, const gchar *object_path,
- const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data)
+int _callmgr_cooldown_set_cooldown_status(callmgr_cooldown_h handle, const char *status)
{
- gchar *cooldown_string = NULL;
- callmgr_cooldown_h handle = user_data;
-
- CM_RETURN_IF_FAIL(handle);
- dbg("__callmgr_cooldown_subscribe_cooldown_signal_cb");
-
- if (g_strcmp0(signal_name, DBUS_SIGNAL_COOLDOWN_CHANGED) == 0) {
- g_variant_get(parameters, "(s)", &cooldown_string);
- if (cooldown_string) {
- dbg("cooldown status: %s", cooldown_string);
- if (strncasecmp(cooldown_string, "LimitAction", strlen("LimitAction")) == 0) {
- handle->cooldown_status = CALLMGR_COOLDOWN_STATUS_LIMIT;
- handle->event_cb(CALLMGR_COOLDOWN_EVENT_LIMIT_ACTION, NULL, handle->user_data);
- } else if (strncasecmp(cooldown_string, "ReleaseAction", strlen("ReleaseAction")) == 0) {
- handle->cooldown_status = CALLMGR_COOLDOWN_STATUS_RELEASE;
- }
- } else {
- err("Failed to get cooldown status.");
- }
- g_free(cooldown_string);
- }
-}
+ int result =0;
-static void __callmgr_cooldown_subscribe_cooldown_signal(callmgr_cooldown_h handle)
-{
- CM_RETURN_IF_FAIL(handle);
- dbg("__callmgr_cooldown_subscribe_cooldown_signal");
-
- if (!handle->dbus_conn) {
- GError *error = NULL;
- handle->dbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!handle->dbus_conn) {
- err("g_bus_get_sync() is failed. (%s)", error->message);
- g_error_free(error);
- return;
- }
+ CM_RETURN_VAL_IF_FAIL(handle, -1);
+ CM_RETURN_VAL_IF_FAIL(status, -1);
+
+ dbg("__cooldown status: %s", status);
+ if (g_strcmp0(status, COOLDOWN_STATUS_LIMIT) == 0) {
+ handle->cooldown_status = CALLMGR_COOLDOWN_STATUS_LIMIT;
+ handle->event_cb(CALLMGR_COOLDOWN_EVENT_LIMIT_ACTION, NULL, handle->user_data);
+ } else if (g_strcmp0(status, COOLDOWN_STATUS_RELEASE) == 0) {
+ handle->cooldown_status = CALLMGR_COOLDOWN_STATUS_RELEASE;
+ } else {
+ err("Unknown type");
+ result = -1;
}
- handle->cooldown_subs_id = g_dbus_connection_signal_subscribe(handle->dbus_conn,
- NULL,
- DBUS_INTERFACE_DEVICED_SYSNOTI,
- DBUS_SIGNAL_COOLDOWN_CHANGED,
- DBUS_PATH_DEVICED_SYSNOTI,
- NULL, G_DBUS_SIGNAL_FLAGS_NONE,
- __callmgr_cooldown_subscribe_cooldown_signal_cb, handle, NULL);
- if (handle->cooldown_subs_id == 0) {
- err("g_dbus_connection_signal_subscribe() is failed.");
- g_object_unref(handle->dbus_conn);
- }
+ return result;
}
static void __callmgr_cooldown_get_cooldown_status(callmgr_cooldown_h handle)
{
GError *error = NULL;
GVariant *dbus_result;
+ GDBusConnection *dbus_conn = NULL;
CM_RETURN_IF_FAIL(handle);
dbg("__callmgr_cooldown_get_cooldown_status");
- if (!handle->dbus_conn) {
- handle->dbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!handle->dbus_conn) {
- err("g_bus_get_sync() is failed. (%s)", error->message);
- g_error_free(error);
- return;
- }
+ dbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!dbus_conn) {
+ err("g_bus_get_sync() is failed. (%s)", error->message);
+ g_error_free(error);
+ return;
}
- dbus_result = g_dbus_connection_call_sync(handle->dbus_conn,
+ dbus_result = g_dbus_connection_call_sync(dbus_conn,
DBUS_NAME_DEVICED,
DBUS_PATH_DEVICED_SYSNOTI,
DBUS_INTERFACE_DEVICED_SYSNOTI,
err("g_dbus_connection_call_sync() is failed. (%s)", error->message);
g_error_free(error);
}
+
+ g_object_unref(dbus_conn);
+
}
int _callmgr_cooldown_init(callmgr_cooldown_h *cooldown_handle, callmgr_cooldown_event_cb cb, void *user_data)
handle->user_data = user_data;
handle->cooldown_status = CALLMGR_COOLDOWN_STATUS_RELEASE;
__callmgr_cooldown_get_cooldown_status(handle);
- __callmgr_cooldown_subscribe_cooldown_signal(handle);
*cooldown_handle = handle;
return 0;
CM_RETURN_IF_FAIL(cooldown_handle);
dbg("_callmgr_cooldown_deinit");
- if (cooldown_handle->cooldown_subs_id) {
- g_dbus_connection_signal_unsubscribe(cooldown_handle->dbus_conn,
- cooldown_handle->cooldown_subs_id);
- cooldown_handle->cooldown_subs_id = 0;
- }
-
- if (cooldown_handle->dbus_conn) {
- g_object_unref(cooldown_handle->dbus_conn);
- cooldown_handle->dbus_conn = NULL;
- }
+ g_free(cooldown_handle);
+ cooldown_handle = NULL;
}
g_free(core_data);
return 0;
}
-/*
-int _callmgr_core_get_audio_state(callmgr_core_data_t *core_data, callmgr_path_type_e *o_audio_state)
-{
- CM_RETURN_VAL_IF_FAIL(core_data, -1);
- dbg("_callmgr_core_get_audio_state is called");
- callmgr_audio_device_e active_device = CALLMGR_AUDIO_DEVICE_NONE_E;
- if (_callmgr_audio_get_active_device(core_data->audio_handle, &active_device) < 0) {
- err("_callmgr_audio_get_active_device() failed");
- return -1;
- }
- switch(active_device) {
- case CALLMGR_AUDIO_DEVICE_SPEAKER_E:
- *o_audio_state = CALL_AUDIO_PATH_SPEAKER_E;
- break;
- case CALLMGR_AUDIO_DEVICE_RECEIVER_E:
- *o_audio_state = CALL_AUDIO_PATH_RECEIVER_E;
- break;
- case CALLMGR_AUDIO_DEVICE_EARJACK_E:
- *o_audio_state = CALL_AUDIO_PATH_EARJACK_E;
- break;
- case CALLMGR_AUDIO_DEVICE_BT_E:
- *o_audio_state = CALL_AUDIO_PATH_BT_E;
- break;
- default:
- err("Invalid device type: [%d]", active_device);
- *o_audio_state = CALL_AUDIO_PATH_NONE_E;
- break;
- }
-
- return 0;
-}
-*/
int _callmgr_core_get_audio_state(callmgr_core_data_t *core_data, callmgr_path_type_e *o_audio_state)
{
CM_RETURN_VAL_IF_FAIL(core_data, -1);
return TRUE;
}
+static gboolean __set_cool_down_status_handler(GDBusInterfaceSkeleton *di,
+ GDBusMethodInvocation *invoc, const gchar *status, gpointer user_data)
+{
+ int result = 0;
+
+ dbg("__set_cool_down_status_handler() is called");
+ callmgr_core_data_t *core_data = (callmgr_core_data_t *)user_data;
+ CM_RETURN_VAL_IF_FAIL(core_data, FALSE);
+
+ result = _callmgr_cooldown_set_cooldown_status(core_data->cooldown_handle, status);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", result));
+
+ return TRUE;
+}
+
+
/********************************************/
static gchar *__callmgr_dbus_convert_name_to_path(const gchar *name)
{
g_signal_connect(di, "handle-get-answering-machine-status", G_CALLBACK(__get_answering_machine_status_handler), core_data);
g_signal_connect(di, "handle-get-video-recording-status", G_CALLBACK(__get_video_recording_status_handler), core_data);
g_signal_connect(di, "handle-set-popup-result", G_CALLBACK(__set_popup_result_handler), core_data);
+ g_signal_connect(di, "handle-set-cool-down-status", G_CALLBACK(__set_cool_down_status_handler), core_data);
__callmgr_dbus_object_export(core_data, di, CALLMGR_DBUS_PATH);
core_data->dbus_skeleton_interface = di;