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