fix message appcontrol argument handling
authorYoung Ik Cho <youngik.cho@samsung.com>
Thu, 18 Apr 2013 07:42:47 +0000 (16:42 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Thu, 18 Apr 2013 07:42:47 +0000 (16:42 +0900)
Change-Id: I289c9e1502b4d702688edb8ff1afd494394f5be5
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
src/message-app-control/MessageAppControlDllEntry.cpp

index c916734..5743b2f 100644 (file)
 //
 
 /**
- * @file        BluetoothAppControlDllEntry.cpp
- * @brief      This is the implementation for the BluetoothAppControlDllEntry.cpp class.
+ * @file        MessageAppControlDllEntry.cpp
+ * @brief      This is the implementation for the MessageAppControlDllEntry.cpp class.
  */
 
 #include <appsvc/appsvc.h>
 
 #include <FBaseSysLog.h>
+#include <FBaseUtilStringTokenizer.h>
+#include <FBaseColHashMap.h>
 #include <FAppAppControl.h>
 
 #include <FBase_StringConverter.h>
 #include <FApp_AppControlManager.h>
 #include <FApp_AppMessageImpl.h>
 #include <FApp_Aul.h>
+#include <FApp_AppArg.h>
 
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+static const wchar_t APP_CONTROL_ATTACH_PATH[] = L"http://tizen.org/appcontrol/data/path";
+static const wchar_t APP_CONTROL_MESSAGE_TYPE[] = L"http://tizen.org/appcontrol/data/message/type";
+
 
 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
 result _OSP_EXPORT_ TerminateAppControl(int req);
+static void OnAppControlResult(void*, int, service_result_e, void*);
+
 static int __processId = -1;
 
 static const char __allowedAppControlMessageTable[][2][96] =
@@ -82,6 +91,19 @@ StartAppControl(int req, const String& aId, const String& oId, const String* pUr
                _AppMessageImpl msg;
                msg.AddData(pMap);
 
+               // type
+               const String& type = msg.GetValue(APP_CONTROL_MESSAGE_TYPE);
+               if (type.IsEmpty())
+               {
+                       String legacyType = msg.GetValue(L"type");
+                       if (!legacyType.IsEmpty())
+                       {
+                               legacyType.ToLowerCase();
+
+                               msg.AddData(APP_CONTROL_MESSAGE_TYPE, legacyType);
+                       }
+               }
+
                // to
                String tmp = msg.GetValue(L"to");
                if (!tmp.IsEmpty())
@@ -120,37 +142,58 @@ StartAppControl(int req, const String& aId, const String& oId, const String* pUr
                        msg.AddData(SERVICE_DATA_TEXT, tmp);
                }
 
-               // vcard
-               String tmpVcard = msg.GetValue(L"attachVcard");
+               const String& path = msg.GetValue(APP_CONTROL_ATTACH_PATH);
+               if (path.IsEmpty())
+               {
+                       ArrayList list;
+                       list.Construct();
+
+                       // vcard
+                       const String& tmpVcard = msg.GetValue(L"attachVcard");
+                       if (!tmpVcard.IsEmpty())
+                       {
+                               list.Add(tmpVcard);
+                       }
 
-               // vcalendar
-               String tmpVcal = msg.GetValue(L"attachVcalendar");
+                       // vcalendar
+                       const String& tmpVcal = msg.GetValue(L"attachVcalendar");
+                       if (!tmpVcal.IsEmpty())
+                       {
+                               list.Add(tmpVcal);
+                       }
+
+                       // video
+                       const String& tmpVideo = msg.GetValue(L"attachVideo");
+                       if (!tmpVideo.IsEmpty())
+                       {
+                               list.Add(tmpVideo);
+                       }
 
-               // video
-               String tmpVideo = msg.GetValue(L"attachVideo");
-               if (!tmpVideo.IsEmpty())
-               {
-                       String delim(L'\n');
-                       String tmpTotal = tmpVcard + delim + tmpVcal + delim + tmpVideo;
-                       SysLog(NID_APP, "total: [%ls]", tmpTotal.GetPointer());
-                       msg.AddData(L"ATTACHFILE", tmpTotal);
-               }
-               else
-               {
                        // image
-                       String tmpImage = msg.GetValue(L"attachImage");
+                       const String& tmpImage = msg.GetValue(L"attachImage");
+                       if (!tmpImage.IsEmpty())
+                       {
+                               list.Add(tmpImage);
+                       }
 
                        // audio
-                       String tmpAudio = msg.GetValue(L"attachAudio");
+                       const String& tmpAudio = msg.GetValue(L"attachAudio");
+                       if (!tmpAudio.IsEmpty())
+                       {
+                               list.Add(tmpAudio);
+                       }
+
+                       if (list.GetCount() != 0)
+                       {
+                               SysLog(NID_APP, "Attaching %d items.", list.GetCount());
 
-                       String delim(L'\n');
-                       String tmpTotal = tmpVcard + delim + tmpVcal + delim + tmpImage + delim + tmpAudio;
-                       SysLog(NID_APP, "total: [%ls]", tmpTotal.GetPointer());
-                       msg.AddData(L"ATTACHFILE", tmpTotal);
+                               _AppMessageImpl::AddValueArray(msg.GetBundle(), APP_CONTROL_ATTACH_PATH, &list);
+                               //msg.AddValueArray(APP_CONTROL_ATTACH_PATH, &list);
+                       }
                }
 
                const String& package = _AppControlManager::GetAliasAppId(aId);
-               __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pUri, pMime, NULL, 0);
+               __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pUri, pMime, NULL, reinterpret_cast<void*>(req));
 
                SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Email AppControl is failed.");
                SysLog(NID_APP, "StartAppControl: Launching Message AppControl succeeded.");
@@ -193,16 +236,37 @@ StartAppControl(int req, const String& aId, const String& oId, const String* pUr
                        msg.AddData(SERVICE_DATA_TEXT, tmp);
                }
 
-#if 0
                tmp = msg.GetValue(L"attachments");
                if (!tmp.IsEmpty())
                {
-                       msg.AddData(APPSVC_DATA_PATH, tmp);
+                       const String& path = msg.GetValue(APP_CONTROL_ATTACH_PATH);
+                       // if path is delivered, then ignore "attachments" data
+                       if (path.IsEmpty())
+                       {
+                               const String delim = L";";
+                               StringTokenizer strTok(tmp, delim);
+
+                               const int count = strTok.GetTokenCount();
+                               if (count > 0)
+                               {
+                                       ArrayList list(SingleObjectDeleter);
+                                       list.Construct();
+
+                                       String token;
+                                       while (strTok.HasMoreTokens())
+                                       {
+                                               strTok.GetNextToken(token);
+                                               list.Add(new (std::nothrow) String(token));
+                                       }
+
+                                       _AppMessageImpl::AddValueArray(msg.GetBundle(), APP_CONTROL_ATTACH_PATH, &list);
+                                       //msg.AddValueArray(APP_CONTROL_ATTACH_PATH, &list);
+                               }
+                       }
                }
-#endif
 
                const String& package = _AppControlManager::GetAliasAppId(aId);
-               __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pUri, pMime, NULL, 0);
+               __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pUri, pMime, OnAppControlResult, reinterpret_cast<void*>(req));
 
                SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Email AppControl is failed.");
                SysLog(NID_APP, "StartAppControl: Launching Email AppControl succeeded.");
@@ -221,6 +285,30 @@ TerminateAppControl(int req)
        return E_SUCCESS;
 }
 
+static void
+OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
+{
+       SysLog(NID_APP, "OnAppControlResult with %d.", res);
+
+       result r = E_SYSTEM;
+       int req = -1;
+       bundle* pBundle = static_cast<bundle*>(b);
+
+       HashMap* pResult = new (std::nothrow) HashMap();
+       SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
+
+       r = pResult->Construct();
+
+       _AppArg::SetArgMap(pBundle, pResult);
+
+       req = reinterpret_cast<int>(userData);
+       _AppControlManager::GetInstance()->FinishAppControl(req, res, pResult);
+
+CATCH:
+       __processId = -1;
+}
+
+
 #ifdef __cplusplus
 }
 #endif