I am working on Veins framework, inside OMNET++. I am developing a kind of controlled flooding in a vehicular network. I am trying to make the vehicles send the data only after 6 seconds (this value may be changed), so I created a schedule at the initialization of each vehicle (on TraCIDemo11p.cc), like this:
if(sendData){ scheduleAt(simTime()+par("dataInterval").doubleValue(),sendDataEvt);}
On the TraCIDemo11p.h I created a map to be my buffer:
//Creating a map to represent the vehicle's message buffer
typedef map<string, WaveShortMessage*> MyMapContextMessageBuffer;
typedef pair<string, WaveShortMessage*> MyPairContextMessageBuffer;
MyMapContextMessageBuffer contextLocalMessageBuffer;
So on the TraCIDemo11p.cc onData(WaveShortMessage* wsm) function I make a copy of the received message, update the number of received messages, add the message in the vehicle buffer and print the content of the buffer just to test if I inserted it correctly:
//duplicating the message, so this vehicle has his own copy of the message
WaveShortMessage* wsmdup = wsm->dup();
//number of received messages
receivedMsgs++;
//add the msg in the vehicle buffer, the GlobalMessageIdentification is the id of the message
contextLocalMessageBuffer.insert(MyPairContextMessageBuffer(wsmdup->getGlobalMessageIdentificaton(),wsmdup));
//accessing something in the ->second on the buffer, it works in this function
cout<<"Sender "<< contextLocalMessageBuffer.begin()->second->getSender()<<endl;
Then at the scheduled time the SEND_DATA_EVT (handleSelfMsg) is called to send the data, but I am getting an error when i try to access the contextLocalMessageBuffer.begin()-second (or it->second).
//handleSelfMsg(cMessage* msg)
case SEND_DATA_EVT
//if the vehicle has received a msg before
if(receivedMsgs != 0){
//and the buffer isn't empty, the function is able to verify if the buffer isnt empty
if(!contextLocalMessageBuffer.empty()){
//if i try to access the begin->first it works
cout<<"GlobalMessageID "<<contextLocalMessageBuffer.begin()->first<<" ";
//but if I try to access the begin->second->getSource(), it doesn't works in this function (i get an Error 139), but works inside of onData
cout<<findHost()->getFullName()<<" messageID "<<contextLocalMessageBuffer.begin()->first<<" "<<contextLocalMessageBuffer.begin()->second->getSource()<<endl;
//if I remove those couts the iterator and the for works but the send doesn't (Error 139), because it is trying to access the it->second
map<string, WaveShortMessage*>::iterator it;
for(it = contextLocalMessageBuffer.begin(); it != contextLocalMessageBuffer.end(); it++){
send(it->second)
}
}
}
//create a new schedule to send data after a new interval
scheduleAt(simTime() + par("dataInterval").doubleValue(), sendDataEvt);
So, to summarize, my problem is that i am able to work with my map(contextLocalMessagebuffer) inside of the onData, but can't access it properly on HandleSelfMsg, both in the same code (TraCIDemo11p.cc). Obs: I tried to create a function that returns the value of the buffer, but the function wasn't able to access the buffer too.
Thanks!