bool PmpIpcProtocol::findProfilesResponse(const std::list<iviLink::Profile::Uid> & profiles, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); CBuffer writeBuf = mWriteBufMgr.getBuffer(); ProfileManager::Ipc::PmMessage* req = reinterpret_cast<ProfileManager::Ipc::PmMessage*>(writeBuf.get()); req->header.type = ProfileManager::Ipc::PMP_PMAL_FIND_PROFILES; iviLink::Ipc::Helpers::CBufferWriter writer(req->data, writeBuf.getSize() - sizeof(req->header)); BaseError err = writer.write(profiles.begin(), profiles.end()); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } req->header.size = writer.getUsedSize(); iviLink::Ipc::MsgID id = mMsgIdGen.getNext(); UInt32 const reqSize = sizeof(ProfileManager::Ipc::PmMessage) + req->header.size; err = mIpc->asyncRequest(id, writeBuf.get(), reqSize, &dirId); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } return true; }
void IpcClient::testCaseShutdownOnRequest() { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__); BaseError err = mIpc->connect(); assert (err.isNoError()); mSema.wait(); }
void PmpIpcProtocol::processFindProfilesRequest(ProfileManager::Ipc::PmMessage const* const req, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); iviLink::Profile::Uid uid; iviLink::Ipc::Helpers::CBufferReader reader(req->data, req->header.size); BaseError err = reader.read(uid); if (!err.isNoError()) { return; } std::map<std::string, std::string> profileParameters; err = reader.readMap(std::inserter(profileParameters, profileParameters.begin())); if (!err.isNoError()) { return; } bool enabledProfile; err = reader.read(enabledProfile); if (!err.isNoError()) { return; } mCore->findProfiles(uid, profileParameters, enabledProfile, dirId); }
void IpcServer::sendKill(iviLink::Ipc::DirectionID * pDirID) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__); std::string dieRequest(DIE_REQUEST); UInt8 * writeBuf = new UInt8(dieRequest.size()); memcpy(writeBuf, dieRequest.c_str(), dieRequest.size()); UInt8 * readBuf = new UInt8(1); UInt32 respSize = 1; timeval begin, end; double requestTime; gettimeofday(&begin, NULL); BaseError err = mIpc->request(mMsgIdGen.getNext(), writeBuf, dieRequest.size(), readBuf, respSize, pDirID); assert (!err.isNoError()); LOG4CPLUS_INFO(mLogger, "Request returned an error as expected"); assert (err.getCode() == CIpcError::ERROR_CONNECTION_LOST); LOG4CPLUS_INFO(mLogger, "Request returned an error and the error code is as expected"); gettimeofday(&end, NULL); requestTime = (end.tv_sec - begin.tv_sec) * 1000.0; // sec to ms requestTime += (end.tv_usec - begin.tv_usec) / 1000.0; // us to ms std::ostringstream s; s << "(" << requestTime << ") ms"; LOG4CPLUS_INFO(mLogger, "Time elapsed requesting: " + s.str()); assert (requestTime < 100); LOG4CPLUS_INFO(mLogger, "Request's time is within the expected limits"); delete writeBuf; delete readBuf; }
bool connect() { BaseError err = BaseError::NoError(); if (mpIpc == NULL) { char const * addr; if (gpNEGOTIATOR_IPC_ADDR != NULL) { addr = gpNEGOTIATOR_IPC_ADDR; } else { addr = ipcNegotiatorId; } mpIpc = new CIpc(addr, *this); } for (int tryNum = 1; tryNum <= MAX_TRY_COUNT; ++tryNum) { err = mpIpc->connect(); if (err.isNoError()) { return true; } sleep(2); } return false; }
CTrustList::CTrustList(std::string pathToStorage) : mpStorage(new CFileStorage(pathToStorage.c_str())) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); BaseError err = mpStorage->connect(); if (!err.isNoError()) LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); }
void L1InterfaceStub::start(bool isServer, const char* sockPath) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); mpAgent = new CConnectivityAgent(isServer); mpAgent->start(); mpIpc = new iviLink::Ipc::CIpc(sockPath, *this); BaseError err = mpIpc->beginWaitForConnection(); assert(err.isNoError()); }
void L1InterfaceStub::processServiceDeallocateResponse(CDataAccessor & accessor) { UInt32 channel_id = accessor.getChannelID(); UInt32 errCode = 0; memcpy(&errCode, accessor.getData(), sizeof(UInt32)); ConnectivityAgentError ret(static_cast<ConnectivityAgentError::AgentErrorCodes>(errCode)); LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateResponse() => " "Channel deallocated responce id = " + convertIntegerToString(channel_id) + " err = " + convertIntegerToString((int)ret.getCode())); if (ret.isNoError()) { ret = deallocateChannel(channel_id); if (ret.isNoError()) { bool found = false; iviLink::Ipc::DirectionID dirId; mRegistryMutex.lock(); { tChannelsRegistryMap::iterator iter = mL1ChannelRegistry.find(channel_id); if (iter != mL1ChannelRegistry.end()) { dirId = iter->second.mClientDir; found = true; mL1ChannelRegistry.erase(iter); } } mRegistryMutex.unlock(); if (found) { UInt8* buf = new UInt8[accessor.getObjectSize()]; accessor.copyToRawArray(buf); BaseError err = mpIpc->asyncRequest(mMsgIdGen.next(), buf, accessor.getObjectSize(), &dirId); if (!err.isNoError()) { LOG4CPLUS_WARN(logger, static_cast<std::string>(err)); } delete [] buf; } else { LOG4CPLUS_INFO(logger, "Channel " + convertIntegerToString(channel_id) + " is not found. Probably, already deleted"); } } } }
void PmpIpcProtocol::processDisableByUidRequest(ProfileManager::Ipc::PmMessage const* const req, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); iviLink::Profile::Uid uid; iviLink::Ipc::Helpers::CBufferReader reader(req->data, req->header.size); BaseError err = reader.read(uid); if (!err.isNoError()) { return; } mCore->disableByClient(uid, dirId); }
void L1InterfaceStub::processServiceDeallocateRequest(CDataAccessor & accessor) { UInt32 channel_id = accessor.getChannelID(); LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => " "Channel deallocate request id = " + convertIntegerToString(channel_id)); ConnectivityAgentError ret = deallocateChannel(channel_id ); accessor.setOpCode(E_DEALLOCATE_CHANNEL_RESP); UInt32 data = ret.getCode(); accessor.setData(reinterpret_cast<UInt8 *>(&data), sizeof(UInt32)); sendRequest(accessor); if (ret.isNoError()) { LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => " "channel successfully deallocated. " "Notifying client"); iviLink::Ipc::DirectionID dirId; bool found = false; mRegistryMutex.lock(); tChannelsRegistryMap::iterator iter = mL1ChannelRegistry.find(accessor.getChannelID()); if (mL1ChannelRegistry.end() != iter) { dirId = iter->second.mClientDir; found = true; LOG4CPLUS_INFO(logger, "L1InterfaceStub::processServiceDeallocateRequest() => " "channel found in registry - removing"); mL1ChannelRegistry.erase(accessor.getChannelID()); } mRegistryMutex.unlock(); if (found) { accessor.setOpCode(E_DEALLOCATE_CHANNEL_NTF); UInt8* buf = new UInt8[accessor.getObjectSize()]; accessor.copyToRawArray(buf); BaseError err = mpIpc->asyncRequest(mMsgIdGen.next(), buf, accessor.getObjectSize(), &dirId); if (!err.isNoError()) { LOG4CPLUS_WARN(logger, static_cast<std::string>(err)); } delete[] buf; } } // ret == OK }
void PmpIpcProtocol::processReadyToServeRequest(ProfileManager::Ipc::PmMessage const* const req, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); iviLink::Ipc::Helpers::CBufferReader reader(req->data, req->header.size); iviLink::Service::SessionUid sesUid; BaseError err = reader.read(sesUid); if (!err.isNoError()) { return; } mPim->readyToServe(sesUid, dirId); }
void NegotiatorTube::onDataReceived(const UInt32 channel_id, const UInt32 read_size) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__); UInt8 * data = new UInt8[read_size]; bzero(data, read_size); UInt32 receivedSize = 0; BaseError err = iviLink::ChannelSupervisor::receiveData(channel_id, data, receivedSize, read_size); if (err.isNoError()) { mNegotiatorStates->processTubeNotification(data); } else { LOG4CPLUS_WARN(mLogger, "Could not receive data: " + static_cast<std::string>(err)); } delete[] data; }
void PmpIpcProtocol::processGetProfileLibPathRequest(ProfileManager::Ipc::PmMessage const* const req, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); iviLink::Ipc::Helpers::CBufferReader reader(req->data, req->header.size); iviLink::Profile::Uid uid; BaseError err = reader.read(uid); LOG4CPLUS_INFO(msLogger, "UID: " + uid.value()); if (!err.isNoError()) { LOG4CPLUS_INFO(msLogger, static_cast<std::string>(err) ); return; } mCore->getProfileLibPath(uid, dirId); }
void L1InterfaceStub::sendIpcNotification(CDataAccessor & accessor, iviLink::Ipc::DirectionID dirId) { assert(dirId != -1); UInt8* buf = new UInt8[accessor.getObjectSize()]; accessor.copyToRawArray(buf); BaseError err = mpIpc->asyncRequest(mMsgIdGen.next(), buf, accessor.getObjectSize(), &dirId); if (!err.isNoError()) { LOG4CPLUS_WARN(logger, "sendIpcNotification error : " + static_cast<std::string>(err)); } delete [] buf; }
bool CTrustList::isKnownUid(iviLink::BaseUid const& uid) const { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); tNameUidVector vec; tNameUidVector::iterator i; BaseError err = mpStorage->readAll(vec); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } LOG4CPLUS_INFO(msLogger, "Looking for: " + uid.value()); for(i = vec.begin(); i != vec.end(); ++i) { if(uid == i->first) return true; } return false; }
void IpcServer::sendPing(iviLink::Ipc::DirectionID * pDirID) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__); std::string request(TEST_REQUEST); std::string response(TEST_RESPONSE); UInt8 * writeBuf = new UInt8(request.size()); memcpy(writeBuf, request.c_str(), request.size()); UInt8 * readBuf = new UInt8(response.size()); UInt32 respSize = response.size(); BaseError err = mIpc->request(mMsgIdGen.getNext(), writeBuf, request.size(), readBuf, respSize, pDirID); assert (err.isNoError()); LOG4CPLUS_INFO(mLogger, "Request sent successfully"); assert (respSize == response.size()); LOG4CPLUS_INFO(mLogger, "Response size is correct"); assert (response == std::string((const char*)readBuf, respSize)); LOG4CPLUS_INFO(mLogger, "Response content is correct"); delete writeBuf; delete readBuf; }
CServiceManager::CServiceManager(iviLink::Android::AppInfo appInfo) : mpClient(0) #ifndef ANDROID , mXmlPath((std::string)SERVICE_REPOSITORY) #else , mXmlPath(appInfo.serviceRepoPath) #endif //ANDROID , mAppInfo(appInfo) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); loadDb(); BaseError err = initPmal(); if(!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, "CServiceManager::CServiceManager()=> PMAL component manager creation error " + static_cast<std::string>(err)); } }
void PmpIpcProtocol::processCreateProfileRequest(ProfileManager::Ipc::PmMessage const* const req, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); iviLink::Ipc::Helpers::CBufferReader reader(req->data, req->header.size); iviLink::Profile::Uid uid; BaseError err = reader.read(uid); if (!err.isNoError()) return; iviLink::Profile::IUid piuid; err = reader.read(piuid); if (!err.isNoError()) return; iviLink::Service::Uid sid; err = reader.read(sid); if (!err.isNoError()) return; mPim->createProfile(uid, piuid, sid, dirId); }
iviLink::BaseUid CTrustList::getOurUid() const { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); BaseUid uid; BaseError err = mpStorage->getOurUid(uid); if (!err.isNoError()) { LOG4CPLUS_WARN(msLogger, static_cast<std::string>(err)); uid = generateNewUid(); LOG4CPLUS_INFO(msLogger, "Our newly-generated uid is: " + uid.value()); err = mpStorage->setOurUid(uid); if (!err.isNoError()) LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); } else { LOG4CPLUS_INFO(msLogger, "Our stored uid is: " + uid.value()); } return uid; }
AuthenticationStateMachine::AuthenticationStateMachine(const std::string& pathToTrlist, iviLink::Android::AppInfo appInfo) : iviLink::Application(iviLink::Service::Uid("AuthenticationService"), appInfo) , SystemControllerMsgProxy("SysCtrl_AuthApp") , mAppInfo(appInfo) , mKeygenThread(NULL) , mpState(NULL) , mInternalPath(pathToTrlist) { LOG4CPLUS_TRACE_METHOD(sLogger, __PRETTY_FUNCTION__); mpAuthenticationProxy = new CAuthenticationProxy(iviLink::Service::Uid("AuthenticationService"), mAppInfo); mKeygenThread = new PrivateKeyGenerationThread(mpAuthenticationProxy); BaseError err = SystemControllerMsgProxy::connect(); if (!err.isNoError()) { LOG4CPLUS_ERROR(sLogger, "Unable to establish connection to system controller " + (std::string)err); killProcess(1); // Watchdog will detect this and restart the stack } }
void ConnectivityAgentMsgProxy::OnRequest(iviLink::Ipc::MsgID id, UInt8 const* pPayload, UInt32 payloadSize, UInt8* const pResponseBuffer, UInt32& bufferSize, iviLink::Ipc::DirectionID) { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); Message const* req = reinterpret_cast<Message const*>(pPayload); assert(req->header.size + sizeof(Message) == payloadSize); assert(bufferSize >= sizeof(Message)); UInt8 role = 0; CBufferReader bufReader(req->data, req->header.size); switch (req->header.type) { case CA_SC_CONNECTION_ESTABLISHED: { BaseError err = bufReader.read(role); if (err.isNoError()) { LOG4CPLUS_INFO(logger, "CA_SC_CONNECTION_ESTABLISHED role = " + convertIntegerToString(role)); onCounterCAConnected(role); } else { LOG4CPLUS_WARN(logger, "CA_SC_CONNECTION_ESTABLISHED err = " + static_cast<std::string>(err)); } } break; case CA_SC_CONNECTION_LOST: onCounterCADisconnected(); break; default: break; } bufferSize = 0; }
BaseError SystemControllerMsgProxy::requestConnectionEstablished(UInt8 gender) { if (!mSystemCtrlIpc) return BaseError(1, getName(), BaseError::IVILINK_FATAL, "no ipc"); Message* req = reinterpret_cast<Message*>(mWriteBuffer); req->header.type = CA_SC_CONNECTION_ESTABLISHED; CBufferWriter writer(req->data, BUFFER_SIZE); BaseError err = writer.write(gender); if (!err.isNoError()) return err; req->header.size = writer.getUsedSize(); iviLink::Ipc::MsgID id = mMsgIdGen.getNext(); UInt32 const reqSize = sizeof(Message) + req->header.size; UInt32 respSize = 0; return mSystemCtrlIpc->request(id, mWriteBuffer, reqSize, mReadBuffer, respSize); }
BaseError AppManMsgProxy::requestShutDown() { LOG4CPLUS_TRACE_METHOD(logger, __PRETTY_FUNCTION__); if (!mpIpc) return BaseError(1, getName(), BaseError::IVILINK_FATAL, "no ipc"); Message* req = reinterpret_cast<Message*>(mWriteBuffer); req->header.type = SC_AM_SHUTDOWN; req->header.size = 0; iviLink::Ipc::MsgID id = mMsgIdGen.getNext(); UInt32 const reqSize = sizeof(Message) + req->header.size; BaseError err = mpIpc->asyncRequest(id, mWriteBuffer, reqSize); if (!err.isNoError()) return err; return BaseError::NoError(getName()); }
std::string CTrustList::getOurName() const { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); std::string name; BaseError err = mpStorage->getOurName(name); if (!err.isNoError()) { LOG4CPLUS_WARN(msLogger, static_cast<std::string>(err)); name = "Generated name" + getOurUid().value(); LOG4CPLUS_INFO(msLogger, "Our newly-generated name is: " + name); err = mpStorage->setOurName(name); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); } } else { LOG4CPLUS_INFO(msLogger, "Our stored name is: " + name); } return name; }
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); }
void CAppManProxy::handleUseService() { LOG4CPLUS_TRACE_METHOD(gCAppManProxyLogger,__PRETTY_FUNCTION__); mpUseListMutex->lock(); if (mUseList.empty()) { mpUseListMutex->unlock(); return; } bool use = mUseList.front().second; Service::Uid service = mUseList.front().first; mpUseListMutex->unlock(); BaseError err = AppMan::CAppManConnectController::instance(mAppInfo)->applicationManager() ->useService(service, use); if (err.isNoError()) { mpUseListMutex->lock(); mUseList.erase(mUseList.begin()); mpUseListMutex->unlock(); } }
void NegotiatorTube::onDataReceived(const UInt32 channel_id, const UInt32 read_size) { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__); UInt8 data[read_size]; bzero(data, read_size); UInt32 receivedSize = 0; BaseError err = iviLink::ChannelSupervisor::receiveData(channel_id, data, receivedSize, read_size); if (err.isNoError()) { pugi::xml_document* doc = new pugi::xml_document(); doc->load((char*) data); Notification * notification = new Notification(doc); if (notification->getType() == Notification::NOTIFICATIONTTYPE_CLIENT_DISCONNECTED) { ProcessorsHolder::getInstance()->processRemoteClientDisconnected( notification->getClientID()); delete notification; } else if (notification->getType() == Notification::NOTIFICATIONTTYPE_INVALIDATE_TIMEDOUT_REQUEST) { ProcessorsHolder::getInstance()->invalidateRemoteTimedOutRequest( notification->getClientID(), notification->getRequestID()); delete notification; } else { // created notification is deleted in processTubeNotification ProcessorsHolder::getInstance()->processTubeNotification(notification, this); } } else { LOG4CPLUS_WARN(mLogger, "Could not receive data: " + static_cast<std::string>(err)); } }
bool PmpIpcProtocol::incomingProfile(iviLink::BaseUid const& profileUid, iviLink::Profile::ApiUid const& papiUid, iviLink::Profile::IUid const& piuid, iviLink::Service::Uid const& serviceUID, iviLink::Ipc::DirectionID const& dirId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ ); CBuffer writeBuf = mWriteBufMgr.getBuffer(); ProfileManager::Ipc::PmMessage* req = reinterpret_cast<ProfileManager::Ipc::PmMessage*>(writeBuf.get()); req->header.type = ProfileManager::Ipc::PMP_PMAL_INCOMMING_PROFILE; iviLink::Ipc::Helpers::CBufferWriter writer(req->data, writeBuf.getSize() - sizeof(req->header)); BaseError err = writer.write(profileUid); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } err = writer.write(papiUid); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } err = writer.write(piuid); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } err = writer.write(serviceUID); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, static_cast<std::string>(err)); return false; } req->header.size = writer.getUsedSize(); iviLink::Ipc::MsgID id = mMsgIdGen.getNext(); UInt32 const reqSize = sizeof(ProfileManager::Ipc::PmMessage) + req->header.size; err = mIpc->asyncRequest(id, writeBuf.get(), reqSize, &dirId); return err.isNoError(); }
BaseError NegotiatorClient::UpdateChannelInfo(std::string const& tag, const UInt32 & channelId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); UpdateChannelInfoRequest * req = NULL; UpdateChannelInfoResponse * res = NULL; BaseError err = CSError(CSError::ERROR_OTHER); //prepare message for channel deallocation std::stringstream messageToBeSent; req = new UpdateChannelInfoRequest(tag.c_str(), channelId); req->Write(messageToBeSent); UInt32 bufSize = 2048; UInt8 buf[bufSize]; memset(buf, 0, bufSize); err = m_ipcClient->sendMessage((const UInt8 *) (messageToBeSent.str().c_str()), messageToBeSent.str().size(), buf, bufSize); if (!err.isNoError()) { LOG4CPLUS_TRACE(msLogger, "NegotiatorClient::UpdateChannelInfo()=> ERROR!! No data received from Negotiator processs"); err = CSError(CSError::IPC_NO_DATA_ERROR, "no data received from negotiator ipc server"); } else { //receive response LOG4CPLUS_TRACE(msLogger, "NegotiatorClient::UpdateChannelInfo()=> Received \n==========\n" + (std::string)((char*) buf) + "\n===========\n"); pugi::xml_document* doc = new pugi::xml_document(); ParseResponse_(doc, (char*) (buf)); res = new UpdateChannelInfoResponse(doc); //get the error from the response ErrorCode errc; const char * errstr; res->GetError(errc, errstr); LOG4CPLUS_TRACE(msLogger, "err code" + convertIntegerToString((int) errc)); if (errc == ERRORCODE_SUCCESS) { UInt32 cId = res->GetChannelId(); LOG4CPLUS_TRACE(msLogger, "updated channel id" + convertIntegerToString(cId)); err = CSError::NoCSError(defErrMsg); } else if (errc == ERRORCODE_TIMEOUT_OCCURRED) { LOG4CPLUS_TRACE(msLogger, "Timeout occurred. Err string: " + (std::string) errstr); err = CSError(CSError::UPDATE_CHANNEL_MAP_TIMEOUT, "update map timeout"); } else { LOG4CPLUS_TRACE(msLogger, "Error occurred. Err string: " + (std::string) errstr); err = CSError(CSError::ERROR_OTHER, "error during map updating"); } } if (res) { delete res; } res = 0; if (req) { delete req; } req = 0; return err; }
BaseError NegotiatorClient::NegotiateChannel(std::string const& tag, UInt32 & channelId) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); LOG4CPLUS_TRACE(msLogger, "NegotiatorClient::NegotiateChannel()=>" + tag); AllocateChannelRequest * req = NULL; AllocateChannelResponse * res = NULL; BaseError err = CSError(CSError::ERROR_OTHER); //prepare message for channel allocation std::stringstream messageToBeSent; req = new AllocateChannelRequest(tag.c_str(), channelId); req->Write(messageToBeSent); UInt32 bufSize = 1000; UInt8 buf[bufSize]; memset(buf, 0, bufSize); err = m_ipcClient->sendMessage((const UInt8 *) (messageToBeSent.str().c_str()), messageToBeSent.str().size(), buf, bufSize); if (!err.isNoError()) { LOG4CPLUS_ERROR(msLogger, "NegotiatorClient::NegotiateChannel()=> ERROR!! No data received from Negotiator processs"); err = CSError(CSError::IPC_NO_DATA_ERROR, "no data received from negotiator ipc server"); } else { //receive response LOG4CPLUS_INFO(msLogger, "NegotiatorClient::NegotiateChannel()=> Received \n==========\n" + std::string((char*) buf) + "\n===========\n"); pugi::xml_document* doc = new pugi::xml_document(); ParseResponse_(doc, (char*) (buf)); res = new AllocateChannelResponse(doc); //get the error from the response ErrorCode errc; const char * errstr; res->GetError(errc, errstr); if (errc == ERRORCODE_SUCCESS) { channelId = res->GetChannelId(); LOG4CPLUS_INFO(msLogger, "NegotiatorClient::NegotiateChannel()=> channedl id = " + convertIntegerToString(channelId)); err = CSError::NoCSError(defErrMsg); } else if (errc == ERRORCODE_TIMEOUT_OCCURRED) { LOG4CPLUS_ERROR(msLogger, "NegotiatorClient::NegotiateChannel()=> negotiation timeout occurred"); err = CSError(CSError::NEGOTIATION_CHANNEL_TIMEOUT, "negotiation timeout"); } else if (errc == ERRORCODE_FREE_CID_NOT_FOUND_IN_MAP) { LOG4CPLUS_ERROR(msLogger, "NegotiatorClient::NegotiateChannel()=> no free cid, Error code " + (std::string) errstr); err = CSError(CSError::NO_FREE_CID_IN_MAP, "no free cid"); } else { LOG4CPLUS_ERROR(msLogger, "NegotiatorClient::NegotiateChannel()=> negotiation channel error, Error code " + (std::string) errstr); err = CSError(CSError::NEGOTIATION_CHANNEL_ERROR, "negotiation channel error"); } } if (res) { delete res; } res = 0; if (req) { delete req; } req = 0; return err; }