Added Gtest for smartcard-service
[platform/core/connectivity/smartcard-service.git] / server / ClientInstance.cpp
index 667608b..2606405 100644 (file)
 
 namespace smartcard_service_api
 {
-       gboolean ClientInstance::_getCertificationHashes(gpointer user_data)
-       {
-               gboolean result = false;
-               ClientInstance *instance = (ClientInstance *)user_data;
-
-               SignatureHelper::getCertificationHashes(instance->getPID(), instance->certHashes);
-
-               return result;
-       }
-
-       void ClientInstance::setPID(int pid)
-       {
-               this->pid = pid;
-
-       }
-
-       ServiceInstance *ClientInstance::createService(unsigned int context)
+       ServiceInstance *ClientInstance::createService()
        {
                ServiceInstance *result = NULL;
 
-               if ((result = getService(context)) == NULL)
-               {
-                       result = new ServiceInstance(this, context);
-                       if (result != NULL)
-                       {
-                               mapServices.insert(make_pair(context, result));
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("alloc failed");
-                       }
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("service already exist [%d]", context);
+               result = new ServiceInstance(this);
+               if (result != NULL) {
+                       mapServices.insert(make_pair(result->getHandle(), result));
+               } else {
+                       _ERR("alloc failed"); //LCOV_EXCL_LINE
                }
 
                return result;
        }
 
-       ServiceInstance *ClientInstance::getService(unsigned int context)
+       ServiceInstance *ClientInstance::getService(unsigned int handle)
        {
+               /* LCOV_EXCL_START */
                ServiceInstance *result = NULL;
                map<unsigned int, ServiceInstance *>::iterator item;
 
-               if ((item = mapServices.find(context)) != mapServices.end())
+               if ((item = mapServices.find(handle)) != mapServices.end())
                {
                        result = item->second;
                }
 
                return result;
+               /* LCOV_EXCL_STOP */
        }
 
-       void ClientInstance::removeService(unsigned int context)
+       void ClientInstance::removeService(unsigned int handle)
        {
+               /* LCOV_EXCL_START */
                map<unsigned int, ServiceInstance *>::iterator item;
 
-               if ((item = mapServices.find(context)) != mapServices.end())
+               if ((item = mapServices.find(handle)) != mapServices.end())
                {
                        delete item->second;
                        mapServices.erase(item);
                }
+               /* LCOV_EXCL_STOP */
        }
 
        void ClientInstance::removeServices()
@@ -103,22 +81,8 @@ namespace smartcard_service_api
                mapServices.clear();
        }
 
-       bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
-       {
-               bool result = true;
-               map<unsigned int, ServiceInstance *>::iterator item;
-
-               for (item = mapServices.begin(); item != mapServices.end(); item++)
-               {
-                       if (ServerIPC::getInstance()->sendMessage(socket, &msg) == false)
-                               result = false;
-               }
-
-               return result;
-       }
-
        void ClientInstance::generateCertificationHashes()
        {
-               g_idle_add(_getCertificationHashes, (gpointer)this);
+               SignatureHelper::getCertificationHashes(getPID(), certHashes);
        }
 } /* namespace smartcard_service_api */