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