sync with master
[platform/framework/native/appfw.git] / src / system / FSys_RuntimeInfoImpl.cpp
index 68f2441..0d4bf1d 100644 (file)
@@ -56,6 +56,7 @@ namespace Tizen { namespace System
 
 static const wchar_t* _ALLOCATED_MEMORY = L"AllocatedMemory";
 static const wchar_t* _MEMORY_ALLOCATED = L"http://tizen.org/runtime/memory.allocated";
+static const wchar_t* _MEMORY_ALLOCATED_SELF = L"http://tizen.org/runtime/memory.allocated.self";
 
 static const wchar_t* _AVAILABLE_EXTERNAL_STORAGE = L"AvailableExternalStorage";
 static const wchar_t* _STORAGE_AVAILABLE_EXTERNAL = L"http://tizen.org/runtime/storage.available.external";
@@ -226,7 +227,6 @@ protected:
                        {                               
                                pIntListener->OnResultReceivedForGetValueAsync(runtimeArg->intValue, runtimeArg->errorCode);
                                RemoveListener(listener);
-                               delete pIntListener;
                        }
                }
                break;
@@ -237,7 +237,6 @@ protected:
                        {
                                pLonglongListener->OnResultReceivedForGetValueAsync(runtimeArg->longLongValue, runtimeArg->errorCode);
                                RemoveListener(listener);
-                               delete pLonglongListener;
                        }
                }
                break;
@@ -278,66 +277,15 @@ _RuntimeInfoImpl::GetValue(const String& key, int& value)
                SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
                value = free_size * 1024;
        }
-       else if (key == _AVAILABLE_MEMORY || key == _AVAILABLE_VIDEO_MEMORY || key == _MAX_ALLOCATABLE_MEMORY || key == _MEMORY_AVAILABLE || key == _MEMORY_AVAILABLE_VIDEO)
+       else if (key == _AVAILABLE_MEMORY || key == _AVAILABLE_VIDEO_MEMORY || key == _MAX_ALLOCATABLE_MEMORY)
        {
                r = GetFromProc(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_FREE, free_size);
                SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
                value = free_size * 1024;
        }
-       else if (key == _MEMORY_ALLOCATED || key == _MEMORY_ALLOCATED_VIDEO)
-       {
-               r = GetFromProc(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_TOTAL, total_size);
-               SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
-               r = GetFromProc(_PROC_SYSTEM_MEMORY_INFO, _PROC_KEY_SYSTEM_MEMORY_FREE, free_size);
-               SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
-               value = (total_size - free_size) * 1024;
-       }
        return r;
 }
 
-long long
-_RuntimeInfoImpl::GetDirectorySize(const char* path)
-{
-       if(path == null)
-       {
-               return 0;
-       }
-
-       char command[512] = {0,};
-       long long size = 0;
-       int ret = 0;
-
-       sprintf(command, "du -sk -P %s >> /tmp/size_of_directory.tmp", path);
-
-       system("rm -rf /tmp/size_of_directory.tmp");
-       system(command);
-
-       FILE* pFile = null;
-       pFile = fopen("/tmp/size_of_directory.tmp", "r");
-       if(pFile == null)
-       {
-               return 0;
-       }
-       ret = fscanf(pFile, "%lld", &size);
-
-       if(ret < 1)
-       {
-               if(pFile != null)
-               {
-                       fclose(pFile);
-               }
-
-               return false;
-       }
-
-       if(pFile != null)
-       {
-               fclose(pFile);
-       }
-       system("rm -rf /tmp/size_of_directory.tmp");
-       return size;
-}
-
 result
 _RuntimeInfoImpl::GetValue(const String& key, long long& value)
 {
@@ -360,6 +308,12 @@ _RuntimeInfoImpl::GetValue(const String& key, long long& value)
                SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
                value = (total_size - free_size) * 1024;
        }
+       else if (key == _MEMORY_ALLOCATED_SELF)
+        {   
+                r = GetFromProcLonglong(_PROC_PROCESS_MEMORY_INFO, _PROC_KEY_PROCESS_MEMORY, free_size);
+                SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get memory size.");
+                value = free_size * 1024;
+        } 
        else if (key == _AVAILABLE_INTERNAL_STORAGE)
        {
                return GetAvailableInternalStorage(value);
@@ -384,9 +338,56 @@ _RuntimeInfoImpl::GetValue(const String& key, long long& value)
        {
                return GetAvailableMediaStorage(value);
        }
+       else
+       {
+               SysLogException(NID_SYS, r, "Key[%ls] is not valid.", key.GetPointer());
+       }
        return r;
 }
 
+long long
+_RuntimeInfoImpl::GetDirectorySize(const char* path)
+{
+       if(path == null)
+       {
+               return 0;
+       }
+
+       char command[512] = {0,};
+       long long size = 0;
+       int ret = 0;
+
+       sprintf(command, "du -sk -P %s >> /tmp/size_of_directory.tmp", path);
+
+       system("rm -rf /tmp/size_of_directory.tmp");
+       system(command);
+
+       FILE* pFile = null;
+       pFile = fopen("/tmp/size_of_directory.tmp", "r");
+       if(pFile == null)
+       {
+               return 0;
+       }
+       ret = fscanf(pFile, "%lld", &size);
+
+       if(ret < 1)
+       {
+               if(pFile != null)
+               {
+                       fclose(pFile);
+               }
+
+               return 0;
+       }
+
+       if(pFile != null)
+       {
+               fclose(pFile);
+       }
+       system("rm -rf /tmp/size_of_directory.tmp");
+       return size;
+}
+
 result
 _RuntimeInfoImpl::GetValue(const String& key, double& value)
 {