add libprivilege-control dependency
[platform/framework/native/appfw.git] / src / app / FApp_AppMessageImpl.cpp
index 33b5d81..659ad7f 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -28,7 +27,9 @@
 #include <FBaseSysLog.h>
 #include <FBaseString.h>
 #include <FBaseColIList.h>
+#include <FBaseColIMap.h>
 #include <FBaseColIEnumerator.h>
+#include <FBaseColArrayList.h>
 
 #include <FBase_StringConverter.h>
 
@@ -112,6 +113,24 @@ _AppMessageImpl::AddData(bundle* pBundle, const String& key, const String& value
 }
 
 result
+_AppMessageImpl::RemoveData(const String& key)
+{
+       SysAssert(__pBundle != NULL);
+
+       return RemoveData(__pBundle, key);
+}
+
+result
+_AppMessageImpl::RemoveData(bundle* pBundle, const String& key)
+{
+       std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
+
+       bundle_del(pBundle, pKey.get());
+
+       return E_SUCCESS;
+}
+
+result
 _AppMessageImpl::SetOperation(bundle* pBundle, const String& operation)
 {
        std::unique_ptr<char[]> pVal(_StringConverter::CopyToCharArrayN(operation));
@@ -230,6 +249,14 @@ _AppMessageImpl::AddStringMap(bundle* pBundle, const IMap* pMap)
                                        _AppMessageImpl::AddData(pBundle, *pKey, *pVal);
                                }
                        }
+                       else if (typeid(*pObj) == typeid(const ArrayList))
+                       {
+                               const ArrayList* pVal = static_cast<const ArrayList*>(pEnum->GetValue());
+                               if (pVal)
+                               {
+                                       _AppMessageImpl::AddValueArray(pBundle, *pKey, pVal);
+                               }
+                       }
                }
        }
 
@@ -237,15 +264,15 @@ _AppMessageImpl::AddStringMap(bundle* pBundle, const IMap* pMap)
 }
 
 ArrayList*
-_AppMessageImpl::GetValueArray(bundle* pBundle, const String& key)
+_AppMessageImpl::GetValueArrayN(bundle* pBundle, const String& key)
 {
        std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
 
-       return GetValueArray(pBundle, pKey.get());
+       return GetValueArrayN(pBundle, pKey.get());
 }
 
 ArrayList*
-_AppMessageImpl::GetValueArray(bundle* pBundle, const char* pKey)
+_AppMessageImpl::GetValueArrayN(bundle* pBundle, const char* pKey)
 {
        int len = 0;
        const char** pStrArray = bundle_get_str_array(pBundle, pKey, &len);
@@ -277,4 +304,76 @@ _AppMessageImpl::GetValueArray(bundle* pBundle, const char* pKey)
        return pArray;
 }
 
+result
+_AppMessageImpl::AddValueArray(const String& key, const IList* pList)
+{
+       SysAssert(__pBundle != NULL);
+
+       return AddValueArray(__pBundle, key, pList);
+}
+
+result
+_AppMessageImpl::AddValueArraySingle(const String& key, const String& value)
+{
+       SysAssert(__pBundle != NULL);
+
+       ArrayList arr;
+       arr.Construct();
+
+       arr.Add(value);
+
+       return AddValueArray(__pBundle, key, &arr);
+}
+
+
+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 count %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