sync with tizen_2.0
[platform/framework/native/appfw.git] / src / system / FSys_RuntimeInfoImpl.cpp
1 //
2 // Open Service Platform
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 /**
19  * @file                FSysRuntimeInfo.cpp
20  * @brief               This is the implementation file for _RuntimeInfoImpl class.
21  *
22  *
23  * This file contains the implementation of _RuntimeInfoImpl class.
24  */
25
26 #include <unique_ptr.h>
27 #include <pthread.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <sys/vfs.h>
33 #include <app_storage.h>
34 #include <devman.h>
35 #include <runtime_info.h>
36 #include <vconf.h>
37
38 #include <FBaseRtEvent.h>
39 #include <FBaseRtIEventArg.h>
40 #include <FBaseRtIEventListener.h>
41 #include <FBaseRtThread.h>
42 #include <FBaseSysLog.h>
43 #include <FApp_AppInfo.h>
44 #include <FBase_StringConverter.h>
45 #include <FSys_EnvironmentImpl.h>
46 #include <FSys_RuntimeInfoImpl.h>
47
48 using namespace Tizen::App;
49 using namespace Tizen::Base;
50 using namespace Tizen::Base::Runtime;
51
52 using namespace std;
53
54 namespace Tizen { namespace System
55 {
56
57 static const wchar_t* _ALLOCATED_MEMORY = L"AllocatedMemory";
58 static const wchar_t* _MEMORY_ALLOCATED = L"http://tizen.org/runtime/memory.allocated";
59
60 static const wchar_t* _AVAILABLE_EXTERNAL_STORAGE = L"AvailableExternalStorage";
61 static const wchar_t* _STORAGE_AVAILABLE_EXTERNAL = L"http://tizen.org/runtime/storage.available.external";
62
63 static const wchar_t* _AVAILABLE_INTERNAL_STORAGE = L"AvailableInternalStorage";
64 static const wchar_t* _STORAGE_AVAILABLE_INTERNAL = L"http://tizen.org/runtime/storage.available.internal";
65
66 static const wchar_t* _AVAILABLE_MEDIA_STORAGE = L"AvailableMediaStorage";
67 static const wchar_t* _STORAGE_AVAILABLE_INTERNAL_MEDIA = L"http://tizen.org/runtime/storage.available.internal.media";
68
69 static const wchar_t* _BATTERY_LEVEL = L"BatteryLevel";
70 static const wchar_t* _CHARGING = L"IsCharging";
71
72 static const wchar_t* _CPU_CORE_ALL_USAGE = L"http://tizen.org/runtime/cpu.core.all.usage";
73
74 static const wchar_t* _MAX_ALLOCATABLE_MEMORY = L"MaxAllocatableMemory";
75 static const wchar_t* _AVAILABLE_VIDEO_MEMORY = L"AvailableVideoMemory";
76 static const wchar_t* _ALLOCATED_VIDEO_MEMORY = L"AllocatedVideoMemory";
77 static const wchar_t* _AVAILABLE_MEMORY = L"AvailableMemory";
78 static const wchar_t* _MEMORY_AVAILABLE = L"http://tizen.org/runtime/memory.available";
79 static const wchar_t* _MEMORY_AVAILABLE_VIDEO = L"http://tizen.org/runtime/memory.available.video";
80 static const wchar_t* _MEMORY_ALLOCATED_VIDEO = L"http://tizen.org/runtime/memory.allocated.video";
81
82 static const wchar_t* _STORAGE_ALLOCATED_INTERNAL_APPLICATION = L"http://tizen.org/runtime/storage.allocated.internal.application";
83 static const wchar_t* _STORAGE_ALLOCATED_INTERNAL_AUDIO = L"http://tizen.org/runtime/storage.allocated.internal.audio";
84 static const wchar_t* _STORAGE_ALLOCATED_INTERNAL_VIDEO = L"http://tizen.org/runtime/storage.allocated.internal.video";
85 static const wchar_t* _STORAGE_ALLOCATED_INTERNAL_IMAGE = L"http://tizen.org/runtime/storage.allocated.internal.image";
86 static const wchar_t* _STORAGE_ALLOCATED_INTERNAL_DOWNLOAD = L"http://tizen.org/runtime/storage.allocated.internal.download";
87 static const wchar_t* _STORAGE_ALLOCATED_EXTERNAL_APPLICATION = L"http://tizen.org/runtime/storage.allocated.external.application";
88 static const wchar_t* _STORAGE_ALLOCATED_EXTERNAL_AUDIO = L"http://tizen.org/runtime/storage.allocated.external.audio";
89 static const wchar_t* _STORAGE_ALLOCATED_EXTERNAL_VIDEO = L"http://tizen.org/runtime/storage.allocated.external.video";
90 static const wchar_t* _STORAGE_ALLOCATED_EXTERNAL_IMAGE = L"http://tizen.org/runtime/storage.allocated.external.image";
91 static const wchar_t* _STORAGE_ALLOCATED_EXTERNAL_DOWNLOAD = L"http://tizen.org/runtime/storage.allocated.external.download";
92
93 static const int _RUNTIME_INFO_EVENT_TYPE_INT = 101;
94 static const int _RUNTIME_INFO_EVENT_TYPE_LONGLONG = 102;
95
96
97 static const char* const _PROC_SYSTEM_MEMORY_INFO = "/proc/meminfo";
98 static const char* const _PROC_PROCESS_MEMORY_INFO = "/proc/self/status";
99 static const char* const _PROC_STAT = "/proc/stat";
100
101 static const char* const _PROC_KEY_SYSTEM_MEMORY_TOTAL = "MemTotal";
102 static const char* const _PROC_KEY_SYSTEM_MEMORY_FREE = "MemFree";
103 static const char* const _PROC_KEY_PROCESS_MEMORY = "VmSize";
104
105 static const char* const _ROOT_PATH = "/";
106 static const char* const _STORAGE_PATH = "/opt/storage/sdcard";
107 static const char* const _MEDIA_PATH = "/opt/usr/media";
108 static const char* const _INTERNAL_PATH = "/opt";
109
110 static const int _MAX_BUFFER_LENGTH = 1024;
111
112 static const int _CPU_USAGE_EVALUATION_INTERVAL = 1000000; //1 sec
113
114 typedef struct {
115     char cpu[20];
116     unsigned long long user;
117     unsigned long long system;
118     unsigned long long nice;
119     unsigned long long idle;
120     unsigned long long wait;
121     unsigned long long hi;
122     unsigned long long si;
123     unsigned long long zero;
124 } procstat_t;
125
126 bool read_proc_stat(procstat_t *p)
127 {
128         FILE *fp = null;
129         int ret = 0;
130
131         fp = fopen(_PROC_STAT, "r");
132         if(fp == null)
133         {
134                 return false;
135         }
136
137         ret = fscanf(fp, "%s %llu %llu %llu %llu %llu %llu %llu %llu",
138         p->cpu,
139         &p->user,
140         &p->system,
141         &p->nice,
142         &p->idle,
143         &p->wait,
144         &p->hi,
145         &p->si,
146         &p->zero);
147
148         if(ret < 1)
149         {
150                 if(fp != null)
151                 {
152                         fclose(fp);
153                 }
154                 return false;
155         }
156
157         if(fp != null)
158         {
159                 fclose(fp);
160         }
161
162         return true;
163 }
164  
165 void diff_proc_stat(procstat_t *a, procstat_t *b, procstat_t *d)
166 {
167         d->user     = a->user   - b->user;
168         d->system   = a->system - b->system;
169         d->nice     = a->nice   - b->nice;
170         d->idle     = a->idle   - b->idle;
171         d->wait     = a->wait   - b->wait;
172         d->hi       = a->hi     - b->hi;
173         d->si       = a->si     - b->si;
174         d->zero     = a->zero   - b->zero;
175 }
176
177 class _RuntimeInfoEventArg : public IEventArg
178 {
179 public:
180         _RuntimeInfoEventArg()
181         : Type(0)
182         , intValue(0)
183         , longLongValue(0)
184         , errorCode(E_SUCCESS)
185         , DirectoryPath(null)
186         , pListener(null)
187         {
188         }
189
190         ~_RuntimeInfoEventArg()
191         {
192                 if(DirectoryPath != null)
193                 {
194                         delete [] DirectoryPath;
195                 }
196         }
197
198         int Type;
199         int intValue;
200         long long longLongValue;
201         result errorCode;
202         char* DirectoryPath;
203         IEventListener* pListener;
204 };
205
206 class _RuntimeInfoEvent : public Event
207 {
208 protected:
209         void FireImpl(IEventListener& listener, const IEventArg& arg)
210         {
211                 const _RuntimeInfoEventArg* runtimeArg = dynamic_cast<const _RuntimeInfoEventArg*> (&arg);
212
213                 if(runtimeArg == null)
214                 {
215                         SysLogException(NID_SYS, E_SYSTEM, "Argument is null.");
216                         return;
217                 }
218
219                 switch(runtimeArg->Type)
220                 {
221                 case _RUNTIME_INFO_EVENT_TYPE_INT:
222                 {
223                         IRuntimeInfoGetIntAsyncResultListener* pIntListener = dynamic_cast<IRuntimeInfoGetIntAsyncResultListener*>(&listener);
224
225                         if(pIntListener == runtimeArg->pListener)
226                         {                               
227                                 pIntListener->OnResultReceivedForGetValueAsync(runtimeArg->intValue, runtimeArg->errorCode);
228                                 RemoveListener(listener);
229                                 delete pIntListener;
230                         }
231                 }
232                 break;
233                 case _RUNTIME_INFO_EVENT_TYPE_LONGLONG:
234                 {
235                         IRuntimeInfoGetLonglongAsyncResultListener* pLonglongListener = dynamic_cast<IRuntimeInfoGetLonglongAsyncResultListener*>(&listener);
236                         if(pLonglongListener == runtimeArg->pListener)
237                         {
238                                 pLonglongListener->OnResultReceivedForGetValueAsync(runtimeArg->longLongValue, runtimeArg->errorCode);
239                                 RemoveListener(listener);
240                                 delete pLonglongListener;
241                         }
242                 }
243                 break;
244                 }
245         }
246 };
247
248 _RuntimeInfoEvent runtimeInfoEvent;
249
250 _RuntimeInfoImpl::_RuntimeInfoImpl(void)
251 {
252 }
253
254 _RuntimeInfoImpl::~_RuntimeInfoImpl(void)
255 {
256 }
257
258 result
259 _RuntimeInfoImpl::GetValue(const String& key, String& value)
260 {
261         return E_OBJ_NOT_FOUND;
262 }
263
264 result
265 _RuntimeInfoImpl::GetValue(const String& key, int& value)
266 {
267         int total_size = 0;
268         int free_size =0;
269         result r = E_OBJ_NOT_FOUND;
270
271         if (key == _BATTERY_LEVEL)
272         {
273                 return GetBatteryLevel(value);
274         }
275         else if (key == _ALLOCATED_MEMORY || key == _ALLOCATED_VIDEO_MEMORY)
276         {
277                 r = GetFromProc(_PROC_PROCESS_MEMORY_INFO, _PROC_KEY_PROCESS_MEMORY, free_size);
278                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
279                 value = free_size * 1024;
280         }
281         else if (key == _AVAILABLE_MEMORY || key == _AVAILABLE_VIDEO_MEMORY || key == _MAX_ALLOCATABLE_MEMORY || key == _MEMORY_AVAILABLE || key == _MEMORY_AVAILABLE_VIDEO)
282         {
283                 r = GetFromProc(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_FREE, free_size);
284                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
285                 value = free_size * 1024;
286         }
287         else if (key == _MEMORY_ALLOCATED || key == _MEMORY_ALLOCATED_VIDEO)
288         {
289                 r = GetFromProc(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_TOTAL, total_size);
290                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
291                 r = GetFromProc(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_FREE, free_size);
292                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
293                 value = (total_size - free_size) * 1024;
294         }
295         return r;
296 }
297
298 long long
299 _RuntimeInfoImpl::GetDirectorySize(const char* path)
300 {
301         if(path == null)
302         {
303                 return 0;
304         }
305
306         char command[512] = {0,};
307         long long size = 0;
308         int ret = 0;
309
310         sprintf(command, "du -sk -P %s >> /tmp/size_of_directory.tmp", path);
311
312         system("rm -rf /tmp/size_of_directory.tmp");
313         system(command);
314
315         FILE* pFile = null;
316         pFile = fopen("/tmp/size_of_directory.tmp", "r");
317         if(pFile == null)
318         {
319                 return 0;
320         }
321         ret = fscanf(pFile, "%lld", &size);
322
323         if(ret < 1)
324         {
325                 if(pFile != null)
326                 {
327                         fclose(pFile);
328                 }
329
330                 return false;
331         }
332
333         if(pFile != null)
334         {
335                 fclose(pFile);
336         }
337         system("rm -rf /tmp/size_of_directory.tmp");
338         return size;
339 }
340
341 result
342 _RuntimeInfoImpl::GetValue(const String& key, long long& value)
343 {
344
345         long long total_size = 0;
346         long long free_size =0;
347         result r = E_OBJ_NOT_FOUND;
348
349         if (key == _MEMORY_AVAILABLE || key == _MEMORY_AVAILABLE_VIDEO)
350         {
351                 r = GetFromProcLonglong(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_FREE, free_size);
352                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
353                 value = free_size * 1024;
354         }
355         else if (key == _MEMORY_ALLOCATED || key == _MEMORY_ALLOCATED_VIDEO)
356         {
357                 r = GetFromProcLonglong(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_TOTAL, total_size);
358                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
359                 r = GetFromProcLonglong(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_FREE, free_size);
360                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
361                 value = (total_size - free_size) * 1024;
362         }
363         else if (key == _AVAILABLE_INTERNAL_STORAGE)
364         {
365                 return GetAvailableInternalStorage(value);
366         }
367         else if (key == _AVAILABLE_EXTERNAL_STORAGE)
368         {
369                 return GetAvailableExternalStorage(value);
370         }
371         else if (key == _AVAILABLE_MEDIA_STORAGE)
372         {
373                 return GetAvailableMediaStorage(value);
374         }
375         else if(key == _STORAGE_AVAILABLE_INTERNAL)
376         {
377                 return GetAvailableInternalStorage(value);
378         }
379         else if(key == _STORAGE_AVAILABLE_EXTERNAL)
380         {
381                 return GetAvailableExternalStorage(value);
382         }
383         else if(key == _STORAGE_AVAILABLE_INTERNAL_MEDIA)
384         {
385                 return GetAvailableMediaStorage(value);
386         }
387         return r;
388 }
389
390 result
391 _RuntimeInfoImpl::GetValue(const String& key, double& value)
392 {
393         return E_OBJ_NOT_FOUND;
394 }
395
396 result
397 _RuntimeInfoImpl::GetValue(const String& key, bool& value)
398 {
399         if (key == _CHARGING)
400         {
401                 return IsChargingMode(value);
402         }
403         else
404         {
405                 return E_OBJ_NOT_FOUND;
406         }
407 }
408
409 result
410 _RuntimeInfoImpl::GetValue(const String& key, UuId& value)
411 {
412         return E_OBJ_NOT_FOUND;
413 }
414
415 result
416 _RuntimeInfoImpl::GetBatteryLevel(int& value)
417 {
418         int batteryValue = -1;
419         batteryValue = device_get_battery_pct();
420         SysTryReturnResult(NID_SYS, !(batteryValue < 0 || value > 100), E_SYSTEM, "[E_SYSTEM] device_get_battery_pct return %d", batteryValue);
421         value = batteryValue;
422
423         return E_SUCCESS;
424 }
425
426 result
427 _RuntimeInfoImpl::IsChargingMode(bool& value)
428 {
429         bool chargeState = false;
430         int ret = 0;
431         ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_BATTERY_IS_CHARGING, &chargeState);
432         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "[E_SYSTEM] runtime_info_get_value_bool returns %d.", ret);
433         value = chargeState;
434         return E_SUCCESS;
435
436 }
437
438 result
439 _RuntimeInfoImpl::GetAvailableInternalStorage(long long& value)
440 {
441         long long temp = 0;
442         long long total = 0;
443         result r = E_SUCCESS;
444
445         r = GetCapacity(_ROOT_PATH, total, temp);
446         SysTryReturn(NID_SYS, !IsFailed(r), E_SYSTEM, r, "[E_SYSTEM] system error has occurred. ");
447
448         value += temp;
449
450         r = GetCapacity(_INTERNAL_PATH, total, temp);
451         SysTryReturn(NID_SYS, !IsFailed(r), E_SYSTEM, r, "[E_SYSTEM] system error has occurred. ");
452
453         value += temp;
454
455         return E_SUCCESS;
456 }
457 result
458 _RuntimeInfoImpl::GetAvailableExternalStorage(long long& value)
459 {
460         int sdCardStatus = 0;
461         int ret = -1;
462         long long total = 0;
463
464         ret = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdCardStatus);
465         SysTryReturn(NID_SYS, !(ret < 0), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] vconf_get_int VCONFKEY_SYSMAN_MMC_STATUS failed");
466
467         if(sdCardStatus == 0)
468         {
469                 value = 0;
470                 return E_SUCCESS;
471         }
472
473         return GetCapacity(_STORAGE_PATH, total, value);
474 }
475
476 result
477 _RuntimeInfoImpl::GetAvailableMediaStorage(long long& value)
478 {
479         long long total = 0;
480         return GetCapacity(_MEDIA_PATH, total, value);
481 }
482
483 result
484 _RuntimeInfoImpl::GetCapacity(const char* path, long long& totalSize, long long& availableSize)
485 {
486         struct statfs fs;
487         if (statfs(path, &fs) < 0)
488         {
489                 SysLogException(NID_SYS, E_SYSTEM, "[E_SYSTEM] statfs() failed");
490                 return E_SYSTEM;
491         }
492
493         totalSize = static_cast< long long >(fs.f_bsize) * static_cast< long long >(fs.f_blocks);
494         availableSize = static_cast< long long >(fs.f_bsize) * static_cast< long long >(fs.f_bavail);
495
496         return E_SUCCESS;
497 }
498
499 result
500 _RuntimeInfoImpl::GetFromProcLonglong(const char* path, const char* key, long long& value)
501 {
502         FILE* pStream = null;
503         char line[_MAX_BUFFER_LENGTH] = {0, };
504         char fieldName[_MAX_BUFFER_LENGTH] = {0, };
505         long long keyValue = 0;
506         pStream = fopen(path, "r");
507         SysTryReturnResult(NID_SYS, pStream != null, E_SYSTEM, "%s open is failed.", path);
508
509         while (fgets(line, sizeof(line), pStream))
510         {
511                 if (sscanf(line, "%s %lld %*s", fieldName, &keyValue) == 2)
512                 {
513                         if (strncmp(fieldName, key, static_cast< int >(strlen(key))) == 0)
514                         {
515                                 value = keyValue;
516                                 fclose(pStream);
517                                 return E_SUCCESS;
518                         }
519                 }
520         }
521         fclose(pStream);
522
523         SysLogException(NID_SYS, E_OBJ_NOT_FOUND, "it can't find %s field", key);
524         return E_OBJ_NOT_FOUND;
525 }
526
527 result
528 _RuntimeInfoImpl::GetFromProc(const char* path, const char* key, int& value)
529 {
530         FILE* pStream = null;
531         char line[_MAX_BUFFER_LENGTH] = {0, };
532         char fieldName[_MAX_BUFFER_LENGTH] = {0, };
533         int keyValue = 0;
534         pStream = fopen(path, "r");
535         SysTryReturnResult(NID_SYS, pStream != null, E_SYSTEM, "%s open is failed.", path);
536
537         while (fgets(line, sizeof(line), pStream))
538         {
539                 if (sscanf(line, "%s %d %*s", fieldName, &keyValue) == 2)
540                 {
541                         if (strncmp(fieldName, key, static_cast< int >(strlen(key))) == 0)
542                         {
543                                 value = keyValue;
544                                 fclose(pStream);
545                                 return E_SUCCESS;
546                         }
547                 }
548         }
549         fclose(pStream);
550
551         SysLogException(NID_SYS, E_OBJ_NOT_FOUND, "it can't find %s field", key);
552         return E_OBJ_NOT_FOUND;
553 }
554
555 void*
556 _RuntimeInfoImpl::GetDirectorySizeAsync(void* data)
557 {       
558         if(data == null)
559         {               
560                 return null;
561         }
562         _RuntimeInfoEventArg* pEventArg = (_RuntimeInfoEventArg*)data;
563         long long size = _RuntimeInfoImpl::GetDirectorySize(pEventArg->DirectoryPath);
564
565         if(pEventArg == null)
566         {
567                 SysLogException(NID_SYS, E_OUT_OF_MEMORY, "It is failed to create instance of _RuntimeInfoEventArg");
568                 return null;
569         }
570         pEventArg->Type = _RUNTIME_INFO_EVENT_TYPE_LONGLONG;
571         pEventArg->longLongValue = size;
572         SysLog(NID_SYS, "Fire event %x %s %lld", pEventArg, pEventArg->DirectoryPath, size);
573         runtimeInfoEvent.Fire(*pEventArg);
574         
575         return null;
576 }
577
578 void*
579 _RuntimeInfoImpl::GetCpuUsageAsync(void* data)
580 {
581         result r = E_SUCCESS;
582
583         int value = 0;
584         procstat_t first, second, diffrence;
585         unsigned long long total, usage;
586
587         if(read_proc_stat(&first) != false)
588         {
589                 usleep(_CPU_USAGE_EVALUATION_INTERVAL);
590                 if(read_proc_stat(&second) != false)
591                 {
592                         diff_proc_stat(&second, &first, &diffrence);
593                         total = diffrence.user + diffrence.system 
594                                 + diffrence.nice + diffrence.idle 
595                                 + diffrence.wait + diffrence.hi 
596                                 + diffrence.si;
597                         usage = 10000 - (diffrence.idle * 10000 / total);
598                         value = usage/100;
599                         r = E_SUCCESS;
600                 }
601                 else
602                 {
603                         r = E_SYSTEM;
604                 }
605         }
606         else
607         {
608                 r = E_SYSTEM;
609         }
610
611         _RuntimeInfoEventArg* pEventArg = (_RuntimeInfoEventArg*) data;
612         if(pEventArg == null)
613         {
614                 SysLogException(NID_SYS, E_OUT_OF_MEMORY, "It is failed to create instance of _RuntimeInfoEventArg");
615                 return null;
616         }
617         pEventArg->errorCode = r;
618         pEventArg->Type = _RUNTIME_INFO_EVENT_TYPE_INT;
619         pEventArg->intValue = value;
620
621         runtimeInfoEvent.Fire(*pEventArg);
622
623         return null;
624 }
625
626 result
627 _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetIntAsyncResultListener* listener)
628 {
629         result r = E_SUCCESS;
630
631         SysTryReturnResult(NID_SYS, listener != null, E_INVALID_ARG, "listener is null");
632
633         if (key == _CPU_CORE_ALL_USAGE)
634         {
635                 if(listener != null)
636                 {
637                         SysLog(NID_SYS, "%x", listener);
638                         runtimeInfoEvent.AddListener(*listener, false);
639                 }
640
641                 int thr_id = 0;
642                 pthread_t p_thread;
643                 _RuntimeInfoEventArg* pEventArg = new (std::nothrow) _RuntimeInfoEventArg();
644                 pEventArg->pListener = listener;
645                 thr_id = pthread_create(&p_thread, null, GetCpuUsageAsync, pEventArg);
646                 pthread_detach(p_thread);
647         }
648         else
649         {
650                 SysLogException(NID_SYS, E_INVALID_ARG, "Required key[%ls] is not valid", key.GetPointer());
651                 r = E_INVALID_ARG;
652         }
653         return r;
654 }
655
656 result
657 _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetLonglongAsyncResultListener* listener)
658 {
659         int thr_id = 0;
660         pthread_t p_thread;
661         result r = E_SUCCESS;
662         char* directoryPath = null;
663
664         SysTryReturnResult(NID_SYS, listener != null, E_INVALID_ARG, "listener is null");
665
666         if(key == _STORAGE_ALLOCATED_INTERNAL_APPLICATION)
667         {
668                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_APPLICATIONS));
669         }       
670         else if (key == _STORAGE_ALLOCATED_INTERNAL_AUDIO)
671         {
672                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_SOUNDS));
673         }
674         else if (key == _STORAGE_ALLOCATED_INTERNAL_VIDEO)
675         {
676                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_VIDEOS));
677         }
678         else if (key == _STORAGE_ALLOCATED_INTERNAL_IMAGE)
679         {
680                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_IMAGES));
681         }
682         else if (key == _STORAGE_ALLOCATED_INTERNAL_DOWNLOAD)
683         {
684                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_DOWNLOADS));
685         }
686         else if (key == _STORAGE_ALLOCATED_EXTERNAL_APPLICATION)
687         {
688                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_EXTERNAL_APPLICATIONS));
689         }
690         else if (key == _STORAGE_ALLOCATED_EXTERNAL_AUDIO)
691         {
692                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_EXTERNAL_SOUNDS));
693         }
694         else if (key == _STORAGE_ALLOCATED_EXTERNAL_VIDEO)
695         {
696                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_EXTERNAL_VIDEOS));
697         }
698         else if (key == _STORAGE_ALLOCATED_EXTERNAL_IMAGE)
699         {
700                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_EXTERNAL_IMAGES));
701         }
702
703         else if (key == _STORAGE_ALLOCATED_EXTERNAL_DOWNLOAD)
704         {
705                 directoryPath = _StringConverter::CopyToCharArrayN(_EnvironmentImpl::GetPredefinedPath(PREDEFINED_DIRECTORY_EXTERNAL_DOWNLOADS));
706         }
707         else
708         {
709                 SysLogException(NID_SYS, E_INVALID_ARG, "Required key[%ls] is not valid", key.GetPointer());
710                 r = E_INVALID_ARG;
711         }
712
713         SysLog(NID_SYS, "%s", GetErrorMessage(r));
714         SysLog(NID_SYS, "%s", directoryPath);
715         if(r == E_SUCCESS)
716         {
717                 if(listener != null)
718                 {
719                         SysLog(NID_SYS, "test %x", listener);
720                         runtimeInfoEvent.AddListener(*listener);
721                 }
722
723                 _RuntimeInfoEventArg* pEventArg = new (std::nothrow) _RuntimeInfoEventArg();
724                 pEventArg->pListener = listener;
725                 pEventArg->DirectoryPath = directoryPath;
726
727                 thr_id = pthread_create(&p_thread, null, GetDirectorySizeAsync, pEventArg);
728                 SysLog(NID_SYS, "%d", thr_id);
729                 pthread_detach(p_thread);
730         }
731
732         return r;
733 }
734
735 _RuntimeInfoImpl*
736 _RuntimeInfoImpl::GetInstance(RuntimeInfo& runtimeinfo)
737 {
738         return runtimeinfo.__pRuntimeInfoImpl;
739 }
740
741 const _RuntimeInfoImpl*
742 _RuntimeInfoImpl::GetInstance(const RuntimeInfo& runtimeinfo)
743 {
744         return runtimeinfo.__pRuntimeInfoImpl;
745 }
746
747 } } //Tizen::System
748