CPMALError CPmalCore::getProfileLibPath(Profile::Uid id, std::string& path) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); bool res = mpIpc->getProfileLibPath(id,path); return res ? CPMALError::NoPMALError() : CPMALError(CPMALError::ERROR_OTHER); }
CPMALError CPIM::generatePIUID(iviLink::CUid const& profileUid, iviLink::Service::Uid const& serviceUID, iviLink::Profile::IUid & piuid) { bool remote = false; mIncomingPrfMapMutex.lock(); { if (!mIncomingPrfMap.empty()) { tIncomingPrfMap::iterator it = mIncomingPrfMap.find(std::make_pair(serviceUID, profileUid)); if (it != mIncomingPrfMap.end()) { piuid = it->second; mIncomingPrfMap.erase(it); remote = true; } } } mIncomingPrfMapMutex.unlock(); if (remote) return CPMALError::NoPMALError(gModuleName); CError err = PIM::getPIUID(piuid); if (!err.isNoError()) { LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "no piuid"); } return CPMALError::NoPMALError(gModuleName); }
CPMALError CPmalCore::getProfileInfo(iviLink::Profile::Uid id, ProfileInfo & profInfo) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); std::string profileManifest; bool res = mpIpc->getManifest(id, profileManifest); profInfo.params.clear(); if (!res) { profInfo.apiUid = BaseUid(""); profInfo.complement = BaseUid(""); profInfo.name = ""; profInfo.uid = BaseUid(""); profInfo.version = 0; return CPMALError(CPMALError::ERROR_OTHER); } pugi::xml_document doc; pugi::xml_parse_result pugiRes = doc.load(profileManifest.c_str()); if(pugi::status_ok != pugiRes.status) { LOG4CPLUS_ERROR(logger, "CPmpCoreProfileInfo::parseXml() :: Error while parsing Profile manifest"); return CPMALError(CPMALError::ERROR_MANIFEST_PARSING); } pugi::xml_node prof = doc.child("profile"); profInfo.uid = iviLink::Profile::Uid(prof.child_value("uid")); profInfo.apiUid = iviLink::Profile::ApiUid(prof.child("api").attribute("uid").value()); profInfo.name = prof.child_value("name"); profInfo.version = atoi(prof.child_value("version")); profInfo.complement = iviLink::Profile::Uid(prof.child_value("complement")); pugi::xml_node attrs = prof.child("attributes"); for (pugi::xml_node_iterator it = attrs.begin(); it != attrs.end(); ++it) { if (it->name() == std::string("attribute")) { std::string atr = it->attribute("name").value(); if (atr != "") { profInfo.params[atr] = it->attribute("value").value(); } } } return CPMALError::NoPMALError(); }
CPMALError CPMALComponentMgr::create(IProfileManagerCallbacks* pClbs, conf::Configurator* pConf/* = NULL*/) { if (mpInstance) return CPMALError(CPMALError::ERROR_PMAL_ALREADY_INITIALIZED, gModuleName, "already created"); mpInstance = new CPMALComponentMgr(); if (!mpInstance) return CPMALError(CPMALError::ERROR_OTHER, gModuleName, "memory error"); CPMALError err = mpInstance->mpImpl->init(pClbs, pConf); if (!err.isNoError()) { delete mpInstance; mpInstance = NULL; } return err; }
CPMALError CPmalCore::findProfiles(iviLink::BaseUid id, const std::map<std::string, std::string> & profileParameters , std::list<iviLink::Profile::Uid> & profiles, bool enabledProfiles/* = true*/) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); profiles.clear(); bool res = mpIpc->findProfiles(id, profileParameters, profiles, enabledProfiles); return res ? CPMALError::NoPMALError() : CPMALError(CPMALError::ERROR_OTHER); }
CPMALError CPIM::unloadProfile(Profile::CProfile *& profile) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__ + (" " + convertIntegerToString((intptr_t)profile))); Profile::IUid piuid; CError err = mInstanceMap.find(profile, piuid); if (!err.isNoError()) { /// @todo what error handling can be here? LOG4CPLUS_INFO(logger, "todo what error handling can be here?"); LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_WRONG_PARAM, gModuleName); } unloadProfile(piuid, profile); return CPMALError::NoPMALError(gModuleName); }
CPMALError init(IProfileManagerCallbacks* pClbs, conf::Configurator* pConfig) { mpProfileManagerCallbacks = pClbs; mpConfig = pConfig; std::string pmpAddr; if (mpConfig) { pmpAddr = mpConfig->getParam("pmp_ipc_address"); } mpIpcProtocol = new Ipc::CIpcProtocol(pmpAddr.empty() ? NULL : pmpAddr.c_str()); BaseError err = mpIpcProtocol->connect(); while(!err.isNoError()) { err = mpIpcProtocol->connect(); usleep(5000000); } if (!err.isNoError()) { delete mpIpcProtocol; mpIpcProtocol = NULL; LOG4CPLUS_ERROR(msLogger, "CComponentMgrImpl::init() " + static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_OTHER, gModuleName, "ipc error"); } mpCore = new CPmalCore(mpIpcProtocol); mpPim = new CPIM(); return CPMALError::NoPMALError(gModuleName); }
CPMALError CPmalCore::disableByUid(iviLink::BaseUid id) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); bool res = mpIpc->disableByUid(id); return res ? CPMALError::NoPMALError() : CPMALError(CPMALError::ERROR_OTHER); }
CPMALError CPmalCore::enableAll() { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); bool res = mpIpc->enableAll(); return res ? CPMALError::NoPMALError() : CPMALError(CPMALError::ERROR_OTHER); }
CPMALError CPIM::loadProfile(iviLink::Profile::Uid const& profileUid, iviLink::Service::Uid const& sid, iviLink::Profile::IProfileCallbackProxy* const pProxy, Profile::CProfile*& pProfile) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__ + (" uid" + profileUid.value())); Profile::CProfile* pProf = NULL; std::string path; // prepearing CPMALComponentMgr* pMgr = CPMALComponentMgr::getInstance(); if (!pMgr) { return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "no instance of CPMALComponentMgr. Something is very wrong"); } IPMALCoreToPIM* pCore = pMgr->getCoreToPIM(); if (!pCore) { return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "no instance of PMAL Core"); } bool profileEnabled = false; CError err = pCore->isEnabledProfile(profileUid, profileEnabled); if (!err.isNoError()) { LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "unable to get state of profile"); } if (!profileEnabled) { LOG4CPLUS_ERROR(logger, "profile is disabled"); return CPMALError(CPMALError::ERROR_UNKNOWN_PROFILE_UID, gModuleName, "profile is disabled or unknown"); } err = pCore->getProfileLibPath(profileUid, path); if (!err.isNoError()) { LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_UNKNOWN_PROFILE_UID, gModuleName, "no profile library path"); } Profile::IUid piuid; { CPMALError err = generatePIUID(profileUid, sid, piuid); if (!err.isNoError()) return err; } // creating LOG4CPLUS_INFO(logger, "creating profile '" + path + "'with piuid '" + piuid.value() + "'"); Profile::CProfileInternal* pProfInt = NULL; PIM::ProfileInitData initData(piuid, sid, pProxy); err = PIM::createProfileImpl(path.c_str(), initData, pProfInt); if (!err.isNoError()) { PIM::releasePIUID(piuid); LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "unable to create profile object"); } assert(pProfInt); err = pProfInt->getError(); if (!err.isNoError()) { PIM::releasePIUID(piuid); err = pProfInt->getError(); LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); PIM::CProfileDestroyer::destroy(pProfInt); return CPMALError(CPMALError::ERROR_PROFILE_INIT, gModuleName, "profile implementation init error"); } // registering pProf = static_cast<Profile::CProfile*>(pProfInt); err = mInstanceMap.registerProfile(piuid, pProf); if (!err.isNoError()) { PIM::CProfileDestroyer::destroy(pProf); LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); return CPMALError(CPMALError::ERROR_PIM_INTERNAL, gModuleName, "unable to register profile object"); } // messaging IPMALIpcToPIM* ipc = pMgr->getIpcToPIM(); assert(ipc); err = ipc->createProfile(profileUid, piuid, sid); if (!err.isNoError()) { /// @todo what error handling can be here? LOG4CPLUS_INFO(logger, "todo what error handling can be here?"); LOG4CPLUS_ERROR(logger, static_cast<std::string>(err)); } // enabling PIM::CProfileEnabler::enable(pProf); pProfile = pProf; return CPMALError::NoPMALError(gModuleName); }