2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_AppArg.cpp
19 * @brief This is the implementation for the _AppArg.cpp class.
27 #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"
50 #include "FAppPkg_PackageManagerImpl.h"
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Base::Utility;
55 using namespace Tizen::App::Package;
58 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
60 namespace Tizen { namespace App
63 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
64 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
65 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
66 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
67 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
68 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
69 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
70 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
71 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
72 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
73 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
74 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
75 static const char OSP_V_VERSION_2_1_0_3[] = "ver_2.1.0.3";
76 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
77 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
78 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
79 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
82 _AppArg::_AppArg(void)
88 _AppArg::~_AppArg(void)
92 bundle_free(__pBundle);
98 _AppArg::Construct(const String& argText)
100 __pBundle = bundle_create();
101 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
103 return CreateLaunchArg(__pBundle, argText);
108 _AppArg::Construct(const IList* pList)
110 __pBundle = bundle_create();
111 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
113 return CreateLaunchArg(__pBundle, pList);
118 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
120 __pBundle = bundle_create();
121 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
123 return CreateAppControlArg(__pBundle, ac, pList);
128 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
130 __pBundle = bundle_create();
131 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
133 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
138 _AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
140 __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
141 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
143 return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
148 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
150 __pBundle = bundle_create();
151 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
153 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
158 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
160 __pBundle = bundle_create();
161 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
163 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
168 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
170 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
171 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
173 return CreateResultArg(__pBundle, pList);
178 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
180 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
181 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
183 return CreateResultArg(__pBundle, pMap);
188 _AppArg::Construct(bundle* b)
190 __pBundle = bundle_dup(b);
191 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
198 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
200 __pBundle = bundle_create();
201 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
203 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
207 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
209 __pBundle = bundle_create();
210 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
212 CreateAppLaunchConditionArg(__pBundle, condition, pList);
214 return CreateResultArg(__pBundle, pMap);
218 _AppArg::GetArgListN(int num) const
220 bundle* pBundle = __pBundle;
221 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
223 ArrayList* pList = new (std::nothrow) ArrayList();
224 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
228 const char* p = NULL;
229 _AppHandler launch_type = GetHandler(pBundle);
233 case _APP_HANDLER_APPCONTROL:
235 // [FIXME] proper request Id required
236 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
239 p = appsvc_get_category(pBundle);
242 pList->Add(*new (std::nothrow) String(p));
246 pList->Add(*new (std::nothrow) String(L""));
250 p = appsvc_get_mime(pBundle);
253 pList->Add(*new (std::nothrow) String(p));
257 pList->Add(*new (std::nothrow) String(L""));
261 p = appsvc_get_uri(pBundle);
264 pList->Add(*new (std::nothrow) String(p));
268 pList->Add(*new (std::nothrow) String(L""));
273 case _APP_HANDLER_DATACONTROL:
275 AddListFromBundle(pList, pBundle, OSP_K_APPID);
277 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
279 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
281 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
284 case _APP_HANDLER_LAUNCH_COND:
285 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
286 AddListFromBundle(pList, pBundle, OSP_K_COND);
289 case _APP_HANDLER_LAUNCH_NORMAL:
290 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
291 pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
295 SysLog(NID_APP, "Invalid handler type");
299 SetArgList(__pBundle, pList);
306 _AppArg::GetArgListN(void) const
308 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
310 ArrayList* pList = new (std::nothrow) ArrayList();
311 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
315 SetArgList(__pBundle, pList);
320 // the returned map is allocated using SingleObjectDeleter
322 _AppArg::GetArgMapN(void) const
324 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
328 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
329 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
331 pHashMap->Construct();
333 SetArgMap(__pBundle, pHashMap);
335 if (pHashMap->GetCount() == 0)
345 IsInternalKey(const char* pKey)
347 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
352 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
357 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
366 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
368 HashMap* pMap = static_cast<HashMap*>(pData);
370 if (pKey && pVal && pMap)
372 if (IsInternalKey(pKey))
374 //SysLog(NID_APP, "(%s)", pKey);
382 case BUNDLE_TYPE_STR:
383 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
386 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
389 case BUNDLE_TYPE_STR_ARRAY:
392 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
393 if (pArr && size > 0)
395 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
400 for (size_t i = 0; i < size; i++)
402 // type unsafe ugly static casting required
403 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
406 const int count = pList->GetCount();
409 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
410 pMap->Add(new (std::nothrow) String(pKey), pList);
414 SysLog(NID_APP, "No object for %s", pKey);
421 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
425 case BUNDLE_TYPE_BYTE:
426 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
428 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
432 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
433 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
434 result r = pBuffer->Construct(size);
435 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
437 r = pBuffer->SetArray((const byte*)pStr, 0, size);
438 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
442 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
446 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
453 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
455 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
461 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
463 // actual argument below
465 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
468 for (int i = 0; i < len; i++)
472 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
473 pList->Add(*new (std::nothrow) String(pa[i]));
478 const char* p = appsvc_get_uri(pBundle);
481 pList->Add(*new (std::nothrow) String(p));
482 SysLog(NID_APP, "argument is %s", p);
490 _AppArg::GetValue(const char* key) const
492 const char* p = appsvc_get_data(__pBundle, key);
498 _AppArg::GetHandler(bundle* b)
500 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
502 const char* p = null;
504 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
508 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
510 return _APP_HANDLER_DATACONTROL;
513 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
515 SysLog(NID_APP, "Building AppControl arguments.");
517 return _APP_HANDLER_APPCONTROL;
521 // not appcontrol nor datacontrol => normal launch or condlaunch
522 p = appsvc_get_data(b, OSP_K_COND);
525 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
526 return _APP_HANDLER_LAUNCH_COND;
530 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
531 return _APP_HANDLER_LAUNCH_NORMAL;
537 return _APP_HANDLER_APPCONTROL;
542 _AppArg::GetCallerPid(bundle* pBundle)
544 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
545 if (pBundleValue == NULL)
547 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
550 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
552 return atoi(pBundleValue);
557 _AppArg::GetCallerAppId(void) const
559 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
561 return String(pBundleValue);
566 _AppArg::GetCalleeAppId(void) const
568 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
570 const AppId retVal = pBundleValue;
572 return _Aul::GetRealAppId(retVal);
577 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
579 bundle* pBundle = bk;
581 const char* p = appsvc_get_data(pBundle, key);
584 pList->Add(*new (std::nothrow) String(p));
588 pList->Add(*new (std::nothrow) String(L""));
594 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
596 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
598 return AddStrArray(b, pKey.get(), pList);
603 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
605 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
607 if (pList == null || pList->GetCount() == 0)
609 SysLog(NID_APP, "No element added for bundle.");
613 _AppMessageImpl::AddValueArray(pb, key, pList);
615 _AppMessageImpl::AddData(pb, pList);
622 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
625 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
627 if (pMap == null || pMap->GetCount() == 0)
629 SysLog(NID_APP, "No element added for bundle.");
633 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
634 while(pEnum->MoveNext() == E_SUCCESS)
636 const String* pKey = static_cast<const String*>(pEnum->GetKey());
637 const Object* pObj = pEnum->GetValue();
641 if (typeid(*pObj) == typeid(const String))
643 const String* pVal = static_cast<const String*>(pEnum->GetValue());
646 _AppMessageImpl::AddData(pb, *pKey, *pVal);
649 else if (typeid(*pObj) == typeid(const ArrayList))
651 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
654 SysLog(NID_APP, "ArrayList type");
656 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
659 else if (typeid(*pObj) == typeid(const ByteBuffer))
661 SysLog(NID_APP, "ByteBuffer type");
662 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
664 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
665 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
675 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
677 if (pMap == null || pList == null)
682 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
683 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
687 while (pEnum->MoveNext() == E_SUCCESS)
689 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
692 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
696 pStr->SubString(0, index, key);
702 pStr->SubString(index + 1, value);
704 pMap->Add(new String(key), new String(value));
706 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
714 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
718 case APP_CTRL_RESULT_SUCCEEDED:
719 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
721 case APP_CTRL_RESULT_CANCELED:
722 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
724 case APP_CTRL_RESULT_TERMINATED:
725 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
727 case APP_CTRL_RESULT_ABORTED:
728 list.Add(* new (std::nothrow) String("aborted"));
730 //case APP_CTRL_RESULT_FAILED:
732 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
741 bool isPathRegistered = false;
742 // handle APP_CTRL_RESULT_SUCCEEDED only
743 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
745 while(pMapEnum->MoveNext() == E_SUCCESS)
747 String* pKey = static_cast<String*>(pMapEnum->GetKey());
750 SysLog(NID_APP, "Invalid entry.");
754 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
756 if (!isPathRegistered)
758 isPathRegistered = true;
762 SysLog(NID_APP, "Selected path key is already registered.");
767 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
770 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
772 StringTokenizer strTok(*pVal, L';');
773 if (strTok.GetTokenCount() == 0)
775 list.Add(* new (std::nothrow) String(*pVal));
780 while(strTok.HasMoreTokens())
782 strTok.GetNextToken(token);
783 list.Add(* new (std::nothrow) String(token));
784 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
795 _AppArg::GetListN(bundle* b, const char* key)
803 const char** pValArray = null;
806 pValArray = appsvc_get_data_array(b, key, &len);
807 if (len == 0 || pValArray == null)
812 ArrayList* pList = new (std::nothrow) ArrayList;
813 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
817 for (int i = 0; i < len; i++)
819 pList->Add(*new (std::nothrow) String(pValArray[i]));
827 _AppArg::CreateLaunchArg(bundle* b, const String& arg)
829 SysAssertf(b != null, "Valid bundle should be supplied");
835 const char** pSa = new (std::nothrow) const char*[1];
836 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
837 pSa[0] = _StringConverter::CopyToCharArrayN(arg);
838 bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
840 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
846 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
853 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
855 SysAssertf(b != null, "Valid bundle should be supplied");
859 AddStrArray(pb, OSP_K_ARG, pList);
861 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
868 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
870 SysAssertf(b != null, "Valid bundle should be supplied");
875 AddStrArray(pb, OSP_K_ARG, pList);
877 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
880 bundle_add(pb, OSP_K_COND, p.get());
883 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
890 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
892 SysAssertf(b != null, "Valid bundle should be supplied");
896 AddStrArray(pb, OSP_K_ARG, pList);
898 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
901 appsvc_set_operation(pb, pOperation.get());
904 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
911 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
913 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
918 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
920 SysAssertf(b != null, "Valid bundle should be supplied");
924 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
925 if (pOperation.get())
927 appsvc_set_operation(pb, pOperation.get());
932 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
935 appsvc_set_uri(pb, pUri.get());
941 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
944 appsvc_set_mime(pb, pMime.get());
950 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
958 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
961 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
962 const IList* pArgList)
964 SysAssertf(b != null, "Valid bundle should be supplied");
966 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
968 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
969 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
970 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
971 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
972 bundle_add(b, AUL_K_NO_CANCEL, "1");
974 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
977 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
980 AddStrArray(b, OSP_K_ARG, pArgList);
987 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
988 const IList* pArgList)
990 SysAssertf(b != null, "Valid bundle should be supplied");
992 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
994 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
995 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
996 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
997 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
998 bundle_add(b, AUL_K_NO_CANCEL, "1");
1000 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1003 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1006 AddStrArray(b, OSP_K_ARG, pArgList);
1013 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1015 SysAssertf(b != null, "Valid bundle should be supplied");
1019 AddStrArray(pb, OSP_K_ARG, pList);
1021 _AppMessageImpl::AddData(pb, pList);
1028 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1030 SysAssertf(b != null, "Valid bundle should be supplied");
1034 AddStrMap(pb, pMap);
1041 _AppArg::CreateBundleFromSvc(void* svc)
1043 bundle* pBundle = GetBundleFromSvc(svc);
1046 return bundle_dup(pBundle);
1054 _AppArg::GetBundleFromSvc(void* svc)
1063 DummyS* pDummy = static_cast<DummyS*>(svc);
1065 if (pDummy && pDummy->pData)
1067 return pDummy->pData;
1075 _AppArg::GetRequestId(int num)
1078 str.Format(10, L"req%05d", num);
1084 _AppArg::GetRequestId(const String& str)
1089 result r = str.SubString(3, sub);
1090 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1092 r = Integer::Parse(sub, i);
1093 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1100 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1102 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1104 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1105 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1107 int res = bundle_add(b, OSP_K_APPID, pId.get());
1108 if (res < 0 && errno == EPERM) // key exists
1110 bundle_del(b, OSP_K_APPID);
1111 bundle_add(b, OSP_K_APPID, pId.get());
1114 appsvc_set_appid(b, pId.get());
1119 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1121 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1125 //SysLog(NID_APP, "Requested ID is %d", reqId);
1129 char buffer[32] = {0, };
1130 snprintf(buffer, 32, "%d", reqId);
1131 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1132 if (res < 0 && errno == EPERM) // key exists
1134 bundle_del(pBundle, OSP_K_REQUEST_ID);
1135 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1140 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1142 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1144 char pBuffer[128] = {0, };
1145 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1146 int res = bundle_add(pBundle, pKey, pBuffer);
1147 if (res < 0 && errno == EPERM) // key exists
1149 bundle_del(pBundle, pKey);
1150 bundle_add(pBundle, pKey, pBuffer);
1156 _AppArg::UpdateSubMode(bundle* pBundle)
1158 appsvc_add_data(pBundle, OSP_K_SUBMODE_CALLEE, "1");
1163 _AppArg::IsSubMode(bundle* pBundle)
1165 const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
1166 if (p && (strncmp(p, "1", sizeof(char)) == 0))
1176 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1178 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1185 return (i < 0) ? -1 : i;
1190 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1192 appsvc_allow_transient_app(pBundle, handle);
1194 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1201 _AppArg::PrintSvcHandle(void* svc)
1203 service_h service = static_cast<service_h>(svc);
1205 if (service == null)
1210 Print(GetBundleFromSvc(service));
1215 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1223 case BUNDLE_TYPE_STR:
1224 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1227 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1231 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1238 _AppArg::Print(bundle* b)
1245 const char* p = null;
1246 p = appsvc_get_data(b, AUL_K_CALLER_PID);
1249 SysLog(NID_APP, "CallerPId[%s]", p);
1252 p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
1255 SysLog(NID_APP, "WaitResult[%s]", p);
1258 p = appsvc_get_data(b, OSP_K_COND);
1261 SysLog(NID_APP, "Condition[%s]", p);
1264 p = appsvc_get_operation(b);
1267 SysLog(NID_APP, "operation[%s]", p);
1270 p = appsvc_get_uri(b);
1273 SysLog(NID_APP, "uri[%s]", p);
1276 p = appsvc_get_mime(b);
1279 SysLog(NID_APP, "mime[%s]", p);
1282 p = appsvc_get_category(b);
1285 SysLog(NID_APP, "Category[%s]", p);
1288 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1291 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1294 for (int i = 0; i < len; i++)
1298 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);