From 2b8cc5b4ffa6ff500bccb36de238f4eeed7917dc Mon Sep 17 00:00:00 2001 From: Byounghui Date: Fri, 3 May 2013 20:59:10 +0900 Subject: [PATCH] Fixed "GetCount" and Delete singleton instance. Change-Id: I1c9cf501629e322a5448025f4842f998fa782a5e Signed-off-by: Byounghui --- src/FMsg_SmsManagerImpl.cpp | 30 ++++++++++++++---------------- src/FMsg_SmsMmsCallbackHandler.cpp | 28 +++++++++++----------------- src/FMsg_SmsMmsCallbackHandler.h | 3 ++- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/FMsg_SmsManagerImpl.cpp b/src/FMsg_SmsManagerImpl.cpp index 0c7d9f0..3859f4d 100644 --- a/src/FMsg_SmsManagerImpl.cpp +++ b/src/FMsg_SmsManagerImpl.cpp @@ -381,34 +381,32 @@ _SmsManagerImpl::GetTotalMessageCount(SmsMessageBoxType type) const break; case SMS_MESSAGE_BOX_TYPE_ALL: { - int spamCount = 0; - int draftCount = 0; - err = msg_count_msg_by_type(__msgHandle, MSG_TYPE_SMS, &msgCount); + int inbox = 0; + int outbox = 0; + int sentbox =0; - if (err != MSG_SUCCESS) - { - r = ConvertException(err); - SysLogException(NID_MSG, r, "[%s] Failed to get the message count", GetErrorMessage(r)); - SetLastResult(r); - return -1; - } countInfo = msg_create_struct(MSG_STRUCT_COUNT_INFO); - err = msg_count_message(__msgHandle, MSG_SPAMBOX_ID , countInfo); + err = msg_count_message(__msgHandle, MSG_INBOX_ID , countInfo); r = ConvertException(err); SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); - msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &spamCount); + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &inbox); - err = msg_count_message(__msgHandle, MSG_DRAFT_ID , countInfo); + err = msg_count_message(__msgHandle, MSG_OUTBOX_ID , countInfo); + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &outbox); + + err = msg_count_message(__msgHandle, MSG_SENTBOX_ID , countInfo); r = ConvertException(err); SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); - msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &draftCount); + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &sentbox); msg_release_struct(&countInfo); - msgCount = msgCount - spamCount - draftCount; - SysLog(NID_MSG, "Total count of messages is [%d] , spam[%d], draft[%d]",msgCount, spamCount, draftCount); + msgCount = inbox + outbox + sentbox; + SysLog(NID_MSG, "Total count of messages is [%d] , inbox[%d], outbox[%d], sentbox[%d]",msgCount, inbox, outbox, sentbox); return msgCount; } diff --git a/src/FMsg_SmsMmsCallbackHandler.cpp b/src/FMsg_SmsMmsCallbackHandler.cpp index 7df373a..753b705 100644 --- a/src/FMsg_SmsMmsCallbackHandler.cpp +++ b/src/FMsg_SmsMmsCallbackHandler.cpp @@ -47,6 +47,7 @@ namespace Tizen { namespace Messaging { _SmsMmsCallbackHandler* _SmsMmsCallbackHandler::__pMessageCallbackHandler = 0; +bool _SmsMmsCallbackHandler::__destroyed = false; _SmsMmsCallbackHandler::_SmsMmsCallbackHandler(void) : __msgHandle(0) @@ -76,12 +77,14 @@ _SmsMmsCallbackHandler::Construct() SysTryReturnResult(NID_MSG, __pTempCbsChannelList != null, E_OUT_OF_MEMORY, "memory allocation failed"); r = __pTempCbsChannelList->Construct(); SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "Failed to construct an ArrayList"); + std::atexit(CloseCbsSettingsHandle); return r; } _SmsMmsCallbackHandler::~_SmsMmsCallbackHandler(void) { + if (__msgHandle) { msg_close_msg_handle(&__msgHandle); @@ -113,8 +116,10 @@ _SmsMmsCallbackHandler::~_SmsMmsCallbackHandler(void) _SmsMmsCallbackHandler* _SmsMmsCallbackHandler::GetInstance(void) { + SysTryReturn(NID_MSG, __destroyed == false, null, E_SYSTEM, "Instance Dead"); + result r = E_SUCCESS; - + if (!__pMessageCallbackHandler) { __pMessageCallbackHandler = new (std::nothrow) _SmsMmsCallbackHandler(); @@ -505,28 +510,17 @@ _SmsMmsCallbackHandler::CloseMessageHandle() return err; } -int +void _SmsMmsCallbackHandler::CloseCbsSettingsHandle() { - int err = MSG_SUCCESS; - - if (__cbsSettingsHandle) - { - err = msg_release_struct(&__cbsSettingsHandle); - __cbsSettingsHandle = 0; - } - if (__pTempCbsChannelList) + if (__pMessageCallbackHandler) { - if (__pTempCbsChannelList->GetCount() > 0) - { - __pTempCbsChannelList->RemoveAll(true); - } - delete __pTempCbsChannelList; - __pTempCbsChannelList = null; + delete __pMessageCallbackHandler; + __pMessageCallbackHandler = null; } + __destroyed = true; - return err; } void diff --git a/src/FMsg_SmsMmsCallbackHandler.h b/src/FMsg_SmsMmsCallbackHandler.h index 21b2fa7..f9a6c44 100644 --- a/src/FMsg_SmsMmsCallbackHandler.h +++ b/src/FMsg_SmsMmsCallbackHandler.h @@ -147,7 +147,7 @@ public: * @exception MSG_ERR_NULL_POINTER Input parameter is NULL. * @exception MSG_ERR_MEMORY_ERROR Memory error. */ - int CloseCbsSettingsHandle(void); + static void CloseCbsSettingsHandle(void); /** * closes the Message Handle for SMS/MMS operation. @@ -254,6 +254,7 @@ private: Tizen::Base::Runtime::Mutex __msgMutex; Tizen::Base::Object* __pCbsUserEvent; Tizen::Base::Object* __pEtwsUserEvent; + static bool __destroyed; }; // _SmsMmsCallbackHandler } } // Tizen::Messaging -- 2.7.4