本文整理汇总了C++中cosnaming::NamingContext_var::rebind方法的典型用法代码示例。如果您正苦于以下问题:C++ NamingContext_var::rebind方法的具体用法?C++ NamingContext_var::rebind怎么用?C++ NamingContext_var::rebind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cosnaming::NamingContext_var
的用法示例。
在下文中一共展示了NamingContext_var::rebind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw
void
VOmniORBHelper::nsRegisterObject(CORBA::Object_ptr obj,
const char* program, const char* object,
int telescopenumber)
throw(CORBA::SystemException,
CosNaming::NamingContext::NotFound,
CosNaming::NamingContext::CannotProceed,
CosNaming::NamingContext::InvalidName,
CosNaming::NamingContext::AlreadyBound)
{
ZThread::Guard<ZThread::RecursiveMutex> guard(m_mutex);
CosNaming::NamingContext_var root = nsRootContext();
CosNaming::Name_var name =
nsPathToObjectName(program, object, telescopenumber);
for(unsigned int n=0; n<name->length()-1; n++)
{
CosNaming::Name_var child_name = name;
child_name->length(n+1);
try
{
CORBA::Object_var object = root->resolve(child_name);
}
catch(CosNaming::NamingContext::NotFound)
{
CosNaming::NamingContext_var
child = root->bind_new_context(child_name);
}
}
root->rebind(name,obj);
}
示例2: ACE_TMAIN
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
//Get reference to Root POA
CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Find the Naming Service
obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(obj.in());
if (CORBA::is_nil(root.in())) {
std::cerr << "Nil Naming Context reference" << std::endl;
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::Name name;
name.length( 1 );
name[0].id = CORBA::string_dup("example");
try {
obj = root->resolve(name);
}
catch(const CosNaming::NamingContext::NotFound&) {
CosNaming::NamingContext_var dummy = root->bind_new_context(name);
}
// Bind the Messenger object
name.length(2);
name[1].id = CORBA::string_dup("Messenger");
// Create an object
PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
obj = poa->id_to_reference(oid.in());
Messenger_var messenger = Messenger::_narrow(obj.in());
root->rebind(name, messenger.in());
std::cout << "Messenger object bound in Naming Service" << std::endl;
// Accept requests
orb->run();
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << "server: Caught a CORBA::Exception: " << ex << std::endl;
return 1;
}
return 0;
}
示例3: main
int main(int argc, char *argv[])
{
CORBA::ORB_var orb = CORBA::ORB::_nil();
try {
orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var obj;
obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
if(CORBA::is_nil(poa)){
throw std::string("error: failed to narrow root POA.");
}
PortableServer::POAManager_var poaManager = poa->the_POAManager();
if(CORBA::is_nil(poaManager)){
throw std::string("error: failed to narrow root POA manager.");
}
OnlineViewer_impl* OnlineViewerImpl = new OnlineViewer_impl(orb, poa);
poa->activate_object(OnlineViewerImpl);
OnlineViewer_var OnlineViewer = OnlineViewerImpl->_this();
OnlineViewerImpl->_remove_ref();
obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj);
if(CORBA::is_nil(namingContext)){
throw std::string("error: failed to narrow naming context.");
}
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup("OnlineViewer");
name[0].kind = CORBA::string_dup("");
namingContext->rebind(name, OnlineViewer);
poaManager->activate();
glmain(argc, argv);
}
catch (CORBA::SystemException& ex) {
std::cerr << ex._rep_id() << std::endl;
}
catch (const std::string& error){
std::cerr << error << std::endl;
}
try {
orb->destroy();
}
catch(...){
}
return 0;
}
示例4: OBJECT_NOT_EXIST
void
TAO_Hash_Naming_Context::rebind (const CosNaming::Name& n,
CORBA::Object_ptr obj)
{
// Check to make sure this object didn't have <destroy> method
// invoked on it.
if (this->destroyed_)
throw CORBA::OBJECT_NOT_EXIST ();
// Get the length of the name.
CORBA::ULong const name_len = n.length ();
// Check for invalid name.
if (name_len == 0)
throw CosNaming::NamingContext::InvalidName();
// If we received compound name, resolve it to get the context in
// which the rebinding should take place, then perform the rebinding
// on target context.
if (name_len > 1)
{
CosNaming::NamingContext_var context = this->get_context (n);
CosNaming::Name simple_name;
simple_name.length (1);
simple_name[0] = n[name_len - 1];
try
{
context->rebind (simple_name, obj);
}
catch (const CORBA::SystemException&)
{
throw CosNaming::NamingContext::CannotProceed(
context.in (), simple_name);
}
}
else
// If we received a simple name, we need to rebind it in this
// context.
{
ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX, ace_mon,
this->lock_,
CORBA::INTERNAL ());
int result = this->context_->rebind (n[0].id,
n[0].kind,
obj,
CosNaming::nobject);
// Check for error conditions.
if (result == -1)
throw CORBA::INTERNAL ();
else if (result == -2)
throw CosNaming::NamingContext::NotFound(
CosNaming::NamingContext::not_object, n);
}
}
示例5: Messenger_i
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
try
{
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
if (parse_args (argc, argv) != 0)
return 1;
// Find the Naming Service.
CORBA::Object_var rootObj = orb->resolve_initial_references("NameService");
CosNaming::NamingContext_var rootNC =
CosNaming::NamingContext::_narrow(rootObj.in());
// Get the Root POA.
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Activate POA manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Create our Messenger servant.
PortableServer::Servant_var<Messenger_i> messenger_servant =
new Messenger_i(orb.in());
// Register it with the RootPOA.
PortableServer::ObjectId_var oid =
poa->activate_object( messenger_servant.in() );
CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
// Bind it in the Naming Service.
CosNaming::Name name;
name.length (1);
name[0].id = CORBA::string_dup("MessengerService");
rootNC->rebind(name, messenger_obj.in());
CORBA::String_var str = orb->object_to_string (messenger_obj.in());
std::ofstream iorFile (ACE_TEXT_ALWAYS_CHAR(ior_output_file));
iorFile << str.in () << std::endl;
iorFile.close ();
std::cout << "IOR written to file " << ior_output_file << std::endl;
// Accept requests
orb->run();
orb->destroy();
}
catch(const CORBA::Exception& ex) {
std::cerr << ex << std::endl;
return 1;
}
return 0;
}
示例6: rebindRecursive
/*!
* @if jp
* @brief 途中のコンテキストを bind しながら Object を rebind する
* @else
* @brief Bind intermediate context recursively and rebind object
* @endif
*/
void CorbaNaming::rebindRecursive(CosNaming::NamingContext_ptr context,
const CosNaming::Name& name,
CORBA::Object_ptr obj)
throw (SystemException, CannotProceed, InvalidName)
{
CORBA::ULong len(name.length());
CosNaming::NamingContext_var cxt;
cxt = CosNaming::NamingContext::_duplicate(context);
for (CORBA::ULong i = 0; i < len; ++i)
{
if (i == (len - 1))
{
cxt->rebind(subName(name, i, i), obj);
return;
}
else
{ // If the context is not a NamingContext, CannotProceed is thrown
if (isNamingContext(cxt))
{
try
{
cxt = cxt->bind_new_context(subName(name, i, i));
}
catch (AlreadyBound& e)
{
(void)(e);
cxt = CosNaming::
NamingContextExt::
_narrow(cxt->resolve(subName(name, i, i)));
}
}
else
throw CannotProceed(cxt, subName(name, i));
}
}
return;
}
示例7: ctrl_servant
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
CORBA::ORB_var orb;
try {
// Initialize orb
orb = CORBA::ORB_init (argc, argv);
// Get reference to Root POA.
CORBA::Object_var obj
= orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var poa
= PortableServer::POA::_narrow (obj.in ());
// Get POA manager
PortableServer::POAManager_var poa_mgr = poa->the_POAManager ();
// Create a policy list. We use persistent objects with
// user-assigned IDs, and explicit activation.
CORBA::PolicyList policy_list;
policy_list.length (6);
policy_list[0] = poa->create_lifespan_policy (
PortableServer::TRANSIENT // REVISIT
);
policy_list[1] = poa->create_id_assignment_policy (
PortableServer::USER_ID
);
policy_list[2] = poa->create_implicit_activation_policy (
PortableServer::NO_IMPLICIT_ACTIVATION
);
policy_list[3] = poa->create_request_processing_policy (
PortableServer::USE_SERVANT_MANAGER
);
policy_list[4] = poa->create_servant_retention_policy (
PortableServer::NON_RETAIN
);
policy_list[5] = poa->create_thread_policy (
PortableServer::SINGLE_THREAD_MODEL
);
// Create a POA for all CCS elements.
PortableServer::POA_var ccs_poa
= poa->create_POA ("CCS_POA", poa_mgr.in (), policy_list);
// Create a controller and set static m_ctrl member
// for thermostats and thermometers.
Controller_impl ctrl_servant (ccs_poa.in (), "/tmp/CCS_assets");
Thermometer_impl::m_ctrl = &ctrl_servant;
// Create a reference for the controller and
// create the corresponding CORBA object.
PortableServer::ObjectId_var oid
= PortableServer::string_to_ObjectId (Controller_oid);
CORBA::Object_var ctrl
= ccs_poa->create_reference_with_id (
oid.in (), "IDL:acme.com/CCS/Controller:1.0"
);
// Get reference to initial naming context.
CosNaming::NamingContext_var inc
= resolve_init<CosNaming::NamingContext> (
orb.in (), "NameService"
);
// Attempt to create CCS context.
CosNaming::Name n;
n.length (1);
n[0].id = CORBA::string_dup ("CCS");
try {
CosNaming::NamingContext_var nc
= inc->bind_new_context (n);
} catch (const CosNaming::NamingContext::AlreadyBound &) {
// Fine, CCS context already exists.
}
// Force binding of controller reference to make
// sure it is always up-to-date.
n.length (2);
n[1].id = CORBA::string_dup ("Controller");
inc->rebind (n, ctrl.in ());
// Instantiate the servant locator for devices.
PortableServer::ServantManager_var locator =
new DeviceLocator_impl (&ctrl_servant);
// Set servant locator.
ccs_poa->set_servant_manager (locator.in ());
// Activate the POA manager.
poa_mgr->activate ();
// Accept requests
orb->run ();
}
catch (const CORBA::Exception & e) {
std::cerr << "Uncaught CORBA exception: "
<< e
<< std::endl;
return 1;
//.........这里部分代码省略.........
示例8: svc
int TestTask::svc()
{
try {
// Get reference to Root POA
CORBA::Object_var obj = orb_->resolve_initial_references ("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ());
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager ();
mgr->activate ();
// Find the Naming Service
obj = orb_->string_to_object (
"corbaloc:iiop:[email protected]:9932/NameService");
CosNaming::NamingContext_var rootB =
CosNaming::NamingContext::_narrow (obj.in ());
if (CORBA::is_nil (rootB.in ())) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Error, Nil Naming Context reference\n")));
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::NamingContext_var example_nc;
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup( "example");
try
{
obj = rootB->resolve (name);
example_nc =
CosNaming::NamingContext::_narrow (obj.in ());
}
catch (const CosNaming::NamingContext::NotFound&)
{
example_nc = rootB->bind_new_context (name);
}
// Bind the Test object
name.length (2);
name[1].id = CORBA::string_dup ("Hello");
// Create an object
Hello servant (orb_.in ());
PortableServer::ObjectId_var oid = poa->activate_object (&servant);
obj = poa->id_to_reference (oid.in ());
rootB->rebind (name, obj.in ());
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("Hello object bound in Naming Service B\n")));
name.length (1);
name[0].id = CORBA::string_dup ("nsB");
obj = orb_->string_to_object (
"corbaloc:iiop:[email protected]:9931/NameService");
CosNaming::NamingContext_var rootA =
CosNaming::NamingContext::_narrow (obj.in ());
rootA->bind_context (name, rootB.in ());
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("Root context of NS B bound in Naming Service A ")
ACE_TEXT ("under name 'nsB'\n")));
CORBA::String_var ior =
orb_->object_to_string (obj.in ());
// Output the IOR to the <ior_output_file>
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Cannot open output file %s for writing ")
ACE_TEXT ("IOR: %C\n"),
ior_output_file,
ior.in ()),
1);
ACE_OS::fprintf (output_file, ACE_TEXT ("%s"), ior.in ());
ACE_OS::fclose (output_file);
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("Wrote IOR file\n")));
// Normally we run the orb and the orb is shutdown by
// calling TestTask::end().
// Accept requests
orb_->run();
orb_->destroy();
return 0;
}
catch (CORBA::Exception& ex)
{
ex._tao_print_exception (ACE_TEXT ("CORBA exception: "));
}
//.........这里部分代码省略.........
示例9: catch
static CORBA::Boolean
bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref)
{
CosNaming::NamingContext_var rootContext;
try {
// Obtain a reference to the root context of the Name service:
CORBA::Object_var obj;
obj = orb->resolve_initial_references("NameService");
// Narrow the reference returned.
rootContext = CosNaming::NamingContext::_narrow(obj);
if( CORBA::is_nil(rootContext) ) {
cerr << "Failed to narrow the root naming context." << endl;
return 0;
}
}
catch (CORBA::NO_RESOURCES&) {
cerr << "Caught NO_RESOURCES exception. You must configure omniORB "
<< "with the location" << endl
<< "of the naming service." << endl;
return 0;
}
catch (CORBA::ORB::InvalidName&) {
// This should not happen!
cerr << "Service required is invalid [does not exist]." << endl;
return 0;
}
try {
// Bind a context called "test" to the root context:
CosNaming::Name contextName;
contextName.length(1);
contextName[0].id = (const char*) "test"; // string copied
contextName[0].kind = (const char*) "my_context"; // string copied
// Note on kind: The kind field is used to indicate the type
// of the object. This is to avoid conventions such as that used
// by files (name.type -- e.g. test.ps = postscript etc.)
CosNaming::NamingContext_var testContext;
try {
// Bind the context to root.
testContext = rootContext->bind_new_context(contextName);
}
catch(CosNaming::NamingContext::AlreadyBound& ex) {
// If the context already exists, this exception will be raised.
// In this case, just resolve the name and assign testContext
// to the object returned:
CORBA::Object_var obj;
obj = rootContext->resolve(contextName);
testContext = CosNaming::NamingContext::_narrow(obj);
if( CORBA::is_nil(testContext) ) {
cerr << "Failed to narrow naming context." << endl;
return 0;
}
}
// Bind objref with name Echo to the testContext:
CosNaming::Name objectName;
objectName.length(1);
objectName[0].id = (const char*) "Echo"; // string copied
objectName[0].kind = (const char*) "Object"; // string copied
try {
testContext->bind(objectName, objref);
}
catch(CosNaming::NamingContext::AlreadyBound& ex) {
testContext->rebind(objectName, objref);
}
// Note: Using rebind() will overwrite any Object previously bound
// to /test/Echo with obj.
// Alternatively, bind() can be used, which will raise a
// CosNaming::NamingContext::AlreadyBound exception if the name
// supplied is already bound to an object.
// Amendment: When using OrbixNames, it is necessary to first try bind
// and then rebind, as rebind on it's own will throw a NotFoundexception if
// the Name has not already been bound. [This is incorrect behaviour -
// it should just bind].
}
catch(CORBA::TRANSIENT& ex) {
cerr << "Caught system exception TRANSIENT -- unable to contact the "
<< "naming service." << endl
<< "Make sure the naming server is running and that omniORB is "
<< "configured correctly." << endl;
return 0;
}
catch(CORBA::SystemException& ex) {
cerr << "Caught a CORBA::" << ex._name()
<< " while using the naming service." << endl;
return 0;
}
return 1;
}
示例10: CannotInitialize
//.........这里部分代码省略.........
catch (CORBA::SystemException&)
{
std::cerr << "ServerActivatorImpl: Cannot narrow object reference of Name Service" << std::endl;
throw CannotInitialize();
}
if (CORBA::is_nil (ns))
{
std::cerr << "ServerActivatorImpl: Name Service is nil" << std::endl;
throw CannotInitialize();
}
// Create the Qedo and Activators naming context
CosNaming::Name current_name;
current_name.length (1);
current_name[0].id = CORBA::string_dup ("Qedo");
current_name[0].kind = CORBA::string_dup ("");
try
{
ns->bind_new_context (current_name);
}
catch (CosNaming::NamingContext::AlreadyBound&)
{
// Ignore this exception
}
catch (CORBA::SystemException&)
{
std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
throw CannotInitialize();
}
current_name.length(2);
current_name[1].id = CORBA::string_dup ("Activators");
current_name[1].kind = CORBA::string_dup ("");
try
{
ns->bind_new_context (current_name);
}
catch (CosNaming::NamingContext::AlreadyBound&)
{
// Ignore this exception
}
catch (CORBA::SystemException&)
{
std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << std::endl;
throw CannotInitialize();
}
// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
char hostname[256];
if (gethostname (hostname, 256))
{
std::cerr << "ServerActivatorImpl: Cannot determine my hostname" << std::endl;
throw CannotInitialize();
}
std::cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << std::endl;
current_name.length (3);
current_name[2].id = CORBA::string_dup (hostname);
current_name[2].kind = CORBA::string_dup ("");
CORBA::Object_var my_ref = this->_this();
try
{
ns->bind (current_name, my_ref);
}
catch (CosNaming::NamingContext::AlreadyBound&)
{
try
{
ns->rebind (current_name, my_ref);
}
catch (CosNaming::NamingContext::InvalidName&)
{
std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
throw CannotInitialize();
}
catch (CORBA::SystemException&)
{
std::cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << std::endl;
throw CannotInitialize();
}
}
catch (CosNaming::NamingContext::InvalidName&)
{
std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
throw CannotInitialize();
}
catch (CORBA::SystemException&)
{
std::cerr << "ServerActivatorImpl: CORBA system exception during bind()" << std::endl;
throw CannotInitialize();
}
}
示例11: self_manage
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
// Initialize orb
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
// Get reference to Root POA.
CORBA::Object_var obj =
orb->resolve_initial_references ("RootPOA");
PortableServer::POA_var rootpoa =
PortableServer::POA::_narrow (obj.in ());
// Activate POA manager
PortableServer::POAManager_var mgr =
rootpoa->the_POAManager ();
mgr->activate ();
PortableServer::POA_var poa;
TAO::Utils::PolicyList_Destroyer PolicyList (3);
PolicyList.length (3);
PolicyList [0] =
rootpoa->create_lifespan_policy (PortableServer::PERSISTENT);
PolicyList [1] =
rootpoa->create_id_assignment_policy (PortableServer::USER_ID);
CORBA::Any CallbackPolicy;
CallbackPolicy <<= BiDirPolicy::BOTH;
const char* sServerPoaName = "TelemetryServer";
PolicyList [2] =
orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
CallbackPolicy);
poa = rootpoa->create_POA (sServerPoaName,
mgr.in(),
PolicyList);
PortableServer::ObjectId_var ServerId =
PortableServer::string_to_ObjectId ("TimeServer");
// Create an object
Time_impl *time_servant = new Time_impl;
PortableServer::ServantBase_var self_manage (time_servant);
poa->activate_object_with_id (ServerId.in (),
time_servant);
// Get a reference after activating the object
CORBA::Object_var object = poa->id_to_reference (ServerId.in ());
TimeModule::Time_var tm = TimeModule::Time::_narrow (object.in ());
// Get reference to initial naming context
CORBA::Object_var name_obj =
orb->resolve_initial_references ("NameService");
CosNaming::NamingContext_var inc =
CosNaming::NamingContext::_narrow (name_obj.in ());
if (CORBA::is_nil (inc.in ()))
{
ACE_ERROR ((LM_ERROR,
"(%P|%t) Error fetching naming context\n"));
}
CosNaming::Name service_name;
service_name.length(1);
service_name[0].id =
CORBA::string_dup ("Time");
inc->rebind (service_name,
tm.in ());
// Run the event loop for fun
ACE_Time_Value tv (3, 0);
// Accept requests
orb->run (&tv);
rootpoa->destroy (0 , 0);
orb->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Caught an exception\n");
return -1;
}
return 0;
//.........这里部分代码省略.........
示例12: main
int main (int argc, char** argv) {
if (!init (argc, argv))
return 1;
// --------------------------------------------------------------------------
// Start HTTP server:
// --------------------------------------------------------------------------
for (size_t i = 1; i < argc; ++i) {
std::stringstream key;
key << "arg_" << i;
wspace.p[key.str()] = argv[i];
}
wspace.p["http_port"] = port;
using namespace codeare::service;
MongooseService& mg = MongooseService::Instance();
// --------------------------------------------------------------------------
// Start CORBA server:
// --------------------------------------------------------------------------
try {
streambuf* out;
streambuf* err;
ofstream log (logfile);
if (log.is_open()) {
out = cout.rdbuf(log.rdbuf());
err = cerr.rdbuf(log.rdbuf());
} else {
cout << "Could not open logfile " << logfile << "." << endl;
cout << "Exiting :(" << endl << endl;
return 1;
}
// Initialise ORB
const char* options[][2] = { { (char*)"traceLevel", debug}, /*{ (char*)"traceFile", logfile}, */{ 0, 0 } };
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);
// Get reference to the RootPOA.
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var _poa = PortableServer::POA::_narrow(obj.in());
// Initialise servant
ReconServant* myReconServant = new ReconServant();
// Activate in RootPDA
PortableServer::ObjectId_var myReconServant_oid
= _poa->activate_object(myReconServant);
// Obtain object reference from servant and register in naming service
CORBA::Object_var SA_obj = myReconServant->_this();
// Obtain a reference to the object, and print it out as string IOR.
CORBA::String_var sior(orb->object_to_string(SA_obj.in()));
// Bind to the name server and lookup
CORBA::Object_var obj1=orb->resolve_initial_references("NameService");
assert(!CORBA::is_nil(obj1.in()));
// Get context
CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj1.in());
assert(!CORBA::is_nil(nc.in()));
// Resolve name
CosNaming::Name m_name;
m_name.length(1);
m_name[0].id=CORBA::string_dup(name);
nc->rebind (m_name,SA_obj.in());
// Activate POA manager
PortableServer::POAManager_var pmgr = _poa->the_POAManager();
pmgr->activate();
// Accept requests from clients
orb->run();
orb->destroy();
free(m_name[0].id); // str_dup does a malloc internally
cout.rdbuf(out);
cerr.rdbuf(err);
} catch(CORBA::SystemException&) {
cerr << "Caught CORBA::SystemException." << endl;
throw DS_SystemException();
} catch(CORBA::Exception&) {
cerr << "Caught CORBA::Exception." << endl;
throw DS_Exception();
} catch(omniORB::fatalException& fe) {
cerr << "Caught omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
throw DS_FatalException();
} catch(...) {
cerr << "Caught unknown exception." << endl;
throw DS_Exception();
}
//.........这里部分代码省略.........
示例13: svc
int TestTask::svc()
{
try {
// Start the Naming Service tasks
namingServiceA_.activate();
// Wait for the Naming Service initialized.
namingServiceA_.waitInit();
namingServiceB_.activate();
// Wait for the Naming Service initialized.
namingServiceB_.waitInit();
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file for writing IOR: ns.ior\n"),
1);
ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ());
ACE_OS::fclose (output_file);
// Get reference to Root POA
CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Activate POA Manager
PortableServer::POAManager_var mgr = poa->the_POAManager();
mgr->activate();
// Find the Naming Service
obj = orb_->string_to_object (namingServiceB_.ior ());
CosNaming::NamingContext_var root =
CosNaming::NamingContext::_narrow(obj.in());
if (CORBA::is_nil(root.in())) {
ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n"));
return 1;
}
// Bind the example Naming Context, if necessary
CosNaming::NamingContext_var example_nc;
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup("example");
try
{
obj = root->resolve(name);
example_nc = CosNaming::NamingContext::_narrow(obj.in());
}
catch (const CosNaming::NamingContext::NotFound&)
{
example_nc = root->bind_new_context(name);
}
// Bind the Test object
name.length(2);
name[1].id = CORBA::string_dup("Hello");
// Create an object
Hello servant(orb_.in ());
PortableServer::ObjectId_var oid = poa->activate_object(&servant);
obj = poa->id_to_reference(oid.in());
root->rebind(name, obj.in());
ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n"));
name.length(1);
obj = orb_->string_to_object (namingServiceA_.ior ());
root = CosNaming::NamingContext::_narrow(obj.in());
root->bind_context (name, example_nc.in ());
ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n"));
if (shutdown_ns_)
{
namingServiceB_.end();
ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n"));
}
// Create shutdown server
NsShutdown shutdown_servant(orb_.in ());
PortableServer::ObjectId_var shutdown_oid = poa->activate_object(&shutdown_servant);
obj = poa->id_to_reference(shutdown_oid.in());
CORBA::String_var ior = orb_->object_to_string (obj.in ());
output_file= ACE_OS::fopen (ior_shutdown_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file %s for writing IOR: %C\n",
ior_shutdown_file,
ior.in ()),
1);
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
// Normally we run the orb and the orb is shutdown by
// calling TestTask::end().
// Accept requests
orb_->run();
orb_->destroy();
//.........这里部分代码省略.........
示例14: while
bool
NameServiceBase::registerName(std::string name, CORBA::Object_ptr obj, bool rebind)
{
if (name.empty())
{
return false;
}
// extract name without contexts
std::string pure_name = name;
std::string contexts = "";
std::string::size_type delimiter_pos = name.find_last_of("/");
if (delimiter_pos != std::string::npos)
{
pure_name = pure_name.replace(0, delimiter_pos + 1, "");
contexts = name.replace(delimiter_pos, std::string::npos, "");
}
CosNaming::Name aName;
aName.length(1);
aName[0].id = CORBA::string_dup(pure_name.c_str());
aName[0].kind = CORBA::string_dup("");
// make sure each context is bound
CosNaming::NamingContext_var context = nameService_;
while (contexts.length())
{
std::string ctx = contexts;
delimiter_pos = contexts.find_first_of("/");
if (delimiter_pos != std::string::npos)
{
ctx = ctx.replace(delimiter_pos, std::string::npos, "");
contexts = contexts.replace(0, delimiter_pos + 1, "");
}
else
{
contexts = "";
}
CosNaming::Name contextName;
contextName.length(1);
contextName[0].id = CORBA::string_dup(ctx.c_str());
contextName[0].kind = CORBA::string_dup("");
try
{
context = context->bind_new_context(contextName);
}
catch (const CosNaming::NamingContext::AlreadyBound&)
{
try
{
// already bound -> take it
CORBA::Object_var dummy;
context = CosNaming::NamingContext::_narrow(dummy = context->resolve(contextName));
}
catch (...)
{
std::cerr << ctx << " is probably no context?" << std::endl;
return false;
}
}
catch (const CosNaming::NamingContext::NotFound&)
{
std::cerr << "Got a `NotFound' exception : " << std::endl;
return false;
}
catch (const CosNaming::NamingContext::CannotProceed&)
{
std::cerr << "Got a `CannotProceed' exception : " << std::endl;
return false;
}
catch (const CosNaming::NamingContext::InvalidName&)
{
std::cerr << "Got a `InvalidName' exception : " << std::endl;
return false;
}
}
// bind the name
try
{
context->bind(aName, obj);
}
catch(const CosNaming::NamingContext::AlreadyBound&)
{
// rebind the name if intended
if (rebind)
{
try
{
context->rebind(aName, obj);
}
catch (const CosNaming::NamingContext::NotFound&)
{
std::cerr << "Got a `NotFound' exception : " << std::endl;
return false;
}
catch (const CosNaming::NamingContext::CannotProceed&)
{
//.........这里部分代码省略.........
示例15: catch
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
std::cout << __FILE__ << " build " << __DATE__ << " " << __TIME__ <<std::endl;
int ret = 0;
CORBA::ORB_var orb;
CORBA::Object_var distrio_manager_obj, root_poa, naming_service;
PortableServer::POA_var poa;
PortableServer::POAManager_var poa_mgr;
CosNaming::NamingContext_var nc;
CosNaming::Name name;
Distrio_Manager_i *distrio_manager;
PortableServer::ObjectId_var distrio_manager_oid;
distrio_manager = new Distrio_Manager_i ();
try {
std::cout << "initialize CORBA orb" << std::endl;
orb = CORBA::ORB_init (argc, argv);
root_poa = orb->resolve_initial_references ("RootPOA");
poa = PortableServer::POA::_narrow (root_poa.in ());
distrio_manager_oid = poa->activate_object (distrio_manager);
distrio_manager_obj = distrio_manager->_this ();
std::cout << "get context of NameService" << std::endl;
naming_service = orb->resolve_initial_references ("NameService");
if (CORBA::is_nil (naming_service)) {
std::cerr << "can't resolve NameService" << std::endl;
ret = -EINVAL;
goto out;
}
nc = CosNaming::NamingContext::_narrow (naming_service.in ());
if (CORBA::is_nil (nc)) {
std::cerr << "resolved invalid NameService object" << std::endl;
ret = -EINVAL;
goto out;
}
std::cout << "bind manager object at NameService" << std::endl;
/* TODO: find out how to build a tree @ the nameservice "distrio/manager" */
name.length (1);
name[0].id = CORBA::string_dup ("distrio_manager");
nc->rebind (name, distrio_manager_obj.in ());
std::cout << "activate POA Manager" << std::endl;
poa_mgr = poa->the_POAManager ();
poa_mgr->activate ();
std::cout << "distrio_manager ready" << std::endl;
orb->run ();
orb->destroy ();
} catch (CORBA::SystemException &e) {
std::cerr << "CORBA initialization failed: " << e << std::endl;
ret = -EINVAL;
goto out;
} catch(CORBA::Exception &e) {
std::cerr << "CORBA initialization failed: " << e << std::endl;
ret = -EINVAL;
goto out;
}
out:
free (distrio_manager);
return ret;
}