the way of multi conditional launch changed.
authorByounghui <byounghui.lim@samsung.com>
Thu, 31 Oct 2013 04:59:52 +0000 (13:59 +0900)
committerByounghui <byounghui.lim@samsung.com>
Thu, 31 Oct 2013 05:01:18 +0000 (14:01 +0900)
Change-Id: Iffbb49c82562d07c3e772b469db70145054968a8
Signed-off-by: Byounghui <byounghui.lim@samsung.com>
plugins/message-condition-handler/MessageConditionHandler.cpp
plugins/message-condition-handler/MessageConditionHandler.h

index a4979d4..5e8089b 100644 (file)
@@ -49,6 +49,7 @@ struct _CharDeleter
 //////////////////////////////////////////////////////////////
 _MessageConditionHandler::_MessageConditionHandler(void)
        : __messageHandle(null)
+       ,__pSmsCondition(null)
 {
        int elapsedTime = 0;    // 10 sec
        while (true)
@@ -94,12 +95,25 @@ _MessageConditionHandler::Register(_AppLaunchCondition& appLaunchCondition)
 {
        SysLog(NID_APP, "Start to register appLaunchConditions.");
        SysTryReturnResult(NID_APP, __messageHandle != NULL, E_INVALID_STATE, "The message handle is NULL.");
-
+       
        result r = E_SUCCESS;
        int err = MESSAGES_ERROR_NONE;
        _MessageType messageType = _MESSAGE_TYPE_NONE;
        String condition;
 
+       if(!__pSmsCondition)
+       {
+               __pSmsCondition = new (std::nothrow) Tizen::Base::Collection::ArrayList();
+               SysTryReturnResult(NID_MSG, __pSmsCondition != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] memory allocation failed.");
+               r = __pSmsCondition->Construct();
+               if (r != E_SUCCESS)
+               {
+                       delete __pSmsCondition;
+                       SysLogException(NID_MSG, r,"[%s] Contruct of ArrayList Failed.", GetErrorMessage(r));
+                       return r;
+               }
+       }
+
        // get condition string
        condition = appLaunchCondition.GetConditionString();
        SysLog(NID_APP, "condition string: [%ls]", condition.GetPointer());
@@ -121,11 +135,11 @@ _MessageConditionHandler::Register(_AppLaunchCondition& appLaunchCondition)
                SysTryReturnResult(NID_APP, r == E_SUCCESS, E_OPERATION_FAILED,
                                "Failed to set incoming sms callback. (%d)", err);
                SysLog(NID_APP, "Port Number: [%d]", port);
-               __portList.Add(*new Integer(port));
+               __pSmsCondition->Add(appLaunchCondition);
 
                // register sms incoming callback
                err = messages_set_message_incoming_cb(__messageHandle,
-                               &_MessageConditionHandler::IncomingSmsMessageCallback, &appLaunchCondition);
+                               &_MessageConditionHandler::IncomingSmsMessageCallback, __pSmsCondition);
                SysTryReturnResult(NID_APP, err == MESSAGES_ERROR_NONE, E_OPERATION_FAILED,
                                "Failed to set incoming sms callback. (%d)", err);
 
@@ -176,6 +190,7 @@ result
 _MessageConditionHandler::Unregister(_AppLaunchCondition& appLaunchCondition)
 {
        SysTryReturnResult(NID_APP, __messageHandle != NULL, E_INVALID_STATE, "The message handle is NULL.");
+       SysLog(NID_APP, "Unregister");
 
        result r = E_SUCCESS;
        int err = MESSAGES_ERROR_NONE;
@@ -193,11 +208,19 @@ _MessageConditionHandler::Unregister(_AppLaunchCondition& appLaunchCondition)
        // SmsPort case
        if (messageType == _MESSAGE_TYPE_SMS_PORT)
        {
+               int port = 0;
+               int count = 0;
                // unset the SMS incoming callback
                err = messages_cb_unset_incoming_cb(__messageHandle);
                SysTryReturnResult(NID_APP, err == MESSAGES_ERROR_NONE, E_OPERATION_FAILED,
                                                "Failed to unset incoming sms callback. (%d)", err);
-               __portList.RemoveAll();
+               port = GetPortNumber(appLaunchCondition.GetConditionString());
+               
+               //Unregister is not working. 
+               //SysLog(NID_APP, "Unregister SMS [%d] num[%d]", port, __pSmsCondition->GetCount());
+               //__pSmsCondition->Remove(appLaunchCondition);
+               //SysLog(NID_APP, "Unregisternum[%d]", __pSmsCondition->GetCount());
+
        }
        // WapPush case
        else if (messageType == _MESSAGE_TYPE_WAP_PUSH)
@@ -359,18 +382,18 @@ _MessageConditionHandler::IncomingSmsMessageCallback(messages_message_h incoming
 {
        SysTryReturnVoidResult(NID_APP, incomingMsg != null, E_INVALID_ARG, "the incoming message is null.");
 
-       _AppLaunchCondition* pAppLaunchCondition = static_cast<_AppLaunchCondition*>(pUserParam);
-       SysTryReturnVoidResult(NID_APP, pAppLaunchCondition != null, E_INVALID_STATE, "pUserData should NOT be null.");
-
-       _MessageConditionHandler* pHandler = dynamic_cast<_MessageConditionHandler*>(pAppLaunchCondition->GetUserData());
-       SysTryReturnVoidResult(NID_APP, pHandler != null, E_INVALID_STATE, "user data is null");
-
        result r = E_SUCCESS;
        char* pTempBody = null;
        char* pTempAddress = null;
        time_t tempTime = 0;
        messages_recipient_type_e recipientType = MESSAGES_RECIPIENT_TO;
        int port = 0;
+       int count = 0;
+       Tizen::Base::Collection::ArrayList *pCondition = null;
+       bool hit = false;
+       int hitCount = 0;
+       _AppLaunchCondition* pAppLaunchCondition = null;
+       _MessageConditionHandler* pHandler = null;
 
        // get each element
        messages_get_text(incomingMsg, &pTempBody);             // body
@@ -378,14 +401,38 @@ _MessageConditionHandler::IncomingSmsMessageCallback(messages_message_h incoming
        messages_get_address(incomingMsg, 0, &pTempAddress, &recipientType);    // sender address
        messages_get_message_port(incomingMsg, &port);   // port number
 
-       // check the condition
-       if (!pHandler->__portList.Contains(*new Integer(port)))
+       pCondition = static_cast<Tizen::Base::Collection::ArrayList*>(pUserParam);
+       SysTryReturnVoidResult(NID_APP, pCondition != null, E_INVALID_STATE, "pUserData should NOT be null.");
+       count = pCondition->GetCount();
+       SysLog(NID_APP, "Condition List Count[%d]", count);
+       
+       for ( int i = 0; i < count ; i++)
+       {
+               
+               pAppLaunchCondition = static_cast<_AppLaunchCondition*>(pCondition->GetAt(i));
+               SysTryReturnVoidResult(NID_APP, pAppLaunchCondition != null, E_INVALID_STATE, "pUserData should NOT be null.");
+
+               pHandler = dynamic_cast<_MessageConditionHandler*>(pAppLaunchCondition->GetUserData());
+               SysTryReturnVoidResult(NID_APP, pHandler != null, E_INVALID_STATE, "user data is null");
+
+               if ( port == pHandler->GetPortNumber(pAppLaunchCondition->GetConditionString()))
+               {
+
+                       hit = true;
+                       pAppLaunchCondition = null;
+                       break;
+               }
+
+
+       }
+
+               // check the condition
+       if (!hit)
        {
                SysLog(NID_APP, "An SMS message received. But not matched with launch condition.");
                SysLog(NID_APP, "Port Number Received: [%d]", port);
                return;
        }
-
        unique_ptr<char[], _CharDeleter> pBody(pTempBody);
        unique_ptr<char[], _CharDeleter> pAddress(pTempAddress);
 
@@ -418,8 +465,25 @@ _MessageConditionHandler::IncomingSmsMessageCallback(messages_message_h incoming
        SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add a TIME to the hash map.", GetErrorMessage(r));
        r = map.Add(new String(L"PORT"), new String(strPort));
        SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add a PORT to the hash map.", GetErrorMessage(r));
+       
+       for ( int i = 0; i < count ; i++)
+       {
+               
+               pAppLaunchCondition = static_cast<_AppLaunchCondition*>(pCondition->GetAt(i));
+               SysTryReturnVoidResult(NID_APP, pAppLaunchCondition != null, E_INVALID_STATE, "pUserData should NOT be null.");
+
+               pHandler = dynamic_cast<_MessageConditionHandler*>(pAppLaunchCondition->GetUserData());
+               SysTryReturnVoidResult(NID_APP, pHandler != null, E_INVALID_STATE, "user data is null");
+
+               if ( port == pHandler->GetPortNumber(pAppLaunchCondition->GetConditionString()))
+               {
+                       SysLog(NID_APP, "launch hit count[%d]", hitCount);
+                       pHandler->Fire(*pAppLaunchCondition, &map);
+
+               }
+
+       }
 
-       pHandler->Fire(*pAppLaunchCondition, &map);
 }
 
 void
index 22d6f65..700703d 100644 (file)
@@ -55,7 +55,7 @@ public:
 
 private:
                messages_service_h __messageHandle;
-               Tizen::Base::Collection::ArrayList __portList;
+               Tizen::Base::Collection::ArrayList *__pSmsCondition;
                Tizen::Base::String __wapApplicationId;
                Tizen::Base::String __wapContentType;
 };