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.
26 #include <unique_ptr.h>
31 #include <appsvc/appsvc.h>
34 #include <FBaseInteger.h>
35 #include <FBaseColArrayList.h>
36 #include <FBaseColHashMap.h>
37 #include <FBaseByteBuffer.h>
38 #include <FBaseUtilStringTokenizer.h>
39 #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"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Utility;
56 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
58 namespace Tizen { namespace App
61 static const char OSP_V_LAUNCH_TYPE_LAUNCH[] = "launch";
62 static const char OSP_V_LAUNCH_TYPE_APPCONTROL[] = "appcontrol";
63 static const char OSP_V_LAUNCH_TYPE_DATACONTROL[] = "datacontrol";
64 static const char OSP_V_LAUNCH_TYPE_CONDTION[] = "condition";
65 static const char OSP_V_REQUEST_TYPE_SQL_QUERY[] = "sql_query";
66 static const char OSP_V_REQUEST_TYPE_SQL_INSERT[] = "sql_insert";
67 static const char OSP_V_REQUEST_TYPE_SQL_UPDATE[] = "sql_update";
68 static const char OSP_V_REQUEST_TYPE_SQL_DELETE[] = "sql_delete";
69 static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
70 static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
71 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
72 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
73 static const char OSP_V_VERSION_2_1_0_3[] = "ver_2.1.0.3";
74 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
75 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
76 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
77 static const char BUNDLE_KEY_PREFIX_UG[] = "__UG_";
78 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
79 const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
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 CreateNotificationArg(__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(LEGACY_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)
362 if (strncmp(BUNDLE_KEY_PREFIX_UG, pKey, strlen(BUNDLE_KEY_PREFIX_UG)) == 0)
371 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
373 HashMap* pMap = static_cast<HashMap*>(pData);
375 if (pKey && pVal && pMap)
377 if (IsInternalKey(pKey))
379 //SysLog(NID_APP, "(%s)", pKey);
387 case BUNDLE_TYPE_STR:
388 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
391 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
394 case BUNDLE_TYPE_STR_ARRAY:
397 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
398 if (pArr && size > 0)
400 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
405 for (size_t i = 0; i < size; i++)
407 // type unsafe ugly static casting required
408 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
411 const int count = pList->GetCount();
414 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
415 pMap->Add(new (std::nothrow) String(pKey), pList);
419 SysLog(NID_APP, "No object for %s", pKey);
426 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
430 case BUNDLE_TYPE_BYTE:
431 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
433 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
437 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
438 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
439 result r = pBuffer->Construct(size);
440 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
442 r = pBuffer->SetArray((const byte*)pStr, 0, size);
443 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
447 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
451 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
458 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
460 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
466 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
468 // actual argument below
470 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
473 for (int i = 0; i < len; i++)
477 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
478 pList->Add(*new (std::nothrow) String(pa[i]));
483 const char* p = appsvc_get_uri(pBundle);
486 pList->Add(*new (std::nothrow) String(p));
487 SysLog(NID_APP, "argument is %s", p);
495 _AppArg::GetValue(const char* key) const
497 const char* p = appsvc_get_data(__pBundle, key);
503 _AppArg::GetHandler(bundle* b)
505 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
507 const char* p = null;
509 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
513 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
515 return _APP_HANDLER_DATACONTROL;
518 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
520 SysLog(NID_APP, "Building AppControl arguments.");
522 return _APP_HANDLER_APPCONTROL;
526 // not appcontrol nor datacontrol => normal launch or condlaunch
527 p = appsvc_get_data(b, OSP_K_COND);
530 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
531 return _APP_HANDLER_LAUNCH_COND;
535 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
536 return _APP_HANDLER_LAUNCH_NORMAL;
542 return _APP_HANDLER_APPCONTROL;
547 _AppArg::GetCallerPid(bundle* pBundle)
549 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
550 if (pBundleValue == NULL)
552 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
555 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
557 return atoi(pBundleValue);
562 _AppArg::GetCallerAppId(void) const
564 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
566 return String(pBundleValue);
571 _AppArg::GetCalleeAppId(void) const
573 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
575 const AppId retVal = pBundleValue;
577 return _Aul::GetRealAppId(retVal);
582 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
584 bundle* pBundle = bk;
586 const char* p = appsvc_get_data(pBundle, key);
589 pList->Add(*new (std::nothrow) String(p));
593 pList->Add(*new (std::nothrow) String(L""));
599 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
601 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
603 return AddStrArray(b, pKey.get(), pList);
608 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
610 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
612 if (pList == null || pList->GetCount() == 0)
614 SysLog(NID_APP, "No element added for bundle.");
618 _AppMessageImpl::AddValueArray(pb, key, pList);
620 _AppMessageImpl::AddData(pb, pList);
627 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
630 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
632 if (pMap == null || pMap->GetCount() == 0)
634 SysLog(NID_APP, "No element added for bundle.");
638 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
639 while(pEnum->MoveNext() == E_SUCCESS)
641 const String* pKey = static_cast<const String*>(pEnum->GetKey());
642 const Object* pObj = pEnum->GetValue();
646 if (typeid(*pObj) == typeid(const String))
648 const String* pVal = static_cast<const String*>(pEnum->GetValue());
651 _AppMessageImpl::AddData(pb, *pKey, *pVal);
654 else if (typeid(*pObj) == typeid(const ArrayList))
656 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
659 SysLog(NID_APP, "ArrayList type");
661 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
664 else if (typeid(*pObj) == typeid(const ByteBuffer))
666 SysLog(NID_APP, "ByteBuffer type");
667 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
669 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
670 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
680 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
682 if (pMap == null || pList == null)
687 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
688 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
692 while (pEnum->MoveNext() == E_SUCCESS)
694 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
697 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
701 pStr->SubString(0, index, key);
707 pStr->SubString(index + 1, value);
709 pMap->Add(new String(key), new String(value));
711 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
719 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
723 case APP_CTRL_RESULT_SUCCEEDED:
724 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
726 case APP_CTRL_RESULT_CANCELED:
727 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
729 case APP_CTRL_RESULT_TERMINATED:
730 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
732 case APP_CTRL_RESULT_ABORTED:
733 list.Add(* new (std::nothrow) String("aborted"));
735 //case APP_CTRL_RESULT_FAILED:
737 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
746 bool isPathRegistered = false;
747 // handle APP_CTRL_RESULT_SUCCEEDED only
748 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
750 while(pMapEnum->MoveNext() == E_SUCCESS)
752 String* pKey = static_cast<String*>(pMapEnum->GetKey());
755 SysLog(NID_APP, "Invalid entry.");
759 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
761 if (!isPathRegistered)
763 isPathRegistered = true;
767 SysLog(NID_APP, "Selected path key is already registered.");
772 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
775 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
777 StringTokenizer strTok(*pVal, L';');
778 if (strTok.GetTokenCount() == 0)
780 list.Add(* new (std::nothrow) String(*pVal));
785 while(strTok.HasMoreTokens())
787 strTok.GetNextToken(token);
788 list.Add(* new (std::nothrow) String(token));
789 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
800 _AppArg::GetListN(bundle* b, const char* key)
808 const char** pValArray = null;
811 pValArray = appsvc_get_data_array(b, key, &len);
812 if (len == 0 || pValArray == null)
817 ArrayList* pList = new (std::nothrow) ArrayList;
818 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
822 for (int i = 0; i < len; i++)
824 pList->Add(*new (std::nothrow) String(pValArray[i]));
832 _AppArg::CreateNotificationArg(bundle* b, const String& arg)
834 SysAssertf(b != null, "Valid bundle should be supplied");
840 std::unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(arg));
841 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pStr.get());
844 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
851 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
853 SysAssertf(b != null, "Valid bundle should be supplied");
857 AddStrArray(pb, OSP_K_ARG, pList);
859 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
866 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
868 SysAssertf(b != null, "Valid bundle should be supplied");
873 AddStrArray(pb, OSP_K_ARG, pList);
875 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
878 bundle_add(pb, OSP_K_COND, p.get());
881 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
888 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
890 SysAssertf(b != null, "Valid bundle should be supplied");
894 AddStrArray(pb, OSP_K_ARG, pList);
896 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
899 appsvc_set_operation(pb, pOperation.get());
902 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
909 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
911 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
916 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
918 SysAssertf(b != null, "Valid bundle should be supplied");
922 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
923 if (pOperation.get())
925 appsvc_set_operation(pb, pOperation.get());
930 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
933 appsvc_set_uri(pb, pUri.get());
939 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
942 appsvc_set_mime(pb, pMime.get());
948 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
956 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
959 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
960 const IList* pArgList)
962 SysAssertf(b != null, "Valid bundle should be supplied");
964 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
966 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
967 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
968 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
969 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
970 bundle_add(b, AUL_K_NO_CANCEL, "1");
972 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
975 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
978 AddStrArray(b, OSP_K_ARG, pArgList);
985 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
986 const IList* pArgList)
988 SysAssertf(b != null, "Valid bundle should be supplied");
990 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
992 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
993 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
994 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
995 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
996 bundle_add(b, AUL_K_NO_CANCEL, "1");
998 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1001 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1004 AddStrArray(b, OSP_K_ARG, pArgList);
1011 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1013 SysAssertf(b != null, "Valid bundle should be supplied");
1017 AddStrArray(pb, OSP_K_ARG, pList);
1019 _AppMessageImpl::AddData(pb, pList);
1026 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1028 SysAssertf(b != null, "Valid bundle should be supplied");
1032 AddStrMap(pb, pMap);
1039 _AppArg::CreateBundleFromSvc(void* svc)
1041 bundle* pBundle = GetBundleFromSvc(svc);
1044 return bundle_dup(pBundle);
1052 _AppArg::GetBundleFromSvc(void* svc)
1054 bundle* pBundle = NULL;
1055 int ret = service_to_bundle(static_cast<service_h>(svc), &pBundle);
1057 return (ret == SERVICE_ERROR_NONE) ? pBundle : NULL;
1062 _AppArg::GetRequestId(int num)
1065 str.Format(10, L"req%05d", num);
1071 _AppArg::GetRequestId(const String& str)
1076 result r = str.SubString(3, sub);
1077 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1079 r = Integer::Parse(sub, i);
1080 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1087 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1089 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1091 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1092 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1094 int res = bundle_add(b, OSP_K_APPID, pId.get());
1095 if (res < 0 && errno == EPERM) // key exists
1097 bundle_del(b, OSP_K_APPID);
1098 bundle_add(b, OSP_K_APPID, pId.get());
1101 appsvc_set_appid(b, pId.get());
1106 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1108 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1112 //SysLog(NID_APP, "Requested ID is %d", reqId);
1116 char buffer[32] = {0, };
1117 snprintf(buffer, 32, "%d", reqId);
1118 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1119 if (res < 0 && errno == EPERM) // key exists
1121 bundle_del(pBundle, OSP_K_REQUEST_ID);
1122 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1127 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1129 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1131 char pBuffer[128] = {0, };
1132 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1133 int res = bundle_add(pBundle, pKey, pBuffer);
1134 if (res < 0 && errno == EPERM) // key exists
1136 bundle_del(pBundle, pKey);
1137 bundle_add(pBundle, pKey, pBuffer);
1143 _AppArg::UpdateSubMode(bundle* pBundle)
1145 appsvc_add_data(pBundle, OSP_K_SUBMODE_CALLEE, "1");
1150 _AppArg::IsSubMode(bundle* pBundle)
1152 const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
1153 if (p && (strncmp(p, "1", sizeof(char)) == 0))
1163 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1165 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1172 return (i < 0) ? -1 : i;
1177 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1179 appsvc_allow_transient_app(pBundle, handle);
1181 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1188 _AppArg::PrintSvcHandle(void* svc)
1190 service_h service = static_cast<service_h>(svc);
1192 if (service == null)
1197 Print(GetBundleFromSvc(service));
1202 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1210 case BUNDLE_TYPE_STR:
1211 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1214 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1218 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1225 _AppArg::Print(bundle* b)
1232 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1235 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1238 for (int i = 0; i < len; i++)
1242 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);