multi conditional launch (wap push)
authorByounghui <byounghui.lim@samsung.com>
Fri, 1 Nov 2013 06:21:44 +0000 (15:21 +0900)
committerByounghui <byounghui.lim@samsung.com>
Fri, 1 Nov 2013 06:21:44 +0000 (15:21 +0900)
Change-Id: Ic1c6e21575a676d5f16b5974de9e575880c304c9
Signed-off-by: Byounghui <byounghui.lim@samsung.com>
plugins/message-condition-handler/MessageConditionHandler.cpp
plugins/message-condition-handler/MessageConditionHandler.h

index 5e8089b..c4b9639 100644 (file)
@@ -50,6 +50,7 @@ struct _CharDeleter
 _MessageConditionHandler::_MessageConditionHandler(void)
        : __messageHandle(null)
        ,__pSmsCondition(null)
+       ,__pWapPushCondition(null)
 {
        int elapsedTime = 0;    // 10 sec
        while (true)
@@ -113,6 +114,19 @@ _MessageConditionHandler::Register(_AppLaunchCondition& appLaunchCondition)
                        return r;
                }
        }
+       
+       if(!__pWapPushCondition)
+       {
+               __pWapPushCondition = new (std::nothrow) Tizen::Base::Collection::ArrayList();
+               SysTryReturnResult(NID_MSG, __pWapPushCondition != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] memory allocation failed.");
+               r = __pWapPushCondition->Construct();
+               if (r != E_SUCCESS)
+               {
+                       delete __pWapPushCondition;
+                       SysLogException(NID_MSG, r,"[%s] Contruct of ArrayList Failed.", GetErrorMessage(r));
+                       return r;
+               }
+       }
 
        // get condition string
        condition = appLaunchCondition.GetConditionString();
@@ -169,10 +183,12 @@ _MessageConditionHandler::Register(_AppLaunchCondition& appLaunchCondition)
 
                SysLog(NID_APP, "Content-Type: [%s]", pWapContentType.get());
                SysLog(NID_APP, "X-WAP-Application-ID: [%s]", pWapApplicationId.get());
+\r
+               __pWapPushCondition->Add(appLaunchCondition);
 
                // add incoming callback with wap application id
                err = messages_push_add_incoming_cb(__messageHandle, pWapApplicationId.get(),
-                               &_MessageConditionHandler::IncomingWapPushMessageCallback, &appLaunchCondition);
+                               &_MessageConditionHandler::IncomingWapPushMessageCallback,__pWapPushCondition);
                SysTryReturnResult(NID_APP, err == MESSAGES_ERROR_NONE, E_OPERATION_FAILED,
                                "Failed to add incoming wap push callback. (%d)", err);
 
@@ -249,6 +265,10 @@ _MessageConditionHandler::Unregister(_AppLaunchCondition& appLaunchCondition)
                err = messages_push_remove_incoming_cb(__messageHandle, pWapApplicationId.get());
                SysTryReturnResult(NID_APP, err == MESSAGES_ERROR_NONE, E_OPERATION_FAILED,
                                                "Failed to remove incoming push callback. (%d)", err);
+               //Unregister is not working. 
+               //SysLog(NID_APP, "Unregister SMS [%d] num[%d]", port, __pWapPushCondition->GetCount());
+               //__pWapPushCondition->Remove(appLaunchCondition);
+               //SysLog(NID_APP, "Unregisternum[%d]", __pWapPushCondition->GetCount());
 
                __wapApplicationId.Clear();
                __wapContentType.Clear();
