2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
31 void ClientInstance::setPID(int pid)
38 certHash = SignatureHelper::getCertificationHash(pid);
43 bool ClientInstance::createService(unsigned int context)
47 if (getService(context) == NULL)
49 ServiceInstance *instance = new ServiceInstance(this, context);
52 mapServices.insert(make_pair(context, instance));
57 SCARD_DEBUG_ERR("alloc failed");
62 SCARD_DEBUG_ERR("service already exist [%d]", context);
68 ServiceInstance *ClientInstance::getService(unsigned int context)
70 ServiceInstance *result = NULL;
71 map<unsigned int, ServiceInstance *>::iterator item;
73 if ((item = mapServices.find(context)) != mapServices.end())
75 result = item->second;
81 void ClientInstance::removeService(unsigned int context)
83 map<unsigned int, ServiceInstance *>::iterator item;
85 if ((item = mapServices.find(context)) != mapServices.end())
88 mapServices.erase(item);
92 void ClientInstance::removeServices()
94 map<unsigned int, ServiceInstance *>::iterator item;
96 for (item = mapServices.begin(); item != mapServices.end(); item++)
104 bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
107 map<unsigned int, ServiceInstance *>::iterator item;
109 for (item = mapServices.begin(); item != mapServices.end(); item++)
111 if (ServerIPC::getInstance()->sendMessage(socket, &msg) == false)
118 } /* namespace smartcard_service_api */