1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
// Package : omniEvents
// channel.cc Created : 2005/04/23
// Author : Alex Tingle
//
// Copyright (C) 2005 Alex Tingle
//
// This file is part of the omniEvents application.
//
// 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.
//
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <signal.h>
#ifdef HAVE_IOSTREAM
# include <iostream>
#else
# include <iostream.h>
#endif
#ifdef HAVE_STD_IOSTREAM
using namespace std;
#endif
#include <omniEvents/EventChannel.h>
/** Signal handler. */
void myShutdown(int signum)
{
OmniEvents::Orb::inst().shutdown(signum);
}
int main(int argc, char **argv)
{
//
// 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=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.
channelSrv->activate("MyChannel");
// 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.
OmniEvents::Orb::inst().run();
// 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;
}
|