govind shinde
asked on
request for member ‘c_str’ in ‘info.AppNetInfoExchange_type::inter_nodes’, which is of non-class type ‘opp_string [10]’
WHILE OMPILING I'M GETTING THE MENTIONED ERROR........
In member function ‘virtual void VirtualApplication::handle Message(cM essage*)’:
src/node/application/Virtu alApplicat ion.cc:96: 70: error: request for member ‘c_str’ in ‘info.AppNetInfoExchange_t ype::inter _nodes’, which is of non-class type ‘opp_string [10]’
fromNetworkLayer(rcvPacket , info.source.c_str(),info.i nter_nodes .c_str(2), info.RSSI, info.LQI);
SOURCE CODE:
#include "VirtualApplication.h"
void VirtualApplication::initia lize()
{
/* Get a valid references to the objects of the Resources Manager module
* the Mobility module and the Radio module, so that we can make direct
* calls to their public methods
*/
cModule *parent = getParentModule();
resMgrModule = check_and_cast <ResourceManager*>(parent- >getSubmod ule("Resou rceManager "));
mobilityModule = check_and_cast <VirtualMobilityManager*>( parent->ge tSubmodule ("Mobility Manager")) ;
radioModule = check_and_cast <Radio*>(parent->getSubmod ule("Commu nication") ->getSubmo dule("Radi o"));
// check that all the pointers are valid
if (!resMgrModule || !mobilityModule || !radioModule)
opp_error("\n Virtual App init: Error in geting a valid reference module(s).");
self = parent->getIndex();
// create the routing level address using self
stringstream out; out << self; selfAddress = out.str();
cpuClockDrift = resMgrModule->getCPUClockD rift();
setTimerDrift(cpuClockDrif t);
disabled = true;
applicationID = par("applicationID").strin gValue(); // make sure par() returns a string
priority = par("priority");
packetHeaderOverhead = par("packetHeaderOverhead" );
constantDataPayload = par("constantDataPayload") ;
isSink = hasPar("isSink") ? par("isSink") : false;
double startup_delay = parent->par("startupOffset ");
// Randomize the delay if the startupRandomization is non-zero
startup_delay += genk_dblrand(0) * (double)parent->par("start upRandomiz ation");
/* Send the STARTUP message to 1)Sensor_Manager, 2)Commmunication module,
* 3) Resource Manager, and $)APP (self message) so that the node starts
* operation. Note that we send the message to the Resource Mgr through
* the unconnected gate "powerConsumption" using sendDirect()
*/
sendDelayed(new cMessage("Sensor Dev Mgr [STARTUP]", NODE_STARTUP),
simTime() + startup_delay, "toSensorDeviceManager");
sendDelayed(new cMessage("Communication [STARTUP]", NODE_STARTUP),
simTime() + startup_delay, "toCommunicationModule");
sendDirect(new cMessage("Resource Mgr [STARTUP]", NODE_STARTUP),
startup_delay, 0, resMgrModule, "powerConsumption");
scheduleAt(simTime() + startup_delay, new cMessage("App [STARTUP]", NODE_STARTUP));
/* Latency measurement is optional. An application can define the
* following two parameters. If they are not defined then the
* declareHistogram and collectHistogram statement are not called.
*/
latencyMax = hasPar("latencyHistogramMa x") ? par("latencyHistogramMax") : 0;
latencyBuckets = hasPar("latencyHistogramBu ckets") ? par("latencyHistogramBucke ts") : 0;
if (latencyMax > 0 && latencyBuckets > 0)
declareHistogram("Applicat ion level latency, in ms", 0, latencyMax, latencyBuckets);
}
void VirtualApplication::handle Message(cM essage * msg)
{
int msgKind = msg->getKind();
if (disabled && msgKind != NODE_STARTUP)
{
delete msg;
return;
}
switch (msgKind) {
case NODE_STARTUP:
{
disabled = false;
startup();
break;
}
case APPLICATION_PACKET:
{
ApplicationPacket *rcvPacket = check_and_cast <ApplicationPacket*>(msg);
AppNetInfoExchange_type info = rcvPacket->getAppNetInfoEx change();
// If the packet has the correct appID OR the appID is the empty string,
// the packet is delivered by calling the app-specific function fromNetworkLayer()
if (applicationID.compare(rcv Packet->ge tApplicati onID()) == 0 || applicationID.compare("") == 0) {
fromNetworkLayer(rcvPacket , info.source.c_str(),info.i nter_nodes .c_str(2), info.RSSI, info.LQI);
if (latencyMax > 0 && latencyBuckets > 0)
collectHistogram("Applicat ion level latency, in ms", 1000 * SIMTIME_DBL(simTime() - info.timestamp));
}
break;
}
case TIMER_SERVICE:
{
handleTimerMessage(msg);
break;
}
case SENSOR_READING_MESSAGE:
{
SensorReadingMessage *sensMsg = check_and_cast <SensorReadingMessage*>(ms g);
handleSensorReading(sensMs g);
break;
}
case NETWORK_CONTROL_MESSAGE:
{
handleNetworkControlMessag e(msg);
break;
}
case MAC_CONTROL_MESSAGE:
{
handleMacControlMessage(ms g);
break;
}
case RADIO_CONTROL_MESSAGE:
{
RadioControlMessage *radioMsg = check_and_cast <RadioControlMessage*>(msg );
handleRadioControlMessage( radioMsg);
break;
}
case OUT_OF_ENERGY:
{
disabled = true;
break;
}
case DESTROY_NODE:
{
disabled = true;
break;
}
default:
{
opp_error("Application module received unexpected message");
}
}
delete msg;
}
void VirtualApplication::finish ()
{
CastaliaModule::finish();
DebugInfoWriter::closeStre am();
}
ApplicationPacket* VirtualApplication::create GenericDat aPacket(do uble data, unsigned int seqNum, int size)
{
ApplicationPacket *newPacket = new ApplicationPacket("App generic packet", APPLICATION_PACKET);
newPacket->setData(data);
newPacket->setSequenceNumb er(seqNum) ;
if (size > 0) newPacket->setByteLength(s ize);
return newPacket;
}
void VirtualApplication::reques tSensorRea ding(int index)
{
// send the request message to the Sensor Device Manager
SensorReadingMessage *reqMsg =
new SensorReadingMessage("App to Sensor Mgr: sample request", SENSOR_READING_MESSAGE);
// We need the index of the vector in the sensorTypes vector
// to distinguish the self messages for each sensor
reqMsg->setSensorIndex(ind ex);
send(reqMsg, "toSensorDeviceManager");
}
// A function used to send control messages
/*void VirtualApplication::toNetw orkLayer(c Message * msg)
{
if (msg->getKind() == APPLICATION_PACKET)
opp_error("toNetworkLayer( ) function used incorrectly to send APPLICATION_PACKET without destination Network address");
send(msg, "toCommunicationModule");
}
*/
// A function used to send data packets
void VirtualApplication::toNetw orkLayer(c Packet * pkt, const char *dst)
{
ApplicationPacket *appPkt = check_and_cast <ApplicationPacket*>(pkt);
appPkt->getAppNetInfoExcha nge().dest ination = string(dst);
appPkt->getAppNetInfoExcha nge().sour ce = selfAddress;
appPkt->getAppNetInfoExcha nge().time stamp = simTime();
appPkt->getAppNetInfoExcha nge().inte r_nodes[1] = inter_node;
appPkt->setApplicationID(a pplication ID.c_str() );
int size = appPkt->getByteLength();
if (size == 0)
size = constantDataPayload;
if (packetHeaderOverhead > 0) size += packetHeaderOverhead;
trace() << "Sending [" << appPkt->getName() << "] of size " <<
size << " bytes to communication layer";
appPkt->setByteLength(size );
send(appPkt, "toCommunicationModule");
}
In member function ‘virtual void VirtualApplication::handle
src/node/application/Virtu
fromNetworkLayer(rcvPacket
SOURCE CODE:
#include "VirtualApplication.h"
void VirtualApplication::initia
{
/* Get a valid references to the objects of the Resources Manager module
* the Mobility module and the Radio module, so that we can make direct
* calls to their public methods
*/
cModule *parent = getParentModule();
resMgrModule = check_and_cast <ResourceManager*>(parent-
mobilityModule = check_and_cast <VirtualMobilityManager*>(
radioModule = check_and_cast <Radio*>(parent->getSubmod
// check that all the pointers are valid
if (!resMgrModule || !mobilityModule || !radioModule)
opp_error("\n Virtual App init: Error in geting a valid reference module(s).");
self = parent->getIndex();
// create the routing level address using self
stringstream out; out << self; selfAddress = out.str();
cpuClockDrift = resMgrModule->getCPUClockD
setTimerDrift(cpuClockDrif
disabled = true;
applicationID = par("applicationID").strin
priority = par("priority");
packetHeaderOverhead = par("packetHeaderOverhead"
constantDataPayload = par("constantDataPayload")
isSink = hasPar("isSink") ? par("isSink") : false;
double startup_delay = parent->par("startupOffset
// Randomize the delay if the startupRandomization is non-zero
startup_delay += genk_dblrand(0) * (double)parent->par("start
/* Send the STARTUP message to 1)Sensor_Manager, 2)Commmunication module,
* 3) Resource Manager, and $)APP (self message) so that the node starts
* operation. Note that we send the message to the Resource Mgr through
* the unconnected gate "powerConsumption" using sendDirect()
*/
sendDelayed(new cMessage("Sensor Dev Mgr [STARTUP]", NODE_STARTUP),
simTime() + startup_delay, "toSensorDeviceManager");
sendDelayed(new cMessage("Communication [STARTUP]", NODE_STARTUP),
simTime() + startup_delay, "toCommunicationModule");
sendDirect(new cMessage("Resource Mgr [STARTUP]", NODE_STARTUP),
startup_delay, 0, resMgrModule, "powerConsumption");
scheduleAt(simTime() + startup_delay, new cMessage("App [STARTUP]", NODE_STARTUP));
/* Latency measurement is optional. An application can define the
* following two parameters. If they are not defined then the
* declareHistogram and collectHistogram statement are not called.
*/
latencyMax = hasPar("latencyHistogramMa
latencyBuckets = hasPar("latencyHistogramBu
if (latencyMax > 0 && latencyBuckets > 0)
declareHistogram("Applicat
}
void VirtualApplication::handle
{
int msgKind = msg->getKind();
if (disabled && msgKind != NODE_STARTUP)
{
delete msg;
return;
}
switch (msgKind) {
case NODE_STARTUP:
{
disabled = false;
startup();
break;
}
case APPLICATION_PACKET:
{
ApplicationPacket *rcvPacket = check_and_cast <ApplicationPacket*>(msg);
AppNetInfoExchange_type info = rcvPacket->getAppNetInfoEx
// If the packet has the correct appID OR the appID is the empty string,
// the packet is delivered by calling the app-specific function fromNetworkLayer()
if (applicationID.compare(rcv
fromNetworkLayer(rcvPacket
if (latencyMax > 0 && latencyBuckets > 0)
collectHistogram("Applicat
}
break;
}
case TIMER_SERVICE:
{
handleTimerMessage(msg);
break;
}
case SENSOR_READING_MESSAGE:
{
SensorReadingMessage *sensMsg = check_and_cast <SensorReadingMessage*>(ms
handleSensorReading(sensMs
break;
}
case NETWORK_CONTROL_MESSAGE:
{
handleNetworkControlMessag
break;
}
case MAC_CONTROL_MESSAGE:
{
handleMacControlMessage(ms
break;
}
case RADIO_CONTROL_MESSAGE:
{
RadioControlMessage *radioMsg = check_and_cast <RadioControlMessage*>(msg
handleRadioControlMessage(
break;
}
case OUT_OF_ENERGY:
{
disabled = true;
break;
}
case DESTROY_NODE:
{
disabled = true;
break;
}
default:
{
opp_error("Application module received unexpected message");
}
}
delete msg;
}
void VirtualApplication::finish
{
CastaliaModule::finish();
DebugInfoWriter::closeStre
}
ApplicationPacket* VirtualApplication::create
{
ApplicationPacket *newPacket = new ApplicationPacket("App generic packet", APPLICATION_PACKET);
newPacket->setData(data);
newPacket->setSequenceNumb
if (size > 0) newPacket->setByteLength(s
return newPacket;
}
void VirtualApplication::reques
{
// send the request message to the Sensor Device Manager
SensorReadingMessage *reqMsg =
new SensorReadingMessage("App to Sensor Mgr: sample request", SENSOR_READING_MESSAGE);
// We need the index of the vector in the sensorTypes vector
// to distinguish the self messages for each sensor
reqMsg->setSensorIndex(ind
send(reqMsg, "toSensorDeviceManager");
}
// A function used to send control messages
/*void VirtualApplication::toNetw
{
if (msg->getKind() == APPLICATION_PACKET)
opp_error("toNetworkLayer(
send(msg, "toCommunicationModule");
}
*/
// A function used to send data packets
void VirtualApplication::toNetw
{
ApplicationPacket *appPkt = check_and_cast <ApplicationPacket*>(pkt);
appPkt->getAppNetInfoExcha
appPkt->getAppNetInfoExcha
appPkt->getAppNetInfoExcha
appPkt->getAppNetInfoExcha
appPkt->setApplicationID(a
int size = appPkt->getByteLength();
if (size == 0)
size = constantDataPayload;
if (packetHeaderOverhead > 0) size += packetHeaderOverhead;
trace() << "Sending [" << appPkt->getName() << "] of size " <<
size << " bytes to communication layer";
appPkt->setByteLength(size
send(appPkt, "toCommunicationModule");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER