Update change log and spec for wrt-plugins-tizen_0.4.42
[framework/web/wrt-plugins-tizen.git] / src / Systeminfo / Systeminfo.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <stddef.h>
19 #include <cassert>
20 #include <math.h>
21 #include <Commons/Exception.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/PrivateObject.h>
24 #include <TimeTracer.h>
25 #include <tapi_common.h>
26 #include <ITapiModem.h>
27 #include <sim.h>
28 #include "Systeminfo.h"
29 #include <Logger.h>
30
31 using namespace WrtDeviceApis::CommonsJavaScript;
32 using namespace WrtDeviceApis::Commons;
33
34
35 namespace DeviceAPI {
36 namespace Systeminfo {
37
38 namespace {
39
40 void BatteryValueCallback(keynode_t *node, void *event_ptr)
41 {
42     if(event_ptr) {
43         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
44     }
45 }
46
47 void PeripheralValueCallback(keynode_t *node, void *event_ptr)
48 {
49     if(event_ptr) {
50         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_PERIPHERAL);
51     }
52 }
53
54 void CellularNetworkValueCallback(keynode_t *node, void *event_ptr)
55 {
56     if(event_ptr) {
57         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CELLULARNETWORK);
58     }
59 }
60
61 void DisplayValueCallback(keynode_t *node, void* event_ptr)
62 {
63     if(event_ptr) {
64         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
65     }
66 }
67
68 void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
69 {
70     if(event_ptr) {
71         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
72     }
73 }
74
75 void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
76 {
77     if(event_ptr) {
78         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
79     }
80 }
81
82 static Eina_Bool StorageValueCallback(void* event_ptr)
83 {
84     if(event_ptr) {
85         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
86     }
87     return ECORE_CALLBACK_RENEW;
88 }
89
90 static Eina_Bool CpuValueCallback(void* event_ptr)
91 {
92     if(event_ptr) {
93         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
94     }
95     return ECORE_CALLBACK_RENEW;
96 }
97
98 void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
99 {
100     LoggerD("enter");
101     if(event_ptr) {
102         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
103     }
104 }
105
106 void localeChangedCallback(runtime_info_key_e key, void* event_ptr)
107 {
108     LoggerD("enter");
109     if(event_ptr) {
110         ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE);
111     }    
112 }
113
114 }
115
116 #define STORAGE_INTERNAL_PATH   "/opt/usr/media"
117 #define STORAGE_SDCARD_PATH     "/opt/storage/sdcard"
118 #define STORAGE_USBHOST_PATH    "/opt/storage/usb"
119 #define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
120 #define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
121 #define CPU_POWER_DEVICE_VALUE          100
122
123 #define RADIAN_VALUE (57.2957)
124
125 enum {
126     STORAGE_TYPE_UNKNOWN = 0,
127     STORAGE_TYPE_INTERNAL = 1,
128     STORAGE_TYPE_MMC = 2,
129     STORAGE_TYPE_USBHOST = 3
130 };
131
132 Systeminfo::OptionalProperty Systeminfo::m_Property;
133
134 Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
135                         m_storageTimer(NULL),
136                         m_cpuTimer(NULL),
137                         m_sensorHandle(0),
138                         m_connectionHandle(NULL)
139 {
140     EventMgrPtr eventMgrPtr(new EventMgr());
141     m_EventMgrPtr = eventMgrPtr;
142     if (m_Property.IsNull()) {
143         mapProperties properties;
144         properties["BATTERY"] = BasePropertyPtr(new Battery());
145         m_Property = properties;
146         (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
147         (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
148         (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
149         (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
150         (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
151         (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
152         (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
153         (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
154         (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
155         (*m_Property)["LOCALE"] = BasePropertyPtr(new Locale());
156         (*m_Property)["PERIPHERAL"] = BasePropertyPtr(new Peripheral());
157     }
158
159     int ret = connection_create(&m_connectionHandle);
160
161         if (CONNECTION_ERROR_NONE == ret) {
162                 LoggerD("Network Client registration success");
163         } else {
164                 LoggerD("Network Client registration success");
165         m_connectionHandle = NULL;
166     }
167
168     m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
169     if (m_sensorHandle < 0) {
170         LoggerD ("sensor attach fail");
171     } else {
172         LoggerD("m_sensorHandle : " << m_sensorHandle);
173         int state = sf_start(m_sensorHandle, 0);
174         if(state < 0) {
175             LoggerD("failed");
176         }
177     }
178 }
179
180 Systeminfo::~Systeminfo()
181 {
182         int state = 0;
183     if (m_storageTimer) {
184         ecore_timer_freeze(m_storageTimer);
185         ecore_timer_del(m_storageTimer);
186         m_storageTimer = NULL;
187     }
188     if (m_cpuTimer) {
189         ecore_timer_freeze(m_cpuTimer);
190         ecore_timer_del(m_cpuTimer);
191         m_cpuTimer = NULL;
192     }
193     m_EventMgrPtr->clearAllEvent();
194
195     if(m_connectionHandle != NULL) {
196         LoggerD("Network Client deregistration success");
197         connection_destroy(m_connectionHandle);
198     } else {
199         LoggerD("Network Client deregistration failed");
200     }
201
202         state = sf_stop(m_sensorHandle);
203         LoggerD("handle 1  state = " << state);
204
205         state = sf_disconnect(m_sensorHandle);
206         LoggerD("handle  state =" << state);
207 }
208
209 DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
210 {
211     LoggerD("enter");
212     DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
213     return deviceCapabilities;
214 }
215
216 void Systeminfo::get(const EventGetSysteminfoPtr& event)
217 {
218     EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
219 }
220
221 void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
222 {
223     if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
224         LoggerD("watch method is not supported");
225         event->setId(-1);
226         return;
227     }
228
229     event->setSysteminfoPtr(this);
230     m_EventMgrPtr->addEvent(event, event->getWatchType());
231
232     EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
233 }
234
235 void Systeminfo::clearWatch(const long id)
236 {
237     if (id < 1) {
238         Throw(WrtDeviceApis::Commons::InvalidArgumentException);
239     } else {
240         int watchType = m_EventMgrPtr->getWatchType(id);
241         switch(watchType) {
242             case WATCH_TYPE_BATTERY:
243                 if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
244                     vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
245                     vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
246                 }
247                 break;
248             case WATCH_TYPE_DISPLAY:
249                 if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
250                     vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
251                 }
252                 break;
253             case WATCH_TYPE_NETWORK:
254                 if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
255                     connection_unset_type_changed_cb(m_connectionHandle);
256                 }
257                 break;
258             case WATCH_TYPE_WIFINETWORK:
259                 if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
260                     if (m_networkRegist == REGIST_WIFI) {
261                         connection_unset_ip_address_changed_cb(m_connectionHandle);
262                         m_networkRegist = REGIST_NOT;
263                     } else if (m_networkRegist== REGIST_ALL) {
264                         m_networkRegist = REGIST_CELLULAR;
265                     }
266                 }
267                 break;
268             case WATCH_TYPE_CELLULARNETWORK:
269                 if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
270                     vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback);
271                     vconf_ignore_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback);
272                     vconf_ignore_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback);
273                     vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback);
274                     if (m_networkRegist == REGIST_CELLULAR) {
275                         connection_unset_ip_address_changed_cb(m_connectionHandle);
276                         m_networkRegist = REGIST_NOT;
277                     } else if (m_networkRegist== REGIST_ALL) {
278                         m_networkRegist = REGIST_WIFI;
279                     }
280                 }
281                 break;
282             case WATCH_TYPE_STORAGE:
283                 if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
284                     if (m_storageTimer) {
285                         ecore_timer_freeze(m_storageTimer);
286                         ecore_timer_del(m_storageTimer);
287                         m_storageTimer = NULL;
288                     }
289                 }
290                 break;
291             case WATCH_TYPE_CPU:
292                 if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
293                     if (m_cpuTimer) {
294                         ecore_timer_freeze(m_cpuTimer);
295                         ecore_timer_del(m_cpuTimer);
296                         m_cpuTimer = NULL;
297                     }
298                 }
299                 break;
300             case WATCH_TYPE_DEVICE_ORIENTATION:
301                 if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
302                     int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
303                     if (state < 0) {
304                         LoggerD("sf_unregister_event fail to gather data\n");
305                     }
306                 }
307                 break;
308             case WATCH_TYPE_LOCALE:
309                 if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
310                     if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE) != RUNTIME_INFO_ERROR_NONE) {
311                         LoggerE("regist failed");
312                         Throw(WrtDeviceApis::Commons::Exception);
313                     }
314                     if (runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_REGION) != RUNTIME_INFO_ERROR_NONE) {
315                         LoggerE("regist failed");
316                         Throw(WrtDeviceApis::Commons::Exception);
317                     }
318                 }
319                 break;
320             case WATCH_TYPE_PERIPHERAL:
321                 if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
322                     vconf_ignore_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback);
323                     vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback);
324                 }
325                 break;
326             case WATCH_TYPE_UNKNOWN:
327                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
328                 break;
329         }
330         m_EventMgrPtr->removeEvent(id, watchType);
331     }
332 }
333
334 BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
335 {
336     Converter converter(context);
337     std::string l_property = converter.toString(property);
338     mapProperties::iterator it = (*m_Property).find(l_property);
339     if (it == (*m_Property).end()) {
340         LoggerE("not existing property");
341         Throw(WrtDeviceApis::Commons::ConversionException);
342         return BasePropertyPtr(NULL);
343     }
344
345     return it->second;
346 }
347
348 void Systeminfo::getWatchValue(const int watchType)
349 {
350     LoggerD(" watch type : " << watchType);
351
352     if (watchType == WATCH_TYPE_BATTERY) {
353         EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
354         for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
355                 (*it)->getWatchValue();
356             }
357     } else if (watchType == WATCH_TYPE_DISPLAY) {
358         EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
359         for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
360             (*it)->getWatchValue();
361         }
362     } else if (watchType == WATCH_TYPE_NETWORK) {
363         EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
364         for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
365             (*it)->getWatchValue();
366         }
367     } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
368         EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
369         EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
370         if (eventListWifi.size() > 0) {
371             for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
372                 (*it)->getWatchValue();
373             }
374         }
375         if (eventListCellular.size() > 0) {
376             for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
377                 (*it)->getWatchValue();
378             }
379         }
380     } else if (watchType == WATCH_TYPE_CPU) {
381         EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
382         for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
383             (*it)->getWatchValue();
384         }
385     } else if (watchType == WATCH_TYPE_STORAGE) {
386         EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
387         for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
388         int storageCnt = 1;
389         int sdcardState = 0;
390         int usbhostState = 0;
391         if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
392             if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
393                 storageCnt++;
394             }
395         }
396         if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
397             if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
398                 storageCnt++;
399             }
400         }
401         LoggerD("storage cnt : " << storageCnt);
402             (*it)->getWatchValue(storageCnt);
403         }
404     }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
405         EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
406         for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
407             (*it)->getWatchValue();
408         }
409     } else if (watchType == WATCH_TYPE_LOCALE) {
410         EventLocaleList eventList = m_EventMgrPtr->getEventLocaleList();
411         for (EventLocaleList::iterator it = eventList.begin(); it != eventList.end(); it++) {
412             (*it)->getWatchValue();
413         }
414     } else if (watchType == WATCH_TYPE_PERIPHERAL) {
415         EventPeripheralList eventList = m_EventMgrPtr->getEventPeripheralList();
416         for (EventPeripheralList::iterator it = eventList.begin(); it != eventList.end(); it++) {
417             (*it)->getWatchValue();
418         }
419     } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
420         EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
421         if (eventListCellular.size() > 0) {
422             for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
423                 (*it)->getWatchValue();
424             }
425         }
426     }
427 }
428
429 connection_h Systeminfo::getConnectionHandle()
430 {
431     return m_connectionHandle;
432 }
433
434 JSValueRef Systeminfo::getCpuValue(JSContextRef context)
435 {
436     LoggerD("enter");
437     Converter converter(context);
438
439     CpuPropertiesPtr cpuPtr(new CpuProperties());
440     FILE *fp = NULL;
441     long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
442
443     fp = fopen("/proc/stat", "r");
444     if(fp == NULL) {
445         return JSValueMakeNull(context);
446     }
447     
448     if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
449         total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
450         diffIdle = idle-m_cpuInfo.idle;
451         if ((total > 0LL) && (diffIdle > 0LL)) {
452             cpuUsage = diffIdle * 100LL / total;
453         cpuPtr->load = (double)cpuUsage / 100.0;
454         m_cpuInfo.usr = usr;
455         m_cpuInfo.system = system;
456         m_cpuInfo.nice = nice;
457         m_cpuInfo.idle = idle;        
458             LoggerD("cpu load : " << cpuPtr->load);
459         }
460     }
461
462     fclose(fp);
463     return JSCpuInfo::createJSObject(context, cpuPtr);
464 }
465
466 void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
467 {
468     LoggerD("enter");
469     event->processGetValue((void *)m_connectionHandle);
470 }
471
472 void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
473 {
474     WatchOption watchOption = event->getWatchOption();
475
476     event->switchToManualAnswer();
477     event->setCancelAllowed(true);
478
479     switch(event->getWatchType()) {
480         case WATCH_TYPE_BATTERY:
481             if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
482                 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
483                 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
484             }
485             break;
486         case WATCH_TYPE_DISPLAY:
487             if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
488                 vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
489             }
490             break;
491         case WATCH_TYPE_NETWORK:
492             if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
493                 connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
494             }
495             break;
496         case WATCH_TYPE_WIFINETWORK:
497             if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
498                 if (m_networkRegist == REGIST_NOT) {
499                     connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
500                     m_networkRegist = REGIST_WIFI;
501                 } else if (m_networkRegist== REGIST_CELLULAR) {
502                     m_networkRegist = REGIST_ALL;
503                 }
504             }
505             break;
506         case WATCH_TYPE_CELLULARNETWORK:
507             if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
508                 vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, CellularNetworkValueCallback, (void *)this);
509                 vconf_notify_key_changed(VCONFKEY_TELEPHONY_CELLID, CellularNetworkValueCallback, (void *)this);
510                 vconf_notify_key_changed(VCONFKEY_TELEPHONY_LAC, CellularNetworkValueCallback, (void *)this);
511                 vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVC_ROAM, CellularNetworkValueCallback, (void *)this);                
512                 if (m_networkRegist == REGIST_NOT) {
513                     connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
514                     m_networkRegist = REGIST_CELLULAR;
515                 } else if (m_networkRegist== REGIST_WIFI) {
516                     m_networkRegist = REGIST_ALL;
517                 }
518             }
519             break;
520         case WATCH_TYPE_STORAGE:
521             if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
522                 if (!m_storageTimer) {
523                     m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
524                     ecore_timer_thaw(m_storageTimer);
525                 }
526             }
527             break;
528         case WATCH_TYPE_CPU:
529             if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
530                 if (!m_cpuTimer) {
531                     m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
532                     ecore_timer_thaw(m_cpuTimer);
533                 }
534             }
535             break;
536         case WATCH_TYPE_DEVICE_ORIENTATION:
537             LoggerD("regist sensor");
538             if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
539                 int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
540                 if (state < 0) {
541                     LoggerD("sensor_register_cb fail to gather data");
542                 } else if (state == 0) {
543                     LoggerD("sensor_register_cb success to gather data");
544                 }
545             } else {
546                 LoggerD("already regist");
547             }
548             break;
549         case WATCH_TYPE_LOCALE:
550             if ((m_EventMgrPtr->getEventLocaleList()).size() == 1) {
551                 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_REGION, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
552                     LoggerE("regist failed");
553                     Throw(WrtDeviceApis::Commons::Exception);
554                 }
555                 if (runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, localeChangedCallback, (void *)this) != RUNTIME_INFO_ERROR_NONE) {
556                     LoggerE("regist failed");
557                     Throw(WrtDeviceApis::Commons::Exception);
558                 }
559             }
560             break;
561         case WATCH_TYPE_PERIPHERAL:
562             if ((m_EventMgrPtr->getEventPeripheralList()).size() == 1) {
563                 vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, PeripheralValueCallback, (void *)this);
564                 vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, PeripheralValueCallback, (void *)this);
565             }
566             break;
567     }
568     event->processGetValue();
569     event->setTimer();
570 }
571
572 ////////////////////////////////////////////////////////////////////////////////////////
573
574 Systeminfo::EventMgr::EventMgr()
575 {
576 }
577
578 Systeminfo::EventMgr::~EventMgr()
579 {
580 }
581
582 void Systeminfo::EventMgr::clearAllEvent()
583 {
584     DPL::Mutex::ScopedLock lock(&m_synchro);
585
586     while (!m_eventBatteryList.empty()) {
587         EventWatchSysteminfoPtr event = m_eventBatteryList.front();
588         LoggerD("removing EventId=" << event->getId());
589         event->clearWatch();
590         m_eventBatteryList.pop_front();
591     }
592     while (!m_eventDisplayList.empty()) {
593         EventWatchSysteminfoPtr event = m_eventDisplayList.front();
594         LoggerD("removing EventId=" << event->getId());
595         event->clearWatch();
596         m_eventDisplayList.pop_front();
597     }
598     while (!m_eventWifiNetworkList.empty()) {
599         EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
600         LoggerD("removing EventId=" << event->getId());
601         event->clearWatch();
602         m_eventWifiNetworkList.pop_front();
603     }
604     while (!m_eventCelluarNetworkList.empty()) {
605         EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
606         LoggerD("removing EventId=" << event->getId());
607         event->clearWatch();
608         m_eventCelluarNetworkList.pop_front();
609     }
610     while (!m_eventStorageList.empty()) {
611         EventWatchSysteminfoPtr event = m_eventStorageList.front();
612         LoggerD("removing EventId=" << event->getId());
613         event->clearWatch();
614         m_eventStorageList.pop_front();
615     }
616     while (!m_eventCpuList.empty()) {
617         EventWatchSysteminfoPtr event = m_eventCpuList.front();
618         LoggerD("removing EventId=" << event->getId());
619         event->clearWatch();
620         m_eventCpuList.pop_front();
621     }
622     while (!m_eventSimList.empty()) {
623         EventWatchSysteminfoPtr event = m_eventSimList.front();
624         LoggerD("removing EventId=" << event->getId());
625         event->clearWatch();
626         m_eventSimList.pop_front();
627     }
628     while (!m_eventDeviceOrientationList.empty()) {
629         EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
630         LoggerD("removing EventId=" << event->getId());
631         event->clearWatch();
632         m_eventDeviceOrientationList.pop_front();
633     }
634     while (!m_eventLocaleList.empty()) {
635         EventWatchSysteminfoPtr event = m_eventLocaleList.front();
636         LoggerD("removing EventId=" << event->getId());
637         event->clearWatch();
638         m_eventLocaleList.pop_front();
639     }
640     while (!m_eventPeripheralList.empty()) {
641         EventWatchSysteminfoPtr event = m_eventPeripheralList.front();
642         LoggerD("removing EventId=" << event->getId());
643         event->clearWatch();
644         m_eventPeripheralList.pop_front();
645     }
646 }
647
648 void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
649 {
650     DPL::Mutex::ScopedLock lock(&m_synchro);
651
652     if (watchType == WATCH_TYPE_BATTERY){
653         m_eventBatteryList.push_back(arg);
654         LoggerD("Event Battery list size=" << m_eventBatteryList.size());
655     } else if (watchType == WATCH_TYPE_DISPLAY) {
656         m_eventDisplayList.push_back(arg);
657         LoggerD("Event display list size=" << m_eventDisplayList.size());
658     } else if (watchType == WATCH_TYPE_WIFINETWORK) {
659         m_eventWifiNetworkList.push_back(arg);
660         LoggerD("Event wifi network list size=" << m_eventWifiNetworkList.size());
661     } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
662         m_eventCelluarNetworkList.push_back(arg);
663         LoggerD("Event cellular network list size=" << m_eventCelluarNetworkList.size());
664     } else if (watchType == WATCH_TYPE_STORAGE) {
665         m_eventStorageList.push_back(arg);
666         LoggerD("Event storage list size=" << m_eventStorageList.size());
667     } else if (watchType == WATCH_TYPE_CPU) {
668         m_eventCpuList.push_back(arg);
669         LoggerD("Event cpu list size=" << m_eventCpuList.size());
670     } else if (watchType == WATCH_TYPE_SIM) {
671         m_eventSimList.push_back(arg);
672         LoggerD("Event sim list size=" << m_eventSimList.size());
673     } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
674         m_eventDeviceOrientationList.push_back(arg);
675         LoggerD("Event device orientation list size=" << m_eventDeviceOrientationList.size());
676     } else if (watchType == WATCH_TYPE_NETWORK) {
677         m_eventNetworkList.push_back(arg);
678         LoggerD("Event network list size=" << m_eventNetworkList.size());
679     } else if (watchType == WATCH_TYPE_LOCALE) {
680         m_eventLocaleList.push_back(arg);
681         LoggerD("Event Locale list size=" << m_eventLocaleList.size());
682     } else if (watchType == WATCH_TYPE_PERIPHERAL) {
683         m_eventPeripheralList.push_back(arg);
684         LoggerD("Event peripheral list size=" << m_eventPeripheralList.size());
685     }
686 }
687
688 void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
689 {
690     DPL::Mutex::ScopedLock lock(&m_synchro);
691     LoggerD("Event id : " << id);
692
693     EventWatchSysteminfoPtr event(NULL);
694
695     LoggerD("trying to delete event, id=" << id);
696
697     if (watchType == WATCH_TYPE_BATTERY) {
698         for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
699             if (id == (*it)->getId()) {
700                 event = *it;
701                 break;
702             }
703         }
704         if (!event) {
705             LoggerE("event id not in the list, nothing to do");
706             return;
707         }
708
709         LoggerD("event Battery list size=" << m_eventBatteryList.size());
710         m_eventBatteryList.remove(event);
711         LoggerD( "event removed, event Battery list size=" << m_eventBatteryList.size());
712     } else if (watchType == WATCH_TYPE_DISPLAY) {
713         for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
714             if (id == (*it)->getId()) {
715                 event = *it;
716                 break;
717             }
718         }
719         if (!event) {
720             LoggerE("event id not in the list, nothing to do");
721             return;
722         }
723
724         LoggerD("event display list size=" << m_eventDisplayList.size());
725         m_eventDisplayList.remove(event);
726         LoggerD( "event removed, event display list size=" << m_eventDisplayList.size());
727     } else if (watchType == WATCH_TYPE_WIFINETWORK) {
728         for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
729         if (id == (*it)->getId()) {
730             event = *it;
731             break;
732         }
733     }
734     if (!event) {
735         LoggerE("event id not in the list, nothing to do");
736         return;
737     }
738
739         LoggerD("event wifi network list size=" << m_eventWifiNetworkList.size());
740         m_eventWifiNetworkList.remove(event);
741         LoggerD( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
742     } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
743         for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
744             if (id == (*it)->getId()) {
745                 event = *it;
746                 break;
747             }
748         }
749         if (!event) {
750             LoggerE("event id not in the list, nothing to do");
751             return;
752         }
753
754         LoggerD("event cellular network list size=" << m_eventCelluarNetworkList.size());
755         m_eventCelluarNetworkList.remove(event);
756         LoggerD( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
757     } else if (watchType == WATCH_TYPE_STORAGE) {
758         for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
759             if (id == (*it)->getId()) {
760                 event = *it;
761                 break;
762             }
763         }
764         if (!event) {
765             LoggerE("event id not in the list, nothing to do");
766             return;
767         }
768
769         LoggerD("event storage list size=" << m_eventStorageList.size());
770         m_eventStorageList.remove(event);
771         LoggerD( "event removed, event storage list size=" << m_eventStorageList.size());
772     } else if (watchType == WATCH_TYPE_CPU) {
773         for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
774             if (id == (*it)->getId()) {
775                 event = *it;
776                 break;
777             }
778         }
779         if (!event) {
780             LoggerE("event id not in the list, nothing to do");
781             return;
782         }
783
784         LoggerD("event cpu list size=" << m_eventCpuList.size());
785         m_eventCpuList.remove(event);
786         LoggerD( "event removed, event cpu list size=" << m_eventCpuList.size());
787     } else if (watchType == WATCH_TYPE_SIM) {
788         for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
789             if (id == (*it)->getId()) {
790                 event = *it;
791                 break;
792             }
793         }
794         if (!event) {
795             LoggerE("event id not in the list, nothing to do");
796             return;
797         }
798
799         LoggerD("event sim list size=" << m_eventSimList.size());
800         m_eventSimList.remove(event);
801         LoggerD( "event removed, event sim list size=" << m_eventSimList.size());
802     } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
803         for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
804             if (id == (*it)->getId()) {
805                 event = *it;
806                 break;
807             }
808         }
809         if (!event) {
810             LoggerE("event id not in the list, nothing to do");
811             return;
812         }
813
814         LoggerD("event device orientation list size=" << m_eventDeviceOrientationList.size());
815         m_eventDeviceOrientationList.remove(event);
816         LoggerD( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
817     } else if (watchType == WATCH_TYPE_NETWORK) {
818         for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
819             if (id == (*it)->getId()) {
820                 event = *it;
821                 break;
822             }
823         }
824         if (!event) {
825             LoggerE("event id not in the list, nothing to do");
826             return;
827         }
828
829         LoggerD("event network list size=" << m_eventNetworkList.size());
830         m_eventNetworkList.remove(event);
831         LoggerD( "event removed, event network list size=" << m_eventNetworkList.size());
832     } else if (watchType == WATCH_TYPE_LOCALE) {
833         for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
834             if (id == (*it)->getId()) {
835                 event = *it;
836                 break;
837             }
838         }
839         if (!event) {
840             LoggerE("event id not in the list, nothing to do");
841             return;
842         }
843
844         LoggerD("event Locale list size=" << m_eventLocaleList.size());
845         m_eventLocaleList.remove(event);
846         LoggerD( "event removed, event Locale list size=" << m_eventLocaleList.size());
847     } else if (watchType == WATCH_TYPE_PERIPHERAL) {
848         for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
849             if (id == (*it)->getId()) {
850                 event = *it;
851                 break;
852             }
853         }
854         if (!event) {
855             LoggerE("event id not in the list, nothing to do");
856             return;
857         }
858
859         LoggerD("event peripheral list size=" << m_eventPeripheralList.size());
860         m_eventPeripheralList.remove(event);
861         LoggerD( "event removed, event peripheral list size=" << m_eventPeripheralList.size());
862     }
863 }
864
865 const int Systeminfo::EventMgr::getWatchType(const long id)
866 {
867     DPL::Mutex::ScopedLock lock(&m_synchro);
868
869     EventWatchSysteminfoPtr event(NULL);
870
871     for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
872         if (id == (*it)->getId()) {
873             event = *it;
874             break;
875         }
876     }
877
878     for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
879         if (id == (*it)->getId()) {
880             event = *it;
881             break;
882         }
883     }
884
885     for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
886         if (id == (*it)->getId()) {
887             event = *it;
888             break;
889         }
890     }
891
892     for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
893         if (id == (*it)->getId()) {
894             event = *it;
895             break;
896         }
897     }
898
899     for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
900         if (id == (*it)->getId()) {
901             event = *it;
902             break;
903         }
904     }
905
906     for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
907         if (id == (*it)->getId()) {
908             event = *it;
909             break;
910         }
911     }
912
913     for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
914         if (id == (*it)->getId()) {
915             event = *it;
916             break;
917         }
918     }
919
920     for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
921         if (id == (*it)->getId()) {
922             event = *it;
923             break;
924         }
925     }
926
927     for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
928         if (id == (*it)->getId()) {
929             event = *it;
930             break;
931         }
932     }
933
934     for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
935         if (id == (*it)->getId()) {
936             event = *it;
937             break;
938         }
939     }
940
941     for (EventLocaleList::iterator it = m_eventLocaleList.begin(); it != m_eventLocaleList.end(); it++) {
942         if (id == (*it)->getId()) {
943             event = *it;
944             break;
945         }
946     }
947
948     for (EventPeripheralList::iterator it = m_eventPeripheralList.begin(); it != m_eventPeripheralList.end(); it++) {
949         if (id == (*it)->getId()) {
950             event = *it;
951             break;
952         }
953     }
954
955     if (!event) {
956         LoggerE("event id not in the list, nothing to do");
957         return WATCH_TYPE_UNKNOWN;
958     }
959
960     return event->getWatchType();
961 }
962
963 EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
964 {
965     return m_eventBatteryList;
966 }
967
968 EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
969 {
970     return m_eventDisplayList;
971 }
972
973 EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
974 {
975     return m_eventNetworkList;
976 }
977
978 EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
979 {
980     return m_eventWifiNetworkList;
981 }
982
983 EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
984 {
985     return m_eventCelluarNetworkList;
986 }
987
988 EventStorageList Systeminfo::EventMgr::getEventStorageList()
989 {
990     return m_eventStorageList;
991 }
992
993 EventCpuList Systeminfo::EventMgr::getEventCpuList()
994 {
995     return m_eventCpuList;
996 }
997
998 EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
999 {
1000     return m_eventDeviceOrientationList;
1001 }
1002
1003 EventSimList Systeminfo::EventMgr::getEventSimList()
1004 {
1005     return m_eventSimList;
1006 }
1007
1008 EventLocaleList Systeminfo::EventMgr::getEventLocaleList()
1009 {
1010     return m_eventLocaleList;
1011 }
1012
1013 EventPeripheralList Systeminfo::EventMgr::getEventPeripheralList()
1014 {
1015     return m_eventPeripheralList;
1016 }
1017
1018 ////////////////////////////////////////////////////////////////////////////////////////
1019
1020 PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
1021     BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
1022     int value=0;
1023     int value2=0;
1024
1025     if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
1026         return JSValueMakeNull(context);
1027     } else {
1028         BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
1029     }
1030
1031     if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
1032         return JSValueMakeNull(context);
1033     } else {
1034         BatteryPtr->isCharging = (value2 == 0) ? false : true;
1035     }
1036
1037     return JSBatteryInfo::createJSObject(context, BatteryPtr);
1038 }
1039
1040 PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
1041     Converter converter(context);
1042
1043     CpuPropertiesPtr cpuPtr(new CpuProperties());
1044     FILE *fp = NULL;
1045     long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
1046
1047     fp = fopen("/proc/stat", "r");
1048     if(fp == NULL) {
1049         return JSValueMakeNull(context);
1050     }
1051     
1052     if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
1053         total = usr + nice + system + idle;
1054         if ((total > 0LL) && (idle > 0LL)) {
1055             cpuUsage = idle * 100LL / total;
1056         cpuPtr->load = (double)cpuUsage / 100.0;
1057             LoggerD("cpu load : " << cpuPtr->load);
1058         }
1059     }
1060
1061     fclose(fp);
1062     return JSCpuInfo::createJSObject(context, cpuPtr);
1063 }
1064
1065 PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
1066     Converter converter(context);
1067     int sdcardState=0;
1068     int usbhostState=0;
1069     int storageCnt=0;
1070     struct statfs fs;
1071     StoragePropertiesPtr internal(new StorageProperties());
1072     StoragePropertiesPtr mmc(new StorageProperties());
1073     StoragePropertiesPtr usbhost(new StorageProperties());
1074     std::vector <JSObjectRef> storagelist;
1075     
1076     if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
1077         return JSValueMakeNull(context);
1078     }
1079
1080     internal->type = "INTERNAL";
1081     internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1082     internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1083     internal->isRemoveable = false;
1084     internal->isRemovable = false;
1085     storagelist.push_back(JSStorageInfo::createJSObject(context, internal));
1086     storageCnt++;
1087
1088     if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
1089         if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
1090             storageCnt++;
1091             if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
1092                 return JSValueMakeNull(context);
1093             }
1094             mmc->type = "MMC";
1095             mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1096             mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1097             mmc->isRemoveable = true;
1098             mmc->isRemovable = true;
1099             storagelist.push_back(JSStorageInfo::createJSObject(context, mmc));
1100         }
1101     }
1102
1103     if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
1104         if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
1105             storageCnt++;
1106             if (statfs(STORAGE_USBHOST_PATH, &fs) < 0)    {
1107                 return JSValueMakeNull(context);
1108             }
1109             usbhost->type = "USB_HOST";
1110             usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
1111             usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
1112             usbhost->isRemoveable = true;
1113             usbhost->isRemovable = true;
1114             storagelist.push_back(JSStorageInfo::createJSObject(context, usbhost));
1115         }
1116     }
1117
1118     return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
1119 }
1120
1121 PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
1122     Converter converter(context);
1123
1124     DisplayPropertiesPtr display(new DisplayProperties());
1125     int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
1126
1127     if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
1128         display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
1129         LoggerD("brightness : " << display->brightness);
1130     }
1131
1132     if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
1133         display->resolutionWidth = resolutionW;
1134         LoggerD("resolutionWidth : " << display->resolutionWidth);
1135     }
1136     if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
1137         display->resolutionHeight = resolutionH;
1138         LoggerD("resolutionHeight : " << display->resolutionHeight);
1139     }
1140     if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
1141         display->dotsPerInchWidth = dotsPerInchX;
1142         LoggerD("dotsPerInchWidth : " << display->dotsPerInchWidth);
1143     }
1144     if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
1145         display->dotsPerInchHeight = dotsPerInchY;
1146         LoggerD("dotsPerInchHeight : " << display->dotsPerInchHeight);
1147     }
1148     if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
1149         display->physicalHeight = physicalH;
1150         LoggerD("physicalHeight : " << display->physicalHeight);
1151     }
1152     if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
1153         display->physicalWidth = physicalW;
1154         LoggerD("physicalWidth : " << display->physicalWidth);
1155     }
1156
1157     return JSDisplayInfo::createJSObject(context, display);
1158 }
1159
1160 PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
1161     LoggerD("enter");
1162     Converter converter(context);
1163     NetworkPropertiesPtr Network(new NetworkProperties());
1164     connection_h connectionHandle = (connection_h)handle;    
1165     connection_type_e connectionType;
1166     int networkType = 0;
1167
1168     if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1169         LoggerD("get connection type is failed");
1170         return JSNetworkInfo::createJSObject(context, Network);
1171     }
1172
1173     if (connectionType == CONNECTION_TYPE_WIFI) {
1174         LoggerD("wifi network");
1175         Network->networkType= "WIFI";
1176     } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
1177         if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
1178             if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1179                 Network->networkType= "NONE";
1180             } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
1181                 Network->networkType= "2G";
1182             } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
1183                 Network->networkType= "2.5";
1184             } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
1185                 Network->networkType= "3G";
1186             } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
1187                 Network->networkType= "4G";
1188             } else {
1189                 Network->networkType= "NONE";
1190             }
1191         }
1192     } else {
1193         Network->networkType= "NONE";
1194     }
1195
1196     return JSNetworkInfo::createJSObject(context, Network);
1197 }
1198
1199 PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
1200     Converter converter(context);
1201     WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
1202     connection_h connectionHandle = (connection_h)handle;    
1203     connection_type_e connectionType;
1204     connection_profile_h profileHandle = NULL;
1205     connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1206     char* ipAddr = NULL;
1207     char* essid = NULL;
1208     int rssi = 0;
1209
1210     if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1211         return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1212     }
1213
1214     if (connectionType == CONNECTION_TYPE_WIFI) {
1215         wifiNetwork->status = "ON";
1216     } else {
1217         wifiNetwork->status = "OFF";
1218         return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1219     }
1220
1221     if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
1222         return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1223     }
1224
1225     if (connection_profile_get_wifi_essid(profileHandle, &essid) == CONNECTION_ERROR_NONE) {
1226         wifiNetwork->ssid = essid;
1227         free(essid);
1228     }
1229
1230     if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1231         wifiNetwork->ipAddress = ipAddr;
1232         free(ipAddr);
1233     }
1234
1235     if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
1236         wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
1237     }
1238
1239     return JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
1240 }
1241
1242 PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
1243     Converter converter(context);
1244     CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
1245     connection_h connectionHandle = (connection_h)handle;    
1246     connection_type_e connectionType;
1247     connection_profile_h profileHandle = NULL;
1248     connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
1249     char* ipAddr = NULL;
1250     char* apn = NULL;
1251     char* imei = NULL;
1252     int plmn = 0, cellId = 0, lac = 0, isRoaming = 0, isFlightMode = 0;
1253     TapiHandle *tapiHandle = NULL;    
1254
1255     TIME_TRACER_ITEM_BEGIN("(cellular)mcc", 0);
1256     if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
1257         cellularNetwork->mcc = plmn / 100;
1258         cellularNetwork->mnc = plmn % 100;
1259     }
1260     TIME_TRACER_ITEM_END("(cellular)mcc", 0);
1261
1262     TIME_TRACER_ITEM_BEGIN("(cellular)cellId", 0);
1263     if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellId) == 0) {
1264         cellularNetwork->cellId = cellId;
1265     }
1266     TIME_TRACER_ITEM_END("(cellular)cellId", 0);
1267
1268     TIME_TRACER_ITEM_BEGIN("(cellular)lac", 0);
1269     if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
1270         cellularNetwork->lac = lac;
1271     }
1272     TIME_TRACER_ITEM_END("(cellular)lac", 0);
1273
1274     TIME_TRACER_ITEM_BEGIN("(cellular)isRoaming", 0);
1275     if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
1276         if (isRoaming) {
1277             cellularNetwork->isRoaming = true;
1278         } else {
1279             cellularNetwork->isRoaming = false;
1280         }
1281     }
1282     TIME_TRACER_ITEM_END("(cellular)isRoaming", 0);
1283
1284         TIME_TRACER_ITEM_BEGIN("(cellular)isFlightMode", 0);
1285     if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode) == 0) {
1286         if (isFlightMode) {
1287             cellularNetwork->isFlightMode = true;
1288         } else {
1289             cellularNetwork->isFlightMode = false;
1290         }
1291     }
1292         TIME_TRACER_ITEM_END("(cellular)isFlightMode", 0);
1293
1294     if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
1295         return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1296     }
1297
1298     if (connectionType == CONNECTION_TYPE_CELLULAR) {
1299         cellularNetwork->status = "ON";
1300         if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
1301                         TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1302             if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1303                 cellularNetwork->apn = apn;
1304                 free(apn);
1305             }
1306                         TIME_TRACER_ITEM_END("(cellular)apn", 0);
1307
1308                         TIME_TRACER_ITEM_BEGIN("(cellular)ipAddress", 0);
1309             if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
1310                 cellularNetwork->ipAddress = ipAddr;
1311                 free(ipAddr);
1312             }
1313                         TIME_TRACER_ITEM_END("(cellular)ipAddress", 0);
1314             connection_profile_destroy(profileHandle);
1315         }
1316     } else {
1317         cellularNetwork->status = "OFF";
1318         if (connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle) == CONNECTION_ERROR_NONE) {
1319                         TIME_TRACER_ITEM_BEGIN("(cellular)apn", 0);
1320             if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
1321                 cellularNetwork->apn = apn;
1322                 free(apn);
1323             }
1324                         TIME_TRACER_ITEM_END("(cellular)apn", 0);
1325             connection_profile_destroy(profileHandle);
1326         }
1327     }
1328
1329     tapiHandle = tel_init(0);
1330     
1331     if (tapiHandle != NULL) {
1332         imei = tel_get_misc_me_imei_sync(tapiHandle);
1333         
1334         if (imei == NULL) {
1335             tel_deinit(tapiHandle);
1336             return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1337         }
1338         
1339         cellularNetwork->imei = imei;
1340         free(imei);
1341         tel_deinit(tapiHandle);
1342     }
1343
1344     return JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
1345 }
1346
1347 PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
1348     Converter converter(context);
1349     SIMPropertiesPtr SIM(new SIMProperties());
1350
1351     sim_state_e state;
1352     char* fullName = NULL;
1353     char* shortName = NULL;
1354     char* msisdn = NULL;
1355     char* iccId = NULL;
1356     char* mcc = NULL;
1357     char* mnc = NULL;
1358     char* msin = NULL;
1359     char* spn = NULL;
1360     int ret = SIM_ERROR_NONE;    
1361
1362     ret = sim_get_state(&state);
1363     if (ret == SIM_ERROR_NONE) {
1364         if (state == SIM_STATE_UNAVAILABLE) {
1365             SIM->state = "ABSENT";
1366         } else if (state == SIM_STATE_LOCKED) {
1367             SIM->state = "PIN_REQUIRED";
1368         } else if (state == SIM_STATE_AVAILABLE) {
1369             SIM->state = "READY";
1370         } else if (state == SIM_STATE_UNKNOWN) {
1371             SIM->state = "INITIALIZING";
1372         }
1373     }
1374
1375     ret = sim_get_cphs_operator_name(&fullName, &shortName);
1376     if (ret == SIM_ERROR_NONE) {
1377         if (fullName) {
1378             SIM->operatorName = fullName;
1379             LoggerD("operatorName : " << SIM->operatorName);
1380             free(fullName);
1381         } else if (shortName) {
1382             SIM->operatorName = shortName;
1383             LoggerD("operatorName : " << SIM->operatorName);
1384             free(shortName);
1385         }
1386     }
1387
1388
1389     ret = sim_get_subscriber_number(&msisdn);
1390     if (ret == SIM_ERROR_NONE) {
1391         if (msisdn) {
1392             SIM->msisdn = msisdn;
1393             LoggerD("msisdn : " << SIM->msisdn);
1394             free(msisdn);
1395         }
1396     }
1397
1398     ret = sim_get_icc_id(&iccId);
1399     if (ret == SIM_ERROR_NONE) {
1400         if (iccId) {
1401             SIM->iccid = iccId;
1402             LoggerD("iccid : " << SIM->iccid);
1403             free(iccId);
1404         }
1405     }
1406
1407     ret = sim_get_mcc(&mcc);
1408     if (ret == SIM_ERROR_NONE) {
1409         if (mcc) {
1410             SIM->mcc = atoi(mcc);
1411             LoggerD("mcc : " << SIM->mcc);
1412             free(mcc);
1413         }
1414     }
1415
1416     ret = sim_get_mnc(&mnc);
1417     if (ret == SIM_ERROR_NONE) {
1418         if (mnc) {
1419             SIM->mnc = atoi(mnc);
1420             LoggerD("mnc : " << SIM->mnc);
1421             free(mnc);
1422         }
1423     }
1424
1425     ret = sim_get_msin(&msin);
1426     if (ret == SIM_ERROR_NONE) {
1427         if (msin) {
1428             SIM->msin = msin;
1429             LoggerD("msin : " << SIM->msin);
1430             free(msin);
1431         }
1432     }
1433
1434     ret = sim_get_spn(&spn);
1435     if (ret == SIM_ERROR_NONE) {
1436         if (spn) {
1437             SIM->spn = spn;
1438             LoggerD("spn : " << SIM->spn);
1439             free(spn);
1440         }
1441     }
1442
1443     return JSSIMInfo::createJSObject(context, SIM);
1444 }
1445
1446 PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
1447     LoggerD("enter");
1448     Converter converter(context);
1449     DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
1450
1451     unsigned long rotation = 0;
1452     int handleOrientaion = 0;
1453
1454     handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
1455     LoggerD("handleOrientaion : " << handleOrientaion);
1456     if (handleOrientaion < 0) {
1457         LoggerD ("sensor attach fail");
1458         return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1459     }
1460     int state = sf_start(handleOrientaion, 0);
1461     if(state < 0) {
1462         LoggerD("start failed");
1463     }
1464
1465     int ret_val = sf_check_rotation(&rotation);
1466     if (ret_val < 0) {
1467         LoggerD("sf_check_rotation fail to gather data\n");
1468     }
1469
1470     LoggerD(" rotation value = " << rotation);
1471
1472     switch (rotation) {
1473         case 0:
1474         case ROTATION_EVENT_0:
1475             LoggerD("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
1476             deviceOrientation->status = "PORTRAIT_PRIMARY";
1477             break;
1478         case ROTATION_EVENT_90:
1479             LoggerD("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
1480             deviceOrientation->status = "LANDSCAPE_PRIMARY";
1481             break;
1482         case ROTATION_EVENT_180:
1483             LoggerD("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
1484             deviceOrientation->status = "PORTRAIT_SECONDARY";
1485             break;
1486         case ROTATION_EVENT_270:
1487             LoggerD("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
1488             deviceOrientation->status = "LANDSCAPE_SECONDARY";
1489             break;
1490         default:
1491             LoggerD(" received data unexpected\n");
1492             break;
1493     }
1494
1495         state = sf_stop(handleOrientaion);
1496         LoggerD("handleOrientaion 1  state = " << state);
1497
1498         state = sf_disconnect(handleOrientaion);
1499         LoggerD("handleOrientaion  state =" << state);
1500
1501     return JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
1502 }
1503
1504 PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
1505     LoggerD("enter");
1506     Converter converter(context);
1507     BuildPropertiesPtr Build(new BuildProperties());
1508
1509     char* model = NULL;
1510     char* manufacturer = NULL;
1511     char* buildVersion = NULL;
1512
1513     if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
1514         if (model != NULL) {
1515             LoggerD("model : " << model);
1516             Build->model = model;
1517             free(model);
1518         }
1519     }
1520
1521     if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &manufacturer) == SYSTEM_INFO_ERROR_NONE) {
1522         if (manufacturer != NULL) {
1523             LoggerD("manufacturer : " << manufacturer);
1524             Build->manufacturer = manufacturer;
1525             free(manufacturer);
1526         }
1527     }
1528
1529     if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &buildVersion) == SYSTEM_INFO_ERROR_NONE) {
1530         if (buildVersion != NULL) {
1531             LoggerD("buildVersion : " << buildVersion);
1532             Build->buildVersion = buildVersion;
1533             free(buildVersion);
1534         }
1535     }
1536
1537     return JSBuildInfo::createJSObject(context, Build);
1538 }
1539
1540 PROPERTY_GET_SYSTEMINFO_DEFINITION(Locale) {
1541     LoggerD("enter");
1542     Converter converter(context);
1543     LocalePropertiesPtr Locale(new LocaleProperties());
1544
1545     char* country = NULL;
1546     char* language = NULL;
1547
1548     if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language) == RUNTIME_INFO_ERROR_NONE) {
1549         if (language != NULL) {
1550             LoggerD("language : " << language);
1551             Locale->language = language;
1552             free(language);
1553         }
1554     }
1555
1556     if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country) == RUNTIME_INFO_ERROR_NONE) {
1557         if (country != NULL) {
1558             LoggerD("country : " << country);
1559             char* token = NULL;
1560             char* countryTemp = NULL;
1561             token = strtok(country, ".");
1562             if (token != NULL) {
1563                 countryTemp = strdup(token);
1564                 if (countryTemp != NULL) {
1565                     Locale->country = countryTemp;
1566                     free(countryTemp);
1567                 }
1568             }            
1569             free(country);            
1570         }
1571     }
1572
1573     return JSLocaleInfo::createJSObject(context, Locale);
1574 }
1575
1576 PROPERTY_GET_SYSTEMINFO_DEFINITION(Peripheral) {
1577     Converter converter(context);
1578     PeripheralPropertiesPtr peripheral(new PeripheralProperties());
1579     int hdmiStatus = 0, wirelessDisplayStatus = 0 ;
1580
1581     if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wirelessDisplayStatus) == 0) {
1582         switch(wirelessDisplayStatus) {
1583             case VCONFKEY_MIRACAST_WFD_SOURCE_ON:
1584                 peripheral->isVideoOutputOn = true;
1585                 break;
1586             default:
1587                 LoggerD("VideOutput status is off");
1588                 break;
1589         }
1590     }
1591
1592     if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmiStatus) == 0) {
1593         switch(hdmiStatus) {
1594             case VCONFKEY_SYSMAN_HDMI_CONNECTED:
1595                 peripheral->isVideoOutputOn = true;
1596                 break;
1597             default:
1598                 LoggerD("VideOutput status is off");
1599                 break;
1600         }
1601     }
1602
1603     return JSPeripheralInfo::createJSObject(context, peripheral);
1604 }
1605
1606 }
1607 }