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 "ClientInstance.h"
25 #include "ServerResource.h"
26 #include "SignatureHelper.h"
28 namespace smartcard_service_api
31 gboolean ClientInstance::_getCertificationHashes(gpointer user_data)
33 gboolean result = false;
34 ClientInstance *instance = (ClientInstance *)user_data;
36 SignatureHelper::getCertificationHashes(instance->getPID(), instance->certHashes);
42 void ClientInstance::setPID(int pid)
49 certHash = SignatureHelper::getCertificationHash(pid);
54 bool ClientInstance::createService(unsigned int context)
58 if (getService(context) == NULL)
60 ServiceInstance *instance = new ServiceInstance(this, context);
63 mapServices.insert(make_pair(context, instance));
68 SCARD_DEBUG_ERR("alloc failed");
73 SCARD_DEBUG_ERR("service already exist [%d]", context);
79 ServiceInstance *ClientInstance::getService(unsigned int context)
81 ServiceInstance *result = NULL;
82 map<unsigned int, ServiceInstance *>::iterator item;
84 if ((item = mapServices.find(context)) != mapServices.end())
86 result = item->second;
92 void ClientInstance::removeService(unsigned int context)
94 map<unsigned int, ServiceInstance *>::iterator item;
96 if ((item = mapServices.find(context)) != mapServices.end())
99 mapServices.erase(item);
103 void ClientInstance::removeServices()
105 map<unsigned int, ServiceInstance *>::iterator item;
107 for (item = mapServices.begin(); item != mapServices.end(); item++)
115 bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
118 map<unsigned int, ServiceInstance *>::iterator item;
120 for (item = mapServices.begin(); item != mapServices.end(); item++)
122 if (ServerIPC::getInstance()->sendMessage(socket, &msg) == false)
129 void ClientInstance::generateCertificationHashes()
132 g_idle_add(_getCertificationHashes, (gpointer)this);
134 SignatureHelper::getCertificationHashes(getPID(), certHashes);
137 } /* namespace smartcard_service_api */