Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

channel.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 //   channel.cc               Created   : 2005/04/23
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2005 Alex Tingle
00006 //
00007 //    This file is part of the omniEvents application.
00008 //
00009 //    omniEvents is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniEvents is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // Description:
00024 //    Demonstates how to make a standalone EventChannel in your own
00025 //    application, using libomniEvents.
00026 //      
00027 
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include "config.h"
00031 #endif
00032 
00033 #include <stdlib.h>
00034 #include <signal.h>
00035 
00036 #ifdef HAVE_IOSTREAM
00037 #  include <iostream>
00038 #else
00039 #  include <iostream.h>
00040 #endif
00041 
00042 #ifdef HAVE_STD_IOSTREAM
00043 using namespace std;
00044 #endif
00045 
00046 #include <omniEvents/EventChannel.h>
00047 
00049 void myShutdown(int signum)
00050 {
00051   OmniEvents::Orb::inst().shutdown(signum);
00052 }
00053 
00054 int main(int argc, char **argv)
00055 {
00056   //
00057   // Start orb.
00058   CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
00059 
00060   const char* action=""; // Use this variable to help report errors.
00061   try {
00062 
00063     action="initialise OmniEvents::Orb";
00064     // Your code MUST include these two lines.
00065     OmniEvents::Orb::inst()._orb=orb;
00066     OmniEvents::Orb::inst().resolveInitialReferences();
00067 
00068     action="activate the RootPOA's POAManager";
00069     // You MUST activate the RootPOA's POAManager. You can do this yourself
00070     // in the normal way, or you can use the reference that OmniEvents::Orb
00071     // has resolved for you.
00072     PortableServer::POAManager_var pman;
00073     pman=OmniEvents::Orb::inst()._RootPOA->the_POAManager();
00074     pman->activate();
00075 
00076     action="create EventChannel servant";
00077     // The constructor just allocates memory.
00078     OmniEvents::EventChannel_i* channelSrv =new OmniEvents::EventChannel_i();
00079 
00080     action="activate EventChannel servant";
00081     // activate() creates & activates the EventChannel's POA and CORBA objects.
00082     channelSrv->activate("MyChannel");
00083 
00084     // From this point, clients may invoke EventChannel operations.
00085     
00086     action="obtain an object reference to the EventChannel";
00087     CosEventChannelAdmin::EventChannel_var channelRef =channelSrv->_this();
00088 
00089     // The user interface of this example is simple: The EventChannel's IOR
00090     // is dumped to the standard output stream.
00091     action="stringify the EventChannel reference";
00092     CORBA::String_var sior =orb->object_to_string(channelRef.in());
00093     cout<<sior.in()<<endl;
00094 
00095     action="set signal handlers";
00096     ::signal(SIGINT , ::myShutdown);
00097     ::signal(SIGTERM, ::myShutdown);
00098  
00099     action="collect orphan requests";
00100     // You MUST call this method, it processes orphan (asynchronous) method
00101     // calls made by the EventChannel.
00102     // You can safely call it instead of CORBA::ORB::run(). If you do not
00103     // want to park the main thread, then you must create a new thread for this
00104     // method.
00105     OmniEvents::Orb::inst().run();
00106 
00107     // OmniEvents::Orb::shutdown() has been called by the myShutdown() signal
00108     // handler. (The user pressed Ctrl-C or killed the process.)
00109 
00110     // In order to make run() return, you MUST call OmniEvents::Orb::shutdown().
00111 
00112     action="destroy orb";
00113     orb->destroy();
00114 
00115   }
00116   catch(CORBA::SystemException& ex) {
00117      cerr<<"Failed to "<<action<<".";
00118 #if defined(HAVE_OMNIORB4)
00119      cerr<<" "<<ex._name();
00120      if(ex.NP_minorString())
00121          cerr<<" ("<<ex.NP_minorString()<<")";
00122 #endif
00123      cerr<<endl;
00124      ::exit(1);
00125   }
00126   catch(CORBA::Exception& ex) {
00127      cerr<<"Failed to "<<action<<"."
00128 #if defined(HAVE_OMNIORB4)
00129        " "<<ex._name()
00130 #endif
00131        <<endl;
00132      ::exit(1);
00133   }
00134 
00135   return 0;
00136 }

Generated on Fri Aug 26 20:56:13 2005 for OmniEvents by  doxygen 1.4.3-20050530