INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

reincarnation through the ServantManager with Mico

reincarnation through the ServantManager with Mico

(OP)
I'm using Mico/Corba to Programm a Predictiongame. I've got a Problem with the server. The Problem is the reincarnation of saved files through the ServantManager. The incarnation of new Game Objects works fine also the serialisation and unserialisation does. After restarting the Server i would like to reincarnate the Game Objects. The ServantManager calls the incarnate method once for the first file but thats it. It doesn't hang or throws an exception. I can't figure out why he does it only once. Is there any good documentation for that? I haven't found anything that could help me to find the resolution for this problem.


CODE --> c++

::Predictiongame::Game_ptr Gameplay_impl::loadSavedGame() {
	// generate a ObjectID so that the ServantManager can
	// decide what Objekttyp has to be generated
	char oidstr[255];
	sprintf(oidstr,"games//game_%d.dat",gameCnt);
	PortableServer::ObjectId_var tmpoid=PortableServer::string_to_ObjectId(oidstr);

	// Generate a reference for a "virtual" Object.
	// The Servant Manager generates a Object with caling the incarnate() method.
	// But he does it only the first time. Why???
	CORBA::Object_var obj = mypoa->create_reference_with_id (tmpoid,"IDL:Game:1.0");
	assert (!CORBA::is_nil (obj));
	::Predictiongame::Game_ptr aref = ::Predictiongame::Game::_narrow (obj);
	assert (!CORBA::is_nil (aref));
	oid[gameCnt] = mypoa->reference_to_id(aref); // get id of the Game Objekt and save it in a array
	gameCnt ++;
	return aref;	
}



// incarnate-method in the Implementation of the ServantManager
PortableServer::Servant GameManager::incarnate (const PortableServer::ObjectId & oid,PortableServer::POA_ptr poa) {
	CORBA::String_var name = PortableServer::ObjectId_to_string (oid);
	cout << "INCARNATE oid: " << PortableServer::ObjectId_to_string(oid) << endl;
	// anhand der ObjectId kann entschieden werden, welcher Typ erzeugt werden soll
	if(strstr(PortableServer::ObjectId_to_string(oid),"game")){
		Game_impl* game = new Game_impl(name);
		game->unserialize();			
		svGameMap[game] = game;
		return game;
	}
	else if(...
		...

	return NULL;
}


int main (int argc, char *argv[]){
	orb = CORBA::ORB_init (argc, argv);
	CORBA::Object_var poaobj = orb->resolve_initial_references ("RootPOA");
	PortableServer::POA_var poa = PortableServer::POA::_narrow (poaobj);
	PortableServer::POAManager_var mgr = poa->the_POAManager();

	CORBA::PolicyList pl;
	pl.length(2);
	pl[0] = poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);
	pl[1] = poa->create_lifespan_policy (PortableServer::PERSISTENT);
	PortableServer::POA_var gamepoa = poa->create_POA ("Games", PortableServer::POAManager::_nil(), pl);
	PortableServer::POAManager_var gamemgr = gamepoa->the_POAManager();
	
	// activate ServantManager
	GameManager * am = new GameManager;
	PortableServer::ServantManager_var amref = am->_this ();
	gamepoa->set_servant_manager (amref);

 	...
	
	// generate Gameplay
	Gameplay_impl * predGame = new Gameplay_impl (gamepoa); 
	PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Gameplay");


	gameplaypoa->activate_object_with_id (*oid, predGame);

	...

	// activate POAs
	mgr->activate ();
	gamemgr->activate ();

	int fileCnt = cntFiles("games//");

	// reincarnate all saved Game Objects.
	for(int i = 0;i < fileCnt;i++){
		predGame->loadSavedGame();
	}
	orb->run();

	...

	return 0;
} 

Thanks for your help.

RE: reincarnation through the ServantManager with Mico

(OP)
I've found a solution. The repoid must be unique too.

CODE --> C++

::Predictiongame::Game_ptr Gameplay_impl::loadSavedGame() {
	// generate a ObjectID so that the ServantManager can
	// decide what Objekttyp has to be generated
	char repoid[255];
	sprintf(repoid,"IDL:Game:1.%d", gameCnt);
	
	char oidstr[255];
	sprintf(oidstr,"games//game_%d.dat",gameCnt);
	PortableServer::ObjectId_var tmpoid=PortableServer::string_to_ObjectId(oidstr);

	// Generate a reference for a "virtual" Object.
	// The Servant Manager generates a Object with caling the incarnate() method.
	CORBA::Object_var obj = mypoa->create_reference_with_id (tmpoid,repoid);
	assert (!CORBA::is_nil (obj));
	::Predictiongame::Game_ptr aref = ::Predictiongame::Game::_narrow (obj);
	assert (!CORBA::is_nil (aref));
	oid[gameCnt] = mypoa->reference_to_id(aref); // get id of the Game Objekt and save it in a array
	gameCnt ++;
	return aref;	
} 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close