571f7009689df2c6c7797ff95cd47db83a4d3eaf
[framework/osp/appwidget-service.git] / src / FShell_AppWidgetManagerStub.cpp
1 //
2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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        FShell_AppWidgetManagerStub.cpp
19  * @brief       This is the implementation for the _AppWidgetManagerStub class.
20  */
21
22 #include <FBaseSysLog.h>
23 #include <FBaseColHashMap.h>
24 #include <FIo_IpcServer.h>
25 #include "FShell_AppWidgetManagerIpcMessage.h"
26 #include "FShell_AppWidgetManagerStub.h"
27
28 namespace Tizen { namespace Shell  { namespace App {
29
30 namespace
31 {
32 const char IPC_SERVER_NAME[] = "osp.shell.ipcserver.appwidgetmanager";
33 const int INVALID_CLIENT_ID = -1;
34 };
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Io;
39 using namespace Tizen::Text;
40 using namespace Tizen::Security;
41
42 _AppWidgetManagerStub::_AppWidgetManagerStub(void)
43 :__pIpcServer(null)
44 {
45 }
46
47 _AppWidgetManagerStub::~_AppWidgetManagerStub(void)
48 {
49         SysLog(NID_SHELL, "Enter\n");
50
51         if ( __pIpcServer != null)
52         {
53                 __pIpcServer->Stop();
54                 delete __pIpcServer;
55         }
56
57         SysLog(NID_SHELL, "Exit\n");
58 }
59
60 result
61 _AppWidgetManagerStub::StartIpcServer(void)
62 {
63         SysLog(NID_SHELL, "Enter.");
64         __pIpcServer = new (std::nothrow) _IpcServer();
65         SysTryReturn(NID_SHELL, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
66
67         result r = __pIpcServer->Construct( IPC_SERVER_NAME, *this, false);
68         SysTryCatch(NID_SHELL, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
69         SysLog(NID_SHELL, "Exit.");
70
71         return E_SUCCESS;
72
73 CATCH:
74         delete __pIpcServer;
75         __pIpcServer = null;
76         return r;
77 }
78
79 bool
80 _AppWidgetManagerStub::OnRequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument, result* pRes)
81 {
82         SysLog(NID_SHELL, "");
83         *pRes = RequestUpdate(appId, providerName, argument);
84         return true;
85 }
86
87 bool
88 _AppWidgetManagerStub::OnRequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument, result* pRes)
89 {
90         SysLog(NID_SHELL, "");
91         *pRes = RequestUpdateInstance(instanceId, argument);
92         return true;
93 }
94
95 bool
96 _AppWidgetManagerStub::OnAcquireRemoteBuffer(const String& instanceId, int w, int h, int* pShmId)
97 {
98         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
99
100         AcquireRemoteBuffer(__pIpcServer->GetClientPackageId(), instanceId, w, h, *pShmId);
101
102         return true;
103 }
104
105 bool
106 _AppWidgetManagerStub::OnAcquireRemoteBufferForPD(const String& instanceId, int w, int h, int* pShmId)
107 {
108         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
109
110         AcquireRemoteBufferForPD(__pIpcServer->GetClientPackageId(), instanceId, w, h, *pShmId);
111
112         return true;
113 }
114
115 bool
116 _AppWidgetManagerStub::OnSyncRemoteBuffer(const String& instanceId, int w, int h, result* pRes)
117 {
118         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
119
120         *pRes = SyncRemoteBuffer(__pIpcServer->GetClientPackageId(), instanceId, w, h);
121
122         return true;
123 }
124
125 bool
126 _AppWidgetManagerStub::OnSyncRemoteBufferForPD(const String& instanceId, result* pRes)
127 {
128         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
129
130         *pRes = SyncRemoteBufferForPD(__pIpcServer->GetClientPackageId(), instanceId);
131
132         return true;
133 }
134
135 bool
136 _AppWidgetManagerStub::OnReleaseRemoteBuffer(const String& instanceId, result* pRes)
137 {
138         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
139
140         *pRes = ReleaseRemoteBuffer(__pIpcServer->GetClientPackageId(), instanceId);
141
142         return true;
143 }
144
145 bool
146 _AppWidgetManagerStub::OnReleaseRemoteBufferForPD(const String& instanceId, result* pRes)
147 {
148         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
149
150         *pRes = ReleaseRemoteBufferForPD(__pIpcServer->GetClientPackageId(), instanceId);
151
152         return true;
153 }
154
155 bool
156 _AppWidgetManagerStub::OnRequestProviderCount(const String& instanceId, int* pProviderCount)
157 {
158         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
159
160         RequestProviderCount(__pIpcServer->GetClientPackageId(), instanceId, *pProviderCount);
161
162         return true;
163 }
164
165 bool
166 _AppWidgetManagerStub::OnSendResult(const String& instanceId, bool isSucceeded)
167 {
168         SysSecureLog(NID_SHELL, "(instanceId:%ls, data:%d)", instanceId.GetPointer(), isSucceeded);
169
170         SendResult(__pIpcServer->GetClientPackageId(), instanceId, isSucceeded);
171
172         return true;
173 }
174
175 bool
176 _AppWidgetManagerStub::OnSendAccessStatus(const String& instanceId, int accessStatus)
177 {
178         SysSecureLog(NID_SHELL, "(instanceId:%ls, data:%d)", instanceId.GetPointer(), accessStatus);
179
180         SendAccessStatus(__pIpcServer->GetClientPackageId(), instanceId, accessStatus);
181
182         return true;
183 }
184
185 void
186 _AppWidgetManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
187 {
188         SysLog(NID_SHELL, "(appId:%ls, clientId:%d)\n", server.GetClientApplicationId().GetPointer(), server.GetClientId());
189
190         SysAssertf(__pIpcServer, "__pIpcServer is null!");
191
192         IPC_BEGIN_MESSAGE_MAP(_AppWidgetManagerStub, message)
193                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestUpdate, &server, OnRequestUpdate)
194                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestUpdateInstance, &server, OnRequestUpdateInstance)
195                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_AcquireRemoteBuffer, &server, OnAcquireRemoteBuffer)
196                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_AcquireRemoteBufferForPD, &server, OnAcquireRemoteBufferForPD)
197                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SyncRemoteBuffer, &server, OnSyncRemoteBuffer)
198                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SyncRemoteBufferForPD, &server, OnSyncRemoteBufferForPD)
199                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_ReleaseRemoteBuffer, &server, OnReleaseRemoteBuffer)
200                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_ReleaseRemoteBufferForPD, &server, OnReleaseRemoteBufferForPD)
201                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestProviderCount, &server, OnRequestProviderCount)
202                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendResult, &server, OnSendResult)
203                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendAccessStatus, &server, OnSendAccessStatus)
204         IPC_END_MESSAGE_MAP()
205 }
206
207 void
208 _AppWidgetManagerStub::OnIpcServerStarted(const _IpcServer& server)
209 {
210         SysLog(NID_SHELL, "\n");
211 }
212
213 void
214 _AppWidgetManagerStub::OnIpcServerStopped(const _IpcServer& server)
215 {
216         SysLog(NID_SHELL, "\n");
217 }
218
219 bool
220 _AppWidgetManagerStub::SendAppWidgetEvent(const int clientId, const String& instanceId, const String& operationId, HashMap* pArgs)
221 {
222         SysLog(NID_SHELL, "The operation type is %ls", operationId.GetPointer());
223         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendAppWidgetEvent(instanceId, operationId, *pArgs));
224         SysTryReturn(NID_SHELL, !IsFailed(r), false, r, "[%s] Propagated.", GetErrorMessage(r));
225
226         return true;
227 }
228
229 bool
230 _AppWidgetManagerStub::SendTouchEvent(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
231 {
232         SysLog(NID_SHELL,"");
233         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendTouchEvent(instanceId, eventType, timestamp, x, y));
234         SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
235
236         return true;
237 }
238
239 bool
240 _AppWidgetManagerStub::SendTouchEventForPD(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
241 {
242         SysLog(NID_SHELL,"");
243         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendTouchEventForPD(instanceId, eventType, timestamp, x, y));
244         SysTryReturn(NID_SHELL, !IsFailed(r), false, r, "[%s] Propagated.", GetErrorMessage(r));
245
246         return true;
247 }
248
249
250 }}}     // Tizen::Shell::App