minor change
[framework/osp/appwidget-service.git] / src / FShell_AppWidgetManagerStub.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FShell_AppWidgetManagerStub.cpp
20  * @brief       This is the implementation for the _AppWidgetManagerStub class.
21  */
22
23 #include <FBase.h>
24 #include <FBaseSysLog.h>
25 #include <FIo_IpcServer.h>
26 #include <FShell_AppWidgetManagerIpcMessage.h>
27
28 #include "FShell_AppWidgetManagerStub.h"
29
30
31 namespace Tizen { namespace Shell  { namespace App {
32
33 namespace
34 {
35 const char IPC_SERVER_NAME[] = "osp.shell.ipcserver.appwidgetmanager";
36 const int INVALID_CLIENT_ID = -1;
37 };
38
39 using namespace Tizen::Base;
40 using namespace Tizen::Io;
41 using namespace Tizen::Text;
42 using namespace Tizen::Security;
43
44
45 _AppWidgetManagerStub::_AppWidgetManagerStub(void)
46 :__pIpcServer(null)
47 {
48         SysLog(NID_APP, "Enter\n");
49
50         SysLog(NID_APP, "Exit\n");
51 }
52
53 _AppWidgetManagerStub::~_AppWidgetManagerStub(void)
54 {
55         SysLog(NID_APP, "Enter\n");
56
57         if ( __pIpcServer != null)
58         {
59                 __pIpcServer->Stop();
60                 delete __pIpcServer;
61         }
62
63         SysLog(NID_APP, "Exit\n");
64 }
65
66 result
67 _AppWidgetManagerStub::StartIpcServer(void)
68 {
69         SysLog(NID_APP, "Enter.");
70         __pIpcServer = new (std::nothrow) _IpcServer();
71         SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
72
73         result r = __pIpcServer->Construct( IPC_SERVER_NAME, *this, false);
74         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
75         SysLog(NID_APP, "Exit.");
76
77         return E_SUCCESS;
78
79 CATCH:
80         delete __pIpcServer;
81         __pIpcServer = null;
82         return r;
83 }
84
85
86 /////////////////////////////////////////////
87 // handlers
88 /////////////////////////////////////////////
89
90
91
92 bool
93 _AppWidgetManagerStub::OnRequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument, result* pRes)
94 {
95         SysLog(NID_APP, "");
96         *pRes = RequestUpdate(appId, providerName, argument);
97         return true;
98 }
99
100 bool
101 _AppWidgetManagerStub::OnRequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument, result* pRes)
102 {
103         SysLog(NID_APP, "");
104         *pRes = RequestUpdateInstance(instanceId, argument);
105         return true;
106 }
107
108 bool
109 _AppWidgetManagerStub::OnRequestSharedMemoryId(const String& instanceId, int w, int h, int* pShmId)
110 {
111         SysLog(NID_APP, "(instanceId:%d)xxx", instanceId.GetPointer());
112
113         RequestSharedMemoryId(__pIpcServer->GetClientAppId(), instanceId, w, h, *pShmId);
114
115         return true;
116 }
117
118 bool
119 _AppWidgetManagerStub::OnRequestSharedMemoryIdForPD(const String& instanceId, int w, int h, int* pShmId)
120 {
121         SysLog(NID_APP, "(instanceId:%d)", instanceId.GetPointer());
122
123         RequestSharedMemoryIdForPD(__pIpcServer->GetClientAppId(), instanceId, w, h, *pShmId);
124
125         return true;
126 }
127
128 bool
129 _AppWidgetManagerStub::OnRequestSyncSharedMemory(const String& instanceId, int w, int h, result* pRes)
130 {
131         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
132
133         *pRes = RequestSyncSharedMemory(__pIpcServer->GetClientAppId(), instanceId, w, h);
134
135         return true;
136 }
137
138 bool
139 _AppWidgetManagerStub::OnRequestSyncSharedMemoryForPD(const String& instanceId, result* pRes)
140 {
141         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
142
143         *pRes = RequestSyncSharedMemoryForPD(__pIpcServer->GetClientAppId(), instanceId);
144
145         return true;
146 }
147
148 bool
149 _AppWidgetManagerStub::OnRequestReleaseSharedMemory(const String& instanceId, result* pRes)
150 {
151         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
152
153         *pRes = RequestReleaseSharedMemory(__pIpcServer->GetClientAppId(), instanceId);
154
155         return true;
156 }
157
158 bool
159 _AppWidgetManagerStub::OnRequestReleaseSharedMemoryForPD(const String& instanceId, result* pRes)
160 {
161         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
162
163         *pRes = RequestReleaseSharedMemoryForPD(__pIpcServer->GetClientAppId(), instanceId);
164
165         return true;
166 }
167
168 bool
169 _AppWidgetManagerStub::SendTouchEvent(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
170 {
171         SysLog(NID_APP,"");
172         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendTouchEvent(instanceId, eventType, timestamp, x, y));
173         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
174         return true;
175 }
176
177 bool
178 _AppWidgetManagerStub::SendTouchEventForPD(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
179 {
180         SysLog(NID_APP,"");
181         result r = __pIpcServer->SendResponse(clientId, new AppWidgetManager_SendTouchEventForPD(instanceId, eventType, timestamp, x, y));
182         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
183
184         return true;
185 }
186
187
188 void
189 _AppWidgetManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
190 {
191         SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
192
193         SysAssertf(__pIpcServer, "__pIpcServer is null!");
194
195         IPC_BEGIN_MESSAGE_MAP(_AppWidgetManagerStub, message)
196                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestUpdate, &server, OnRequestUpdate)
197                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestUpdateInstance, &server, OnRequestUpdateInstance)
198                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSharedMemoryId, &server, OnRequestSharedMemoryId)
199                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSharedMemoryIdForPD, &server, OnRequestSharedMemoryIdForPD)
200                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSyncSharedMemory, &server, OnRequestSyncSharedMemory)
201                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestSyncSharedMemoryForPD, &server, OnRequestSyncSharedMemoryForPD)
202                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestReleaseSharedMemory, &server, OnRequestReleaseSharedMemory)
203                 IPC_MESSAGE_HANDLER_EX(AppWidgetManager_RequestReleaseSharedMemoryForPD, &server, OnRequestReleaseSharedMemoryForPD)
204         IPC_END_MESSAGE_MAP()
205 }
206
207 void
208 _AppWidgetManagerStub::OnIpcServerStarted(const _IpcServer& server)
209 {
210         SysLog(NID_APP, "\n");
211 }
212
213 void
214 _AppWidgetManagerStub::OnIpcServerStopped(const _IpcServer& server)
215 {
216         SysLog(NID_APP, "\n");
217 }
218
219 void
220 _AppWidgetManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
221 {
222         SysLog(NID_APP, "(clientId:%d)\n", clientId);
223
224 }
225
226 void
227 _AppWidgetManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
228 {
229         SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
230 }
231
232
233 }}}//namespace Tizen { namespace Shell  { namespace App {