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