2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 /* standard library header */
21 /* SLP library header */
25 #include "ClientDispatcher.h"
26 #include "SEService.h"
29 #include "ClientChannel.h"
31 namespace smartcard_service_api
33 ClientDispatcher::ClientDispatcher()
37 ClientDispatcher::~ClientDispatcher()
39 mapSESerivces.clear();
42 ClientDispatcher &ClientDispatcher::getInstance()
44 static ClientDispatcher clientDispatcher;
46 return clientDispatcher;
49 bool ClientDispatcher::addSEService(unsigned int handle, SEService *service)
52 map<unsigned int, SEService *>::iterator item;
56 if ((item = mapSESerivces.find(handle)) == mapSESerivces.end())
58 mapSESerivces.insert(make_pair(handle, service));
62 _DBG("SEService [%p] exists", handle);
70 void ClientDispatcher::removeSEService(unsigned int handle)
72 map<unsigned int, SEService *>::iterator item;
76 if ((item = mapSESerivces.find(handle)) != mapSESerivces.end())
78 mapSESerivces.erase(item);
82 _DBG("SEService doesn't exist");
88 void *ClientDispatcher::dispatcherThreadFunc(DispatcherMsg *msg, void *data)
95 /* this messages are response from server */
98 /* SE Service requests */
99 case Message::MSG_REQUEST_READERS :
100 case Message::MSG_REQUEST_SHUTDOWN :
102 DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
104 if (msg->isSynchronousCall() == false)
106 /* Asynchronous call */
107 g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
111 /* Synchronous call */
112 SEService::dispatcherCallback(tempMsg);
117 /* Reader requests */
118 case Message::MSG_REQUEST_OPEN_SESSION :
120 DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
122 if (msg->isSynchronousCall() == false)
124 /* Asynchronous call */
125 g_idle_add((GSourceFunc)&Reader::dispatcherCallback, (gpointer)tempMsg);
129 /* Synchronous call */
130 Reader::dispatcherCallback(tempMsg);
135 /* Session requests */
136 case Message::MSG_REQUEST_OPEN_CHANNEL :
137 case Message::MSG_REQUEST_GET_ATR :
138 case Message::MSG_REQUEST_CLOSE_SESSION :
139 case Message::MSG_REQUEST_GET_CHANNEL_COUNT :
141 DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
143 if (msg->isSynchronousCall() == false)
145 /* Asynchronous call */
146 g_idle_add((GSourceFunc)&Session::dispatcherCallback, (gpointer)tempMsg);
150 /* Synchronous call */
151 Session::dispatcherCallback(tempMsg);
156 /* ClientChannel requests */
157 case Message::MSG_REQUEST_TRANSMIT :
158 case Message::MSG_REQUEST_CLOSE_CHANNEL :
160 DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
162 if (msg->isSynchronousCall() == false)
164 /* Asynchronous call */
165 g_idle_add((GSourceFunc)&ClientChannel::dispatcherCallback, (gpointer)tempMsg);
169 /* Synchronous call */
170 ClientChannel::dispatcherCallback(tempMsg);
175 case Message::MSG_NOTIFY_SE_INSERTED :
176 case Message::MSG_NOTIFY_SE_REMOVED :
178 map<unsigned int, SEService *>::iterator item;
180 for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
182 DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
184 tempMsg->caller = item->second;
186 /* Always asynchronous call */
187 g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
192 case Message::MSG_OPERATION_RELEASE_CLIENT :
194 map<unsigned int, SEService *>::iterator item;
196 for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
198 DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
200 tempMsg->caller = item->second;
203 /* Always asynchronous call */
204 g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
218 } /* namespace open_mobile_api */
219 #endif /* USE_GDBUS */