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.
17 /* standard library header */
20 /* SLP library header */
24 #include "ClientDispatcher.h"
25 #include "SEService.h"
28 #include "ClientChannel.h"
30 namespace smartcard_service_api
32 ClientDispatcher::ClientDispatcher()
36 ClientDispatcher::~ClientDispatcher()
38 mapSESerivces.clear();
41 ClientDispatcher &ClientDispatcher::getInstance()
43 static ClientDispatcher clientDispatcher;
45 return clientDispatcher;
48 bool ClientDispatcher::addSEService(void *context, SEService *service)
51 map<void *, SEService *>::iterator item;
55 if ((item = mapSESerivces.find(context)) == mapSESerivces.end())
57 mapSESerivces.insert(make_pair(context, service));
61 SCARD_DEBUG("SEService [%p] exists", context);
69 void ClientDispatcher::removeSEService(void *context)
71 map<void *, SEService *>::iterator item;
75 if ((item = mapSESerivces.find(context)) != mapSESerivces.end())
77 mapSESerivces.erase(item);
81 SCARD_DEBUG("SEService doesn't exist");
87 void *ClientDispatcher::dispatcherThreadFunc(DispatcherMsg *msg, void *data)
94 /* this messages are response from server */
97 /* SE Service requests */
98 case Message::MSG_REQUEST_READERS :
99 case Message::MSG_REQUEST_SHUTDOWN :
101 if (msg->isSynchronousCall() == false)
103 DispatcherMsg *tempMsg = new DispatcherMsg(msg);
105 /* Asynchronous call */
106 g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
110 /* Synchronous call */
111 SEService::dispatcherCallback(msg);
116 /* Reader requests */
117 case Message::MSG_REQUEST_OPEN_SESSION :
119 if (msg->isSynchronousCall() == false)
121 DispatcherMsg *tempMsg = new DispatcherMsg(msg);
123 /* Asynchronous call */
124 g_idle_add((GSourceFunc)&Reader::dispatcherCallback, (gpointer)tempMsg);
128 /* Synchronous call */
129 Reader::dispatcherCallback(msg);
134 /* Session requests */
135 case Message::MSG_REQUEST_OPEN_CHANNEL :
136 case Message::MSG_REQUEST_GET_ATR :
137 case Message::MSG_REQUEST_CLOSE_SESSION :
138 case Message::MSG_REQUEST_GET_CHANNEL_COUNT :
140 if (msg->isSynchronousCall() == false)
142 DispatcherMsg *tempMsg = new DispatcherMsg(msg);
144 /* Asynchronous call */
145 g_idle_add((GSourceFunc)&Session::dispatcherCallback, (gpointer)tempMsg);
149 /* Synchronous call */
150 Session::dispatcherCallback(msg);
155 /* ClientChannel requests */
156 case Message::MSG_REQUEST_TRANSMIT :
157 case Message::MSG_REQUEST_CLOSE_CHANNEL :
159 if (msg->isSynchronousCall() == false)
161 DispatcherMsg *tempMsg = new DispatcherMsg(msg);
163 /* Asynchronous call */
164 g_idle_add((GSourceFunc)&ClientChannel::dispatcherCallback, (gpointer)tempMsg);
168 /* Synchronous call */
169 ClientChannel::dispatcherCallback(msg);
174 case Message::MSG_NOTIFY_SE_INSERTED :
175 case Message::MSG_NOTIFY_SE_REMOVED :
177 map<void *, SEService *>::iterator item;
179 for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
181 DispatcherMsg *tempMsg = new DispatcherMsg(msg);
183 tempMsg->caller = item->second;
185 /* Always asynchronous call */
186 g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
191 case Message::MSG_OPERATION_RELEASE_CLIENT :
193 map<void *, SEService *>::iterator item;
195 for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
197 DispatcherMsg *tempMsg = new DispatcherMsg(msg);
199 tempMsg->caller = item->second;
202 /* Always asynchronous call */
203 g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
217 } /* namespace open_mobile_api */