Merge "Add a _LocalizedNumParser class and 4 static functions" into tizen_2.1
[platform/framework/native/appfw.git] / src / system / FSys_SystemInfoImpl.cpp
index 86eaf5d..6b7542a 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -20,6 +19,9 @@
  * @brief              This is the implementation file for _SystemInfoImpl class.
  */
 #include <unique_ptr.h>
+#include <unistd.h>
+
+#include <ITapiModem.h>
 
 #include <FBaseBoolean.h>
 #include <FBaseInteger.h>
@@ -150,9 +152,9 @@ static const wchar_t* _SUPPORTED = L"Supported";
 static const wchar_t* _UNSUPPORTED = L"Unsupported";
 
 static bool firstRequest = false;
-static HashMap integerList;
-static HashMap boolList;
-static HashMap stringList;
+static HashMap integerList(SingleObjectDeleter);
+static HashMap boolList(SingleObjectDeleter);
+static HashMap stringList(SingleObjectDeleter);
 
 void
 PrepareCache(void)
@@ -265,12 +267,12 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
                PrepareCache();
        }
 
-       String* pValue = (String*)stringList.GetValue(key);
+       String* pValue = (String*)stringList.GetValue(tizenKey);
 
        if(pValue != null)
        {
                value = *pValue;
-               r = E_SUCCESS;
+               return E_SUCCESS;
        }
 
        if (key == _NETWORK_TYPE) //Compatibility
@@ -433,6 +435,40 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
        {
                r = E_OBJ_NOT_FOUND;
        }
+       else if (tizenKey == _DUID)
+       {
+               int ret = 0;
+               TapiHandle* handle = null;
+               int time_count = 0;
+               int status = 0;
+
+               handle = tel_init(null);
+               if(handle != null)
+               {
+                       while(time_count < 30) //Wait 30 second.
+                       {
+                               ret = tel_check_modem_power_status(handle, &status);
+                               SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
+                               if(ret != TAPI_API_SUCCESS)
+                               {
+                                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
+                                       tel_deinit(handle);
+                                       return E_SYSTEM;
+                               }
+
+                               if(status == 0)
+                               {
+                                       break;
+                               }
+
+                               usleep(1000000);
+                               time_count++;
+                       }
+                       tel_deinit(handle);
+               }
+               _SystemClient* pSystemClient = _SystemClient::GetInstance();
+               r = pSystemClient->GetValue(tizenKey, value);
+       }
        else
        {
                r = GetFromRegistry(tizenKey, value);
@@ -440,12 +476,12 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
                if(r != E_SUCCESS)
                {
                        _SystemClient* pSystemClient = _SystemClient::GetInstance();
-                       r = pSystemClient->GetValue(key, value);
+                       r = pSystemClient->GetValue(tizenKey, value);
                }
        }
        if( r == E_SUCCESS)
        {
-               stringList.Add(new String(key), new String(value));
+               stringList.Add(new String(tizenKey), new String(value));
        }
        return r;
 }
@@ -461,7 +497,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, int& value)
                PrepareCache();
        }
 
-       Integer* pValue = (Integer*)integerList.GetValue(key);
+       Integer* pValue = (Integer*)integerList.GetValue(tizenKey);
 
        if(pValue != null)
        {
@@ -490,13 +526,13 @@ _SystemInfoImpl::GetSysInfo(const String& key, int& value)
                if(r != E_SUCCESS)
                {
                        _SystemClient* pSystemClient = _SystemClient::GetInstance();
-                       r = pSystemClient->GetValue(key, value);
+                       r = pSystemClient->GetValue(tizenKey, value);
                }
        }
 
        if(r == E_SUCCESS)
        {
-               integerList.Add(new String(key), new Integer(value));
+               integerList.Add(new String(tizenKey), new Integer(value));
        }
 
        return r;
@@ -525,7 +561,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
                PrepareCache();
        }
 
-       Boolean* pValue = (Boolean*)boolList.GetValue(key);
+       Boolean* pValue = (Boolean*)boolList.GetValue(tizenKey);
 
        if(pValue != null)
        {
@@ -537,13 +573,13 @@ _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
        if(r != E_SUCCESS)
        {
                _SystemClient* pSystemClient = _SystemClient::GetInstance();
-               r = pSystemClient->GetValue(key, value);
+               r = pSystemClient->GetValue(tizenKey, value);
        }
        SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
 
        if(r == E_SUCCESS)
        {
-               boolList.Add(new String(key), new Boolean(value));
+               boolList.Add(new String(tizenKey), new Boolean(value));
        }
 
        return r;
@@ -611,6 +647,34 @@ _SystemInfoImpl::GetImei(String& imei)
 {
        result r = E_SUCCESS;
 
+       int ret = 0;
+       TapiHandle* handle = null;
+       int time_count = 0;
+       int status = 0;
+
+       handle = tel_init(null);
+       SysTryReturnResult(NID_SYS, handle != null, E_SYSTEM, "It is failed to get handle of telephony.");
+       while(time_count < 30) //Wait 30 second.
+       {
+               ret = tel_check_modem_power_status(handle, &status);
+               SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
+               if(ret != TAPI_API_SUCCESS)
+               {
+                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
+                       tel_deinit(handle);
+                       return E_SYSTEM;
+               }
+
+               if(status == 0)
+               {
+                       break;
+               }
+
+               usleep(1000000);
+               time_count++;
+       }
+       tel_deinit(handle);
+
        ArrayList requestMessage;
        ArrayList responseMessage;