change IpcService to run on seperated thread
[framework/osp/appwidget-service.git] / src / FShell_LiveboxManagerStub.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // All rights reserved.
5 //
6 // This software contains confidential and proprietary information
7 // of Samsung Electronics Co., Ltd.
8 // The user of this software agrees not to disclose, disseminate or copy such
9 // Confidential Information and shall use the software only in accordance with
10 // the terms of the license agreement the user entered into with Samsung.
11 //
12
13 /**
14  * @file        FAppAppManager.cpp
15  * @brief       This is the implementation for the AppManager class.
16  */
17
18 #include <FBase.h>
19 #include <FBaseSysLog.h>
20 #include <FIo_IpcServer.h>
21 #include <FShell_LiveboxManagerIpcMessage.h>
22
23 #include "FShell_LiveboxManagerStub.h"
24
25
26 namespace Tizen { namespace Shell  { namespace App {
27
28 namespace
29 {
30 const char IPC_SERVER_NAME[] = "osp.shell.ipcserver.liveboxmanager";
31 const int INVALID_CLIENT_ID = -1;
32 };
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
36 using namespace Tizen::Text;
37 using namespace Tizen::Security;
38
39
40 _LiveboxManagerStub::_LiveboxManagerStub(void)
41 :__pIpcServer(null)
42 {
43         SysLog(NID_APP, "Enter\n");
44
45         SysLog(NID_APP, "Exit\n");
46 }
47
48 _LiveboxManagerStub::~_LiveboxManagerStub(void)
49 {
50         SysLog(NID_APP, "Enter\n");
51
52         if ( __pIpcServer != null)
53         {
54                 __pIpcServer->Stop();
55                 delete __pIpcServer;
56         }
57
58         SysLog(NID_APP, "Exit\n");
59 }
60
61 result
62 _LiveboxManagerStub::StartIpcServer(void)
63 {
64         SysLog(NID_APP, "Enter.");
65         __pIpcServer = new (std::nothrow) _IpcServer();
66         SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
67
68         result r = __pIpcServer->Construct( IPC_SERVER_NAME, *this, false);
69         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
70         SysLog(NID_APP, "Exit.");
71
72         return E_SUCCESS;
73
74 CATCH:
75         delete __pIpcServer;
76         __pIpcServer = null;
77         return r;
78 }
79
80
81 /////////////////////////////////////////////
82 // handlers
83 /////////////////////////////////////////////
84
85
86
87 bool
88 _LiveboxManagerStub::OnRequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, result* pRes)
89 {
90         SysLog(NID_APP, "");
91         *pRes = RequestUpdate(appId, providerName);
92         return true;
93 }
94
95 bool
96 _LiveboxManagerStub::OnRequestSharedMemoryId(const String& instanceId, int w, int h, int* pShmId)
97 {
98         SysLog(NID_APP, "(instanceId:%d)xxx", instanceId.GetPointer());
99
100         RequestSharedMemoryId(__pIpcServer->GetClientAppId(), instanceId, w, h, *pShmId);
101
102         return true;
103 }
104
105 bool
106 _LiveboxManagerStub::OnRequestSharedMemoryIdForPD(const String& instanceId, int w, int h, int* pShmId)
107 {
108         SysLog(NID_APP, "(instanceId:%d)", instanceId.GetPointer());
109
110         RequestSharedMemoryIdForPD(__pIpcServer->GetClientAppId(), instanceId, w, h, *pShmId);
111
112         return true;
113 }
114
115 bool
116 _LiveboxManagerStub::OnRequestSyncSharedMemory(const String& instanceId, int w, int h, result* pRes)
117 {
118         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
119
120         *pRes = RequestSyncSharedMemory(__pIpcServer->GetClientAppId(), instanceId, w, h);
121
122         return true;
123 }
124
125 bool
126 _LiveboxManagerStub::OnRequestSyncSharedMemoryForPD(const String& instanceId, result* pRes)
127 {
128         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
129
130         *pRes = RequestSyncSharedMemoryForPD(__pIpcServer->GetClientAppId(), instanceId);
131
132         return true;
133 }
134
135 bool
136 _LiveboxManagerStub::OnRequestReleaseSharedMemory(const String& instanceId, result* pRes)
137 {
138         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
139
140         *pRes = RequestReleaseSharedMemory(__pIpcServer->GetClientAppId(), instanceId);
141
142         return true;
143 }
144
145 bool
146 _LiveboxManagerStub::OnRequestReleaseSharedMemoryForPD(const String& instanceId, result* pRes)
147 {
148         SysLog(NID_APP, "(instanceId:%ls)", instanceId.GetPointer());
149
150         *pRes = RequestReleaseSharedMemoryForPD(__pIpcServer->GetClientAppId(), instanceId);
151
152         return true;
153 }
154
155 bool
156 _LiveboxManagerStub::SendTouchEvent(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
157 {
158         SysLog(NID_APP,"");
159         result r = __pIpcServer->SendResponse(clientId, new LiveboxManager_SendTouchEvent(instanceId, eventType, timestamp, x, y));
160         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
161         return true;
162 }
163
164 bool
165 _LiveboxManagerStub::SendTouchEventForPD(const int clientId, const String& instanceId, int eventType, double timestamp, double x, double y)
166 {
167         SysLog(NID_APP,"");
168         result r = __pIpcServer->SendResponse(clientId, new LiveboxManager_SendTouchEventForPD(instanceId, eventType, timestamp, x, y));
169         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
170
171         return true;
172 }
173
174
175 void
176 _LiveboxManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
177 {
178         SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
179
180         IPC_BEGIN_MESSAGE_MAP(_LiveboxManagerStub, message)
181                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestUpdate, &server, OnRequestUpdate)
182                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestSharedMemoryId, &server, OnRequestSharedMemoryId)
183                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestSharedMemoryIdForPD, &server, OnRequestSharedMemoryIdForPD)
184                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestSyncSharedMemory, &server, OnRequestSyncSharedMemory)
185                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestSyncSharedMemoryForPD, &server, OnRequestSyncSharedMemoryForPD)
186                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestReleaseSharedMemory, &server, OnRequestReleaseSharedMemory)
187                 IPC_MESSAGE_HANDLER_EX(LiveboxManager_RequestReleaseSharedMemoryForPD, &server, OnRequestReleaseSharedMemoryForPD)
188         IPC_END_MESSAGE_MAP()
189 }
190
191 void
192 _LiveboxManagerStub::OnIpcServerStarted(const _IpcServer& server)
193 {
194         SysLog(NID_APP, "\n");
195 }
196
197 void
198 _LiveboxManagerStub::OnIpcServerStopped(const _IpcServer& server)
199 {
200         SysLog(NID_APP, "\n");
201 }
202
203 void
204 _LiveboxManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
205 {
206         SysLog(NID_APP, "(clientId:%d)\n", clientId);
207
208 }
209
210 void
211 _LiveboxManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
212 {
213         SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
214 }
215
216
217 }}}//namespace Tizen { namespace Shell  { namespace App {