@@ -390,7 +410,6 @@ _MessageConditionHandler::IncomingSmsMessageCallback(messages_message_h incoming
        int port = 0;
        int count = 0;
        Tizen::Base::Collection::ArrayList *pCondition = null;
-       bool hit = false;
        int hitCount = 0;
        _AppLaunchCondition* pAppLaunchCondition = null;
        _MessageConditionHandler* pHandler = null;
@@ -401,38 +420,6 @@ _MessageConditionHandler::IncomingSmsMessageCallback(messages_message_h incoming
        messages_get_address(incomingMsg, 0, &pTempAddress, &recipientType);    // sender address
        messages_get_message_port(incomingMsg, &port);   // port number
 
-       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);
 
@@ -465,7 +452,12 @@ _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));
-       
+
+       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++)
        {
                
@@ -477,13 +469,13 @@ _MessageConditionHandler::IncomingSmsMessageCallback(messages_message_h incoming
 
                if ( port == pHandler->GetPortNumber(pAppLaunchCondition->GetConditionString()))
                {
+                       hitCount++;
                        SysLog(NID_APP, "launch hit count[%d]", hitCount);
                        pHandler->Fire(*pAppLaunchCondition, &map);
-
                }
 
        }
-
+       SysTryReturnVoidResult(NID_APP, hitCount > 0, E_SYSTEM, "An SMS message[%d] received. But not matched with launch condition.", port);
 }
 
 void
@@ -491,12 +483,14 @@ _MessageConditionHandler::IncomingWapPushMessageCallback(const char* pHeader, co
 {
        SysTryReturnVoidResult(NID_APP, pHeader != null, E_INVALID_ARG, "the header is null.");
        SysTryReturnVoidResult(NID_APP, pBody != null, E_INVALID_ARG, "the body is null.");
+       
 
-       _AppLaunchCondition* pAppLaunchCondition = static_cast<_AppLaunchCondition*>(pUserParam);
-       SysTryReturnVoidResult(NID_APP, pAppLaunchCondition != null, E_INVALID_STATE, "pUserParam should NOT be null.");
-
-       _MessageConditionHandler* pHandler = dynamic_cast<_MessageConditionHandler*>(pAppLaunchCondition->GetUserData());
-       SysTryReturnVoidResult(NID_APP, pHandler != null, E_INVALID_STATE, "user data is null");
+       int count = 0;
+       Tizen::Base::Collection::ArrayList *pCondition = null;
+       int hitCount = 0;
+       _AppLaunchCondition* pAppLaunchCondition = null;
+       _MessageConditionHandler* pHandler = null;
+       String header;
 
        ByteBuffer *msgBody = new ByteBuffer();
        SysTryReturnVoidResult(NID_APP, msgBody != null, E_OUT_OF_MEMORY, "Failed to add a BODY to the hash map.");     
@@ -520,7 +514,36 @@ _MessageConditionHandler::IncomingWapPushMessageCallback(const char* pHeader, co
        r = map.Add(new String(L"BODY"), msgBody);
        SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "Failed to add a BODY to the hash map.");
 
-       pHandler->Fire(*pAppLaunchCondition, &map);
+       header = pHeader;
+
+       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++)
+       {
+               String condition, id, type;
+
+               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");
+               
+               condition = pAppLaunchCondition->GetConditionString();
+               pHandler->GetWapConditions(condition, id, type);
+
+               if (header.Contains(id))
+               {       
+                       hitCount++;
+                       SysLog(NID_APP, "launch hit count[%d]", hitCount);
+                       pHandler->Fire(*pAppLaunchCondition, &map);
+               }
+
+       }
+       SysTryReturnVoidResult(NID_APP, hitCount > 0, E_SYSTEM, "An WapPush[%s] received. But not matched with launch condition.", pHeader);
+
 }
 
 Tizen::Base::DateTime
index 700703d..51cd89f 100644 (file)
@@ -56,6 +56,7 @@ public:
 private:
                messages_service_h __messageHandle;
                Tizen::Base::Collection::ArrayList *__pSmsCondition;
+               Tizen::Base::Collection::ArrayList *__pWapPushCondition;
                Tizen::Base::String __wapApplicationId;
                Tizen::Base::String __wapContentType;
 };