fix array list handling for AppControl argument
authorYoung Ik Cho <youngik.cho@samsung.com>
Thu, 21 Mar 2013 10:04:54 +0000 (19:04 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Thu, 21 Mar 2013 10:05:20 +0000 (19:05 +0900)
Change-Id: Idee2715bb84384df47dce6d8252aa7aad3d80cc2
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
inc/FAppAppControl.h
src/app/FApp_AppArg.cpp
src/app/FApp_AppMessageImpl.cpp
src/app/inc/FApp_AppMessageImpl.h

index 36d67ce..609366a 100755 (executable)
@@ -1127,7 +1127,7 @@ public:
         * @return              An error code
         * @param[in]   pUriData        A pointer to the URI data
         * @param[in]   pDataType       A pointer to the MIME type (RFC 2046) data
-        * @param[in]   pExtraData      A pointer to an argument map of key and value pair where the key is of type String and the value is of type String to deliver to the resolved application @n
+        * @param[in]   pExtraData      A pointer to an argument map of key and value pair where the key is of type String and the value is of type String or of type ArrayList of String to deliver to the resolved application @n
         *                                                      The maximum size is 16 kilo bytes.
         * @param[in]   pListener       The application control callback listener @n
         *                                                      Some application need to get the result by implementing the IAppControlResponseListener interface.
index 2d5a38e..bc319ed 100755 (executable)
@@ -637,9 +637,8 @@ _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
 
 
 result
-_AppArg::AddStrArray(bundle* b, const char* key, const IList* pList)
+_AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
 {
-       bundle* pb = b;
        SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
 
        if (pList == null || pList->GetCount() == 0)
@@ -648,47 +647,11 @@ _AppArg::AddStrArray(bundle* b, const char* key, const IList* pList)
                return E_SUCCESS;
        }
 
-       int i = 0;
-       const int count = pList->GetCount();
-
-       const char** pSa = new (std::nothrow) const char*[count];
-       SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Memory allocation failure with cound %d.", count);
-
-       for (i = 0; i < count; i++)
-       {
-               pSa[i] = null;
-
-               const String* pStr = static_cast<const String*>(pList->GetAt(i));
-               if (pStr)
-               {
-                       pSa[i] = _StringConverter::CopyToCharArrayN(*pStr);
-               }
-       }
-
-       result r = E_SUCCESS;
-
-       int ret = bundle_add_str_array(pb, key, pSa, count);
-       if (ret >= 0)
-       {
-               _AppMessageImpl::AddData(pb, pList);
-       }
-       else
-       {
-               SysLog(NID_APP, "Bundle add failre :%d.", ret);
-               r = E_SYSTEM;
-       }
+       _AppMessageImpl::AddValueArray(pb, key, pList);
 
        _AppMessageImpl::AddData(pb, pList);
 
-//CATCH:
-       for (i = 0; i < count; i++)
-       {
-               delete[] pSa[i];
-       }
-
-       delete[] pSa;
-
-       return r;
+       return E_SUCCESS;
 }
 
 
@@ -723,11 +686,11 @@ _AppArg::AddStrMap(bundle* b, const IMap* pMap)
                        else if (typeid(*pObj) == typeid(const ArrayList))
                        {
                                const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
-                               if (pList && *pKey == TIZEN_APPCONTROL_DATA_LEGACY)
+                               if (pList)
                                {
-                                       SysLog(NID_APP, "Legacy AppControl argument");
-                                       _AppArg::AddStrArray(pb, OSP_K_ARG, pList);
-                                       _AppMessageImpl::AddData(pb, pList);
+                                       SysLog(NID_APP, "ArrayList type");
+
+                                       _AppMessageImpl::AddValueArray(pb, *pKey, pList);
                                }
                        }
                        else if (typeid(*pObj) == typeid(const ByteBuffer))
index 33b5d81..1eedd98 100644 (file)
@@ -277,4 +277,54 @@ _AppMessageImpl::GetValueArray(bundle* pBundle, const char* pKey)
        return pArray;
 }
 
+result
+_AppMessageImpl::AddValueArray(bundle* pBundle, const String& key, const IList* pList)
+{
+       std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
+
+       return AddValueArray(pBundle, pKey.get(), pList);
+}
+
+result
+_AppMessageImpl::AddValueArray(bundle* pBundle, const char* pKey, const IList* pList)
+{
+       SysTryReturnResult(NID_APP, pBundle != NULL, E_INVALID_ARG, "Empty bundle.");
+
+       if (pList == null || pList->GetCount() == 0)
+       {
+               SysLog(NID_APP, "No element added for bundle.");
+               return E_SUCCESS;
+       }
+
+       int i = 0;
+       const int count = pList->GetCount();
+
+       const char** pSa = new (std::nothrow) const char*[count];
+       SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Memory allocation failure with cound %d.", count);
+
+       // element is deliverately iterate with GetAt() for IList
+       for (i = 0; i < count; i++)
+       {
+               pSa[i] = null;
+
+               const String* pStr = static_cast<const String*>(pList->GetAt(i));
+               if (pStr)
+               {
+                       pSa[i] = _StringConverter::CopyToCharArrayN(*pStr);
+                       //SysLog(NID_APP, "%s", pSa[i]);
+               }
+       }
+
+       int ret = bundle_add_str_array(pBundle, pKey, pSa, count);
+
+       for (i = 0; i < count; i++)
+       {
+               delete[] pSa[i];
+       }
+
+       delete[] pSa;
+
+       return (ret == 0) ? E_SUCCESS : E_SYSTEM;
+}
+
 }} // Tizen::App
index 7e94722..0bfb8f7 100644 (file)
@@ -83,9 +83,11 @@ public:
        static result AddStringMap(bundle* pBundle,  const Tizen::Base::Collection::IMap* pMap);
 
        static Tizen::Base::Collection::ArrayList* GetValueArray(bundle* pBundle, const char* pKey);
-
        static Tizen::Base::Collection::ArrayList* GetValueArray(bundle* pBundle, const Tizen::Base::String& key);
 
+       static result AddValueArray(bundle* pBundle, const char* pKey, const Tizen::Base::Collection::IList* pList);
+       static result AddValueArray(bundle* pBundle, const Tizen::Base::String& key, const Tizen::Base::Collection::IList* pList);
+
 private:
        bundle* __pBundle;
 };