2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FApp_AppArg.cpp
20 * @brief This is the implementation for the _AppArg.cpp class.
28 #include <unique_ptr.h>
32 #include <appsvc/appsvc.h>
35 #include <FBaseInteger.h>
36 #include <FBaseColArrayList.h>
37 #include <FBaseColHashMap.h>
38 #include <FBaseUtilStringTokenizer.h>
40 #include <FBaseSysLog.h>
41 #include <FBase_StringConverter.h>
43 #include "FApp_MapDataControlImpl.h"
44 #include "FApp_AppControlImpl.h"
45 #include "FApp_SqlDataControlImpl.h"
46 #include "FApp_AppControlEventArg.h"
47 #include "FApp_AppArg.h"
48 #include "FApp_AppMessageImpl.h"
49 #include "FAppPkg_PackageManagerImpl.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Utility;
54 using namespace Tizen::App::Package;
57 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
59 namespace Tizen { namespace App
62 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
63 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
64 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
65 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
66 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
67 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
68 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
69 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
70 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
71 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
72 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
73 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
74 static const char OSP_V_VERSION_2_1_0_2[] = "ver_2.1.0.2";
75 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
76 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
77 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
78 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
80 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_ID[] = "client_id";
81 static const char SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET[] = "client_secret";
82 static const char SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY[] = "service_category";
84 static const char SMS_KEY_SERVICE_CALLER[] = "service_caller";
85 static const char SMS_KEY_SERVICE_DATA[] = "service_data";
88 _AppArg::_AppArg(void)
94 _AppArg::~_AppArg(void)
98 bundle_free(__pBundle);
104 _AppArg::Construct(const String& argText)
106 __pBundle = bundle_create();
107 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
109 return CreateLaunchArg(__pBundle, argText);
114 _AppArg::Construct(const IList* pList)
116 __pBundle = bundle_create();
117 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
119 return CreateLaunchArg(__pBundle, pList);
124 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
126 __pBundle = bundle_create();
127 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
129 return CreateAppControlArg(__pBundle, ac, pList);
134 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
136 __pBundle = bundle_create();
137 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
139 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
144 _AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
146 __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
147 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
149 return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
154 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
156 __pBundle = bundle_create();
157 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
159 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
164 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
166 __pBundle = bundle_create();
167 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
169 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
174 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
176 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
177 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
179 return CreateResultArg(__pBundle, pList);
184 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
186 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
187 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
189 return CreateResultArg(__pBundle, pMap);
194 _AppArg::Construct(bundle* b)
196 __pBundle = bundle_dup(b);
197 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
204 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
206 __pBundle = bundle_create();
207 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
209 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
213 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
215 __pBundle = bundle_create();
216 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
218 CreateAppLaunchConditionArg(__pBundle, condition, pList);
220 return CreateResultArg(__pBundle, pMap);
224 _AppArg::GetArgListN(int num) const
226 bundle* pBundle = __pBundle;
227 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
229 ArrayList* pList = new (std::nothrow) ArrayList();
230 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
234 const char* p = NULL;
235 _AppHandler launch_type = GetHandler(pBundle);
239 case _APP_HANDLER_APPCONTROL:
241 // [FIXME] proper request Id required
242 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
245 p = appsvc_get_category(pBundle);
248 pList->Add(*new (std::nothrow) String(p));
252 pList->Add(*new (std::nothrow) String(L""));
256 p = appsvc_get_mime(pBundle);
259 pList->Add(*new (std::nothrow) String(p));
263 pList->Add(*new (std::nothrow) String(L""));
267 p = appsvc_get_uri(pBundle);
270 pList->Add(*new (std::nothrow) String(p));
274 pList->Add(*new (std::nothrow) String(L""));
279 case _APP_HANDLER_DATACONTROL:
281 AddListFromBundle(pList, pBundle, OSP_K_APPID);
283 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
285 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
287 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
290 case _APP_HANDLER_LAUNCH_COND:
291 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
292 AddListFromBundle(pList, pBundle, OSP_K_COND);
295 case _APP_HANDLER_LAUNCH_NORMAL:
296 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
297 pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
301 SysLog(NID_APP, "Invalid handler type");
305 SetArgList(__pBundle, pList);
312 _AppArg::GetArgListN(void) const
314 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
316 ArrayList* pList = new (std::nothrow) ArrayList();
317 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
321 SetArgList(__pBundle, pList);
326 // the returned map is allocated using SingleObjectDeleter
328 _AppArg::GetArgMapN(void) const
330 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
332 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
333 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
335 pHashMap->Construct();
337 SetArgMap(__pBundle, pHashMap);
339 if (pHashMap->GetCount() == 0)
345 ArrayList* pList = _AppMessageImpl::GetValueArrayN(__pBundle, OSP_K_ARG);
348 pHashMap->Add(new (std::nothrow) String(TIZEN_APPCONTROL_DATA_LEGACY), pList);
354 IsInternalKey(const char* pKey)
356 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
361 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
366 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
375 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
377 HashMap* pMap = static_cast<HashMap*>(pData);
379 if (pKey && pVal && pMap)
381 if (IsInternalKey(pKey))
383 //SysLog(NID_APP, "(%s)", pKey);
391 case BUNDLE_TYPE_STR:
392 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
395 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
398 case BUNDLE_TYPE_STR_ARRAY:
401 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
402 if (pArr && size > 0)
404 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
409 for (size_t i = 0; i < size; i++)
411 // type unsafe ugly static casting required
412 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
415 const int count = pList->GetCount();
418 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
419 pMap->Add(new (std::nothrow) String(pKey), pList);
423 SysLog(NID_APP, "No object for %s", pKey);
430 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
434 case BUNDLE_TYPE_BYTE:
435 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
437 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
441 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
442 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
443 result r = pBuffer->Construct(size);
444 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
446 r = pBuffer->SetArray((const byte*)pStr, 0, size);
447 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
451 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
455 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
462 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
464 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
470 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
472 // actual argument below
474 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
477 for (int i = 0; i < len; i++)
481 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
482 pList->Add(*new (std::nothrow) String(pa[i]));
487 const char* p = appsvc_get_uri(pBundle);
490 pList->Add(*new (std::nothrow) String(p));
491 SysLog(NID_APP, "argument is %s", p);
495 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_CALLER);
498 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_CALLER, p);
499 pList->Add(*new (std::nothrow) String(tmp));
500 SysLog(NID_APP, "service_caller is %s", p);
503 p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_DATA);
506 tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_DATA, p);
507 pList->Add(*new (std::nothrow) String(tmp));
508 SysLog(NID_APP, "service_data is set");
511 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_ID);
514 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_ID, p);
515 pList->Add(*new (std::nothrow) String(tmp));
516 SysLog(NID_APP, "client_id is %s", p);
519 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET);
522 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET, p);
523 pList->Add(*new (std::nothrow) String(tmp));
524 SysLog(NID_APP, "client_secret is %s", p);
527 p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY);
530 tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY, p);
531 pList->Add(*new (std::nothrow) String(tmp));
532 SysLog(NID_APP, "service_category is %s", p);
540 _AppArg::GetValue(const char* key) const
542 const char* p = appsvc_get_data(__pBundle, key);
548 _AppArg::GetHandler(bundle* b)
550 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
552 const char* p = null;
554 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
558 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
560 return _APP_HANDLER_DATACONTROL;
563 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
565 SysLog(NID_APP, "Building AppControl arguments.");
567 return _APP_HANDLER_APPCONTROL;
571 // not appcontrol nor datacontrol => normal launch or condlaunch
572 p = appsvc_get_data(b, OSP_K_COND);
575 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
576 return _APP_HANDLER_LAUNCH_COND;
580 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
581 return _APP_HANDLER_LAUNCH_NORMAL;
587 return _APP_HANDLER_APPCONTROL;
592 _AppArg::GetCallerPid(bundle* pBundle)
594 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
595 if (pBundleValue == NULL)
597 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
600 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
602 return atoi(pBundleValue);
607 _AppArg::GetCallerAppId(void) const
609 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
611 return String(pBundleValue);
616 _AppArg::GetCalleeAppId(void) const
618 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
620 String retVal = pBundleValue;
623 // [INFO] ugly code for submode callee
624 retVal.SubString(11, temp);
625 if (temp == L"_AppControl")
628 retVal.SubString(0, 10, id);
629 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(id);
631 retVal = id + L'.' + name;
632 SysLog(NID_APP, "Converted caller Id is %ls", retVal.GetPointer());
640 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
642 bundle* pBundle = bk;
644 const char* p = appsvc_get_data(pBundle, key);
647 pList->Add(*new (std::nothrow) String(p));
651 pList->Add(*new (std::nothrow) String(L""));
657 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
659 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
661 return AddStrArray(b, pKey.get(), pList);
666 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
668 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
670 if (pList == null || pList->GetCount() == 0)
672 SysLog(NID_APP, "No element added for bundle.");
676 _AppMessageImpl::AddValueArray(pb, key, pList);
678 _AppMessageImpl::AddData(pb, pList);
685 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
688 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
690 if (pMap == null || pMap->GetCount() == 0)
692 SysLog(NID_APP, "No element added for bundle.");
696 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
697 while(pEnum->MoveNext() == E_SUCCESS)
699 const String* pKey = static_cast<const String*>(pEnum->GetKey());
700 const Object* pObj = pEnum->GetValue();
704 if (typeid(*pObj) == typeid(const String))
706 const String* pVal = static_cast<const String*>(pEnum->GetValue());
709 _AppMessageImpl::AddData(pb, *pKey, *pVal);
712 else if (typeid(*pObj) == typeid(const ArrayList))
714 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
717 SysLog(NID_APP, "ArrayList type");
719 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
722 else if (typeid(*pObj) == typeid(const ByteBuffer))
724 SysLog(NID_APP, "ByteBuffer type");
725 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
727 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
728 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
738 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
740 if (pMap == null || pList == null)
745 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
746 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
750 while (pEnum->MoveNext() == E_SUCCESS)
752 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
755 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
759 pStr->SubString(0, index, key);
765 pStr->SubString(index + 1, value);
767 pMap->Add(new String(key), new String(value));
769 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
777 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
781 case APP_CTRL_RESULT_SUCCEEDED:
782 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
784 case APP_CTRL_RESULT_CANCELED:
785 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
787 case APP_CTRL_RESULT_TERMINATED:
788 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
790 case APP_CTRL_RESULT_ABORTED:
791 list.Add(* new (std::nothrow) String("aborted"));
793 //case APP_CTRL_RESULT_FAILED:
795 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
804 bool isPathRegistered = false;
805 // handle APP_CTRL_RESULT_SUCCEEDED only
806 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
808 while(pMapEnum->MoveNext() == E_SUCCESS)
810 String* pKey = static_cast<String*>(pMapEnum->GetKey());
813 SysLog(NID_APP, "Invalid entry.");
817 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
819 if (!isPathRegistered)
821 isPathRegistered = true;
825 SysLog(NID_APP, "Selected path key is already registered.");
830 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
833 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
835 StringTokenizer strTok(*pVal, L';');
836 if (strTok.GetTokenCount() == 0)
838 list.Add(* new (std::nothrow) String(*pVal));
843 while(strTok.HasMoreTokens())
845 strTok.GetNextToken(token);
846 list.Add(* new (std::nothrow) String(token));
847 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
858 _AppArg::GetListN(bundle* b, const char* key)
866 const char** pValArray = null;
869 pValArray = appsvc_get_data_array(b, key, &len);
870 if (len == 0 || pValArray == null)
875 ArrayList* pList = new (std::nothrow) ArrayList;
876 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
880 for (int i = 0; i < len; i++)
882 pList->Add(*new (std::nothrow) String(pValArray[i]));
890 _AppArg::CreateLaunchArg(bundle* b, const String& arg)
892 SysAssertf(b != null, "Valid bundle should be supplied");
898 const char** pSa = new (std::nothrow) const char*[1];
899 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
900 pSa[0] = _StringConverter::CopyToCharArrayN(arg);
901 bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
903 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
909 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
916 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
918 SysAssertf(b != null, "Valid bundle should be supplied");
922 AddStrArray(pb, OSP_K_ARG, pList);
924 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
931 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
933 SysAssertf(b != null, "Valid bundle should be supplied");
938 AddStrArray(pb, OSP_K_ARG, pList);
940 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
943 bundle_add(pb, OSP_K_COND, p.get());
946 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
953 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
955 SysAssertf(b != null, "Valid bundle should be supplied");
959 AddStrArray(pb, OSP_K_ARG, pList);
961 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
964 appsvc_set_operation(pb, pOperation.get());
967 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
974 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
976 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
981 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
983 SysAssertf(b != null, "Valid bundle should be supplied");
987 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
988 if (pOperation.get())
990 appsvc_set_operation(pb, pOperation.get());
995 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
998 appsvc_set_uri(pb, pUri.get());
1004 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
1007 appsvc_set_mime(pb, pMime.get());
1011 AddStrMap(pb, pMap);
1013 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
1021 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
1024 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
1025 const IList* pArgList)
1027 SysAssertf(b != null, "Valid bundle should be supplied");
1029 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1031 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1032 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
1033 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1034 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_2);
1036 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1039 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1042 AddStrArray(b, OSP_K_ARG, pArgList);
1049 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
1050 const IList* pArgList)
1052 SysAssertf(b != null, "Valid bundle should be supplied");
1054 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
1056 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
1057 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
1058 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1059 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_2);
1061 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1064 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1067 AddStrArray(b, OSP_K_ARG, pArgList);
1074 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1076 SysAssertf(b != null, "Valid bundle should be supplied");
1080 AddStrArray(pb, OSP_K_ARG, pList);
1082 _AppMessageImpl::AddData(pb, pList);
1089 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1091 SysAssertf(b != null, "Valid bundle should be supplied");
1095 AddStrMap(pb, pMap);
1102 _AppArg::CreateBundleFromSvc(void* svc)
1104 bundle* pBundle = GetBundleFromSvc(svc);
1107 return bundle_dup(pBundle);
1115 _AppArg::GetBundleFromSvc(void* svc)
1124 DummyS* pDummy = static_cast<DummyS*>(svc);
1126 if (pDummy && pDummy->pData)
1128 return pDummy->pData;
1136 _AppArg::GetRequestId(int num)
1139 str.Format(10, L"req%05d", num);
1145 _AppArg::GetRequestId(const String& str)
1150 result r = str.SubString(3, sub);
1151 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1153 r = Integer::Parse(sub, i);
1154 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1161 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1163 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1165 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1166 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1168 int res = bundle_add(b, OSP_K_APPID, pId.get());
1169 if (res < 0 && errno == EPERM) // key exists
1171 bundle_del(b, OSP_K_APPID);
1172 bundle_add(b, OSP_K_APPID, pId.get());
1175 appsvc_set_appid(b, pId.get());
1180 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1182 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1186 //SysLog(NID_APP, "Requested ID is %d", reqId);
1190 char buffer[32] = {0, };
1191 snprintf(buffer, 32, "%d", reqId);
1192 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1193 if (res < 0 && errno == EPERM) // key exists
1195 bundle_del(pBundle, OSP_K_REQUEST_ID);
1196 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1201 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1203 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1205 char pBuffer[128] = {0, };
1206 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1207 int res = bundle_add(pBundle, pKey, pBuffer);
1208 if (res < 0 && errno == EPERM) // key exists
1210 bundle_del(pBundle, pKey);
1211 bundle_add(pBundle, pKey, pBuffer);
1216 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1218 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1225 return (i < 0) ? -1 : i;
1230 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1232 appsvc_allow_transient_app(pBundle, handle);
1234 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1241 _AppArg::PrintSvcHandle(void* svc)
1243 service_h service = static_cast<service_h>(svc);
1245 if (service == null)
1250 Print(GetBundleFromSvc(service));
1255 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1263 case BUNDLE_TYPE_STR:
1264 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1267 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1271 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1278 _AppArg::Print(bundle* b)
1285 const char* p = null;
1286 p = appsvc_get_data(b, AUL_K_CALLER_PID);
1289 SysLog(NID_APP, "CallerPId[%s]", p);
1292 p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
1295 SysLog(NID_APP, "WaitResult[%s]", p);
1298 p = appsvc_get_data(b, OSP_K_COND);
1301 SysLog(NID_APP, "Condition[%s]", p);
1304 p = appsvc_get_operation(b);
1307 SysLog(NID_APP, "operation[%s]", p);
1310 p = appsvc_get_uri(b);
1313 SysLog(NID_APP, "uri[%s]", p);
1316 p = appsvc_get_mime(b);
1319 SysLog(NID_APP, "mime[%s]", p);
1322 p = appsvc_get_category(b);
1325 SysLog(NID_APP, "Category[%s]", p);
1328 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1331 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1334 for (int i = 0; i < len; i++)
1338 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);