Hi All,
I am developing a position based multcast protocol.I am using getLoc(double x......) method in the MobileNode class of mobilenode.cc file to find the position of the node.In the MobileNode constructor the variables X_,Y_,and Z_ are initialized to 0.0 and i found that this part of the code is working fien by using fprintf().But iside the getLoc() method or update_position() method i am getting segmentation fault if I trying to access variables X_,Y_Z_,position_update_time_ etc.
I think my problem is, I have not created an object of MobileNode class before calling getLoc method.In my agent class i declared a variable MobileNode mn_ and claaed the getLoc method using mn_->getLoc(&x,&y,&z).I am working on this problem from the last week and not getting the correct result.If my guess is correct please tell me where to create the MobileNode object.Otherwise tell me the reason of this sementation fault.
More details of error...
in my agent class
MobileNode mn_;
In my agent implemntation class
void LMP_MR::send_hello_pkt(void){
fprintf(stderr, "Listen to me HELLO.....\n");
Packet *p = Packet::alloc();
position *ps = getMyPosition();
.........................................
...........................................
}
position* LMP_MR::getMyPosition(){
position* pos;
double myx,myy,myz;
myx = myy = myz = 0.0;
//fprintf(stderr, "Declaration is fine....\n");
mn_->getLoc(&myx, &myy, &myz); //========>>>>Here is the segmentation fault
fprintf(stderr, "getMyPosition() is called....\n");
pos->x = myx;
pos->y = myy;
pos->z = myz;
return pos;
}
The getLoc method in mobilenode.cc is below.
void MobileNode::getLoc(double *x, double *y, double *z)
{
fprintf(stderr, "getLoc() is called....%f\n");//,X_);
//fprintf(stderr,"positin update time fro getLoc()%f \n",position_update_time_);
update_position();
fprintf(stderr, "After update_position() ....\n");
*x = X_;
*y = Y_;
*z = Z_;
}
If i am trying to print X_,position_update_time_ etc the result is segmentation fault...
Please help me.
Ajish