Returning an object.
John Ronan
j0n@spirit.wit.ie
Tue, 10 Mar 1998 11:49:14 +0000 (GMT)
Howdy.
I have an object which has a method that returns a pointer to another
object... I'm doing something silly but I really don't know where I'm
going wrong. If anyone could point out where i'm wrong I would be most
grateful....
Here is the main IDL
module CorBot {
interface Robot{
//
exception ServerError{string reason;boolean itIsFatal;};
readonly attribute short GripPosn;
.
.
.
short Grip(in short posn)
raises(ServerError);
.
.
};
interface RobotController{
exception NoRobotsLeft{string reason;};
readonly attribute short nmrOfAvailableRobots;
Robot GetRobot()
raises(NoRobotsLeft);
};
};
-- Main client code -----------------
CorBot::RobotController_var localRobotControllerObject = CorBot::RobotController::_narrow(obj);
if (CORBA::is_nil(localRobotControllerObject)) {
cerr << "Corbot_clt: cannot invoke on a nil object reference.\n" << endl;
return 1;
}
CorBot::Robot_var herbie;
// Client never get's past this... I always catch an unknown
// system exception
herbie=localRobotControllerObject->GetRobot();
---Implementation code------------
class RobotController_i: public virtual CorBot::_sk_RobotController {
CORBA::Short m_nmrOfAvailableRobots;
public:
RobotController_i(void);
virtual ~RobotController_i(void);
virtual CORBA::Short nmrOfAvailableRobots(){
return m_nmrOfAvailableRobots;
}
virtual CorBot::Robot* GetRobot();
};
CorBot::Robot* RobotController_i::GetRobot(){
if(m_nmrOfAvailableRobots==0){
throw CorBot::RobotController::NoRobotsLeft("Out of robots, please try
again later");
}
CorBot::Robot* m_TempRobotPointer=new Robot_i();
return CorBot::Robot::_duplicate(m_TempRobotPointer);
}
----------------------------------------------
Aplogys for the long mail,
TNX for your patience
J
--
John Ronan EI7IG: j0n@spirit.wit.ie, jronan@unix1.wit.ie
-------------------------------------------------------------------------------
"As Phil De Glanville said, each game is unique, and this one is no
different to any other." (John Sleightholme - BBC1)
--------- Linux Guru wannabe, part time sysadmin, full time student. ----------