2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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
8 // http://floralicense.org/license/
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.
18 * @file FShell_AppWidgetManagerProxy.cpp
19 * @brief This is the implementation for the _AppWidgetManagerProxy class.
23 #include <FBaseInteger.h>
24 #include <FBaseDouble.h>
25 #include <FBaseColHashMap.h>
26 #include <FShellTypes.h>
27 #include <FIo_IpcClient.h>
28 #include <FShell_AppWidgetManagerIpcMessage.h>
29 #include "FShell_AppWidgetProviderManagerImpl.h"
30 #include "FShell_AppWidgetManagerProxy.h"
32 namespace Tizen { namespace Shell {
36 const char IPC_SERVER_NAME[] = "osp.shell.ipcserver.appwidgetmanager";
39 using namespace Tizen::Io;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
43 _AppWidgetManagerProxy::_AppWidgetManagerProxy()
46 SysLog(NID_SHELL, "");
49 _AppWidgetManagerProxy::~_AppWidgetManagerProxy()
57 _AppWidgetManagerProxy*
58 _AppWidgetManagerProxy::GetInstance()
60 static std::unique_ptr<_AppWidgetManagerProxy> __pAppWidgetProxy(null);
61 if (__pAppWidgetProxy.get() == null)
63 std::unique_ptr<_AppWidgetManagerProxy> pAppWidgetProxy(new (std::nothrow)_AppWidgetManagerProxy);
64 SysTryReturn(NID_SHELL, pAppWidgetProxy.get(), null, E_OUT_OF_MEMORY, "Allocating new _AppWidgetManagerProxy failed!");
66 result r = pAppWidgetProxy->Construct();
67 SysTryReturn(NID_SHELL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
69 __pAppWidgetProxy = std::move(pAppWidgetProxy);
73 if (!__pAppWidgetProxy->IsConnected())
75 result r = __pAppWidgetProxy->Construct();
76 SysTryReturn(NID_SHELL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
80 return __pAppWidgetProxy.get();
84 _AppWidgetManagerProxy::Construct(void)
86 SysLog(NID_SHELL, "Enter.");
88 std::unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient() );
89 SysTryReturnResult(NID_SHELL, pIpcClient, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
91 const int MAX_TRY_COUNT = 2;
92 const int TRY_SLEEP_TIME = 65;
97 result r = pIpcClient->Construct(IPC_SERVER_NAME, this);
100 SysLog(NID_APP, "Succeeded in connecting service(%s)", IPC_SERVER_NAME);
101 __pIpcClient = pIpcClient.release();
105 SysTryReturn(NID_APP, ++count < MAX_TRY_COUNT, E_SYSTEM, r, "[%s] Failed to connect service.(%s)", GetErrorMessage(r), IPC_SERVER_NAME);
107 Tizen::Base::Runtime::Thread::Sleep(TRY_SLEEP_TIME);
110 SysLog(NID_SHELL, "Exit.");
115 _AppWidgetManagerProxy::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument)
117 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
118 SysLog(NID_SHELL, "Enter.");
119 // String providerId;
120 // if( providerName.IsEmpty() == true)
122 // providerId = appId;
126 // providerId = appId + "." + providerName;
129 result ret = E_SUCCESS;
130 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestUpdate(appId, providerName, argument, &ret));
131 result r = __pIpcClient->SendRequest(*pMsg.get());
132 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
138 _AppWidgetManagerProxy::RequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument)
140 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
141 SysLog(NID_SHELL, "Enter.");
143 result ret = E_SUCCESS;
144 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestUpdateInstance(instanceId, argument, &ret));
145 result r = __pIpcClient->SendRequest(*pMsg.get());
146 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
152 _AppWidgetManagerProxy::RequestSharedMemoryId(const Tizen::Base::String& instanceId, int width, int height, int& shmId )
154 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
156 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSharedMemoryId(instanceId, width, height, &shmId));
157 result r = __pIpcClient->SendRequest(*pMsg.get());
158 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
159 SysLog(NID_SHELL, "shmId(%d) is retrieved from appwidget-service", shmId);
165 _AppWidgetManagerProxy::RequestSharedMemoryIdForPD(const Tizen::Base::String& instanceId, int width, int height, int& shmId )
167 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
169 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSharedMemoryIdForPD(instanceId, width, height, &shmId));
170 result r = __pIpcClient->SendRequest(*pMsg.get());
171 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest is failed.");
172 SysLog(NID_SHELL, "shmId(%d) is retrieved from appwidget-service", shmId);
178 _AppWidgetManagerProxy::RequestSyncSharedMemory(const Tizen::Base::String& instanceId, int width, int height)
180 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
181 SysLog(NID_SHELL, "");
183 result ret = E_FAILURE;
184 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSyncSharedMemory(instanceId, width, height, &ret));
185 result r = __pIpcClient->SendRequest(*pMsg.get());
186 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
191 _AppWidgetManagerProxy::RequestSyncSharedMemoryForPD(const Tizen::Base::String& instanceId)
193 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
194 SysLog(NID_SHELL, "");
196 result ret = E_FAILURE;
197 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSyncSharedMemoryForPD(instanceId, &ret));
198 result r = __pIpcClient->SendRequest(*pMsg.get());
199 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
204 _AppWidgetManagerProxy::RequestReleaseSharedMemory(const Tizen::Base::String& instanceId)
206 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
207 SysLog(NID_SHELL, "");
209 result ret = E_FAILURE;
210 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestReleaseSharedMemory(instanceId, &ret));
211 result r = __pIpcClient->SendRequest(*pMsg.get());
212 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
217 _AppWidgetManagerProxy::RequestReleaseSharedMemoryForPD(const Tizen::Base::String& instanceId)
219 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
220 SysLog(NID_SHELL, "");
222 result ret = E_FAILURE;
223 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestReleaseSharedMemoryForPD(instanceId, &ret));
224 result r = __pIpcClient->SendRequest(*pMsg.get());
225 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
230 _AppWidgetManagerProxy::RequestProviderCount(const Tizen::Base::String& instanceId, int &count)
232 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
233 SysLog(NID_SHELL, "");
235 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestProviderCount(instanceId, &count));
236 result r = __pIpcClient->SendRequest(*pMsg.get());
237 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "SendRequest failed.");
243 _AppWidgetManagerProxy::SendResult(const Tizen::Base::String& instanceId, bool isSucceeded)
245 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
246 SysLog(NID_SHELL, "");
248 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_SendResult(instanceId, isSucceeded));
249 result r = __pIpcClient->SendRequest(*pMsg.get());
250 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "SendRequest failed.");
256 _AppWidgetManagerProxy::SendAccessStatus(const Tizen::Base::String& instanceId, int accessStatus)
258 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
259 SysLog(NID_SHELL, "");
261 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_SendAccessStatus(instanceId, accessStatus));
262 result r = __pIpcClient->SendRequest(*pMsg.get());
263 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "SendRequest failed.");
269 _AppWidgetManagerProxy::OnTouchEventReceived(const Tizen::Base::String& instanceId, int eventType, double timeStamp, double x, double y )
271 return _AppWidgetProviderManagerImpl::GetInstance()->ForwardTouchEvent(instanceId, eventType, timeStamp, x, y);
275 _AppWidgetManagerProxy::OnAppWidgetEventReceived(const String& instanceId, const String& operationId, const HashMap& args)
277 return _AppWidgetProviderManagerImpl::GetInstance()->HandleAppWidgetRequest(operationId, &args, true);
281 _AppWidgetManagerProxy::OnTouchEventReceivedForPD(const Tizen::Base::String& instanceId, int eventType, double timeStamp, double x, double y )
283 return _AppWidgetProviderManagerImpl::GetInstance()->ForwardTouchEventForPD(instanceId, eventType, timeStamp, x, y);
287 _AppWidgetManagerProxy::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
289 SysLog(NID_SHELL, "Enter.");
290 IPC_BEGIN_MESSAGE_MAP(_AppWidgetManagerProxy, message)
291 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendAppWidgetEvent, &client, OnAppWidgetEventReceived)
292 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendTouchEvent, &client, OnTouchEventReceived)
293 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendTouchEventForPD, &client, OnTouchEventReceivedForPD )
294 IPC_END_MESSAGE_MAP()
296 SysLog(NID_SHELL, "Exit.");
300 _AppWidgetManagerProxy::IsConnected(void) const
302 return (__pIpcClient != null);
306 _AppWidgetManagerProxy::OnIpcServerDisconnected(_IpcClient& client)
308 SysLog(NID_SHELL, "IPC Server[%ls] is disconnected.", client.GetName().GetPointer());