📄 server.cxx
字号:
//-----------------------------------------------------------------------------// Copyright (c) 2003-2020 EBUPT INFO CO.,LTD//-----------------------------------------------------------------------------// Automatically generated server for the following IDL interfaces:// Hello//#include <omg/orb.hh>#include <it_cal/iostream.h>#include <it_cal/fstream.h>#include <string.h>#include <stdlib.h>#include <it_ts/termination_handler.h>#include <omg/PortableServer.hh>IT_USING_NAMESPACE_STD#include "it_print_funcs.h"#include "it_random_funcs.h"#include "HelloImpl.h"// global_orb -- make ORB global so all code can find it.// CORBA::ORB_var global_orb = CORBA::ORB::_nil();// termination_handler_callback() -- handle fatal signals/events gracefully.//void termination_handler_callback( long sig_type){ cout << "Received shutdown signal" << endl; if (!CORBA::is_nil(global_orb)) { cout << "Shutting down ORB." << endl; global_orb->shutdown(0); } else { cout << "ORB not initialised, aborting." << endl; abort(); }}// write_reference() -- export object reference to file.// This is a useful way to advertise objects for simple tests and demos.// The CORBA naming service is a more scalable way to advertise references.//voidwrite_reference( CORBA::Object_ptr ref, const char* objref_file){ CORBA::String_var stringified_ref = global_orb->object_to_string(ref); cout << "Writing stringified object reference to " << objref_file << endl; ofstream os(objref_file); os << stringified_ref; if (!os.good()) { cerr << "Failed to write to " << objref_file << endl; }}// create_simple_poa() -- Create a POA for simple servant management.// PortableServer::POA_ptrcreate_simple_poa( const char* poa_name, PortableServer::POA_ptr parent_poa, PortableServer::POAManager_ptr poa_manager){ // Create a policy list. Policies not set in the list get default values. // CORBA::PolicyList policies; policies.length(1); int i = 0; // Make the POA single threaded. // policies[i++] = parent_poa->create_thread_policy( PortableServer::SINGLE_THREAD_MODEL ); assert(i==1); return parent_poa->create_POA(poa_name, poa_manager, policies);}// main() -- set up a POA, create and export object references.//intmain( int argc, char **argv){ int exit_status = 0; // Return code from main. // Variables to hold our servants. // Note: PortableServer::Servant is a pointer type - it's actually a // typedef for PortableServer::ServantBase*. // PortableServer::Servant the_Hello = 0; // Handle signals gracefully. // IT_TerminationHandler termination_handler(termination_handler_callback); try { CORBA::Object_var tmp_ref; // For temporary object references. // Initialise the ORB and Root POA. // cout << "Initializing the ORB" << endl; global_orb = CORBA::ORB_init(argc, argv); tmp_ref = global_orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(tmp_ref); assert(!CORBA::is_nil(root_poa)); PortableServer::POAManager_var root_poa_manager = root_poa->the_POAManager(); assert(!CORBA::is_nil(root_poa_manager)); // Initialise the global printer object. // global_print = new IT_GeniePrint(global_orb); // Initialise the global random generator object. // global_random = new IT_GenieRandom(global_orb); // Now create our own POA. // PortableServer::POA_var my_poa = create_simple_poa("my_poa", root_poa, root_poa_manager); // Create servants and export object references. // // Note: _create is a useful convenience function created by // the genie, it is not a standard CORBA function. // PortableServer::ObjectId_var oid; // Create a servant for interface Hello. // the_Hello = HelloImpl::_create(my_poa); oid = my_poa->activate_object(the_Hello); tmp_ref = my_poa->id_to_reference(oid); write_reference(tmp_ref,"Hello.ref"); // Activate the POA Manager and let the ORB process requests. // root_poa_manager->activate(); cout << "Waiting for requests..." << endl; global_orb->run(); } catch (CORBA::Exception& e) { cout << "Unexpected CORBA exception: " << e << endl; exit_status = 1; } // Delete the servants. // delete the_Hello; // Delete the global print and random objects. // delete global_print; delete global_random; // Ensure that the ORB is properly shutdown and cleaned up. // try { global_orb->shutdown(1); global_orb->destroy(); } catch (...) { // Do nothing. } return exit_status;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -