示例#1
0
Components::Deployment::ServerActivator_ptr
get_server_activator (CORBA::ORB_ptr orb, CosNaming::NamingContext_ptr ns, const char* hostname)
{
	cout << "Getting Component Server Activator from Qedo/Activators/" << hostname << endl;

	CosNaming::Name server_activator_name;
	server_activator_name.length (3);
	server_activator_name[0].id = CORBA::string_dup ("Qedo");
	server_activator_name[0].kind = CORBA::string_dup ("");
	server_activator_name[1].id = CORBA::string_dup ("Activators");
	server_activator_name[1].kind = CORBA::string_dup ("");
	server_activator_name[2].id = CORBA::string_dup (hostname);
	server_activator_name[2].kind = CORBA::string_dup ("");

	Components::Deployment::ServerActivator_var server_activator;
	CORBA::Object_var server_activator_obj;

	try
	{
		server_activator_obj = ns->resolve (server_activator_name);
	}
	catch (CosNaming::NamingContext::NotFound&)
	{
		cerr << "Component Server Activator not found in Name Service" << endl;
		orb->destroy();
		exit (1);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "CORBA system exception during resolve()" << endl;
		orb->destroy();
		exit (1);
	}

	try
	{
		server_activator = Components::Deployment::ServerActivator::_narrow (server_activator_obj);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "Cannot narrow Component Server Activator" << endl;
		orb->destroy();
		exit (1);
	}

	return server_activator._retn();
}
示例#2
0
int main(int argc, char ** argv)
{
    try {
        // init ORB
        CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
 
        // init POA
        CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj);
        PortableServer::POAManager_var manager = poa->the_POAManager();
 
        // create service
        Math_operation * service = new Math_operation;
 
        // register within the naming service
        try {
            CORBA::Object_var ns_obj = orb->resolve_initial_references("NameService");
            if (!CORBA::is_nil(ns_obj)) {
                CosNaming::NamingContext_ptr nc = CosNaming::NamingContext::_narrow(ns_obj);
                CosNaming::Name name;
                name.length(1);
                name[0].id = CORBA::string_dup("TestServer");
                name[0].kind = CORBA::string_dup("");
                nc->rebind(name, service->_this());
                cout << argv[0] << ": server 'TestServer' bound" << endl;
            }
        } catch (CosNaming::NamingContext::NotFound &) {
            cerr << "not found" << endl;
        } catch (CosNaming::NamingContext::InvalidName &) {
            cerr << "invalid name" << endl;
        } catch (CosNaming::NamingContext::CannotProceed &) {
            cerr << "cannot proceed" << endl;
        }
 
        // run
        manager->activate();
        orb->run();
 
        // clean up
        delete service;
 
        // quit
        orb->destroy();
    } catch (CORBA::UNKNOWN) {
        cerr << "unknown exception" << endl;
    } catch (CORBA::SystemException &) {
        cerr << "system exception" << endl;
    }
}
示例#3
0
//---------------------------------------------------------//
bool CServer::destroy_corba()
{
	try 
	{
		int count = 0;
		char** args = 0;
	
		CORBA::ORB_ptr orb = CORBA::ORB_init(count, args);
		CORBA::release(orb);

		orb->shutdown(true);
		orb->destroy();

		omniORB::setLogFunction(0);
	}
	catch(CORBA::SystemException& err) 
	{
		LOG4CPLUS_ERROR(CServer::server_logger(), 
		"corba::SystemException: " << ToString(err));
	}
	catch(CORBA::Exception& err) 
	{
		LOG4CPLUS_ERROR(CServer::server_logger(), 
		"corba::Exception: " << ToString(err));
	}
	catch(omniORB::fatalException& err) 
	{		
		LOG4CPLUS_ERROR(CServer::server_logger(), 
		"omniORB::FatalException: " << ToString(err));
	}
	catch (std::exception err) {
		LOG4CPLUS_ERROR(CServer::server_logger(),
		"std::exception occured while destroy_corba()" <<
		err.what());	
	}
	catch (...) {
		LOG4CPLUS_ERROR(CServer::server_logger(),
		"Unknown exception occured while destroying corba.");
	};
	return true;
}
示例#4
0
void
deploy_test_components (CORBA::ORB_ptr orb, CosNaming::NamingContext_ptr ns, const char* hostname)
{
	cout << "Getting Component Installation from Qedo/ComponentInstallation/" << hostname << endl;

	CosNaming::Name installer_name;
	installer_name.length (3);
	installer_name[0].id = CORBA::string_dup ("Qedo");
	installer_name[0].kind = CORBA::string_dup ("");
	installer_name[1].id = CORBA::string_dup ("ComponentInstallation");
	installer_name[1].kind = CORBA::string_dup ("");
	installer_name[2].id = CORBA::string_dup (hostname);
	installer_name[2].kind = CORBA::string_dup ("");

	Components::Deployment::ComponentInstallation_var component_installer;
	CORBA::Object_var component_installer_obj;

	try
	{
		component_installer_obj = ns->resolve (installer_name);
	}
	catch (CosNaming::NamingContext::NotFound&)
	{
		cerr << "Component Installer not found in Name Service" << endl;
		orb->destroy();
		exit (1);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "CORBA system exception during resolve()" << endl;
		orb->destroy();
		exit (1);
	}

	try
	{
		component_installer = Components::Deployment::ComponentInstallation::_narrow (component_installer_obj);
	}
	catch (CORBA::SystemException&)
	{
		cerr << "Cannot narrow Component Installer" << endl;
		orb->destroy();
		exit (1);
	}

#ifdef _WIN32
	std::string servant_loc = getCurrentDirectory() + "\\dinner_SERVANT.dll";
	std::string phil_loc = getCurrentDirectory() + "\\dinner_PhilosopherImpl.dll";
	std::string cutl_loc = getCurrentDirectory() + "\\dinner_CutleryImpl.dll";
	std::string obse_loc = getCurrentDirectory() + "\\dinner_ObserverImpl.dll";
#else
	std::string servant_loc = getCurrentDirectory() + "/libdinner_SERVANT.so";
	std::string phil_loc = getCurrentDirectory() + "/libdinner_PhilosopherImpl.so";
	std::string cutl_loc = getCurrentDirectory() + "/libdinner_CutleryImpl.so";
	std::string obse_loc = getCurrentDirectory() + "/libdinner_ObserverImpl.so";
#endif
	std::string loc_p = servant_loc + ";create_PhilosopherHomeS;" + phil_loc + ";create_PhilosopherHomeE";
	std::string loc_c = servant_loc + ";create_CutleryHomeS;" + cutl_loc + ";create_CutleryHomeE";
	std::string loc_o = servant_loc + ";create_ObserverHomeS;" + obse_loc + ";create_ObserverHomeE";

	try
	{
		component_installer->install ("PHILOSOPHER", loc_p.c_str());
		component_installer->install ("CUTLERY", loc_c.c_str());
		component_installer->install ("OBSERVER", loc_o.c_str());
	}
	catch (Components::Deployment::InvalidLocation&)
	{
		cerr << "Component Installer raised Components::Deployment::InvalidLocation" << endl;
	}
	catch (Components::Deployment::InstallationFailure&)
	{
		cerr << "Component Installer raised Components::Deployment::InstallationFailure" << endl;
	}
}
示例#5
0
void CORBAThread::run()
{
	uint32 realCurrTime = 0;
    uint32 realPrevTime = getMSTime();
	uint32 prevSleepTime = 0;                               // used for balanced full tick time length near WORLD_SLEEP_CONST

	CosNaming::NamingContext_var rootContext;
	try
	{
		sLog.outBasic("Initializing CORBA...");
		CORBA::ORB_ptr orb = CORBA::ORB_init(argnb,argtab,"omniORB4");

		sLog.outBasic("Initializing CORBA POA...");
		CORBA::Object_var obj = orb->resolve_initial_references("NameService");
		rootContext = CosNaming::NamingContext::_narrow(obj);
		PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
		if( CORBA::is_nil(rootContext) ) {
			sLog.outError("RootContext configuration failed !");
		}

		sLog.outBasic("Prepare FirstCallBack object...");
		FirstCallBack_var v = FirstCallBack::_narrow(obj);

		FirstCallBack_i* FCB = new FirstCallBack_i();

		// Activate the object.  This tells the POA that this object is
		// ready to accept requests.
		PortableServer::ObjectId_var FCBid = poa->activate_object(FCB);

		// Obtain a reference to the object.
		FirstCallBack_var FCBref = FCB->_this();

		// Decrement the reference count of the object implementation, so
		// that it will be properly cleaned up when the POA has determined
		// that it is no longer needed.
		FCB->_remove_ref();
		
		/** TODO : activate objects there

		*/

		sLog.outBasic("Activate CORBA POA Manager...");
		PortableServer::POAManager_var pman = poa->the_POAManager();
		pman->activate();

		if(CORBA::is_nil(v))
			sLog.outError("Cannot Initialize FirstCallBack object");
		else
		{
			CORBA::String_var src = (const char*) "Toto";
			CORBA::String_var dest = v->nerzhulCB(src);
			sLog.outError("String recv %s",dest);
		}

		sLog.outBasic("CORBA Thread launched successfuly !");
		while(!MustStop())
		{
			// Updates
			realCurrTime = getMSTime();
			uint32 diff = getMSTimeDiff(realPrevTime,realCurrTime);

			// Main update there if need
			realPrevTime = realCurrTime;
			if (diff <=  CLUSTER_SLEEP_CONST+prevSleepTime)
			{
				prevSleepTime = CLUSTER_SLEEP_CONST+prevSleepTime-diff;
				ACE_Based::Thread::Sleep(prevSleepTime);
			}
			else
				prevSleepTime = 0;
		}

		sLog.outBasic("Destroy CORBA ORB...");
		orb->destroy();
	}
	catch(CORBA::SystemException& ex)
	{
		sLog.outError("CORBA System Exception : %s",ex._name());
	}
	catch(CORBA::Exception& ex)
	{
		sLog.outError("CORBA Exception : %s",ex._name());
	}
	catch(omniORB::fatalException& ex)
	{
		sLog.outError("omniORB fatalException : file => %s / line => %d / error : %s",ex.file(),ex.line(),ex.errmsg());
	}

	sLog.outBasic("CORBA Thread finished successfuly !");
}