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