#include <string.h>
#include <vconf.h>
#include <status.h>
-#include <aul.h>
#include <syspopup_caller.h>
+#include <aul.h>
+
+#include "alarm.h"
#include "bluetooth-api.h"
#include "bt-internal-types.h"
typedef struct {
guint event_id;
int timeout;
+ time_t start_time;
+ int alarm_id;
} bt_adapter_timer_t;
bt_adapter_timer_t visible_timer;
#define BT_CORE_PATH "/org/projectx/bt_core"
#define BT_CORE_INTERFACE "org.projectx.btcore"
-
static gboolean __bt_timeout_handler(gpointer user_data)
{
int result = BLUETOOTH_ERROR_NONE;
+ time_t current_time;
+ int time_diff;
- visible_timer.timeout--;
+ /* Take current time */
+ time(¤t_time);
+ time_diff = difftime(current_time, visible_timer.start_time);
/* Send event to application */
_bt_send_event(BT_ADAPTER_EVENT,
BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INT16, &visible_timer.timeout,
+ DBUS_TYPE_INT16, &time_diff,
DBUS_TYPE_INVALID);
- if (visible_timer.timeout <= 0) {
+ if (visible_timer.timeout <= time_diff) {
g_source_remove(visible_timer.event_id);
visible_timer.event_id = 0;
visible_timer.timeout = 0;
if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
BT_DBG("Set vconf failed\n");
-
return FALSE;
}
return TRUE;
}
+static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param)
+{
+ BT_DBG("__bt_visibility_alarm_cb \n");
+
+ /* Switch Off visibility in Bluez */
+ _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
+ visible_timer.alarm_id = 0;
+ alarmmgr_fini();
+ return 0;
+}
+
+static void __bt_visibility_alarm_create()
+{
+ alarm_id_t alarm_id;
+ int result;
+
+ result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, visible_timer.timeout,
+ 0, NULL, &alarm_id);
+ if(result < 0) {
+ BT_DBG("Failed to create alarm error = %d\n", result);
+ alarmmgr_fini();
+ } else {
+ BT_DBG("Alarm created = %d\n", alarm_id);
+ visible_timer.alarm_id = alarm_id;
+ }
+}
+
int __bt_set_visible_time(int timeout)
{
+ int result;
+
if (visible_timer.event_id > 0) {
g_source_remove(visible_timer.event_id);
visible_timer.event_id = 0;
}
+ if (visible_timer.alarm_id > 0) {
+ alarmmgr_remove_alarm(visible_timer.alarm_id);
+ visible_timer.alarm_id = 0;
+ }
+
visible_timer.timeout = timeout;
if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
if (timeout <= 0)
return BLUETOOTH_ERROR_NONE;
+ /* Take start time */
+ time(&(visible_timer.start_time));
visible_timer.event_id = g_timeout_add_seconds(1,
- __bt_timeout_handler, NULL);
+ __bt_timeout_handler, NULL);
+
+ /* Set Alarm timer to switch off BT */
+ result = alarmmgr_init("bt-service");
+ if (result != 0)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ result = alarmmgr_set_cb(__bt_visibility_alarm_cb, NULL);
+ if (result != 0)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ __bt_visibility_alarm_create();
return BLUETOOTH_ERROR_NONE;
}
int ret;
DBusGConnection *conn;
- BT_CHECK_PARAMETER(device_path);
- BT_CHECK_PARAMETER(dev_info);
+ BT_CHECK_PARAMETER(device_path, return);
+ BT_CHECK_PARAMETER(dev_info, return);
conn = _bt_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
BT_ERR("Fail to init obex server");
+ if (_bt_network_activate() != BLUETOOTH_ERROR_NONE)
+ BT_ERR("Fail to activate network");
+
/* add the vconf noti handler */
vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
__bt_phone_name_changed_cb, NULL);
DBusGProxy *proxy;
char *adapter_path = NULL;
- BT_CHECK_PARAMETER(status);
+ BT_CHECK_PARAMETER(status, return);
*status = 0; /* 0: disabled */
GValue *value;
char *address = NULL;
- BT_CHECK_PARAMETER(local_address);
+ BT_CHECK_PARAMETER(local_address, return);
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
char *ptr = NULL;
int ret = BLUETOOTH_ERROR_NONE;
- BT_CHECK_PARAMETER(local_name);
+ BT_CHECK_PARAMETER(local_name, return);
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
GError *error = NULL;
char *ptr = NULL;
- BT_CHECK_PARAMETER(local_name);
+ BT_CHECK_PARAMETER(local_name, return);
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
GValue *value;
int ret = BLUETOOTH_ERROR_NONE;
- BT_CHECK_PARAMETER(service_uuid);
- BT_CHECK_PARAMETER(used);
+ BT_CHECK_PARAMETER(service_uuid, return);
+ BT_CHECK_PARAMETER(used, return);
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
GValue *value;
GValue *timeout_value;
- BT_CHECK_PARAMETER(mode);
+ BT_CHECK_PARAMETER(mode, return);
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
timeout = -1;
- __bt_set_visible_time(timeout);
+ ret = __bt_set_visible_time(timeout);
done:
g_value_unset(&val_timeout);
GError *error = NULL;
DBusGProxy *proxy;
- BT_CHECK_PARAMETER(dev_list);
+ BT_CHECK_PARAMETER(dev_list, return);
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
DBusGProxy *adapter_proxy;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- BT_CHECK_PARAMETER(device_address);
- BT_CHECK_PARAMETER(dev_info);
+ BT_CHECK_PARAMETER(device_address, return);
+ BT_CHECK_PARAMETER(dev_info, return);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
int _bt_get_timeout_value(int *timeout)
{
- *timeout = 0;
+ time_t current_time;
+ int time_diff;
+
+ /* Take current time */
+ time(¤t_time);
+ time_diff = difftime(current_time, visible_timer.start_time);
+
+ BT_DBG("Time diff = %d\n", time_diff);
- *timeout = visible_timer.timeout;
+ *timeout = visible_timer.timeout - time_diff;
return BLUETOOTH_ERROR_NONE;
}