add new features
[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         SysLog(NID_SHELL, "Enter\n");
46
47         SysLog(NID_SHELL, "Exit\n");
48 }
49
50 _AppWidgetManagerStub::~_AppWidgetManagerStub(void)
51 {
52         SysLog(NID_SHELL, "Enter\n");
53
54         if ( __pIpcServer != null)
55         {
56                 __pIpcServer->Stop();
57                 delete __pIpcServer;
58         }
59
60         SysLog(NID_SHELL, "Exit\n");
61 }
62
63 result
64 _AppWidgetManagerStub::StartIpcServer(void)
65 {
66         SysLog(NID_SHELL, "Enter.");
67         __pIpcServer = new (std::nothrow) _IpcServer();
68         SysTryReturn(NID_SHELL, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
69
70         result r = __pIpcServer->Construct( IPC_SERVER_NAME, *this, false);
71         SysTryCatch(NID_SHELL, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
72         SysLog(NID_SHELL, "Exit.");
73
74         return E_SUCCESS;
75
76 CATCH:
77         delete __pIpcServer;
78         __pIpcServer = null;
79         return r;
80 }
81
82 bool
83 _AppWidgetManagerStub::OnRequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument, result* pRes)
84 {
85         SysLog(NID_SHELL, "");
86         *pRes = RequestUpdate(appId, providerName, argument);
87         return true;
88 }
89
90 bool
91 _AppWidgetManagerStub::OnRequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument, result* pRes)
92 {
93         SysLog(NID_SHELL, "");
94         *pRes = RequestUpdateInstance(instanceId, argument);
95         return true;
96 }
97
98 bool
99 _AppWidgetManagerStub::OnRequestSharedMemoryId(const String& instanceId, int w, int h, int* pShmId)
100 {
101         SysSecureLog(NID_SHELL, "(instanceId:%d)xxx", instanceId.GetPointer());
102
103         RequestSharedMemoryId(__pIpcServer->GetClientPackageId(), instanceId, w, h, *pShmId);
104
105         return true;
106 }
107
108 bool
109 _AppWidgetManagerStub::OnRequestSharedMemoryIdForPD(const String& instanceId, int w, int h, int* pShmId)
110 {
111         SysSecureLog(NID_SHELL, "(instanceId:%d)", instanceId.GetPointer());
112
113         RequestSharedMemoryIdForPD(__pIpcServer->GetClientPackageId(), instanceId, w, h, *pShmId);
114
115         return true;
116 }
117
118 bool
119 _AppWidgetManagerStub::OnRequestSyncSharedMemory(const String& instanceId, int w, int h, result* pRes)
120 {
121         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
122
123         *pRes = RequestSyncSharedMemory(__pIpcServer->GetClientPackageId(), instanceId, w, h);
124
125         return true;
126 }
127
128 bool
129 _AppWidgetManagerStub::OnRequestSyncSharedMemoryForPD(const String& instanceId, result* pRes)
130 {
131         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
132
133         *pRes = RequestSyncSharedMemoryForPD(__pIpcServer->GetClientPackageId(), instanceId);
134
135         return true;
136 }
137
138 bool
139 _AppWidgetManagerStub::OnRequestReleaseSharedMemory(const String& instanceId, result* pRes)
140 {
141         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
142
143         *pRes = RequestReleaseSharedMemory(__pIpcServer->GetClientPackageId(), instanceId);
144
145         return true;
146 }
147
148 bool
149 _AppWidgetManagerStub::OnRequestReleaseSharedMemoryForPD(const String& instanceId, result* pRes)
150 {
151         SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer());
152
153         *pRes = RequestReleaseSharedMemoryForPD(__pIpcServer->GetClientPackageId(), instanceId);
154
155         return true;
156 }
157
158 bool
159 _AppWidgetManagerStub::OnSendResult(const String& instanceId, bool isSucceeded)
160 {
161         SysSecureLog(NID_SHELL, "(instanceId:%ls, data:%d)", instanceId.GetPointer(), isSucceeded);
162
163         SendResult(__pIpcServer->GetClientPackageId(), instanceId, isSucceeded);
164
165         return true;
166 }
167
168 bool
169 _AppWidgetManagerStub::SendAppWidgetEvent(const int clientId, const String& instanceId, const String& operationId, HashMap* pArgs)
170 {
171         SysLog(NID_SHELL, "The operation type is %ls", operationId.GetPointer());
172         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendAppWidgetEvent(instanceId, operationId, *pArgs));
173         SysTryReturn(NID_SHELL, !IsFailed(r), false, r, "[%s] Propagated.", GetErrorMessage(r));
174
175         return true;
176 }
177
178 bool
179 _AppWidgetManagerStub::SendTouchEvent(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
180 {
181         SysLog(NID_SHELL,"");
182         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendTouchEvent(instanceId, eventType, timestamp, x, y));
183         SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
184
185         return true;
186 }
187
188 bool
189 _AppWidgetManagerStub::SendTouchEventForPD(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
190 {
191         SysLog(NID_SHELL,"");
192         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendTouchEventForPD(instanceId, eventType, timestamp, x, y));
193         SysTryReturn(NID_SHELL, !IsFailed(r), false, r, "[%s] Propagated.", GetErrorMessage(r));
194
195         return true;
196 }
197
198 void
199 _AppWidgetManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
200 {
201         SysLog(NID_SHELL, "(appId:%ls, clientId:%d)\n", server.GetClientApplicationId().GetPointer(), server.GetClientId());
202
203         SysAssertf(__pIpcServer, "__pIpcServer is null!");
204
205         IPC_BEGIN_MESSAGE_MAP(_AppWidgetManagerStub, message)
206                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestUpdate, &server, OnRequestUpdate)
207                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestUpdateInstance, &server, OnRequestUpdateInstance)
208                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSharedMemoryId, &server, OnRequestSharedMemoryId)
209                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSharedMemoryIdForPD, &server, OnRequestSharedMemoryIdForPD)
210                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSyncSharedMemory, &server, OnRequestSyncSharedMemory)
211                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSyncSharedMemoryForPD, &server, OnRequestSyncSharedMemoryForPD)
212                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestReleaseSharedMemory, &server, OnRequestReleaseSharedMemory)
213                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestReleaseSharedMemoryForPD, &server, OnRequestReleaseSharedMemoryForPD)
214                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_SendResult, &server, OnSendResult)
215         IPC_END_MESSAGE_MAP()
216 }
217
218 void
219 _AppWidgetManagerStub::OnIpcServerStarted(const _IpcServer& server)
220 {
221         SysLog(NID_SHELL, "\n");
222 }
223
224 void
225 _AppWidgetManagerStub::OnIpcServerStopped(const _IpcServer& server)
226 {
227         SysLog(NID_SHELL, "\n");
228 }
229
230 void
231 _AppWidgetManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
232 {
233         SysLog(NID_SHELL, "(clientId:%d)\n", clientId);
234
235 }
236
237 void
238 _AppWidgetManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
239 {
240         SysLog(NID_SHELL, "(appId:%ls, clientId:%d)\n", server.GetClientApplicationId().GetPointer(), clientId);
241 }
242
243 }}}     // Tizen::Shell::App