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