app namespace source cleanup
[platform/framework/native/appfw.git] / src / app / FApp_ConditionManagerProxy.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_ConditionManagerProxy.cpp
19  * @brief       This is the implementation for the _ConditionManagerProxy.cpp class.
20  */
21
22 #include <new>
23 #include <memory>
24
25 #include <unique_ptr.h>
26
27 #include <FBaseErrors.h>
28 #include <FBaseSysLog.h>
29 #include <FIo_IpcClient.h>
30
31 #include "FApp_ConditionManagerIpcMessages.h"
32 #include "FApp_ConditionManagerProxy.h"
33
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
38
39 namespace Tizen { namespace App
40 {
41
42 const char CONDITION_MANAGER_IPC_NAME[] = "osp.app.ipcserver.conditionmanager";
43
44 _ConditionManagerProxy::_ConditionManagerProxy(void)
45         : __pIpcClient(null)
46 {
47 }
48
49
50 _ConditionManagerProxy::~_ConditionManagerProxy(void)
51 {
52         delete __pIpcClient;
53 }
54
55 result
56 _ConditionManagerProxy::Construct()
57 {
58         std::unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient());
59         SysTryReturnResult(NID_APP, pIpcClient.get() != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
60
61         result r = pIpcClient->Construct(CONDITION_MANAGER_IPC_NAME);
62         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%%s] _IpcClient constructing faliied.", GetErrorMessage(r));
63
64         __pIpcClient = pIpcClient.release();
65
66         return E_SUCCESS;
67 }
68
69 result
70 _ConditionManagerProxy::RegisterAppLaunch(const AppId& appId, const String& condition,
71                                                                                   const IList* pArguments, AppManager::LaunchOption option)
72 {
73         SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
74         SysLog(NID_APP, "");
75
76         result response = E_SUCCESS;
77         const ArrayList* pArrayList = dynamic_cast<const ArrayList*>(pArguments);
78         ArrayList dummy;
79         dummy.Construct();
80
81         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) ConditionManager_RegisterAppLaunch(
82                                                 appId, condition, (pArrayList != null) ? *pArrayList : dummy,
83                                                 static_cast<int>(AppManager::LAUNCH_OPTION_DEFAULT), &response));
84         result r = __pIpcClient->SendRequest(*pMsg.get());
85
86         SysTryReturn(NID_APP, !IsFailed(r), r, r, "__pIpcClient->SendRequest is failed. (%s)", GetErrorMessage(r));
87
88         return response;
89 }
90
91
92 result
93 _ConditionManagerProxy::UnregisterAppLaunch(const AppId& appId, const String* pCondition)
94 {
95         SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
96         SysLog(NID_APP, "");
97
98
99         result response = E_SUCCESS;
100         std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) ConditionManager_UnregisterAppLaunch(
101                                                                                                         appId, (pCondition != null) ? *pCondition : L"", &response));
102         result r = __pIpcClient->SendRequest(*pMsg.get());
103
104         SysTryReturn(NID_APP, !IsFailed(r), r, r, "__pIpcClient->SendRequest is failed. (%s)", GetErrorMessage(r));
105
106         return response;
107 }
108
109 bool
110 _ConditionManagerProxy::IsAppLaunchRegistered(const AppId& appId, const String* pCondition) const
111 {
112         SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
113         SysLog(NID_APP, "");
114
115         bool isAppLaunchRegistered = false;
116         result exception = E_SYSTEM;
117         std::auto_ptr<IPC::Message> pMsg(new (std::nothrow) ConditionManager_IsAppLaunchRegistered(
118                         appId, (pCondition != null) ? *pCondition : L"", &isAppLaunchRegistered, &exception));
119         result r = __pIpcClient->SendRequest(*pMsg.get());
120
121         SysTryReturn(NID_APP, !IsFailed(r), false, r, "__pIpcClient->SendRequest is failed. (%s)", GetErrorMessage(r));
122         SysTryReturn(NID_APP, !IsFailed(exception), false, exception, "__pIpcClient->SendRequest is failed. (%s)", GetErrorMessage(exception));
123
124         return isAppLaunchRegistered;
125 }
126
127
128 } } // Tizen::App