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";
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 static const char BUNDLE_KEY_PREFIX_UG[] = "__UG_";
80 static const char OSP_K_SUBMODE_CALLEE[] = "__OSP_SUB_CALLEE__";
81 static const char OSP_K_SERVICE_CALLEE[] = "__OSP_SERVICE_CALLEE__";
83 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
84 const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
87 _AppArg::_AppArg(void)
93 _AppArg::~_AppArg(void)
97 bundle_free(__pBundle);
103 _AppArg::Construct(const String& argText)
105 __pBundle = bundle_create();
106 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
108 return CreateNotificationArg(__pBundle, argText);
113 _AppArg::Construct(const IList* pList)
115 __pBundle = bundle_create();
116 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
118 return CreateLaunchArg(__pBundle, pList);
123 _AppArg::Construct(const _AppControlImpl& ac, const IList* pList)
125 __pBundle = bundle_create();
126 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
128 return CreateAppControlArg(__pBundle, ac, pList);
133 _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String* pMime, const IMap* pList)
135 __pBundle = bundle_create();
136 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
138 return CreateAppControlArg(__pBundle, ac, pUri, pMime, pList);
143 _AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
145 __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
146 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
148 return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
153 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
155 __pBundle = bundle_create();
156 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
158 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
163 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
165 __pBundle = bundle_create();
166 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
168 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
173 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
175 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
176 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
178 return CreateResultArg(__pBundle, pList);
183 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
185 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
186 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
188 return CreateResultArg(__pBundle, pMap);
193 _AppArg::Construct(bundle* b)
195 __pBundle = bundle_dup(b);
196 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
203 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
205 __pBundle = bundle_create();
206 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
208 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
212 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
214 __pBundle = bundle_create();
215 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
217 CreateAppLaunchConditionArg(__pBundle, condition, pList);
219 return CreateResultArg(__pBundle, pMap);
223 _AppArg::GetArgListN(int num) const
225 bundle* pBundle = __pBundle;
226 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
228 ArrayList* pList = new (std::nothrow) ArrayList();
229 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
233 const char* p = NULL;
234 _AppHandler launch_type = GetHandler(pBundle);
238 case _APP_HANDLER_APPCONTROL:
240 // [FIXME] proper request Id required
241 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
244 p = appsvc_get_category(pBundle);
247 pList->Add(*new (std::nothrow) String(p));
251 pList->Add(*new (std::nothrow) String(L""));
255 p = appsvc_get_mime(pBundle);
258 pList->Add(*new (std::nothrow) String(p));
262 pList->Add(*new (std::nothrow) String(L""));
266 p = appsvc_get_uri(pBundle);
269 pList->Add(*new (std::nothrow) String(p));
273 pList->Add(*new (std::nothrow) String(L""));
278 case _APP_HANDLER_DATACONTROL:
280 AddListFromBundle(pList, pBundle, OSP_K_APPID);
282 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
284 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
286 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
289 case _APP_HANDLER_LAUNCH_COND:
290 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
291 AddListFromBundle(pList, pBundle, OSP_K_COND);
294 case _APP_HANDLER_LAUNCH_NORMAL:
295 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
296 pList->Add(*new (std::nothrow) String(LEGACY_OPERATION_MAIN));
300 SysLog(NID_APP, "Invalid handler type");
304 SetArgList(__pBundle, pList);
311 _AppArg::GetArgListN(void) const
313 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
315 ArrayList* pList = new (std::nothrow) ArrayList();
316 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
320 SetArgList(__pBundle, pList);
325 // the returned map is allocated using SingleObjectDeleter
327 _AppArg::GetArgMapN(void) const
329 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
333 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
334 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
336 pHashMap->Construct();
338 SetArgMap(__pBundle, pHashMap);
340 if (pHashMap->GetCount() == 0)
350 IsInternalKey(const char* pKey)
352 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
357 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
362 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
367 if (strncmp(BUNDLE_KEY_PREFIX_UG, pKey, strlen(BUNDLE_KEY_PREFIX_UG)) == 0)
376 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
378 HashMap* pMap = static_cast<HashMap*>(pData);
380 if (pKey && pVal && pMap)
382 if (IsInternalKey(pKey))
384 //SysLog(NID_APP, "(%s)", pKey);
392 case BUNDLE_TYPE_STR:
393 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
396 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
399 case BUNDLE_TYPE_STR_ARRAY:
402 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
403 if (pArr && size > 0)
405 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
410 for (size_t i = 0; i < size; i++)
412 // type unsafe ugly static casting required
413 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
416 const int count = pList->GetCount();
419 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
420 pMap->Add(new (std::nothrow) String(pKey), pList);
424 SysLog(NID_APP, "No object for %s", pKey);
431 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
435 case BUNDLE_TYPE_BYTE:
436 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
438 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
442 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
443 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
444 result r = pBuffer->Construct(size);
445 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
447 r = pBuffer->SetArray((const byte*)pStr, 0, size);
448 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
452 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
456 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
463 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
465 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
471 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
473 // actual argument below
475 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
478 for (int i = 0; i < len; i++)
482 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
483 pList->Add(*new (std::nothrow) String(pa[i]));
488 const char* p = appsvc_get_uri(pBundle);
491 pList->Add(*new (std::nothrow) String(p));
492 SysLog(NID_APP, "argument is %s", p);
500 _AppArg::GetValue(const char* key) const
502 const char* p = appsvc_get_data(__pBundle, key);
508 _AppArg::GetHandler(bundle* b)
510 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
512 const char* p = null;
514 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
518 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
520 return _APP_HANDLER_DATACONTROL;
523 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
525 SysLog(NID_APP, "Building AppControl arguments.");
527 return _APP_HANDLER_APPCONTROL;
531 // not appcontrol nor datacontrol => normal launch or condlaunch
532 p = appsvc_get_data(b, OSP_K_COND);
535 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
536 return _APP_HANDLER_LAUNCH_COND;
540 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
541 return _APP_HANDLER_LAUNCH_NORMAL;
547 return _APP_HANDLER_APPCONTROL;
552 _AppArg::GetCallerPid(bundle* pBundle)
554 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
555 if (pBundleValue == NULL)
557 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
560 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
562 return atoi(pBundleValue);
567 _AppArg::GetCallerAppId(void) const
569 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
571 return String(pBundleValue);
576 _AppArg::GetCalleeAppId(void) const
578 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
580 const AppId retVal = pBundleValue;
582 return _Aul::GetRealAppId(retVal);
587 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
589 bundle* pBundle = bk;
591 const char* p = appsvc_get_data(pBundle, key);
594 pList->Add(*new (std::nothrow) String(p));
598 pList->Add(*new (std::nothrow) String(L""));
604 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
606 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
608 return AddStrArray(b, pKey.get(), pList);
613 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
615 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
617 if (pList == null || pList->GetCount() == 0)
619 SysLog(NID_APP, "No element added for bundle.");
623 _AppMessageImpl::AddValueArray(pb, key, pList);
625 _AppMessageImpl::AddData(pb, pList);
632 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
635 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
637 if (pMap == null || pMap->GetCount() == 0)
639 SysLog(NID_APP, "No element added for bundle.");
643 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
644 while(pEnum->MoveNext() == E_SUCCESS)
646 const String* pKey = static_cast<const String*>(pEnum->GetKey());
647 const Object* pObj = pEnum->GetValue();
651 if (typeid(*pObj) == typeid(const String))
653 const String* pVal = static_cast<const String*>(pEnum->GetValue());
656 _AppMessageImpl::AddData(pb, *pKey, *pVal);
659 else if (typeid(*pObj) == typeid(const ArrayList))
661 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
664 SysLog(NID_APP, "ArrayList type");
666 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
669 else if (typeid(*pObj) == typeid(const ByteBuffer))
671 SysLog(NID_APP, "ByteBuffer type");
672 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
674 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
675 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
685 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
687 if (pMap == null || pList == null)
692 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
693 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
697 while (pEnum->MoveNext() == E_SUCCESS)
699 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
702 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
706 pStr->SubString(0, index, key);
712 pStr->SubString(index + 1, value);
714 pMap->Add(new String(key), new String(value));
716 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
724 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
728 case APP_CTRL_RESULT_SUCCEEDED:
729 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
731 case APP_CTRL_RESULT_CANCELED:
732 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
734 case APP_CTRL_RESULT_TERMINATED:
735 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
737 case APP_CTRL_RESULT_ABORTED:
738 list.Add(* new (std::nothrow) String("aborted"));
740 //case APP_CTRL_RESULT_FAILED:
742 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
751 bool isPathRegistered = false;
752 // handle APP_CTRL_RESULT_SUCCEEDED only
753 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
755 while(pMapEnum->MoveNext() == E_SUCCESS)
757 String* pKey = static_cast<String*>(pMapEnum->GetKey());
760 SysLog(NID_APP, "Invalid entry.");
764 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
766 if (!isPathRegistered)
768 isPathRegistered = true;
772 SysLog(NID_APP, "Selected path key is already registered.");
777 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
780 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
782 StringTokenizer strTok(*pVal, L';');
783 if (strTok.GetTokenCount() == 0)
785 list.Add(* new (std::nothrow) String(*pVal));
790 while(strTok.HasMoreTokens())
792 strTok.GetNextToken(token);
793 list.Add(* new (std::nothrow) String(token));
794 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
805 _AppArg::GetListN(bundle* b, const char* key)
813 const char** pValArray = null;
816 pValArray = appsvc_get_data_array(b, key, &len);
817 if (len == 0 || pValArray == null)
822 ArrayList* pList = new (std::nothrow) ArrayList;
823 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
827 for (int i = 0; i < len; i++)
829 pList->Add(*new (std::nothrow) String(pValArray[i]));
837 _AppArg::CreateNotificationArg(bundle* b, const String& arg)
839 SysAssertf(b != null, "Valid bundle should be supplied");
845 std::unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(arg));
846 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pStr.get());
849 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
856 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
858 SysAssertf(b != null, "Valid bundle should be supplied");
862 AddStrArray(pb, OSP_K_ARG, pList);
864 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
871 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
873 SysAssertf(b != null, "Valid bundle should be supplied");
878 AddStrArray(pb, OSP_K_ARG, pList);
880 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
883 bundle_add(pb, OSP_K_COND, p.get());
886 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
893 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList* pList)
895 SysAssertf(b != null, "Valid bundle should be supplied");
899 AddStrArray(pb, OSP_K_ARG, pList);
901 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
904 appsvc_set_operation(pb, pOperation.get());
907 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
914 _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
916 return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
921 _AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
923 SysAssertf(b != null, "Valid bundle should be supplied");
927 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
928 if (pOperation.get())
930 appsvc_set_operation(pb, pOperation.get());
935 std::unique_ptr<char[]> pUri(_StringConverter::CopyToCharArrayN(*pUriData));
938 appsvc_set_uri(pb, pUri.get());
944 std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(*pMimeType));
947 appsvc_set_mime(pb, pMime.get());
953 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
961 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
964 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
965 const IList* pArgList)
967 SysAssertf(b != null, "Valid bundle should be supplied");
969 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
971 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
972 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
973 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
974 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
975 bundle_add(b, AUL_K_NO_CANCEL, "1");
977 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
980 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
983 AddStrArray(b, OSP_K_ARG, pArgList);
990 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
991 const IList* pArgList)
993 SysAssertf(b != null, "Valid bundle should be supplied");
995 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
997 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
998 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
999 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
1000 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
1001 bundle_add(b, AUL_K_NO_CANCEL, "1");
1003 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
1006 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
1009 AddStrArray(b, OSP_K_ARG, pArgList);
1016 _AppArg::CreateResultArg(bundle* b, const IList* pList)
1018 SysAssertf(b != null, "Valid bundle should be supplied");
1022 AddStrArray(pb, OSP_K_ARG, pList);
1024 _AppMessageImpl::AddData(pb, pList);
1031 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
1033 SysAssertf(b != null, "Valid bundle should be supplied");
1037 AddStrMap(pb, pMap);
1044 _AppArg::CreateBundleFromSvc(void* svc)
1046 bundle* pBundle = GetBundleFromSvc(svc);
1049 return bundle_dup(pBundle);
1057 _AppArg::GetBundleFromSvc(void* svc)
1059 bundle* pBundle = NULL;
1060 int ret = service_to_bundle(static_cast<service_h>(svc), &pBundle);
1062 return (ret == SERVICE_ERROR_NONE) ? pBundle : NULL;
1067 _AppArg::GetRequestId(int num)
1070 str.Format(10, L"req%05d", num);
1076 _AppArg::GetRequestId(const String& str)
1081 result r = str.SubString(3, sub);
1082 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1084 r = Integer::Parse(sub, i);
1085 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
1092 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
1094 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1096 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
1097 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
1099 int res = bundle_add(b, OSP_K_APPID, pId.get());
1100 if (res < 0 && errno == EPERM) // key exists
1102 bundle_del(b, OSP_K_APPID);
1103 bundle_add(b, OSP_K_APPID, pId.get());
1106 appsvc_set_appid(b, pId.get());
1111 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1113 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1117 //SysLog(NID_APP, "Requested ID is %d", reqId);
1121 char buffer[32] = {0, };
1122 snprintf(buffer, 32, "%d", reqId);
1123 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1124 if (res < 0 && errno == EPERM) // key exists
1126 bundle_del(pBundle, OSP_K_REQUEST_ID);
1127 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1132 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1134 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1136 char pBuffer[128] = {0, };
1137 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1138 int res = bundle_add(pBundle, pKey, pBuffer);
1139 if (res < 0 && errno == EPERM) // key exists
1141 bundle_del(pBundle, pKey);
1142 bundle_add(pBundle, pKey, pBuffer);
1148 _AppArg::UpdateSubMode(bundle* pBundle)
1150 appsvc_add_data(pBundle, OSP_K_SUBMODE_CALLEE, "1");
1155 _AppArg::IsSubMode(bundle* pBundle)
1157 const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
1158 return (p && (strncmp(p, "1", sizeof(char)) == 0));
1163 _AppArg::UpdateServiceApp(bundle* pBundle)
1165 appsvc_add_data(pBundle, OSP_K_SERVICE_CALLEE, "1");
1170 _AppArg::IsServiceApp(bundle* pBundle)
1172 const char* p = appsvc_get_data(pBundle, OSP_K_SERVICE_CALLEE);
1173 return (p && (strncmp(p, "1", sizeof(char)) == 0));
1178 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1180 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1187 return (i < 0) ? -1 : i;
1192 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1194 appsvc_allow_transient_app(pBundle, handle);
1196 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1203 _AppArg::PrintSvcHandle(void* svc)
1205 service_h service = static_cast<service_h>(svc);
1207 if (service == null)
1212 Print(GetBundleFromSvc(service));
1217 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1225 case BUNDLE_TYPE_STR:
1226 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1229 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1233 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1240 _AppArg::Print(bundle* b)
1247 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1250 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1253 for (int i = 0; i < len; i++)
1257 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);