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 <FIo_IpcClient.h>
24 #include <FShell_AppWidgetManagerIpcMessage.h>
25 #include "FShell_AppWidgetProviderManagerImpl.h"
26 #include "FShell_AppWidgetManagerProxy.h"
28 namespace Tizen { namespace Shell {
32 const char IPC_SERVER_NAME[] = "osp.shell.ipcserver.appwidgetmanager";
35 using namespace Tizen::Io;
38 _AppWidgetManagerProxy::_AppWidgetManagerProxy()
41 SysLog(NID_SHELL, "");
44 _AppWidgetManagerProxy::~_AppWidgetManagerProxy()
52 _AppWidgetManagerProxy*
53 _AppWidgetManagerProxy::GetInstance()
55 static std::unique_ptr<_AppWidgetManagerProxy> __pAppWidgetProxy(null);
56 if (__pAppWidgetProxy.get() == null)
58 std::unique_ptr<_AppWidgetManagerProxy> pAppWidgetProxy(new (std::nothrow)_AppWidgetManagerProxy);
59 SysTryReturn(NID_SHELL, pAppWidgetProxy.get(), null, E_OUT_OF_MEMORY, "Allocating new _AppWidgetManagerProxy failed!");
61 result r = pAppWidgetProxy->Construct();
62 SysTryReturn(NID_SHELL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
64 __pAppWidgetProxy = std::move(pAppWidgetProxy);
68 if (!__pAppWidgetProxy->IsConnected())
70 result r = __pAppWidgetProxy->Construct();
71 SysTryReturn(NID_SHELL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
75 return __pAppWidgetProxy.get();
79 _AppWidgetManagerProxy::Construct(void)
81 SysLog(NID_SHELL, "Enter.");
83 std::unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient() );
84 SysTryReturnResult(NID_SHELL, pIpcClient, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
86 const int MAX_TRY_COUNT = 5;
87 const int TRY_SLEEP_TIME = 250;
92 result r = pIpcClient->Construct(IPC_SERVER_NAME, this);
95 SysLog(NID_APP, "Succeeded in connecting service(%s)", IPC_SERVER_NAME);
96 __pIpcClient = pIpcClient.release();
100 SysTryReturn(NID_APP, ++count < MAX_TRY_COUNT, E_SYSTEM, r, "[%s] Failed to connect service.(%s)", GetErrorMessage(r), IPC_SERVER_NAME);
102 Tizen::Base::Runtime::Thread::Sleep(TRY_SLEEP_TIME);
105 SysLog(NID_SHELL, "Exit.");
110 _AppWidgetManagerProxy::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument)
112 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
113 SysLog(NID_SHELL, "Enter.");
114 // String providerId;
115 // if( providerName.IsEmpty() == true)
117 // providerId = appId;
121 // providerId = appId + "." + providerName;
124 result ret = E_SUCCESS;
125 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestUpdate(appId, providerName, argument, &ret));
126 result r = __pIpcClient->SendRequest(*pMsg.get());
127 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
133 _AppWidgetManagerProxy::RequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument)
135 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
136 SysLog(NID_SHELL, "Enter.");
138 result ret = E_SUCCESS;
139 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestUpdateInstance(instanceId, argument, &ret));
140 result r = __pIpcClient->SendRequest(*pMsg.get());
141 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
147 _AppWidgetManagerProxy::RequestSharedMemoryId(const Tizen::Base::String& instanceId, int width, int height, int& shmId )
149 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
151 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSharedMemoryId(instanceId, width, height, &shmId));
152 result r = __pIpcClient->SendRequest(*pMsg.get());
153 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
154 SysLog(NID_SHELL, "shmId(%d) is retrieved from appwidget-service", shmId);
160 _AppWidgetManagerProxy::RequestSharedMemoryIdForPD(const Tizen::Base::String& instanceId, int width, int height, int& shmId )
162 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
164 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSharedMemoryIdForPD(instanceId, width, height, &shmId));
165 result r = __pIpcClient->SendRequest(*pMsg.get());
166 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest is failed.");
167 SysLog(NID_SHELL, "shmId(%d) is retrieved from appwidget-service", shmId);
173 _AppWidgetManagerProxy::RequestSyncSharedMemory(const Tizen::Base::String& instanceId, int width, int height)
175 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
176 SysLog(NID_SHELL, "");
178 result ret = E_FAILURE;
179 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSyncSharedMemory(instanceId, width, height, &ret));
180 result r = __pIpcClient->SendRequest(*pMsg.get());
181 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
186 _AppWidgetManagerProxy::RequestSyncSharedMemoryForPD(const Tizen::Base::String& instanceId)
188 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
189 SysLog(NID_SHELL, "");
191 result ret = E_FAILURE;
192 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestSyncSharedMemoryForPD(instanceId, &ret));
193 result r = __pIpcClient->SendRequest(*pMsg.get());
194 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
199 _AppWidgetManagerProxy::RequestReleaseSharedMemory(const Tizen::Base::String& instanceId)
201 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
202 SysLog(NID_SHELL, "");
204 result ret = E_FAILURE;
205 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestReleaseSharedMemory(instanceId, &ret));
206 result r = __pIpcClient->SendRequest(*pMsg.get());
207 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
212 _AppWidgetManagerProxy::RequestReleaseSharedMemoryForPD(const Tizen::Base::String& instanceId)
214 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
215 SysLog(NID_SHELL, "");
217 result ret = E_FAILURE;
218 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_RequestReleaseSharedMemoryForPD(instanceId, &ret));
219 result r = __pIpcClient->SendRequest(*pMsg.get());
220 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "SendRequest failed.");
225 _AppWidgetManagerProxy::SendResult(const Tizen::Base::String& instanceId, bool isSucceeded)
227 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_SYSTEM, "__pIpcClient instance must not be null.");
228 SysLog(NID_SHELL, "");
230 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppWidgetManager_SendResult(instanceId, isSucceeded));
231 result r = __pIpcClient->SendRequest(*pMsg.get());
232 SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "SendResult failed.");
238 _AppWidgetManagerProxy::OnTouchEventReceived(const Tizen::Base::String& instanceId, int eventType, double timeStamp, double x, double y )
240 return _AppWidgetProviderManagerImpl::GetInstance()->ForwardTouchEvent(instanceId, eventType, timeStamp, x, y);
244 _AppWidgetManagerProxy::OnTouchEventReceivedForPD(const Tizen::Base::String& instanceId, int eventType, double timeStamp, double x, double y )
246 return _AppWidgetProviderManagerImpl::GetInstance()->ForwardTouchEventForPD(instanceId, eventType, timeStamp, x, y);
250 _AppWidgetManagerProxy::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
252 SysLog(NID_SHELL, "Enter.");
253 IPC_BEGIN_MESSAGE_MAP(_AppWidgetManagerProxy, message)
254 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendTouchEvent, &client, OnTouchEventReceived )
255 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendTouchEventForPD, &client, OnTouchEventReceivedForPD )
256 IPC_END_MESSAGE_MAP()
258 SysLog(NID_SHELL, "Exit.");
262 _AppWidgetManagerProxy::IsConnected(void) const
264 return (__pIpcClient != null);
268 _AppWidgetManagerProxy::OnIpcServerDisconnected(_IpcClient& client)
270 SysLog(NID_SHELL, "IPC Server[%ls] is disconnected.", client.GetName().GetPointer());