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 "ClientInstance.h"
26 #include "ServerResource.h"
27 #include "SignatureHelper.h"
29 namespace smartcard_service_api
32 gboolean ClientInstance::_getCertificationHashes(gpointer user_data)
34 gboolean result = false;
35 ClientInstance *instance = (ClientInstance *)user_data;
37 SignatureHelper::getCertificationHashes(instance->getPID(), instance->certHashes);
43 void ClientInstance::setPID(int pid)
50 certHash = SignatureHelper::getCertificationHash(pid);
55 bool ClientInstance::createService(unsigned int context)
59 if (getService(context) == NULL)
61 ServiceInstance *instance = new ServiceInstance(this, context);
64 mapServices.insert(make_pair(context, instance));
69 SCARD_DEBUG_ERR("alloc failed");
74 SCARD_DEBUG_ERR("service already exist [%d]", context);
80 ServiceInstance *ClientInstance::getService(unsigned int context)
82 ServiceInstance *result = NULL;
83 map<unsigned int, ServiceInstance *>::iterator item;
85 if ((item = mapServices.find(context)) != mapServices.end())
87 result = item->second;
93 void ClientInstance::removeService(unsigned int context)
95 map<unsigned int, ServiceInstance *>::iterator item;
97 if ((item = mapServices.find(context)) != mapServices.end())
100 mapServices.erase(item);
104 void ClientInstance::removeServices()
106 map<unsigned int, ServiceInstance *>::iterator item;
108 for (item = mapServices.begin(); item != mapServices.end(); item++)
116 bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
119 map<unsigned int, ServiceInstance *>::iterator item;
121 for (item = mapServices.begin(); item != mapServices.end(); item++)
123 if (ServerIPC::getInstance()->sendMessage(socket, &msg) == false)
130 void ClientInstance::generateCertificationHashes()
133 g_idle_add(_getCertificationHashes, (gpointer)this);
135 SignatureHelper::getCertificationHashes(getPID(), certHashes);
138 } /* namespace smartcard_service_api */