[omniORB] Dynamically generate objects (here: EventChannel) ???

Alex Tingle alex.tingle at bronermetals.com
Wed Oct 4 12:46:59 BST 2006


Sebastian,

>     try {
>       channelSrv->activate("EventChannel");
>     } catch(...)
>     {
> ==>   std::cout << "AdapterAlreadyExists" << std::endl;
>     }

You get the message "AdapterAlreadyExists" because you wrote it!!

The two exceptions activate() might throw are:
  PortableServer::POA::ObjectAlreadyActive
  PortableServer::POA::AdapterAlreadyExists

Either way, your problem is caused by the fact that you are trying to 
create multiple EventChannels with the same name. The name must be 
unique, because it is used as an ObjectId within omniORB.

If you don't care what the name is, then just call 
OmniEvents::newUniqueId(), like this...

  CORBA::String_var channelId =OmniEvents::newUniqueId();
  channelSrv->activate(channelId.in());

regards,

-Alex

--
Dammit Jim, I'm a programmer... not a mind reader!

On 2 Oct 2006, at 20:00, Sebastian Bickel wrote:

> Ist there a technique to dynamically generate CORBA objects during
> runtime. I want to generate multiple event channels, but if I do that 
> in
> the implementation of the CORBA object, I get a "AlreadyExist"-Message.
> Can you please help me.
>
>
> The code is attached. I only want to create multiple objects of the
> event channel during runtime, but it doesn't succeed. Please help me.
> // A little bit changed from the examples to omniEvents
> //
> //                      Package   : omniEvents
> //   channel.cc               Created   : 2005/04/23
> //                            Author    : Alex Tingle
> //
> //    Copyright (C) 2005 Alex Tingle
> //
> //    This file is part of the omniEvents application and has been
> modified
> //     during the study thesis of Sebastian BIckel.
> //
> //    omniEvents is free software; you can redistribute it and/or
> //    modify it under the terms of the GNU Lesser General Public
> //    License as published by the Free Software Foundation; either
> //    version 2.1 of the License, or (at your option) any later 
> version.
>
> //
> //    omniEvents is distributed in the hope that it will be useful,
> //    but WITHOUT ANY WARRANTY; without even the implied warranty of
> //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> //    Lesser General Public License for more details.
> //
> //    You should have received a copy of the GNU Lesser General Public
> //    License along with this library; if not, write to the Free
> Software
> //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> 02111-1307  USA
> //
> // Description:
> //    Demonstates how to make a standalone EventChannel in your own
> //    application, using libomniEvents.
> //
>
>
>
>
>
>
> [...]
>
>
> #include <omniEvents/EventChannel.h>
>
>
> /** Signal handler. */
> void myShutdown(int signum)
> {
>   OmniEvents::Orb::inst().shutdown(signum);
> }
>
>
> void * event_channel_task (void *)
> {
>       std::cout << "OmniEvents::Orb::inst().run() calling!" <<
> std::endl;
>       OmniEvents::Orb::inst().run();
>       std::cout << "OmniEvents::Orb::inst().run() called!" << 
> std::endl;
>
> }
>
>
> #include "channel_factory.h"
> #include <pthread.h>
>
>
> std::string * ChannelFactory::createChannel(CORBA::ORB_var orb)
> {
>   //
>   // Start orb.
>   // CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
>
>
>   const char* action=""; // Use this variable to help report errors.
>   try {
>     action="initialise OmniEvents::Orb";
>     // Your code MUST include these two lines.
>     OmniEvents::Orb::inst()._orb=CORBA::ORB::_duplicate(orb);
>     OmniEvents::Orb::inst().resolveInitialReferences();
>
>
>     action="activate the RootPOA's POAManager";
>     // You MUST activate the RootPOA's POAManager. You can do this
> yourself
>     // in the normal way, or you can use the reference that
> OmniEvents::Orb
>     // has resolved for you.
>     PortableServer::POAManager_var pman;
>     pman=OmniEvents::Orb::inst()._RootPOA->the_POAManager();
>     pman->activate();
>
>
>     action="create EventChannel servant";
>     // The constructor just allocates memory.
>     OmniEvents::EventChannel_i* channelSrv =new
> OmniEvents::EventChannel_i();
>
>
>     action="activate EventChannel servant";
>     // activate() creates & activates the EventChannel's POA and CORBA
> objects.
>     try {
>       channelSrv->activate("EventChannel");
>     } catch(...)
>     {
> ==>   std::cout << "AdapterAlreadyExists" << std::endl;
>     }
>
>
>     // From this point, clients may invoke EventChannel operations.
>     action="obtain an object reference to the EventChannel";
>     CosEventChannelAdmin::EventChannel_var channelRef =channelSrv-
>> _this();
>
>
>     // The user interface of this example is simple: The EventChannel's
> IOR
>     // is dumped to the standard output stream.
>     action="stringify the EventChannel reference";
>     CORBA::String_var sior =orb->object_to_string(channelRef.in());
>     cout<<sior.in()<<endl;
>
>
>
>     action="set signal handlers";
>     ::signal(SIGINT , ::myShutdown);
>     ::signal(SIGTERM, ::myShutdown);
>
>     action="collect orphan requests";
>     // You MUST call this method, it processes orphan (asynchronous)
> method
>     // calls made by the EventChannel.
>     // You can safely call it instead of CORBA::ORB::run(). If you do
> not
>     // want to park the main thread, then you must create a new thread
> for this
>     // method.
>     //cout<<"Calling OmniEvents::Orb::inst().run()
> asynchronusly..."<<endl;
>     // OmniEvents::Orb::inst().run();
>     pthread_t thread;
>     pthread_create(&thread    // Thread-Id
>                ,NULL          // Attributes
>                ,::event_channel_task // Function
>                ,NULL);   // Arguments (none)
>
>     // OmniEvents::Orb::inst().run();
>     std::string * str_iop = new std::string();
>     (*str_iop) = sior.in();
>     return str_iop;
>
>
>     // OmniEvents::Orb::shutdown() has been called by the myShutdown()
> signal
>     // handler. (The user pressed Ctrl-C or killed the process.)
>
>
>     // In order to make run() return, you MUST call
> OmniEvents::Orb::shutdown().
>
>
>     action="destroy orb";
>     orb->destroy();
>
>
>   }
>   catch(CORBA::SystemException& ex) {
>      cerr<<"Failed to "<<action<<".";
> #if defined(HAVE_OMNIORB4)
>      cerr<<" "<<ex._name();
>      if(ex.NP_minorString())
>          cerr<<" ("<<ex.NP_minorString()<<")";
> #endif
>      cerr<<endl;
>      ::exit(1);
>   }
>   catch(CORBA::Exception& ex) {
>      cerr<<"Failed to "<<action<<"."
> #if defined(HAVE_OMNIORB4)
>        " "<<ex._name()
> #endif
>        <<endl;
>      ::exit(1);
>   }
>
>
>   return 0;
> }
>
>
>
>
>
>
> Greetings
>
>
>
>
> Sebastian
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list




More information about the omniORB-list mailing list