#include <vconf.h>
#include <pthread.h>
#include <sys/time.h>
+#include <TapiUtility.h>
+#include <ITapiNetwork.h>
wifi_manager_h wifi = NULL;
static bool display_on;
static int brightness_val = 0;
static int brightness_flag = 0;
+static int ss_val = 0;
+static int ss_flag = 0;
static history_item_s *data_obj = NULL;
static int listener_hsp =0;
static int wifi_scan_hsp=0;
static int wifi_connected_hsp=0;
static int display_hsp=0;
+static int gps_hsp=0;
+static int charging_hsp=0;
static event_pool events_buf[10];
static int buff_count = 0;
static pthread_cond_t fill = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t battery_lister_mutex = PTHREAD_MUTEX_INITIALIZER;
static int fill_ptr = 0;
static int use_ptr = 0;
+static TapiHandle *handle = NULL;
ENTER;
_INFO(" device brightness changed =%d ",brightness_level);
-
-
- if(brightness_level >0 && brightness_level <=10)
+ if(data_obj)
{
data_obj->state_1 &= ~brightness_val;
- brightness_val=0;
+ brightness_val = brightness_level;
data_obj->state_1 |= brightness_val;
data_obj->event_code = ET_NONE;
data_obj->event_tag = NULL;
}
- else if(brightness_level >10 && brightness_level <=25)
+
+ EXIT;
+}
+
+
+static void fill_battery_capacity_change(int charging_level)
+{
+ ENTER;
+
+ _INFO(" device battery_capacity changed =%d ",charging_level);
+ if(data_obj)
{
- data_obj->state_1 &= ~brightness_val;
- brightness_val=1;
- data_obj->state_1 |= brightness_val;
data_obj->event_code = ET_NONE;
data_obj->event_tag = NULL;
}
- else if(brightness_level >25 && brightness_level <=50)
+
+ EXIT;
+}
+
+
+
+static void fill_charging_status_change(int charging)
+{
+ ENTER;
+
+ _INFO(" device charging_status changed =%d ",charging);
+ if(data_obj)
{
- data_obj->state_1 &= ~brightness_val;
- brightness_val=2;
- data_obj->state_1 |= brightness_val;
- data_obj->event_code = ET_NONE;
- data_obj->event_tag = NULL;
+ if(charging)
+ {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_FLAG_START;
+ data_obj->event_tag = NULL;
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if(data_obj->event_tag)
+ {
+ listener_hsp++;
+ charging_hsp = listener_hsp;
+ _INFO("event Tag creation succeeded \n");
+ data_obj->event_tag->sp_idx = charging_hsp;
+ }
+ else
+ {
+ _ERR(" data_obj->event_tag object creation fails ");
+ return;
+ }
+
+ data_obj->state_2 |= ST2_CHARGING_FLAG;
+ }
+ else
+ {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_FLAG_FINISH;
+ data_obj->event_tag = NULL;
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if(data_obj->event_tag)
+ {
+ _INFO("event Tag creation succeeded \n");
+ data_obj->event_tag->sp_idx = charging_hsp;
+ }
+ else
+ {
+ _ERR(" data_obj->event_tag object creation fails ");
+ return ;
+ }
+
+ data_obj->state_2 &= ~(ST2_CHARGING_FLAG);
+ }
}
- else if(brightness_level >50 && brightness_level <=75)
+
+ EXIT;
+}
+
+
+
+
+static void fill_signal_strength_change(int ss)
+{
+ ENTER;
+
+ _INFO(" device signal_strength changed =%d ",ss);
+ if(data_obj)
{
- data_obj->state_1 &= ~brightness_val;
- brightness_val=3;
- data_obj->state_1 |= brightness_val;
+ data_obj->state_1 &= ~ss_val << ST1_PHONE_SIGNAL_STRENGTH_SHIFT;
+ ss_val = ss;
+ data_obj->state_1 |= ss_val << ST1_PHONE_SIGNAL_STRENGTH_SHIFT;
data_obj->event_code = ET_NONE;
data_obj->event_tag = NULL;
}
- else if(brightness_level >75 && brightness_level <=100)
+
+ EXIT;
+}
+
+
+
+
+static void fill_location_change(int gps)
+{
+ ENTER;
+
+ _INFO(" maps location changed =%d ",gps);
+ if(data_obj)
{
- data_obj->state_1 &= ~brightness_val;
- brightness_val=4;
- data_obj->state_1 |= brightness_val;
- data_obj->event_code = ET_NONE;
- data_obj->event_tag = NULL;
+ if(gps)
+ {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_ACTIVE;
+ data_obj->event_code |= ET_FLAG_START;
+ data_obj->event_tag = NULL;
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if(data_obj->event_tag)
+ {
+ listener_hsp++;
+ gps_hsp = listener_hsp;
+ _INFO("event Tag creation succeeded \n");
+ data_obj->event_tag->sp_idx = gps_hsp;
+ }
+ else
+ {
+ _ERR(" data_obj->event_tag object creation fails ");
+ return;
+ }
+
+ data_obj->state_1 |= ST1_GPS_ON_FLAG;
+ }
+ else
+ {
+ data_obj->event_code = ET_NONE;
+ data_obj->event_code |= ET_ACTIVE;
+ data_obj->event_code |= ET_FLAG_FINISH;
+ data_obj->event_tag = NULL;
+ data_obj->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+ if(data_obj->event_tag)
+ {
+ _INFO("event Tag creation succeeded \n");
+ data_obj->event_tag->sp_idx = gps_hsp;
+ }
+ else
+ {
+ _ERR(" data_obj->event_tag object creation fails ");
+ return ;
+ }
+
+ data_obj->state_1 &= ~(ST1_GPS_ON_FLAG);
+ }
}
-
-
static void bm_create_event_data(int type,int val)
{
ENTER;
case LISTEN_BRIGHTNESS_CHANGE:
fill_display_brightness_change(val);
break;
+ case LISTEN_BATTERY_CAPACITY_CHANGE:
+ fill_battery_capacity_change(val);
+ break;
+ case LISTEN_LOCATION_CHANGE:
+ fill_location_change(val);
+ break;
+ case LISTEN_CHARGING_STATUS_CHANGE:
+ fill_charging_status_change(val);
+ break;
+ case LISTEN_SIGNAL_STRENGTH_CHANGE:
+ fill_signal_strength_change(val);
+ break;
default:
return;
}
pthread_cond_signal(&fill);
pthread_mutex_unlock(&battery_lister_mutex);
- BM_FREE(event);
- EXIT;
+ BM_FREE(event);
+ EXIT;
pthread_exit(NULL);
+
}
return;
}
display_event->type = LISTEN_BRIGHTNESS_CHANGE;
- display_event->val = brightness_level;
+ display_event->val = brightness_flag;
pthread_t producer ;
+static void __bm_battery_capacity_change(keynode_t *key, void* data)
+{
+ ENTER;
+ _INFO("device battery_capacity changed succeeded\n");
+ int charging =0;
+ vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &charging);
+
+ _INFO(" device battery_capacity changed =%d ",charging);
+
+ event_pool *charging_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if(!charging_event)
+ {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+ charging_event->type = LISTEN_BATTERY_CAPACITY_CHANGE;
+ charging_event->val = charging;
+
+
+ pthread_t producer ;
+ if(pthread_create(&producer, NULL, event_producer, charging_event))
+ {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+
+ EXIT;
+}
+
+
+static void __bm_charging_status_change(keynode_t *key, void* data)
+{
+ ENTER;
+ _INFO("device charging_status changed succeeded\n");
+ int charging =0;
+ vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charging);
+
+ _INFO(" device charging_status changed =%d ",charging);
+
+ event_pool *charging_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if(!charging_event)
+ {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+ charging_event->type = LISTEN_CHARGING_STATUS_CHANGE;
+ charging_event->val = charging;
+
+
+ pthread_t producer ;
+ if(pthread_create(&producer, NULL, event_producer, charging_event))
+ {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+
+ EXIT;
+}
+
+
+
+static void __bm_location_change(keynode_t *key, void* data)
+{
+ ENTER;
+ _INFO("device location changed succeeded\n");
+ int charging =0;
+ vconf_get_int(VCONFKEY_LOCATION_ENABLED, &charging);
+
+ _INFO(" device location changed =%d ",charging);
+
+ event_pool *location_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if(!location_event)
+ {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+ location_event->type = LISTEN_LOCATION_CHANGE;
+ location_event->val = charging;
+
+
+ pthread_t producer ;
+ if(pthread_create(&producer, NULL, event_producer, location_event))
+ {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+
+ EXIT;
+}
+
+
+
+
+static void __bm_noti_signal_strength(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
+{
+ ENTER;
+ _INFO("device signal strength changed succeeded\n");
+ struct tel_noti_network_signal_strength *noti = data;
+ int sig_strength = noti->dbm;
+
+ _INFO(" device signal strength changed =%d ",sig_strength);
+
+ int flag;
+ if(sig_strength >0 && sig_strength <=12)
+ {
+ flag = 0;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >12 && sig_strength <=25)
+ {
+ flag = 1;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >25 && sig_strength <=37)
+ {
+ flag = 2;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >37 && sig_strength <=50)
+ {
+ flag = 3;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >50 && sig_strength <=62)
+ {
+ flag = 4;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >62 && sig_strength <=75)
+ {
+ flag = 5;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >75 && sig_strength <=87)
+ {
+ flag = 6;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+ else if(sig_strength >87 && sig_strength <=100)
+ {
+ flag = 7;
+ if(ss_flag == flag)
+ return;
+ else
+ ss_flag = flag;
+ }
+
+ event_pool *signal_event = (event_pool *)calloc(1, sizeof(event_pool));
+ if(!signal_event)
+ {
+ _ERR("Failed to allocated memory ");
+ return;
+ }
+ signal_event->type = LISTEN_SIGNAL_STRENGTH_CHANGE;
+ signal_event->val = ss_flag;
+
+
+ pthread_t producer ;
+ if(pthread_create(&producer, NULL, event_producer, signal_event))
+ {
+ _ERR("Failed to pthread_create.");
+ return;
+ }
+
+
+ EXIT;
+}
+
+
+
+static int bm_charging_status_listeners()
+{
+ ENTER;
+
+ /* Charging callbacks */
+ int ret = 0;
+ ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, __bm_charging_status_change, NULL);
+ if (ret != 0) {
+ _ERR("failed to register a cb key:%s err:%d","VCONFKEY_SYSMAN_CHARGER_STATUS", ret);
+ return 1;
+ }
+
+ EXIT;
+ return 0;
+
+}
+
+
+
+static int bm_battery_capacity_listeners()
+{
+ ENTER;
+
+ /* Charging callbacks */
+ int ret = 0;
+ ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, __bm_battery_capacity_change, NULL);
+ if (ret != 0) {
+ _ERR("failed to register a cb key:%s err:%d","VCONFKEY_SYSMAN_BATTERY_CAPACITY", ret);
+ return 1;
+ }
+
+ EXIT;
+ return 0;
+
+}
+
+
+
+static int bm_location_listeners()
+{
+ ENTER;
+
+ /* Charging callbacks */
+ int ret = 0;
+ ret = vconf_notify_key_changed(VCONFKEY_LOCATION_ENABLED, __bm_location_change, NULL);
+ if (ret != 0) {
+ _ERR("failed to register a cb key:%s err:%d","VCONFKEY_LOCATION_ENABLED", ret);
+ return 1;
+ }
+
+ EXIT;
+ return 0;
+
+}
+
+
static int bm_screen_subscribe_listeners()
{
ENTER;
+static int bm_signal_strength_listeners()
+{
+ ENTER;
+ /* Screen callbacks */
+ handle = tel_init(NULL);
+ if(handle)
+ {
+ int ret = tel_register_noti_event(handle,TAPI_NOTI_NETWORK_SIGNALSTRENGTH, __bm_noti_signal_strength, NULL);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("device_add_callback failed: %s", get_error_message(ret));
+ return 1;
+ }
+ }
+
+ EXIT;
+ return 0;
+
+}
+
+
+
static int bm_display_brightness_listeners()
{
ENTER;
else
_ERR("Brightness listeners failed to subscribed\n");
+
+ /* battery_capacity change callbacks */
+ if(!bm_battery_capacity_listeners())
+ _INFO("battery_capacity listeners succeeded to subscribed\n");
+ else
+ _ERR("battery_capacity listeners failed to subscribed\n");
+
+ /* battery charging change callbacks */
+ if(!bm_charging_status_listeners())
+ _INFO("battery charging listeners succeeded to subscribed\n");
+ else
+ _ERR("battery charging listeners failed to subscribed\n");
+
+ /* GPS change callbacks */
+ if(!bm_location_listeners())
+ _INFO("location listeners succeeded to subscribed\n");
+ else
+ _ERR("location listeners failed to subscribed\n");
+
+
+ /* Signal strength callbacks */
+ if(!bm_signal_strength_listeners())
+ _INFO("Signal strength listeners succeeded to subscribed\n");
+ else
+ _ERR("Signal strength listeners failed to subscribed\n");
+
EXIT;
return BATTERY_MONITOR_ERROR_NONE;
}
//Brightness
- if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS,__bm_display_brightness_change) < 0)
+ if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, __bm_display_brightness_change) < 0)
{
_ERR("failed to de-register vconf callback");
}
+ //Battery capacity
+ if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, __bm_battery_capacity_change) < 0)
+ {
+ _ERR("failed to de-register vconf callback");
+ }
+
+ //Battery charging
+ if (vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, __bm_charging_status_change) < 0)
+ {
+ _ERR("failed to de-register vconf callback");
+ }
+
+ if(handle)
+ {
+ int ret = tel_deregister_noti_event(handle,TAPI_NOTI_NETWORK_SIGNALSTRENGTH);
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _ERR("tel_deregister_noti_event failed: %s", get_error_message(ret));
+ return 1;
+ }
+ tel_deinit(handle);
+ }
+
if(data_obj)
{
BM_FREE(data_obj);