CError NegotiatorIPCHandler::UpdateMap(std::string tag, UInt32 cid) { LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__); CError err = CSError(CSError::ERROR_OTHER); //store in the map ChannelInfo chInfo; chInfo.tag = tag; chInfo.timeStamp = time(NULL); Notification * noti = new CAAllocationNotification(tag.c_str(), cid); std::stringstream messageToBeSent; noti->Write(messageToBeSent); delete noti; LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::UpdateMap()=>Message: \n==========\n" + messageToBeSent.str() + "\n===========\n"); m_negotiatorTube->sendDataTube(messageToBeSent.str().c_str()); LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>WAIT FOR CAALLOCATED"); waitStateForTag(NegotiaterStates::CAALLOCATED, tag, OTHER_SIDE_RESP_TIMEOUT_MS); LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>CAALLOCATED"); if (m_negotiatorStates->GetTagState(tag.c_str()) != NegotiaterStates::CAALLOCATED) { LOG4CPLUS_ERROR(msLogger, "CAALLOCATED: other side response timed out for tag " + tag); return CSError(CSError::UPDATE_MAP_TIMEOUT); } messageToBeSent.str(std::string()); m_map->addChannelInfo(cid, chInfo); noti = new UpdateMapNotification(tag.c_str(), cid); noti->Write(messageToBeSent); delete noti; LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::UpdateMap()=>Message: \n==========\n" + messageToBeSent.str() + "\n===========\n"); m_negotiatorTube->sendDataTube(messageToBeSent.str().c_str()); LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::UpdateMap()=> Current state is " + m_negotiatorStates->StateToString( m_negotiatorStates->GetTagState(tag.c_str()))); m_negotiatorTube->sendDataTube(messageToBeSent.str().c_str()); LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>WAIT FOR ALLOCDONE / IDLE"); waitStateForTag(NegotiaterStates::IDLE, tag, OTHER_SIDE_RESP_TIMEOUT_MS); LOG4CPLUS_INFO(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>ALLOCDONE / IDLE"); //get remote notification UpdateMapNotification * remoteNotification = (UpdateMapNotification *) m_negotiatorStates->GetNotification(tag.c_str()); ErrorCode errc; const char * errstr; if (remoteNotification) { remoteNotification->GetError(errc, errstr); if (errc == ERRORCODE_SUCCESS) { err = CSError::NoCSError("no error"); } } else { LOG4CPLUS_ERROR(msLogger, "(UpdateMapNotification *) m_negotiatorStates->GetNotification \ returned NULL! other side response timed out"); err = CSError(CSError::UPDATE_MAP_TIMEOUT); } return err; }
CError NegotiatorIPCHandler::UpdateMap(std::string tag, UInt32 cid) { CError err = CSError(CSError::ERROR_OTHER); //store in the map ChannelInfo chInfo; chInfo.tag = tag; chInfo.timeStamp = time(NULL); Notification * noti = new CAAllocationNotification(tag.c_str(), cid); std::stringstream messageToBeSent; noti->Write(messageToBeSent); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::UpdateMap()=>Message: \n==========\n" + messageToBeSent.str()+"\n===========\n"); m_negotiatorTube->sendDataTube(messageToBeSent.str().c_str()); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>WAIT FOR CAALLOCATED"); m_negotiatorStates->mStateCond.lock(); if(m_negotiatorStates->GetTagState(tag.c_str()) != NegotiaterStates::CAALLOCATED) { m_negotiatorStates->mStateCond.wait(); } m_negotiatorStates->mStateCond.unlock(); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>CAALLOCATED"); delete noti; messageToBeSent.str(std::string()); m_map->addChannelInfo(cid, chInfo); noti = new UpdateMapNotification(tag.c_str(), cid); noti->Write(messageToBeSent); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::UpdateMap()=>Message: \n==========\n" + messageToBeSent.str()+"\n===========\n"); m_negotiatorTube->sendDataTube(messageToBeSent.str().c_str()); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::UpdateMap()=> Current state is "+convertIntegerToString((int)m_negotiatorStates->GetTagState(tag.c_str()))); m_negotiatorTube->sendDataTube(messageToBeSent.str().c_str()); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>WAIT FOR ALLOCDONE"); m_negotiatorStates->mStateCond.lock(); //if(m_negotiatorStates->GetTagState(tag.c_str()) != NegotiaterStates::ALLOCDONE) if(m_negotiatorStates->GetTagState(tag.c_str()) != NegotiaterStates::IDLE) { m_negotiatorStates->mStateCond.wait(); } m_negotiatorStates->mStateCond.unlock(); LOG4CPLUS_TRACE(msLogger, "NegotiatorIPCHandler::NegotiateChannel()==>ALLOCDONE / IDLE"); //get remote notification UpdateMapNotification * remoteNotification = (UpdateMapNotification *) m_negotiatorStates->GetNotification(tag.c_str()); ErrorCode errc; const char * errstr; remoteNotification->GetError(errc, errstr); if (errc == ERRORCODE_SUCCESS) { err = CSError::NoCSError("no error"); } if (noti) delete noti; return err; }