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