Exemplo n.º 1
0
      BaseError CServiceManager::incomingProfile(Service::Uid const& service,
            Profile::Uid const& profile, Profile::ApiUid const& api)
      {
         LOG4CPLUS_TRACE(msLogger, "CServiceManager::incomingProfileRequest()=> requested  profile "
            + profile.value() +"for service"+service.value() );

         mActiveServicesMutex.lock();
         tServiceMap::iterator it = mActiveServices.find(service);
         if (mActiveServices.end() == it)
         {
            mActiveServicesMutex.unlock();
            return BaseError(1,"ServiceManager",BaseError::IVILINK_ERROR,"Can't load incoming profile");
         }
         ERROR_CODE err = it->second->incomingProfileRequest(profile,api);
         bool allLoaded = it->second->allLoaded();
         mActiveServicesMutex.unlock();

         if (ERR_OK != err)
         {
            if (mpClient)
            {
                LOG4CPLUS_ERROR(msLogger, service.value() + ": error " + convertIntegerToString(int(err)) +
                                "in incomingProfileRequest(" + profile.value() + ","+ api.value() + ")");
               mpClient->serviceLoadError(service);
            }
            unload(service);
            return BaseError(1,gModuleName, BaseError::IVILINK_ERROR, "incomingProfile-Error");
         }
         if (allLoaded && mpClient)
         {
            mpClient->serviceLoaded(service);
         }
         return BaseError::NoError(gModuleName, "incomingProfile-No_Error");
      }
Exemplo n.º 2
0
 bool CServiceManager::incomingLoad(const Service::Uid & service)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    mSystemServicesMutex.lock();
    tServiceSet::const_iterator it = mSystemServices.find(service);
    if (mSystemServices.end() == it)
    {
        LOG4CPLUS_ERROR( msLogger, "incomingLoad(" + service.value() + "): failed to find service");
       mSystemServicesMutex.unlock();
       return false;
    }
    mSystemServicesMutex.unlock();
    if(isServiceAlreadyLoaded(service)) 
    {
       return true;
    }
    CService * pService = new CService(mXmlPath, mAppInfo, service);
    mCallbacksMutex.lock();
    if (!pService->incomingLoad(mCallbacks))
    {
       mCallbacksMutex.unlock();
       delete pService;
        LOG4CPLUS_ERROR( msLogger, "pService->incomingLoad(" + service.value() + ") return false");
       return false;
    }
    mCallbacksMutex.unlock();
    mActiveServicesMutex.lock();
    mActiveServices[service] = pService;
    mActiveServicesMutex.unlock();
    return true;
 }
Exemplo n.º 3
0
 void CServiceManager::profileDied(Service::Uid const& service,
       Profile::IUid const& profileInstance )
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    LOG4CPLUS_WARN(msLogger, "service dropped: "+service.value());
    mActiveServicesMutex.lock();
    tServiceMap::iterator it = mActiveServices.find(service);
    Service::Uid complementedService = service;
    bool hasFound = false;
    if(mActiveServices.end() == it)
    {
       LOG4CPLUS_INFO(msLogger, "service was not among active, looking for its complement");
       for(it = mActiveServices.begin(); it != mActiveServices.end(); it++)
       {
          LOG4CPLUS_INFO(msLogger, "service: "+it->second->getUid().value());
          LOG4CPLUS_INFO(msLogger, "service's complement: "+it->second->getPairUid().value());
          if(it->second->getPairUid().value().compare(service.value()) == 0)
          {
             LOG4CPLUS_INFO(msLogger, "complement dropped: "+service.value());
             LOG4CPLUS_INFO(msLogger, "of: "+it->second->getUid().value());
             complementedService = it->second->getUid().value();
             hasFound = true;
             break;
          } else {
             LOG4CPLUS_TRACE(msLogger, "service dropped and current service's complement are not equal");
          }
       }
    } else {
       hasFound = true;
    }
    if(!hasFound)
    {  
       LOG4CPLUS_ERROR(msLogger, "The service that was dropped was now found among mActiveServices and their complements");
       mActiveServicesMutex.unlock();
       return;
    }
    if (it->second->correctState() && mpClient)
    {
       mpClient->serviceDropped(complementedService);
    }
    it->second->profileDied(profileInstance);
    if (it->second->allDied())
    {
       CService * pService = it->second;
       mActiveServices.erase(it);
       mActiveServicesMutex.unlock();
       delete pService;
    }
    else
    {
       mActiveServicesMutex.unlock();
    }
 }
