7fcf2c42b3b417480a4ded20d96888c81c1bb852
[platform/framework/native/appfw.git] / src / server / app / FApp_AppLaunchCondition.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file         FApp_AppLaunchCondition.cpp
19  * @brief       This is the implementation for the _ConditionManagerStub class.
20  */
21 #include <new>
22 #include "FApp_AppLaunchCondition.h"
23
24 namespace Tizen { namespace App {
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28
29
30 _AppLaunchCondition::_AppLaunchCondition(void)
31 : __appId(L""), __pArguments(null), __option(AppManager::LAUNCH_OPTION_DEFAULT), __conditionString(L""), __pUserData(null), __regSectionName(L"")
32 {
33 }
34
35 _AppLaunchCondition::~_AppLaunchCondition(void)
36 {
37         if (__pArguments != null)
38         {
39                 __pArguments->RemoveAll(true);
40                 delete __pArguments;
41         }
42 }
43
44 result
45 _AppLaunchCondition::Construct(const AppId& appId, const String& conditionString, const IList* pArgs, AppManager::LaunchOption option, const String* pRegSectionName)
46 {
47         __appId = appId;
48         __option = option;
49         __conditionString = conditionString;
50         __pUserData = null;
51         __regSectionName = (pRegSectionName != null) ? *pRegSectionName : L"";
52
53         return CopyArgumentsDeeply(pArgs);
54 }
55
56 AppId
57 _AppLaunchCondition::GetAppId(void) const
58 {
59         return __appId;
60 }
61
62 String
63 _AppLaunchCondition::GetConditionString(void) const
64 {
65         return __conditionString;
66 }
67
68 Object*
69 _AppLaunchCondition::GetUserData(void) const
70 {
71         return const_cast<Object*>(__pUserData);
72 }
73
74 result
75 _AppLaunchCondition::SetUserData(const Object* pUserData)
76 {
77         __pUserData = pUserData;
78         return E_SUCCESS;
79 }
80
81 result
82 _AppLaunchCondition::CopyArgumentsDeeply(const IList *pArgs)
83 {
84         result r = E_SUCCESS;
85
86         if (pArgs != null && pArgs->GetCount()  > 0)
87         {
88                 __pArguments = new (std::nothrow) ArrayList();
89                 SysTryReturnResult(NID_APP, __pArguments != null, E_OUT_OF_MEMORY, "failed to allocate 'pArguments'!");
90
91                 __pArguments->Construct();
92                 // deep copy
93                 for (int i = 0; i < pArgs->GetCount() ; i++)
94                 {
95                         r = __pArguments->Add(* new (std::nothrow) String(* static_cast<const String*>(pArgs->GetAt(i))));
96                         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s]", GetErrorMessage(r));
97                 }
98         }
99
100         return E_SUCCESS;
101
102 CATCH:
103         __pArguments->RemoveAll(true);
104         delete __pArguments;
105         __pArguments = null;
106         return r;
107 }
108
109
110 }}//namespace Tizen { namespace App {