Click here to Skip to main content
15,914,066 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: File Copy Hook? Pin
Priyank Bolia27-May-05 2:21
Priyank Bolia27-May-05 2:21 
GeneralRe: File Copy Hook? Pin
vikramlinux27-May-05 2:14
vikramlinux27-May-05 2:14 
GeneralRe: File Copy Hook? Pin
Priyank Bolia27-May-05 2:23
Priyank Bolia27-May-05 2:23 
GeneralRe: File Copy Hook? Pin
John M. Drescher27-May-05 4:28
John M. Drescher27-May-05 4:28 
GeneralRe: File Copy Hook? Pin
Priyank Bolia27-May-05 8:47
Priyank Bolia27-May-05 8:47 
GeneralRe: File Copy Hook? Pin
John M. Drescher27-May-05 10:53
John M. Drescher27-May-05 10:53 
GeneralRe: File Copy Hook? Pin
Priyank Bolia28-May-05 2:02
Priyank Bolia28-May-05 2:02 
GeneralCORBA - NameService Pin
torpedus26-May-05 22:33
torpedus26-May-05 22:33 
Hi,

I am developping a new CORBA application from Visual C++.
I reach to create new objects into a server and link their reference, i.e IOR, from a cliente in order to make calls to methods from its remote interface. I do all this using a text tile that the server writes and the client reads in order to get the IOR.
I would like to use a NameService in order to not using that text file and start developping a real remote distrubited application.
My code is the following one, and is the same as described for example by Omni distribution:


--------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////

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::ORB::InvalidName& ex) {
// 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::COMM_FAILURE& ex) {
cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
<< "naming service." << endl;
return 0;
}
catch(CORBA::SystemException&) {
cerr << "Caught a CORBA::SystemException while using the naming service."
<< endl;
return 0;
}

return 1;
}

//////////////////////////////////////////////////////////////////////

int
main(int argc, char **argv)
{
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);

Echo_i* myecho = new Echo_i();

PortableServer::ObjectId_var myechoid = poa->activate_object(myecho);

// Obtain a reference to the object, and register it in
// the naming service.
obj = myecho->_this();

CORBA::String_var x;
x = orb->object_to_string(obj);
cerr << x << "\n";

if( !bindObjectToName(orb, obj) )
return 1;

myecho->_remove_ref();

PortableServer::POAManager_var pman = poa->the_POAManager();
pman->activate();

orb->run();
}
catch(CORBA::SystemException&) {
cerr << "Caught CORBA::SystemException." << endl;
}
catch(CORBA::Exception&) {
cerr << "Caught CORBA::Exception." << endl;
}
catch(omniORB::fatalException& fe) {
cerr << "Caught omniORB::fatalException:" << endl;
cerr << " file: " << fe.file() << endl;
cerr << " line: " << fe.line() << endl;
cerr << " mesg: " << fe.errmsg() << endl;
}
catch(...) {
cerr << "Caught unknown exception." << endl;
}

return 0;
}

.....................................................................................................

I run the application omniNames.exe with parameters:
omniNames.exe -start 12345 .. . . . .
That seems to work. It runs in console mode, not as a service.
If I execute my server, with the code descrive on top, I get the following exception error:
catch(CORBA::SystemException&) {
cerr << "Caught CORBA::SystemException." << endl;
}

Otherwise, If I replace the following line
obj = orb->resolve_initial_references("NameService");
for that one:
obj = orb->resolve_initial_references("corbaloc:iio:localhost:12345/NameService");

Now, I don't get the same error, I get other one:
catch(CORBA::ORB::InvalidName& ex) {
// This should not happen!
cerr << "Service required is invalid [does not exist]." << endl;
return 0;

Does anybody have any idea what is happening?
Must I run omniNames as a service? and if so, Why?
Do I need other configuration?

I would like to use Omni CORBA distrubution.


Thanks, and pardon for my english ( I am spanish... )


.
GeneralRe: CORBA - NameService Pin
Bob Stanneveld26-May-05 22:52
Bob Stanneveld26-May-05 22:52 
GeneralRe: CORBA - NameService Pin
torpedus26-May-05 23:02
torpedus26-May-05 23:02 
GeneralRe: CORBA - NameService Pin
Bob Stanneveld26-May-05 23:28
Bob Stanneveld26-May-05 23:28 
Generallanguage and AFX_TARG_... question Pin
tim63526-May-05 22:21
tim63526-May-05 22:21 
GeneralInsert my Win32 window into an MFC Dialog Pin
anderslundsgard26-May-05 21:45
anderslundsgard26-May-05 21:45 
GeneralCWnd::CreateControl copy/paste problem Pin
Johan O26-May-05 20:40
Johan O26-May-05 20:40 
GeneralRe: CWnd::CreateControl copy/paste problem Pin
Ryan Binns27-May-05 2:34
Ryan Binns27-May-05 2:34 
GeneralRe: CWnd::CreateControl copy/paste problem Pin
Johan O27-May-05 9:41
Johan O27-May-05 9:41 
GeneralCBitmap.GetBitmapDimensions() problem Pin
toxcct26-May-05 20:36
toxcct26-May-05 20:36 
GeneralRe: CBitmap.GetBitmapDimensions() problem Pin
PJ Arends26-May-05 22:12
professionalPJ Arends26-May-05 22:12 
GeneralRe: CBitmap.GetBitmapDimensions() problem Pin
toxcct26-May-05 22:19
toxcct26-May-05 22:19 
GeneralRe: CBitmap.GetBitmapDimensions() problem Pin
PJ Arends26-May-05 22:29
professionalPJ Arends26-May-05 22:29 
GeneralRe: CBitmap.GetBitmapDimensions() problem Pin
Gary R. Wheeler28-May-05 2:45
Gary R. Wheeler28-May-05 2:45 
GeneralRe: CBitmap.GetBitmapDimensions() problem Pin
toxcct28-May-05 6:42
toxcct28-May-05 6:42 
QuestionEnumWindows usage ? Pin
toxcct26-May-05 20:22
toxcct26-May-05 20:22 
AnswerRe: EnumWindows usage ? Pin
22491726-May-05 21:14
22491726-May-05 21:14 
AnswerRe: EnumWindows usage ? Pin
ThatsAlok26-May-05 21:32
ThatsAlok26-May-05 21:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.