Exemplo n.º 4
0
 bool CServiceManager::isServiceAlreadyLoaded(const Service::Uid & service)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    MutexLocker lock(mActiveServicesMutex);
    tServiceMap::const_iterator sit = mActiveServices.find(service);
    if (mActiveServices.end() != sit)
    {
       LOG4CPLUS_WARN( msLogger, "incomingLoad(" + service.value() + "): service already loaded");
       return true; //dmi3s  #1248579 was false. should be false.
    }
    return false;
 }
Exemplo n.º 5
0
 Error CServiceManager::load(const Service::Uid & service)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    mSystemServicesMutex.lock();
    tServiceSet::const_iterator it = mSystemServices.find(service);
    if (mSystemServices.end() == it)
    {
       mSystemServicesMutex.unlock();
       LOG4CPLUS_ERROR(msLogger, "hasn't found the requested service");
       return Error(SERVICE_NOT_FOUND, "The service requested: " + service.value() 
          + " was not found among system services, please check that it is present in " + mXmlPath, false);
    }
    mSystemServicesMutex.unlock();
    mActiveServicesMutex.lock();
    tServiceMap::const_iterator sit = mActiveServices.find(service);
    if (mActiveServices.end() != sit)
    {
       mActiveServicesMutex.unlock();
       LOG4CPLUS_ERROR(msLogger, "The requested service is among active!");
       return Error(SERVICE_ALREADY_LOADED, "The service requested: " + service.value() 
          + " is already loaded!", false);
    }
    mActiveServicesMutex.unlock();
    CService * pService = new CService(mXmlPath, mAppInfo, service);
    mCallbacksMutex.lock();
    Error cserviceError = pService->load(mCallbacks);
    if (!cserviceError.isNoError())
    {
       mCallbacksMutex.unlock();
       LOG4CPLUS_ERROR(msLogger, "CService couldn't load the service: " + cserviceError.toString());
       delete pService;
       return cserviceError;
    }
    mCallbacksMutex.unlock();
    mActiveServicesMutex.lock();
    mActiveServices[service] = pService;
    mActiveServicesMutex.unlock();
    LOG4CPLUS_TRACE(msLogger, "Loaded a service successfully");
    return Error::NoError();
 }
Exemplo n.º 6
0
 void CRunApp::useService(const Service::Uid & service, bool use)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    std::string strUse =use ? std::string("true") : std::string("false");
    LOG4CPLUS_FATAL(msLogger, "service: " + service.value() + "use : " + strUse);
    if (use)
    {
       mServices.insert(service);
    }
    else
    {
       mServices.erase(service);
    }
 }
Exemplo n.º 7
0
void ServiceRepository::init()
{
    LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__ );
    std::string repoPath;
#ifndef ANDROID
    char buf[256];
    getcwd(buf,255);
    repoPath = std::string(buf)+"/../database/services/";
#else
    repoPath = mConfigurator->getParam("path_to_services");
#endif //ANDROID

    std::string dbPath = repoPath
            #ifndef ANDROID
            + "HeadUnitServices.xml";
            #else
            + "AndroidServices.xml";
            #endif //ANDROID

    LOG4CPLUS_INFO(mLogger, "services xml path = " + repoPath);
    LOG4CPLUS_INFO(mLogger, "DB path = " + dbPath);

    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file(dbPath.c_str());
    if (result)
    {
        pugi::xml_node device_node = doc.child("device");
        for (pugi::xml_node service_node = device_node.child("service");
                service_node; service_node = service_node.next_sibling("service"))
        {
            if (strcmp(service_node.attribute("name").value(), "") != 0)
            {
                Service::Uid sid = Service::Uid(service_node.attribute("name").value());
                std::string maniPath = repoPath + sid.value() + std::string(".xml");
                UInt32 prio = atoi(service_node.attribute("priority").value());
                mServices.insert(std::make_pair(sid,new ServiceInfo(maniPath, prio)));
            }
        }
    }
    else
    {
        LOG4CPLUS_FATAL(mLogger, "Service repository load error: " +
                std::string(result.description()));
        killProcess(1);
    }
}