2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FApp_AppManagerProxy.cpp
20 * @brief This is the implementation for the _AppManagerProxy class.
26 #include <FBaseErrors.h>
28 #include <FBaseSysLog.h>
29 #include <FIo_IpcClient.h>
31 #include "FApp_Types.h"
32 #include "FApp_AppInfo.h"
33 #include "FApp_IAppManagerEventListener.h"
34 #include "FApp_IAppManagerServiceEventListener.h"
35 #include "FApp_AppManagerEventArg.h"
36 #include "FApp_AppManagerProxy.h"
37 #include "FApp_AppManagerIpcMessage.h"
42 const char IPC_SERVER_NAME[] = "osp.app.ipcserver.appmanager";
43 const int INVALID_CLIENT_ID = -1;
47 namespace Tizen { namespace App
50 using namespace Tizen::Base;
51 using namespace Tizen::Io;
52 using namespace Tizen::Base::Runtime;
55 _IAppManager* _AppManagerProxy::__pSelf = null;
56 _IAppManagerServiceEventListener* _AppManagerProxy::__pServiceEventListener = null;
58 _AppManagerProxy::_AppManagerProxy(void)
64 _AppManagerProxy::~_AppManagerProxy(void)
71 _AppManagerProxy::Construct(void)
73 __pIpcClient = new (std::nothrow) _IpcClient();
74 SysTryReturnResult(NID_APP, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
76 result r = __pIpcClient->Construct(IPC_SERVER_NAME, this);
77 SysTryReturn(NID_APP, !IsFailed(r), r, r, "_IpcClient constructing faliied [%s].", GetErrorMessage(r));
83 _AppManagerProxy::GetService(void)
85 _AppManagerProxy* pProxy = null;
89 SysLog(NID_APP, "Create new instance");
91 pProxy = new (std::nothrow) _AppManagerProxy();
92 SysTryReturn(NID_APP, pProxy != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to create _AppManagerProxy");
94 result r = pProxy->Construct();
95 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] pProxy->Construct() failure.", GetErrorMessage(r));
108 _AppManagerProxy::SetService(_IAppManager* pAppManager)
110 __pSelf = pAppManager;
115 _AppManagerProxy::LaunchApplication(const AppId& appId, int req)
117 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
120 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_LaunchApplication(appId, req));
121 result r = __pIpcClient->SendRequest(*pMsg.get());
122 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
128 _AppManagerProxy::TerminateApplication(const AppId& appId)
130 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
133 result response = E_SUCCESS;
134 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_TerminateApplication(appId, &response));
135 result r = __pIpcClient->SendRequest(*pMsg.get());
136 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
142 _AppManagerProxy::IsRunning(const AppId& appId)
144 bool isRunning = false;
146 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_IsRunning(appId, &isRunning));
147 result r = __pIpcClient->SendRequest(*pMsg.get());
148 SysTryReturn(NID_APP, !IsFailed(r), false, r, "SendRequest is failed.");
153 _AppManagerProxy::GetRunningAppList(Collection::ArrayList* pArray)
155 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
159 result response = E_SUCCESS;
160 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_GetRunningAppList(pArray, &response));
161 result r = __pIpcClient->SendRequest(*pMsg.get());
162 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
168 _AppManagerProxy::RegisterApplication(const String& packageId, const String& executableName, _AppType appType, int pId)
170 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
173 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_RegisterApplication(packageId, executableName, static_cast<int>(appType), pId));
174 result r = __pIpcClient->SendRequest(*pMsg.get());
175 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
181 _AppManagerProxy::UnregisterApplication(int pId)
183 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
187 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_UnregisterApplication(pId));
188 result r = __pIpcClient->SendRequest(*pMsg.get());
189 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
195 _AppManagerProxy::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
197 IPC_BEGIN_MESSAGE_MAP(_AppManagerProxy, message)
198 IPC_MESSAGE_HANDLER_EX(AppManager_OnEventReceived, &client, OnEventReceived )
199 IPC_MESSAGE_HANDLER_EX(AppManager_OnTerminateApplicationRequested, &client, OnTerminateApplicationRequested )
200 IPC_END_MESSAGE_MAP()
204 _AppManagerProxy::OnEventReceived(const _AppManagerEventArg& arg)
206 SysTryReturnResult(NID_APP, __pServiceEventListener != null, E_INVALID_STATE, "__pServiceEventListener instance must not be null.");
208 __pServiceEventListener->OnServiceEventReceived(-1, arg);
214 _AppManagerProxy::OnTerminateApplicationRequested(void)
216 SysTryReturnVoidResult(NID_APP, __pServiceEventListener != null, E_INVALID_STATE, "[E_INVALID_STATE] __pServiceEventListener instance must not be null.");
218 __pServiceEventListener->OnTerminateApplicationRequested(-1);
222 _AppManagerProxy::InitEventListener(_IAppManagerServiceEventListener* pListener)
224 __pServiceEventListener = pListener;
229 _AppManagerProxy::AddEventListener(int clientId)
231 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
234 std::auto_ptr<IPC::Message> pMsg(new (std::nothrow) AppManager_AddEventListener(_AppInfo::GetProcessId()));
235 result r = __pIpcClient->SendRequest(*pMsg);
236 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
242 _AppManagerProxy::RemoveEventListener(int clientId)
244 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
247 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_RemoveEventListener(_AppInfo::GetProcessId()));
248 result r = __pIpcClient->SendRequest(*pMsg);
249 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");