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