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_RAISE_MODE[] = "__OSP_RAISE_MODE__";
83 _AppArg::_AppArg(void)
89 _AppArg::~_AppArg(void)
93 bundle_free(__pBundle);
99 _AppArg::Construct(const String& argText)
101 __pBundle = bundle_create();
102 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
104 return CreateNotificationArg(__pBundle, argText);
109 _AppArg::Construct(const IList* pList)
111 __pBundle = bundle_create();
112 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
114 return CreateLaunchArg(__pBundle, pList);
119 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
121 __pBundle = bundle_create();
122 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
124 return CreateSqlDataControlArg(__pBundle, dc, requestType, pList);
129 _AppArg::Construct(const _MapDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
131 __pBundle = bundle_create();
132 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
134 return CreateMapDataControlArg(__pBundle, dc, requestType, pList);
139 _AppArg::ConstructResult(const _AppArg& arg, const IList* pList)
141 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
142 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
144 return CreateResultArg(__pBundle, pList);
149 _AppArg::ConstructResult(const _AppArg& arg, const IMap* pMap)
151 int ret = aul_create_result_bundle(arg.GetBundle(), &__pBundle);
152 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure : %d.", ret);
154 return CreateResultArg(__pBundle, pMap);
159 _AppArg::Construct(const bundle* b)
161 __pBundle = bundle_dup(const_cast<bundle*>(b));
162 SysTryReturnResult(NID_APP, __pBundle != null, E_INVALID_STATE, "Bundle creatioin from service handle failure.");
169 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList)
171 __pBundle = bundle_create();
172 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
174 return CreateAppLaunchConditionArg(__pBundle, condition, pList);
178 _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
180 __pBundle = bundle_create();
181 SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
183 CreateAppLaunchConditionArg(__pBundle, condition, pList);
185 return CreateResultArg(__pBundle, pMap);
189 _AppArg::GetArgListN(int num) const
191 bundle* pBundle = __pBundle;
192 SysTryReturn(NID_APP, pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
194 ArrayList* pList = new (std::nothrow) ArrayList();
195 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
199 const char* p = NULL;
200 _AppHandler launch_type = GetHandler(pBundle);
204 case _APP_HANDLER_APPCONTROL:
206 // [FIXME] proper request Id required
207 pList->Add(*new (std::nothrow) String(GetRequestId(num)));
210 p = appsvc_get_category(pBundle);
213 pList->Add(*new (std::nothrow) String(p));
217 pList->Add(*new (std::nothrow) String(L""));
221 p = appsvc_get_mime(pBundle);
224 pList->Add(*new (std::nothrow) String(p));
228 pList->Add(*new (std::nothrow) String(L""));
232 p = appsvc_get_uri(pBundle);
235 pList->Add(*new (std::nothrow) String(p));
239 pList->Add(*new (std::nothrow) String(L""));
244 case _APP_HANDLER_DATACONTROL:
246 AddListFromBundle(pList, pBundle, OSP_K_APPID);
248 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
250 AddListFromBundle(pList, pBundle, OSP_K_REQUEST_ID);
252 AddListFromBundle(pList, pBundle, OSP_K_DATACONTROL_PROVIDER);
255 case _APP_HANDLER_LAUNCH_COND:
256 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_CONDITIONAL));
257 AddListFromBundle(pList, pBundle, OSP_K_COND);
260 case _APP_HANDLER_LAUNCH_NORMAL:
261 pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
262 pList->Add(*new (std::nothrow) String(LEGACY_OPERATION_MAIN));
266 SysLog(NID_APP, "Invalid handler type");
270 SetArgList(__pBundle, pList);
277 _AppArg::GetArgListN(void) const
279 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
281 ArrayList* pList = new (std::nothrow) ArrayList();
282 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
286 SetArgList(__pBundle, pList);
291 // the returned map is allocated using SingleObjectDeleter
293 _AppArg::GetArgMapN(void) const
295 SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
299 HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
300 SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
302 pHashMap->Construct();
304 SetArgMap(__pBundle, pHashMap);
306 if (pHashMap->GetCount() == 0)
316 IsInternalKey(const char* pKey)
318 if (strncmp(BUNDLE_KEY_PREFIX_AUL, pKey, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
323 if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, pKey, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
328 if (strncmp(BUNDLE_KEY_PREFIX_OSP, pKey, strlen(BUNDLE_KEY_PREFIX_OSP)) == 0)
333 if (strncmp(BUNDLE_KEY_PREFIX_UG, pKey, strlen(BUNDLE_KEY_PREFIX_UG)) == 0)
342 BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
344 HashMap* pMap = static_cast<HashMap*>(pData);
346 if (pKey && pVal && pMap)
348 if (IsInternalKey(pKey))
350 //SysLog(NID_APP, "(%s)", pKey);
358 case BUNDLE_TYPE_STR:
359 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
362 pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
365 case BUNDLE_TYPE_STR_ARRAY:
368 bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
369 if (pArr && size > 0)
371 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
376 for (size_t i = 0; i < size; i++)
378 // type unsafe ugly static casting required
379 pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
382 const int count = pList->GetCount();
385 SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
386 pMap->Add(new (std::nothrow) String(pKey), pList);
390 SysLog(NID_APP, "No object for %s", pKey);
397 SysLog(NID_APP, "No entry for str array %s(%d)", pKey, size);
401 case BUNDLE_TYPE_BYTE:
402 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
404 SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
408 ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
409 SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
410 result r = pBuffer->Construct(size);
411 SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
413 r = pBuffer->SetArray((const byte*)pStr, 0, size);
414 SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
418 pMap->Add(new (std::nothrow) String(pKey), pBuffer);
422 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
429 _AppArg::SetArgMap(bundle* pBundle, HashMap* pMap)
431 bundle_foreach(pBundle, BundleIterFnCb, reinterpret_cast<void*>(pMap));
437 _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
439 // actual argument below
441 const char** pa = appsvc_get_data_array(pBundle, OSP_K_ARG, &len);
444 for (int i = 0; i < len; i++)
448 //SysLog(NID_APP, "%d/%dth arg [%s]", i, len, pa[i]);
449 pList->Add(*new (std::nothrow) String(pa[i]));
454 const char* p = appsvc_get_uri(pBundle);
457 pList->Add(*new (std::nothrow) String(p));
458 SysLog(NID_APP, "argument is %s", p);
466 _AppArg::GetValue(const char* key) const
468 const char* p = appsvc_get_data(__pBundle, key);
474 _AppArg::GetHandler(bundle* b)
476 SysTryReturn(NID_APP, b != null, _APP_HANDLER_NONE, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
478 const char* p = null;
480 p = appsvc_get_data(b, OSP_K_LAUNCH_TYPE);
484 if (strcmp(p, OSP_V_LAUNCH_TYPE_DATACONTROL) == 0)
486 return _APP_HANDLER_DATACONTROL;
489 if (strcmp(p, OSP_V_LAUNCH_TYPE_APPCONTROL) == 0)
491 SysLog(NID_APP, "Building AppControl arguments.");
493 return _APP_HANDLER_APPCONTROL;
497 // not appcontrol nor datacontrol => normal launch or condlaunch
498 p = appsvc_get_data(b, OSP_K_COND);
501 SysLog(NID_APP, "Building Conditional AppLaunch arguments.");
502 return _APP_HANDLER_LAUNCH_COND;
506 SysLog(NID_APP, "Building Normal AppLaunch arguments.");
507 return _APP_HANDLER_LAUNCH_NORMAL;
513 return _APP_HANDLER_APPCONTROL;
518 _AppArg::GetCallerPid(bundle* pBundle)
520 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_ORG_CALLER_PID);
521 if (pBundleValue == NULL)
523 pBundleValue = bundle_get_val(pBundle, AUL_K_CALLER_PID);
526 SysTryReturn(NID_APP, pBundleValue != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
528 return atoi(pBundleValue);
533 _AppArg::GetCallerAppId(void) const
535 const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
537 return String(pBundleValue);
542 _AppArg::GetCalleeAppId(bundle* pBundle)
544 const char* pBundleValue = bundle_get_val(pBundle, AUL_K_CALLEE_APPID);
546 const AppId retVal = pBundleValue;
548 return _Aul::GetRealAppId(retVal);
553 _AppArg::AddListFromBundle(ArrayList* pList, bundle* bk, const char* key)
555 bundle* pBundle = bk;
557 const char* p = appsvc_get_data(pBundle, key);
560 pList->Add(*new (std::nothrow) String(p));
564 pList->Add(*new (std::nothrow) String(L""));
570 _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
572 std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(key));
574 return AddStrArray(b, pKey.get(), pList);
579 _AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
581 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
583 if (pList == null || pList->GetCount() == 0)
585 SysLog(NID_APP, "No element added for bundle.");
589 _AppMessageImpl::AddValueArray(pb, key, pList);
591 _AppMessageImpl::AddData(pb, pList);
598 _AppArg::AddStrMap(bundle* b, const IMap* pMap)
601 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
603 if (pMap == null || pMap->GetCount() == 0)
605 SysLog(NID_APP, "No element added for bundle.");
609 std::unique_ptr<IMapEnumerator> pEnum (pMap->GetMapEnumeratorN());
610 while(pEnum->MoveNext() == E_SUCCESS)
612 const String* pKey = static_cast<const String*>(pEnum->GetKey());
613 const Object* pObj = pEnum->GetValue();
617 if (typeid(*pObj) == typeid(const String))
619 const String* pVal = static_cast<const String*>(pEnum->GetValue());
622 _AppMessageImpl::AddData(pb, *pKey, *pVal);
625 else if (typeid(*pObj) == typeid(const ArrayList))
627 const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
630 SysLog(NID_APP, "ArrayList type");
632 _AppMessageImpl::AddValueArray(pb, *pKey, pList);
635 else if (typeid(*pObj) == typeid(const ByteBuffer))
637 SysLog(NID_APP, "ByteBuffer type");
638 const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
640 std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
641 bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
651 _AppArg::FillMapFromList(IMap* pMap, const IList* pList)
653 if (pMap == null || pList == null)
658 std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
659 SysTryReturnResult(NID_APP, pEnum != null, E_OUT_OF_MEMORY, "Getting enumerator failed.");
663 while (pEnum->MoveNext() == E_SUCCESS)
665 String* pStr = dynamic_cast<String*>(pEnum->GetCurrent());
668 if (pStr == null || pStr->IndexOf(L':', 0, index) != E_SUCCESS)
672 pStr->SubString(0, index, key);
678 pStr->SubString(index + 1, value);
680 pMap->Add(new String(key), new String(value));
682 SysLog(NID_APP, "Added (%ls, %ls).", key.GetPointer(), value.GetPointer());
690 _AppArg::FillLegacyAppControlResult(IList& list, int res, const IMap* pArgs, const Tizen::Base::String& aId)
694 case APP_CTRL_RESULT_SUCCEEDED:
695 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED));
697 case APP_CTRL_RESULT_CANCELED:
698 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_CANCELED));
700 case APP_CTRL_RESULT_TERMINATED:
701 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_TERMINATED));
703 case APP_CTRL_RESULT_ABORTED:
704 list.Add(* new (std::nothrow) String("aborted"));
706 //case APP_CTRL_RESULT_FAILED:
708 list.Add(* new (std::nothrow) String(APPCONTROL_RESULT_FAILED));
717 bool isPathRegistered = false;
718 // handle APP_CTRL_RESULT_SUCCEEDED only
719 std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
721 while(pMapEnum->MoveNext() == E_SUCCESS)
723 String* pKey = static_cast<String*>(pMapEnum->GetKey());
726 SysLog(NID_APP, "Invalid entry.");
730 if (*pKey == L"path" || *pKey == L"http://tizen.org/appcontrol/data/selected")
732 if (!isPathRegistered)
734 isPathRegistered = true;
738 SysLog(NID_APP, "Selected path key is already registered.");
743 String* pVal = dynamic_cast<String*>(pMapEnum->GetValue());
746 SysLog(NID_APP, "Adding value (%ls).", pVal->GetPointer());
748 StringTokenizer strTok(*pVal, L';');
749 if (strTok.GetTokenCount() == 0)
751 list.Add(* new (std::nothrow) String(*pVal));
756 while(strTok.HasMoreTokens())
758 strTok.GetNextToken(token);
759 list.Add(* new (std::nothrow) String(token));
760 SysLog(NID_APP, "Adding tokenized value (%ls).", token.GetPointer());
771 _AppArg::GetListN(bundle* b, const char* key)
779 const char** pValArray = null;
782 pValArray = appsvc_get_data_array(b, key, &len);
783 if (len == 0 || pValArray == null)
788 ArrayList* pList = new (std::nothrow) ArrayList;
789 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
793 for (int i = 0; i < len; i++)
795 pList->Add(*new (std::nothrow) String(pValArray[i]));
803 _AppArg::CreateNotificationArg(bundle* b, const String& arg)
805 SysAssertf(b != null, "Valid bundle should be supplied");
811 std::unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(arg));
812 bundle_add(pb, TIZEN_NOTIFICATION_DATA, pStr.get());
815 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
822 _AppArg::CreateLaunchArg(bundle* b, const IList* pList)
824 SysAssertf(b != null, "Valid bundle should be supplied");
828 AddStrArray(pb, OSP_K_ARG, pList);
830 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
837 _AppArg::CreateAppLaunchConditionArg(bundle* b, const String& condition, const IList* pList)
839 SysAssertf(b != null, "Valid bundle should be supplied");
844 AddStrArray(pb, OSP_K_ARG, pList);
846 std::unique_ptr<char[]> p(_StringConverter::CopyToCharArrayN(condition));
849 bundle_add(pb, OSP_K_COND, p.get());
852 bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_CONDTION);
860 const int MAX_LEN_DATA_CONTROL_REQ_TYPE = 8;
863 _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _DataControlRequestType requestType,
864 const IList* pArgList)
866 SysAssertf(b != null, "Valid bundle should be supplied");
868 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
870 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
871 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
872 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
873 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
874 bundle_add(b, AUL_K_NO_CANCEL, "1");
876 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
879 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
882 AddStrArray(b, OSP_K_ARG, pArgList);
889 _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _DataControlRequestType requestType,
890 const IList* pArgList)
892 SysAssertf(b != null, "Valid bundle should be supplied");
894 bundle_add(b, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_DATACONTROL);
896 char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
897 snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
898 bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
899 bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
900 bundle_add(b, AUL_K_NO_CANCEL, "1");
902 std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
905 bundle_add(b, OSP_K_DATACONTROL_PROVIDER, pProvider.get());
908 AddStrArray(b, OSP_K_ARG, pArgList);
915 _AppArg::CreateResultArg(bundle* b, const IList* pList)
917 SysAssertf(b != null, "Valid bundle should be supplied");
921 AddStrArray(pb, OSP_K_ARG, pList);
923 _AppMessageImpl::AddData(pb, pList);
930 _AppArg::CreateResultArg(bundle* b, const IMap* pMap)
932 SysAssertf(b != null, "Valid bundle should be supplied");
943 _AppArg::CreateBundleFromSvc(void* svc)
945 bundle* pBundle = GetBundleFromSvc(svc);
948 return bundle_dup(pBundle);
956 _AppArg::GetBundleFromSvc(void* svc)
958 bundle* pBundle = NULL;
959 int ret = service_to_bundle(static_cast<service_h>(svc), &pBundle);
961 return (ret == SERVICE_ERROR_NONE) ? pBundle : NULL;
966 _AppArg::GetRequestId(int num)
969 str.Format(10, L"req%05d", num);
975 _AppArg::GetRequestId(const String& str)
980 result r = str.SubString(3, sub);
981 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
983 r = Integer::Parse(sub, i);
984 SysTryReturn(NID_APP, !IsFailed(r), -1, r, "[%s] Propagating.", GetErrorMessage(r));
991 _AppArg::UpdateAppId(bundle* b, const AppId& appId)
993 SysTryReturnVoidResult(NID_APP, b != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
995 std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
996 SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
998 int res = bundle_add(b, OSP_K_APPID, pId.get());
999 if (res < 0 && errno == EPERM) // key exists
1001 bundle_del(b, OSP_K_APPID);
1002 bundle_add(b, OSP_K_APPID, pId.get());
1005 appsvc_set_appid(b, pId.get());
1010 _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
1012 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1016 //SysLog(NID_APP, "Requested ID is %d", reqId);
1020 char buffer[32] = {0, };
1021 snprintf(buffer, 32, "%d", reqId);
1022 int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1023 if (res < 0 && errno == EPERM) // key exists
1025 bundle_del(pBundle, OSP_K_REQUEST_ID);
1026 bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
1031 _AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
1033 SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
1035 char pBuffer[128] = {0, };
1036 snprintf(pBuffer, 128, "%ls", value.GetPointer());
1037 int res = bundle_add(pBundle, pKey, pBuffer);
1038 if (res < 0 && errno == EPERM) // key exists
1040 bundle_del(pBundle, pKey);
1041 bundle_add(pBundle, pKey, pBuffer);
1047 _AppArg::UpdateRaiseMode(bundle* pBundle)
1049 appsvc_add_data(pBundle, OSP_K_RAISE_MODE, "1");
1054 _AppArg::IsRaiseMode(bundle* pBundle)
1056 const char* p = appsvc_get_data(pBundle, OSP_K_RAISE_MODE);
1057 return (p && (strncmp(p, "1", sizeof(char)) == 0));
1061 _AppArg::GetRequestIdFromBundle(bundle* pBundle)
1063 const char* p = appsvc_get_data(pBundle, OSP_K_REQUEST_ID);
1070 return (i < 0) ? -1 : i;
1075 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
1077 appsvc_allow_transient_app(pBundle, handle);
1079 SysLog(NID_APP, "Window Handle 0x%x added.", handle);
1086 _AppArg::PrintSvcHandle(void* svc)
1088 service_h service = static_cast<service_h>(svc);
1090 if (service == null)
1095 Print(GetBundleFromSvc(service));
1100 BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, void* pData)
1108 case BUNDLE_TYPE_STR:
1109 bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
1112 SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
1116 SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
1123 _AppArg::Print(bundle* b)
1130 bundle_foreach(b, BundlePrintIterFnCb, NULL);
1133 const char** pa = appsvc_get_data_array(b, OSP_K_ARG, &len);
1136 for (int i = 0; i < len; i++)
1140 SysLog(NID_APP, "%dth arg [%s]", i, pa[i]);