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_AppManagerStub.cpp
20 * @brief This is the implementation for the _AppManagerStub class.
23 #include <FBaseSysLog.h>
24 #include <FIo_IpcServer.h>
25 #include <FSec_AccessController.h>
27 #include <FApp_AppManagerProxy.h>
28 #include <FApp_AppManagerIpcMessage.h>
30 #include "FApp_AppManagerService.h"
31 #include "FApp_AppManagerStub.h"
32 #include "FApp_ContextManager.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Io;
37 using namespace Tizen::Text;
38 using namespace Tizen::Security;
41 namespace Tizen { namespace App {
44 _AppManagerStub::_AppManagerStub(void)
46 __pAppManagerService(null)
48 SysLog(NID_APP, "Enter\n");
50 SysLog(NID_APP, "Exit\n");
53 _AppManagerStub::~_AppManagerStub(void)
55 SysLog(NID_APP, "Enter\n");
57 if ( __pIpcServer != null)
63 delete __pAppManagerService;
65 SysLog(NID_APP, "Exit\n");
69 _AppManagerStub::Construct(_ContextManager *pContextMgr)
71 SysTryReturnResult(NID_APP, pContextMgr != null, E_INVALID_ARG, "pContextMgr is null.");
73 SysLog(NID_APP, "Enter\n");
77 __pAppManagerService = new (std::nothrow) _AppManagerService();
78 SysTryReturnResult(NID_APP, __pAppManagerService != null, E_OUT_OF_MEMORY, "Not enough memory.");
80 r = __pAppManagerService->Construct(pContextMgr, this);
81 SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pAppManagerService->Construct. (%s)", GetErrorMessage(r) );
83 _AppManagerProxy::SetService(__pAppManagerService);
87 SysLog(NID_APP, "Exit\n");
93 _AppManagerStub::StartIpcServer(void)
95 __pIpcServer = new (std::nothrow) _IpcServer();
96 SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
98 result r = __pIpcServer->Construct( "osp.app.ipcserver.appmanager", *this);
99 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
110 // server to client message
112 _AppManagerStub::OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg)
114 // SysLog(NID_APP, "appId:%ls, executableName:%ls, appType:%d", arg.GetAppId().GetPointer(), arg.GetName().GetPointer(), arg.GetAppType());
115 SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
117 result r = __pIpcServer->SendResponse(clientId, new AppManager_OnEventReceived(arg));
118 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
124 _AppManagerStub::OnTerminateApplicationRequested(int clientId)
126 SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
128 result r = __pIpcServer->SendResponse(clientId, new AppManager_OnTerminateApplicationRequested());
129 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
135 /////////////////////////////////////////////
137 /////////////////////////////////////////////
140 _AppManagerStub::OnLaunchApplication(const AppId& appId, const String& execName, int req)
142 SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
144 SysLog(NID_APP, "(appId:%ls)", appId.GetPointer());
146 __pAppManagerService->LaunchApplication(appId, execName, req);
153 _AppManagerStub::OnTerminateApplication(const AppId& appId, const String& execName, result *pRes)
155 SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pAppManagerService is null!");
157 SysLog(NID_APP, "(appId:%ls, %ls)", appId.GetPointer(), execName.GetPointer());
159 // APPLICATION_MANAGER
160 *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPLICATION_KILL);
164 SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application does not have the privilege to call this method.");
165 *pRes = E_PRIVILEGE_DENIED;
169 *pRes = __pAppManagerService->TerminateApplication(appId, execName);
176 _AppManagerStub::OnIsRunning(const AppId& appId, const String& execName, bool *pRes)
178 SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = false, E_INVALID_STATE, "__pAppManagerService is null!");
180 SysLog(NID_APP, "_AppManagerStub::IsRunning(%ls, %ls)", appId.GetPointer(), execName.GetPointer());
181 *pRes = __pAppManagerService->IsRunning(appId, execName);
188 _AppManagerStub::OnGetRunningAppList(Tizen::Base::Collection::ArrayList* pArray, result *pRes)
190 SysTryReturn(NID_APP, pArray != null, E_INVALID_ARG, E_INVALID_ARG, "pArray shoud not be null!");
191 SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pAppManagerService is null!");
194 *pRes = __pAppManagerService->GetRunningAppList(pArray);
201 _AppManagerStub::OnRegisterApplication(const AppId& appId, const String& executableName, int appType, int pid)
203 SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
204 SysLog(NID_APP, "_AppManagerStub::RegisterApplication(appId:%ls, pid:%d)\n", appId.GetPointer(), pid);
206 __pAppManagerService->RegisterApplication(appId, executableName, static_cast<_AppType>(appType), pid, __pIpcServer->GetClientId());
213 _AppManagerStub::OnUnregisterApplication(int pid)
215 SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
216 SysLog(NID_APP, "_AppManagerStub::UnregisterApplication(pid:%d)\n", pid);
217 __pAppManagerService->UnregisterApplication(pid);
224 _AppManagerStub::OnAddEventListener(int pid)
226 SysTryReturn(NID_APP, __pIpcServer != null, true, E_INVALID_STATE, "__pIpcServer should not be null!");
228 __pAppManagerService->AddEventListener(__pIpcServer->GetClientId());//, this);
233 _AppManagerStub::OnRemoveEventListener(int pid)
235 SysTryReturn(NID_APP, __pIpcServer != null, true, E_INVALID_STATE, "__pIpcServer should not be null!");
237 __pAppManagerService->RemoveEventListener(__pIpcServer->GetClientId());//, this);
243 _AppManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
245 SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
247 IPC_BEGIN_MESSAGE_MAP(_AppManagerStub, message)
248 IPC_MESSAGE_HANDLER_EX(AppManager_LaunchApplication, &server, OnLaunchApplication)
249 IPC_MESSAGE_HANDLER_EX(AppManager_TerminateApplication, &server, OnTerminateApplication)
250 IPC_MESSAGE_HANDLER_EX(AppManager_IsRunning, &server, OnIsRunning)
251 IPC_MESSAGE_HANDLER_EX(AppManager_GetRunningAppList, &server, OnGetRunningAppList)
252 IPC_MESSAGE_HANDLER_EX(AppManager_RegisterApplication, &server, OnRegisterApplication)
253 IPC_MESSAGE_HANDLER_EX(AppManager_UnregisterApplication, &server, OnUnregisterApplication)
254 IPC_MESSAGE_HANDLER_EX(AppManager_AddEventListener, &server, OnAddEventListener)
255 IPC_MESSAGE_HANDLER_EX(AppManager_RemoveEventListener, &server, OnRemoveEventListener)
256 IPC_END_MESSAGE_MAP()
260 _AppManagerStub::OnIpcServerStarted(const _IpcServer& server)
262 // SysLog(NID_APP, "\n");
266 _AppManagerStub::OnIpcServerStopped(const _IpcServer& server)
268 // SysLog(NID_APP, "\n");
272 _AppManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
274 // SysLog(NID_APP, "(clientId:%d)\n", clientId);
278 _AppManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
280 // SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
284 }}//namespace Tizen { namespace App {