[Performance] Reduce the delay on SimInfo.Construct().
authorJaemin Ahn <j.m.ahn@samsung.com>
Fri, 5 Apr 2013 00:13:33 +0000 (09:13 +0900)
committerJaemin Ahn <j.m.ahn@samsung.com>
Fri, 5 Apr 2013 00:13:33 +0000 (09:13 +0900)
Change-Id: I79c090052278713af01412b409e21ca8140281e3
Signed-off-by: Jaemin Ahn <j.m.ahn@samsung.com>
src/FTel_SimInfoImpl.cpp
src/FTel_SimInfoImpl.h

index b215c6f..805d409 100644 (file)
@@ -43,37 +43,12 @@ namespace Tizen { namespace Telephony
 
 
 _SimInfoImpl::_SimInfoImpl(void)
-       : __mcc(-1)
-       , __mnc(-1)
-       , __simType(SIM_TYPE_UNKNOWN)
-       , __isAvailable(false)
-       , __isIccIdValid(false)
-       , __isMccValid(false)
-       , __isMncValid(false)
-       , __isOperatorNameValid(false)
-       , __isPhoneNumberValid(false)
-       , __isSpnValid(false)
-       , __isSimTypeValid(false)
+       : __isAvailable(false)
 {
 }
 
 _SimInfoImpl::_SimInfoImpl(const _SimInfoImpl& rhs)
-       : __mcc(rhs.__mcc)
-       , __mnc(rhs.__mnc)
-       , __iccId(rhs.__iccId)
-       , __imsi(rhs.__imsi)
-       , __operatorName(rhs.__operatorName)
-       , __phoneNumber(rhs.__phoneNumber)
-       , __spn(rhs.__spn)
-       , __simType(rhs.__simType)
-       , __isAvailable(rhs.__isAvailable)
-       , __isIccIdValid(rhs.__isIccIdValid)
-       , __isMccValid(rhs.__isMccValid)
-       , __isMncValid(rhs.__isMncValid)
-       , __isOperatorNameValid(rhs.__isOperatorNameValid)
-       , __isPhoneNumberValid(rhs.__isPhoneNumberValid)
-       , __isSpnValid(rhs.__isSpnValid)
-       , __isSimTypeValid(rhs.__isSimTypeValid)
+       : __isAvailable(rhs.__isAvailable)
 {
 }
 
@@ -84,233 +59,174 @@ _SimInfoImpl::~_SimInfoImpl(void)
 result
 _SimInfoImpl::Construct(void)
 {
-       TapiHandle* pHandle = null;
        int err = SIM_ERROR_NONE;
        sim_state_e simState = SIM_STATE_UNAVAILABLE;
 
-       int mnc = -1;
-       int mcc = -1;
-
-       String spn;
-       String iccId;
-       String operatorName;
-       String phoneNumber;
-
-       char* pTemp = null;
-       char* pTempFullName = null;
-       char* pTempShortName = null;
-
-       // Checking availability
        err = sim_get_state(&simState);
-       SysLog(NID_TEL, "The return value of sim_get_state() is 0x%x and the simState is %d", err, simState);
+       SysLog(NID_TEL, "The return value of sim_get_state() is [0x%x] and the simState is [%d]", err, simState);
 
        if (err == SIM_ERROR_NONE && simState == SIM_STATE_AVAILABLE)
        {
                __isAvailable = true;
        }
-       SysTryReturnResult(NID_TEL, __isAvailable, E_DEVICE_UNAVAILABLE, "The operation failed due to a missing SIM card.");
 
-       // Getting mnc
-       err = sim_get_mnc(&pTemp);
-       SysLog(NID_TEL, "The return value of sim_get_mnc() is 0x%x and the mnc value is %s", err, pTemp);
+       SysTryReturnResult(NID_TEL, __isAvailable, E_DEVICE_UNAVAILABLE, "The operation failed because the SIM card is not ready.");
 
-       if (err != SIM_ERROR_NONE)
-       {
-               SysLog(NID_TEL, "Failed to get the Mobile Network Code (MNC).");
-               __isMncValid = false;
-       }
-       else
-       {
-               unique_ptr<char, _CharDeleter> pMnc(pTemp);
+       return E_SUCCESS;
+}
 
-               if(pMnc.get() != null)
-               {
-                       mnc = atoi(pMnc.get());
-               }
-               __isMncValid = true;
-       }
-       __mnc = mnc;
+int
+_SimInfoImpl::GetMnc(void) const
+{
+       int err = SIM_ERROR_NONE;
+       char* pMnc = null;
+       int mnc = -1;
 
-       // Getting mcc
-       err = sim_get_mcc(&pTemp);
-       SysLog(NID_TEL, "The return value of sim_get_mcc() is 0x%x,and the mcc value is %s", err, pTemp);
+       SysTryReturn(NID_TEL, __isAvailable, mnc, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-       if (err != SIM_ERROR_NONE)
-       {
-               SysLog(NID_TEL, "Failed to get the Mobile Country Code (MCC).");
-               __isMccValid = false;
-       }
-       else
-       {
-               unique_ptr<char, _CharDeleter> pMcc(pTemp);
+       err = sim_get_mnc(&pMnc);
+       SysLog(NID_TEL, "The return value of sim_get_mnc() is [0x%x] and the mnc value is [%s]", err, pMnc);
+       SysTryReturn(NID_TEL, err == SIM_ERROR_NONE && pMnc != null, mnc, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-               if(pMcc.get() != null)
-               {
-                       mcc = atoi(pMcc.get());
-               }
-               __isMccValid = true;
-       }
-       __mcc = mcc;
+       mnc = atoi(pMnc);
+       free(pMnc);
 
-       // Getting spn
-       err = sim_get_spn(&pTemp);
-       SysLog(NID_TEL, "The return value of sim_get_spn() is 0x%x and the spn value is %s", err, pTemp);
+       return mnc;
+}
 
-       if (err != SIM_ERROR_NONE)
-       {
-               SysLog(NID_TEL, "Failed to get the Service Provider Name (SPN).");
-               __isSpnValid = false;
-       }
-       else
-       {
-               unique_ptr<char, _CharDeleter> pSpn(pTemp);
+int
+_SimInfoImpl::GetMcc(void) const
+{
+       int err = SIM_ERROR_NONE;
+       char* pMcc = null;
+       int mcc = -1;
 
-               if(pSpn.get() != null)
-               {
-                       spn = String(pSpn.get());
-               }
-               __isSpnValid = true;
-       }
+       SysTryReturn(NID_TEL, __isAvailable, mcc, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-       __spn = spn;
+       err = sim_get_mcc(&pMcc);
+       SysLog(NID_TEL, "The return value of sim_get_mcc() is [0x%x] and the mcc value is [%s]", err, pMcc);
+       SysTryReturn(NID_TEL, err == SIM_ERROR_NONE && pMcc != null, mcc, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-       // Getting icc id
-       err = sim_get_icc_id(&pTemp);
-       SysLog(NID_TEL, "The return value of sim_get_icc_id() is 0x%x and the iccid value is %s", err, pTemp);
+       mcc = atoi(pMcc);
+       free(pMcc);
 
-       if (err != SIM_ERROR_NONE)
-       {
-               SysLog(NID_TEL, "Failed to get the Integrated Circuit Card(ICC) ID.");
-               __isIccIdValid = false;
-       }
-       else
-       {
-               unique_ptr<char, _CharDeleter> pIccId(pTemp);
+       return mcc;
+}
 
-               if (pIccId.get() != null)
-               {
-                       iccId = String(pIccId.get());
-               }
-               __isIccIdValid = true;
-       }
-       __iccId = iccId;
+String
+_SimInfoImpl::GetSpn(void) const
+{
+       int err = SIM_ERROR_NONE;
+       char* pSpn = null;
+       String spn;
 
-       // Getting operator name
-       err = sim_get_cphs_operator_name(&pTempFullName, &pTempShortName);
+       SysTryReturn(NID_TEL, __isAvailable, spn, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-       SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is 0x%x. full[%s] short[%s]", err, pTempFullName, pTempShortName);
-       if (err != SIM_ERROR_NONE)
-       {
-               SysLog(NID_TEL, "Failed to get the operator name.");
-               __isOperatorNameValid = false;
-       }
-       else
-       {
-               unique_ptr<char, _CharDeleter> pFullName(pTempFullName);
-               unique_ptr<char, _CharDeleter> pShortName(pTempShortName);
+       err = sim_get_spn(&pSpn);
+       SysLog(NID_TEL, "The return value of sim_get_spn() is [0x%x] and the spn value is [%s]", err, pSpn);
+       SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, spn, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-               operatorName = String((const char*) pFullName.get());
-               SysLog(NID_TEL, "The Operator Name is [%ls]", operatorName.GetPointer());
-               __isOperatorNameValid = true;
-       }
-       __operatorName = operatorName;
+       spn = String(pSpn);
 
-       // Getting phone number
-       err = sim_get_subscriber_number(&pTemp);
-       SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is 0x%x and the phone number is [%s]", err, pTemp);
-       if (err != SIM_ERROR_NONE)
+       if (pSpn != null)
        {
-               SysLog(NID_TEL, "Failed to get the phone number.");
-               __isPhoneNumberValid = false;
+               free(pSpn);
        }
-       else
+
+       return spn;
+}
+
+String
+_SimInfoImpl::GetIccId(void) const
+{
+       int err = SIM_ERROR_NONE;
+       char* pIccId = null;
+       String iccId;
+
+       SysTryReturn(NID_TEL, __isAvailable, iccId, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+
+       err = sim_get_icc_id(&pIccId);
+       SysLog(NID_TEL, "The return value of sim_get_icc_id() is [0x%x] and the iccid value is [%s]", err, pIccId);
+       SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, iccId, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+
+       iccId = String(pIccId);
+
+       if (pIccId != null)
        {
-               unique_ptr<char, _CharDeleter> pPhoneNumber(pTemp);
-               if (pPhoneNumber.get() != null)
-               {
-                       phoneNumber = String((const char*) pPhoneNumber.get());
-               }
-               __isPhoneNumberValid = true;
+               free(pIccId);
        }
-       __phoneNumber = phoneNumber;
 
-       // Getting SIM type
-       pHandle = tel_init(null);
-       SysTryReturnResult(NID_TEL, pHandle != null, E_SYSTEM,
-                       "[%s] A system error has occurred. Failed to initialize TApi library.", GetErrorMessage(E_SYSTEM));
+       return iccId;
+}
+
+String
+_SimInfoImpl::GetOperatorName(void) const
+{
+       int err = SIM_ERROR_NONE;
+       char* pFullName = null;
+       char* pShortName = null;
+       String operatorName;
 
-       TelSimCardType_t simType = TAPI_SIM_CARD_TYPE_UNKNOWN;
-       err = tel_get_sim_type(pHandle, &simType);
-       SysLog(NID_TEL, "The return value of tel_get_sim_type() is 0x%x and the SIM type is %d", err, simType);
-       if (err != SIM_ERROR_NONE)
+       SysTryReturn(NID_TEL, __isAvailable, operatorName, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+
+       err = sim_get_cphs_operator_name(&pFullName, &pShortName);
+       SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is [0x%x]. full[%s] short[%s]", err, pFullName, pShortName);
+       SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, operatorName, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+
+       if ((pFullName != null) && (strlen(pFullName) > 0))
        {
-               SysLog(NID_TEL, "Failed to get the SIM type.");
-               __isSimTypeValid = false;
+               operatorName = String(pFullName);
        }
-       else
+       else if ((pShortName != null) && (strlen(pShortName) > 0))
        {
-               __isSimTypeValid = true;
+               operatorName = String(pShortName);
        }
 
-       switch(simType)
+       if (pFullName != null)
        {
-       case TAPI_SIM_CARD_TYPE_GSM:
-               __simType = SIM_TYPE_GSM;
-               break;
-       case TAPI_SIM_CARD_TYPE_USIM:
-               __simType = SIM_TYPE_USIM;
-               break;
-       case TAPI_SIM_CARD_TYPE_RUIM:
-               __simType = SIM_TYPE_RUIM;
-               break;
-       case TAPI_SIM_CARD_TYPE_IMS:
-               __simType = SIM_TYPE_ISIM;
-               break;
-       case TAPI_SIM_CARD_TYPE_UNKNOWN:        // Fall through
-       default:
-               __simType = SIM_TYPE_UNKNOWN;
-               break;
+               free(pFullName);
+       }
+       if (pShortName != null)
+       {
+               free(pShortName);
        }
 
-       tel_deinit(pHandle);
-
-       return E_SUCCESS;
+       return operatorName;
 }
 
-int
-_SimInfoImpl::GetMnc(void) const
+String
+_SimInfoImpl::GetPhoneNumber(void) const
 {
-       return __mnc;
-}
+       int err = SIM_ERROR_NONE;
+       char* pPhoneNumber = null;
+       String phoneNumber;
 
-int
-_SimInfoImpl::GetMcc(void) const
-{
-       return __mcc;
-}
+       SysTryReturn(NID_TEL, __isAvailable, phoneNumber, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-String
-_SimInfoImpl::GetSpn(void) const
-{
-       return __spn;
-}
+       err = sim_get_subscriber_number(&pPhoneNumber);
+       SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is [0x%x] and the phone number is [%s]", err, pPhoneNumber);
+       SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, phoneNumber, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
 
-String
-_SimInfoImpl::GetIccId(void) const
-{
-       return __iccId;
-}
+       phoneNumber = String(pPhoneNumber);
 
-String
-_SimInfoImpl::GetOperatorName(void) const
-{
-       return __operatorName;
-}
+       if (pPhoneNumber != null)
+       {
+               free(pPhoneNumber);
+       }
 
-String
-_SimInfoImpl::GetPhoneNumber(void) const
-{
-       return __phoneNumber;
+       return phoneNumber;
 }
 
 String
@@ -334,7 +250,44 @@ _SimInfoImpl::GetImsi(void) const
 SimType
 _SimInfoImpl::GetSimType(void) const
 {
-       return __simType;
+       TapiHandle* pHandle = null;
+       int err = SIM_ERROR_NONE;
+       TelSimCardType_t simCardType = TAPI_SIM_CARD_TYPE_UNKNOWN;
+       SimType simType = SIM_TYPE_UNKNOWN;
+
+       SysTryReturn(NID_TEL, __isAvailable, SIM_TYPE_UNKNOWN, E_DEVICE_UNAVAILABLE,
+               "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+
+       pHandle = tel_init(null);
+       SysTryReturn(NID_TEL, pHandle != null, SIM_TYPE_UNKNOWN, E_SYSTEM,
+               "[%s] A system error has occurred. Failed to initialize TAPI library.", GetErrorMessage(E_SYSTEM));
+
+       err = tel_get_sim_type(pHandle, &simCardType);
+       SysLog(NID_TEL, "The return value of tel_get_sim_type() is [0x%x] and the SIM type is [%d]", err, simCardType);
+
+       switch(simCardType)
+       {
+       case TAPI_SIM_CARD_TYPE_GSM:
+               simType = SIM_TYPE_GSM;
+               break;
+       case TAPI_SIM_CARD_TYPE_USIM:
+               simType = SIM_TYPE_USIM;
+               break;
+       case TAPI_SIM_CARD_TYPE_RUIM:
+               simType = SIM_TYPE_RUIM;
+               break;
+       case TAPI_SIM_CARD_TYPE_IMS:
+               simType = SIM_TYPE_ISIM;
+               break;
+       case TAPI_SIM_CARD_TYPE_UNKNOWN:        // Fall through
+       default:
+               simType = SIM_TYPE_UNKNOWN;
+               break;
+       }
+
+       tel_deinit(pHandle);
+
+       return simType;
 }
 
 bool
@@ -348,22 +301,7 @@ _SimInfoImpl::operator =(const _SimInfoImpl& rhs)
 {
        if (this != &rhs)
        {
-               __mcc = rhs.__mcc;
-               __mnc = rhs.__mnc;
-               __iccId = rhs.__iccId;
-               __imsi = rhs.__imsi;
-               __operatorName = rhs.__operatorName;
-               __phoneNumber = rhs.__phoneNumber;
-               __spn = rhs.__spn;
-               __simType = rhs.__simType;
                __isAvailable = rhs.__isAvailable;
-               __isIccIdValid = rhs.__isIccIdValid;
-               __isMccValid = rhs.__isMccValid;
-               __isMncValid = rhs.__isMncValid;
-               __isOperatorNameValid = rhs.__isOperatorNameValid;
-               __isPhoneNumberValid = rhs.__isPhoneNumberValid;
-               __isSpnValid = rhs.__isSpnValid;
-               __isSimTypeValid = rhs.__isSimTypeValid;
        }
 
        return *this;
@@ -379,22 +317,7 @@ _SimInfoImpl::Equals(const Tizen::Base::Object& rhs) const
                return false;
        }
 
-       if (__mcc != pRhs->__mcc ||
-               __mnc != pRhs->__mnc ||
-               __iccId != pRhs->__iccId ||
-               __imsi != pRhs->__imsi ||
-               __operatorName != pRhs->__operatorName ||
-               __phoneNumber != pRhs->__phoneNumber ||
-               __spn != pRhs->__spn ||
-               __simType != pRhs->__simType ||
-               __isAvailable != pRhs->__isAvailable ||
-               __isIccIdValid != pRhs->__isIccIdValid ||
-               __isMccValid != pRhs->__isMccValid ||
-               __isMncValid != pRhs->__isMncValid ||
-               __isOperatorNameValid != pRhs->__isOperatorNameValid ||
-               __isPhoneNumberValid != pRhs->__isPhoneNumberValid ||
-               __isSpnValid != pRhs->__isSpnValid ||
-               __isSimTypeValid != pRhs->__isSimTypeValid)
+       if (__isAvailable != pRhs->__isAvailable)
        {
                return false;
        }
@@ -407,22 +330,7 @@ _SimInfoImpl::GetHashCode(void) const
 {
        int hashCode = _HASH_CODE_INITIAL_VALUE;
 
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __mcc;
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __mnc;
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __iccId.GetHashCode();
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __imsi.GetHashCode();
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __operatorName.GetHashCode();
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __phoneNumber.GetHashCode();
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __spn.GetHashCode();
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __simType;
        hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isAvailable ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isIccIdValid ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isMccValid ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isMncValid ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isOperatorNameValid ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isPhoneNumberValid ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isSpnValid ? 0 : 1);
-       hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isSimTypeValid ? 0 : 1);
 
        return hashCode;
 }
index 5c7f82b..b436aef 100644 (file)
@@ -149,22 +149,7 @@ public:
        virtual int GetHashCode(void) const;
 
 private:
-       int __mcc;
-       int __mnc;
-       Tizen::Base::String __iccId;
-       Tizen::Base::String __imsi;
-       Tizen::Base::String __operatorName;
-       Tizen::Base::String __phoneNumber;
-       Tizen::Base::String __spn;
-       SimType __simType;
        bool __isAvailable;
-       bool __isIccIdValid;
-       bool __isMccValid;
-       bool __isMncValid;
-       bool __isOperatorNameValid;
-       bool __isPhoneNumberValid;
-       bool __isSpnValid;
-       bool __isSimTypeValid;
 
        friend class _SimStateManagerImpl;