OmniEvents
channel.cc
Go to the documentation of this file.
1// Package : omniEvents
2// channel.cc Created : 2005/04/23
3// Author : Alex Tingle
4//
5// Copyright (C) 2005 Alex Tingle
6//
7// This file is part of the omniEvents application.
8//
9// omniEvents is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// omniEvents is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22//
23// Description:
24// Demonstates how to make a standalone EventChannel in your own
25// application, using libomniEvents.
26//
27
28
29#ifdef HAVE_CONFIG_H
30# include "config.h"
31#endif
32
33#include <stdlib.h>
34#include <signal.h>
35
36#ifdef HAVE_IOSTREAM
37# include <iostream>
38#else
39# include <iostream.h>
40#endif
41
42#ifdef HAVE_STD_IOSTREAM
43using namespace std;
44#endif
45
46#include <omniEvents/EventChannel.h>
47
49void myShutdown(int signum)
50{
52}
53
54int main(int argc, char **argv)
55{
56 //
57 // Start orb.
58 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv);
59
60 const char* action=""; // Use this variable to help report errors.
61 try {
62
63 action="initialise OmniEvents::Orb";
64 // Your code MUST include these two lines.
67
68 action="activate the RootPOA's POAManager";
69 // You MUST activate the RootPOA's POAManager. You can do this yourself
70 // in the normal way, or you can use the reference that OmniEvents::Orb
71 // has resolved for you.
72 PortableServer::POAManager_var pman;
73 pman=OmniEvents::Orb::inst()._RootPOA->the_POAManager();
74 pman->activate();
75
76 action="create EventChannel servant";
77 // The constructor just allocates memory.
79
80 action="activate EventChannel servant";
81 // activate() creates & activates the EventChannel's POA and CORBA objects.
82 channelSrv->activate("MyChannel");
83
84 // From this point, clients may invoke EventChannel operations.
85
86 action="obtain an object reference to the EventChannel";
87 CosEventChannelAdmin::EventChannel_var channelRef =channelSrv->_this();
88
89 // The user interface of this example is simple: The EventChannel's IOR
90 // is dumped to the standard output stream.
91 action="stringify the EventChannel reference";
92 CORBA::String_var sior =orb->object_to_string(channelRef.in());
93 cout<<sior.in()<<endl;
94
95 action="set signal handlers";
96 ::signal(SIGINT , ::myShutdown);
97 ::signal(SIGTERM, ::myShutdown);
98
99 action="collect orphan requests";
100 // You MUST call this method, it processes orphan (asynchronous) method
101 // calls made by the EventChannel.
102 // You can safely call it instead of CORBA::ORB::run(). If you do not
103 // want to park the main thread, then you must create a new thread for this
104 // method.
106
107 // OmniEvents::Orb::shutdown() has been called by the myShutdown() signal
108 // handler. (The user pressed Ctrl-C or killed the process.)
109
110 // In order to make run() return, you MUST call OmniEvents::Orb::shutdown().
111
112 action="destroy orb";
113 orb->destroy();
114
115 }
116 catch(CORBA::SystemException& ex) {
117 cerr<<"Failed to "<<action<<".";
118#if defined(HAVE_OMNIORB4)
119 cerr<<" "<<ex._name();
120 if(ex.NP_minorString())
121 cerr<<" ("<<ex.NP_minorString()<<")";
122#endif
123 cerr<<endl;
124 ::exit(1);
125 }
126 catch(CORBA::Exception& ex) {
127 cerr<<"Failed to "<<action<<"."
128#if defined(HAVE_OMNIORB4)
129 " "<<ex._name()
130#endif
131 <<endl;
132 ::exit(1);
133 }
134
135 return 0;
136}
CORBA::ORB_ptr orb
Definition eventf.cc:60
int main(int argc, char **argv)
The main process entry point.
Definition channel.cc:54
void myShutdown(int signum)
Signal handler.
Definition channel.cc:49
Servant for CosEventChannelAdmin::EventChannel objects, also inherits from omni_thread.
void activate(const char *channelName, const PersistNode *node=NULL)
Creates the channel's POA, and any child objects.
PortableServer::POA_var _RootPOA
Definition Orb.h:89
CORBA::ORB_var _orb
Definition Orb.h:88
void shutdown(int)
Sets _shutdownRequested.
Definition Orb.h:126
void resolveInitialReferences()
_orb must already have been initialized before this method is called.
Definition Orb.cc:55
static Orb & inst()
Definition Orb.h:81
void run()
Parks the main thread, but also picks up (and ignores) responses from orphan requests.
Definition Orb.cc:124