diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-10-21 21:41:34 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-10-21 21:41:34 +0000 |
commit | a5fdebc5f6375078ec1763850a4ca23ec7fe6458 (patch) | |
tree | bcf0a25c3d45a209a6e3ac37b233a4812f29c732 /apps/Orbix-Examples | |
download | ATCD-a5fdebc5f6375078ec1763850a4ca23ec7fe6458.tar.gz |
Initial revision
Diffstat (limited to 'apps/Orbix-Examples')
46 files changed, 6265 insertions, 0 deletions
diff --git a/apps/Orbix-Examples/Event_Comm/Consumer/Input_Handler.cpp b/apps/Orbix-Examples/Event_Comm/Consumer/Input_Handler.cpp new file mode 100644 index 00000000000..29d8b1218b2 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Consumer/Input_Handler.cpp @@ -0,0 +1,130 @@ +#include "Input_Handler.h" +// @(#)Input_Handler.cpp 1.1 10/18/96 + +#include "Notification_Receiver_Handler.h" + +#if defined (ACE_HAS_ORBIX) + +Input_Handler::~Input_Handler (void) +{ + ACE_DEBUG ((LM_DEBUG, "closing down Input_Handler::~Input_Handler\n")); + this->handle_close (); +} + +int +Input_Handler::consumer_initiated_shutdown (void) +{ + return this->consumer_initiated_shutdown_; +} + +void +Input_Handler::consumer_initiated_shutdown (int c) +{ + this->consumer_initiated_shutdown_ = c; +} + +ACE_HANDLE +Input_Handler::get_handle (void) const +{ + return this->handle_; +} + +int +Input_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + ACE_DEBUG ((LM_DEBUG, "closing down Consumer::Input_Handler\n")); + + Event_Comm::Notification_Receiver *receiver = this->receiver_handler_->receiver (); + Event_Comm::Notifier *notifier = this->receiver_handler_->notifier (); + + if (this->consumer_initiated_shutdown ()) + { + // Only try to unsubscribe if the Consumer initiated the + // shutdown. Otherwise, the Supplier initiated it and + // it has probably gone away by now! + TRY { + // Gracefully shutdown the Receiver by removing it + // from the Notifier's internal map. + + notifier->unsubscribe (receiver, "", IT_X); + } CATCHANY { + cerr << IT_X << endl; + } ENDTRY; + } + // Don't execute a callback here otherwise we'll recurse indefinitely! + if (ACE_Service_Config::reactor ()->remove_handler (this, ACE_Event_Handler::READ_MASK + | ACE_Event_Handler::DONT_CALL) == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "remove_handler")); + + // *Must* be allocated dyanmically! + delete (void *) this; + return 0; +} + +Input_Handler::Input_Handler (Notification_Receiver_Handler *ch, + ACE_HANDLE handle) + : receiver_handler_ (ch), + handle_ (handle), + consumer_initiated_shutdown_ (0) +{ + if (ACE_Service_Config::reactor ()->register_handler (this, + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR ((LM_ERROR, "Input_Handler::Input_Handler\n")); +} + +int +Input_Handler::handle_input (ACE_HANDLE h) +{ + char buf[BUFSIZ]; + ssize_t n; + + // Read up to BUFSIZ worth of data from ACE_HANDLE h. + + n = ACE_OS::read (h, buf, sizeof buf - 1); + + if (n > 0) + { + // Null terminate the buffer, replacing the '\n' with '\0'. + if (buf[n - 1] == '\n' || buf[n - 1] == EOF) + buf[n - 1] = '\0'; + else + buf[n] = '\0'; + ACE_DEBUG ((LM_DEBUG, "notifying for event %s\n", buf)); + + } + else + { + ACE_OS::strcpy (buf, "quit"); + ACE_DEBUG ((LM_DEBUG, "shutting down Input_Handler\n")); + } + + Event_Comm::Notifier *notifier = this->receiver_handler_->notifier (); + + ACE_ASSERT (notifier != 0); + + if (ACE_OS::strcmp (buf, "quit") == 0) + { + // Consumer wants to shutdown. + this->consumer_initiated_shutdown (1); + + // Tell the main event loop to shutdown. + ACE_Service_Config::end_reactor_event_loop (); + } + else + { + TRY { + Event_Comm::Notification notification; + + notification.tag_ = ACE_OS::strdup (buf); + + notifier->send_notification (notification, IT_X); + } + CATCHANY { + cerr << "Unexpected exception " << IT_X << endl; + } ENDTRY; + } + + /* NOTREACHED */ + return 0; +} +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/Consumer/Input_Handler.h b/apps/Orbix-Examples/Event_Comm/Consumer/Input_Handler.h new file mode 100644 index 00000000000..d2b87d90f57 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Consumer/Input_Handler.h @@ -0,0 +1,71 @@ +/* -*- C++ -*- */ +// @(#)Input_Handler.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Input_Handler.h +// +// = DESCRIPTION +// Subclass of ACE ACE_Service_Object that receives unsubscribes from +// the Notifier when input is received from the keyboard. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_INPUT_HANDLER_H) +#define _INPUT_HANDLER_ + +#include "ace/Service_Config.h" + +#if defined (ACE_HAS_ORBIX) +// Forward declaration. +class Notification_Receiver_Handler; + +class Input_Handler : public ACE_Service_Object + // = TITLE + // Handles input events generated from a keyboard. + // + // = DESCRIPTION +{ +public: + Input_Handler (Notification_Receiver_Handler *, ACE_HANDLE h = 0); + + virtual int handle_input (ACE_HANDLE); + // Dispatch the callback when events occur. + + virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, + ACE_Reactor_Mask = ACE_Event_Handler::NULL_MASK); + // Close down the handler. + + int consumer_initiated_shutdown (void); + // Report whether the Consumer initiated the shutdown. + + void consumer_initiated_shutdown (int); + // Indicate that the Consumer initiated the shutdown. + +private: + ~Input_Handler (void); + // Ensure dynamic allocation. + + virtual ACE_HANDLE get_handle (void) const; + + ACE_HANDLE handle_; + // ACE_HANDLE where the input comes from. + + Notification_Receiver_Handler *receiver_handler_; + // Pointer to the <Notification_Receiver_Handler> that + // receives notifications from the <Event_Comm::Notifier>. + + int consumer_initiated_shutdown_; + // Keep track of whether the Consumer initiated the shutdown. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _INPUT_HANDLER_H */ diff --git a/apps/Orbix-Examples/Event_Comm/Consumer/Makefile b/apps/Orbix-Examples/Event_Comm/Consumer/Makefile new file mode 100644 index 00000000000..872b72a1880 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Consumer/Makefile @@ -0,0 +1,165 @@ +#---------------------------------------------------------------------------- +# @(#)Makefile 1.1 10/18/96 +# +# Makefile for the Consumer. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +BIN = consumer + +FILES = Notification_Receiver_Handler \ + Input_Handler + +LSRC = $(addsuffix .cpp,$(FILES)) consumer.cpp +LOBJ = $(addsuffix .o,$(FILES)) +SHOBJ = $(addsuffix .so,$(FILES)) + +SRX = ../src/.obj + +LDLIBS = $(addprefix .shobj/,$(LOBJ)) ../src/libEvent_Comm.a +VLDLIBS = $(LDLIBS:%=%$(VAR)) + +BUILD = $(VBIN) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.lib.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.bin.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +CPPFLAGS += -I../include +VLDLIBS += -lgen + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + +Notification_Receiver_Handler.o: Notification_Receiver_Handler.cpp \ + Notification_Receiver_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/CORBA_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + ../include/Event_Comm_i.h ../include/Notification_Receiver_i.h \ + ../include/Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + ../include/Event_Comm.hh +Input_Handler.o: Input_Handler.cpp Input_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + Notification_Receiver_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/CORBA_Handler.h \ + ../include/Event_Comm_i.h ../include/Notification_Receiver_i.h \ + ../include/Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + ../include/Event_Comm.hh +consumer.o: consumer.cpp \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + Notification_Receiver_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/CORBA_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + ../include/Event_Comm_i.h ../include/Notification_Receiver_i.h \ + ../include/Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + ../include/Event_Comm.hh Input_Handler.h + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/apps/Orbix-Examples/Event_Comm/Consumer/Notification_Receiver_Handler.cpp b/apps/Orbix-Examples/Event_Comm/Consumer/Notification_Receiver_Handler.cpp new file mode 100644 index 00000000000..eccf499f6c0 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Consumer/Notification_Receiver_Handler.cpp @@ -0,0 +1,114 @@ +#include "Notification_Receiver_Handler.h" +// @(#)Notification_Receiver_Handler.cpp 1.1 10/18/96 + + +#if defined (ACE_HAS_ORBIX) + +#if defined (ACE_HAS_MT_ORBIX) +typedef ACE_MT_CORBA_Handler CORBA_HANDLER; +#else +typedef ACE_ST_CORBA_Handler CORBA_HANDLER; +#endif /* ACE_HAS_MT_ORBIX */ + +int +Notification_Receiver_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ +// ACE_ST_CORBA_Handler::remove_service (Event_Comm_Notification_Receiver_IMPL); + + if (this->receiver_ != 0) + { + ACE_DEBUG ((LM_DEBUG, "closing down Notification_Receiver_Handler\n")); + CORBA_HANDLER::instance ()->deactivate_service (Event_Comm_Notification_Receiver_IMPL, + this->receiver_->_marker ()); + CORBA::release (this->receiver_); + this->receiver_ = 0; + CORBA::release (this->notifier_); + this->notifier_ = 0; + // *Must* be allocated dynamically in order to delete this! + delete this; + } + return 0; +} + +Notification_Receiver_Handler::Notification_Receiver_Handler (int argc, char *argv[]) + : notifier_ (0), + receiver_ (0) +{ + const char *server_name = Event_Comm_Notification_Receiver_IMPL; + char buf[BUFSIZ]; + char *receiver_marker = buf; + char *filtering_criteria; + char *host; + char *notifier_marker; + char *service_location = argv[0]; + + // First see if we have any environment variables. + filtering_criteria = ACE_OS::getenv ("FILTERING_CRITERIA"); + host = ACE_OS::getenv ("HOST"); + notifier_marker = ACE_OS::getenv ("NOTIFIER_MARKER"); + + // Then override these variables with command-line arguments. + filtering_criteria = argc > 1 ? argv[1] : ""; + host = argc > 2 ? argv[2] : "tango.cs"; + notifier_marker = argc > 3 ? argv[3] : "notifier:" Event_Comm_Notifier_IR; + + CORBA::Orbix.setDiagnostics (0); + + struct utsname name; + + // Make the marker name be the "/hostname/processid" + ACE_OS::uname (&name); + sprintf (buf, "/%s/%d", name.nodename, ACE_OS::getpid ()); + + CORBA_HANDLER::instance ()->activate_service (Event_Comm_Notification_Receiver_IMPL, + receiver_marker, service_location); + + // Create the receiver object. + this->receiver_ = new TIE_Event_Comm_Notification_Receiver (Notification_Receiver_i) + (new Notification_Receiver_i); + + this->receiver_->_marker (receiver_marker); + + ACE_ASSERT (this->receiver_); + + TRY { + // Get a binding to the notifier. + this->notifier_ = Event_Comm::Notifier::_bind (notifier_marker, host, IT_X); + + if (this->notifier_ != CORBA::OBJECT_NIL) + // Subscribe ourselves with the notifier's broker. + this->notifier_->subscribe (this->receiver_, + filtering_criteria, IT_X); + } CATCHANY { + cerr << "Unexpected exception " << IT_X << endl; + ACE_OS::exit (1); + } ENDTRY; + // Print out context. + + receiver_marker = (char *) this->receiver_->_marker (); + CORBA::BOA::activationMode mode = CORBA::Orbix.myActivationMode (); + ACE_DEBUG ((LM_DEBUG, "starting up a %spersistent server in mode %d with marker name %s\n", + mode == CORBA::BOA::persistentActivationMode ? "" : "non-", + mode, receiver_marker)); +} + +Event_Comm::Notification_Receiver * +Notification_Receiver_Handler::receiver (void) +{ + return this->receiver_; +} + +Event_Comm::Notifier * +Notification_Receiver_Handler::notifier (void) +{ + return this->notifier_; +} + +// Destroy a Receiver target object. + +Notification_Receiver_Handler::~Notification_Receiver_Handler (void) +{ + this->handle_close (-1, ACE_Event_Handler::RWE_MASK); +} + +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/Consumer/Notification_Receiver_Handler.h b/apps/Orbix-Examples/Event_Comm/Consumer/Notification_Receiver_Handler.h new file mode 100644 index 00000000000..9ccd472ef1b --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Consumer/Notification_Receiver_Handler.h @@ -0,0 +1,62 @@ +/* -*- C++ -*- */ +// @(#)Notification_Receiver_Handler.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notifier_Receiver_Handler.h +// +// = DESCRIPTION +// Subclass of Corba_Handler that sets up the Notification_Receiver handler +// for use with the ACE ACE_Reactor. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_NOTIFICATION_RECEIVER_HANDLER_H) +#define _NOTIFICATION_RECEIVER_HANDLER_H + +#include "ace/CORBA_Handler.h" +#include "Event_Comm_i.h" + +#if defined (ACE_HAS_ORBIX) + +class Notification_Receiver_Handler + // = TITLE + // Subclass of Corba_Handler that sets up the Notification Receiver handler + // for use with the ACE ACE_Reactor. + // + // = DESCRIPTION + // Note that this class doesn't inherit from ACE_ST_CORBA_Handler (unlike + // the Supplier's Notifier_Handler class). Instead, it uses an + // alternative interface that can be called directly. +{ +public: + Notification_Receiver_Handler (int argc, char *argv[]); + + Event_Comm::Notification_Receiver *receiver (void); + Event_Comm::Notifier *notifier (void); + + virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, + ACE_Reactor_Mask = ACE_Event_Handler::NULL_MASK); + // Close down the handler. + +private: + ~Notification_Receiver_Handler (void); + // Ensure dynamic allocation. + + Event_Comm::Notification_Receiver *receiver_; + // Pointer to an IDL <Notification_Receiver> proxy object. + + Event_Comm::Notifier *notifier_; + // Pointer to an IDL <Notifier> proxy object. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _NOTIFICATION_RECEIVER_HANDLER_H */ diff --git a/apps/Orbix-Examples/Event_Comm/Consumer/consumer.cpp b/apps/Orbix-Examples/Event_Comm/Consumer/consumer.cpp new file mode 100644 index 00000000000..7133a8c8749 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Consumer/consumer.cpp @@ -0,0 +1,114 @@ +/* -*- C++ -*- */ +// @(#)consumer.cpp 1.1 10/18/96 + +// Consumer driver for the Orbix Notification example. + +#include "ace/Log_Msg.h" +#include "Notification_Receiver_Handler.h" +#include "Input_Handler.h" + +#if defined (ACE_HAS_ORBIX) + +class Consumer : public ACE_Event_Handler +{ +public: + Consumer (int argc, char *argv[]); + ~Consumer (void); + + void run (void); + // Execute the consumer; + +private: + virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); + + virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); + + Input_Handler *ih_; + // Handler for keyboard input. + + Notification_Receiver_Handler *nrh_; + // Handler for CORBA Consumer. + + ACE_Service_Config daemon_; + // ACE server event-loop mechanism. +}; + +int +Consumer::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + ACE_DEBUG ((LM_DEBUG, "closing down Consumer\n")); + return 0; +} + +int +Consumer::handle_signal (int signum, siginfo_t *, ucontext_t *) +{ + ACE_DEBUG ((LM_DEBUG, "%S\n", signum)); + + // Indicate that the consumer initiated the shutdown. + this->ih_->consumer_initiated_shutdown (1); + + // Shut down the event loop. + ACE_Service_Config::end_reactor_event_loop (); + return 0; +} + +// Run the event loop until someone calls +// calls ACE_Service_Config::end_reactor_event_loop(). + +void +Consumer::run (void) +{ + if (ACE_Service_Config::run_reactor_event_loop () == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "run_reactor_event_loop")); +} + +Consumer::Consumer (int argc, char *argv[]) + : ih_ (0), + nrh_ (0) +{ + // Initialize the server. + if (this->daemon_.open (argc, argv) == -1) + { + if (errno == ENOENT) // There's no svc.conf file, so use static linking... + { + ACE_DEBUG ((LM_DEBUG, "no config file, using static binding\n")); + // The constructor registers the handlers... + this->nrh_ = new Notification_Receiver_Handler (argc, argv); + ACE_ASSERT (this->nrh_ != 0); + this->ih_ = new Input_Handler (this->nrh_); + ACE_ASSERT (this->ih_ != 0); + } + else + ACE_ERROR ((LM_ERROR, "%p\n%a", "open", 1)); + } + + if (ACE_Service_Config::reactor ()->register_handler (SIGINT, this) == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "register_handler")); +} + +Consumer::~Consumer (void) +{ + // Free up the handlers if they were statically bound. + this->ih_->handle_close (); + this->nrh_->handle_close (); +} + +int +main (int argc, char *argv[]) +{ + // Initialize the supplier and consumer object references. + Consumer consumer (argc, argv); + + // Loop forever handling events. + consumer.run (); + + return 0; +} +#else /* !defined ACE_HAS_ORBIX */ +int +main (int argc, char *argv[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, "you must have Orbix to run application %s\n", argv[0]), 1); +} +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/Makefile b/apps/Orbix-Examples/Event_Comm/Makefile new file mode 100644 index 00000000000..3e0c8ae2dd8 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Makefile @@ -0,0 +1,26 @@ +#---------------------------------------------------------------------------- +# @(#)Makefile 1.1 10/18/96 +# +# Makefile for the consumer/supplier notification application +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +INFO = README + +DIRS = libsrc \ + Consumer \ + Supplier + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nested.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nolocal.GNU + diff --git a/apps/Orbix-Examples/Event_Comm/README b/apps/Orbix-Examples/Event_Comm/README new file mode 100644 index 00000000000..1bd7b5d8c45 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/README @@ -0,0 +1,109 @@ +OVERVIEW + +This directory contains source code for a prototype CORBA-based +distributed notification mechanism. This mechanism implements a +"publish/subscribe" communication protocol. It allows Suppliers to +pass messages containing object references to a dynamically managed +group of Consumers. This is similar to the OMG COSS Event Service, +though not as sophisticated. + +This example also illustrates how to integrate Orbix with the ACE +libraries. + +DIRECTORY STRUCTURE + +There are 4 directories: + +Supplier + + -- The supplier test driver, which must be started + first. It has an instance of an IDL Notifier + object. This object accepts subscriptions from Consumers + and forwards events sent to it either via Consumers or + via its standard input. + + The Supplier must be registered with the ORB using the + following command: + + % putit Event_Comm_Notifier <pathname>/supplier + +Consumer + + -- The consumer test driver, which must be started + after the Supplier. It has an instance of an + IDL Notification_Receiver object. This object is + used to receive notifications from the Notifier object + residing in the Supplier. When the Consumer starts up it + gets an object reference to the Supplier's Notifier. + It then subscribes its Notification_Receiver object with + the Supplier's Notifier by passing an object reference. + + In addition to passing an object reference to a + Notification_Receiver, the Consumer also may specify a + filtering criteria, which is a regular expression. If + the filtering criteria is the string "" then the Notifier + will send all Notifications to the Consumer (i.e., "" is + treated as a "wildcard"). Otherwise, the filtering + criteria is considered to be a regular expression, + and only those Notification tags that match the regular + expression will be forwarded to the Consumer. The regular + expressions are those used by ed(1) (see the regexp(5) + manual page for more info). + + The Consumer must be registered with the ORB + using the following command: + + % putit Event_Comm_Notification_Receiver <pathname>/consumer + +include + + -- This contains links to the appropriate header + files. + +libsrc + + -- This contains the IDL files and IDL implementation + classes that support the distributed notification scheme. + These are shared by the Consumer and Supplier. + +RUNNING THE TESTS + +To run the tests do the following: + +1. Compile everything. + +2. Start up the Orbix daemon (orbixd) if it's not already + running. + +3. Register the Consumer (i.e., Notification_Receiver) and Supplier + (i.e., Notifier) with the Orbix daemon (orbixd), as described + above. + +4. Start the Supplier/supplier executable. + +5. Start up as many copies of the Consumer/consumer as you'd like. + Typically, I run each one in its own window. If you'd like to use + different machines make sure that you start up the Orbix daemon on + each one and register the Consumer. + +6. Once the Consumers have subscribed you can send them info by typing + commands in the Supplier window. These will be sent to all the + Consumers who have subscribed. Likewise, you can send messages + from a Consumer to all other Consumers by typing messages in a + Consumer window. + + Note that if you type "quit", ^D, or ^C in a Consumer window the + Consumer will unsubscribe and shutdown its handlers and exit. + Likewise, if you type "quit", ^D, or ^C in the Supplier window + the Supplier will disconnect all of its Consumers and exit. + When a Consumer is disconnected from its Supplier it automatically + shuts itself down. + +7. When you want to terminate a Consumer or a Supplier, just type ^C + and the process will shut down gracefully. + +Please let me know if there are any questions. + + Doug + +schmidt@cs.wustl.edu diff --git a/apps/Orbix-Examples/Event_Comm/Supplier/Input_Handler.cpp b/apps/Orbix-Examples/Event_Comm/Supplier/Input_Handler.cpp new file mode 100644 index 00000000000..96a89f0ac6b --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Supplier/Input_Handler.cpp @@ -0,0 +1,120 @@ +#include "Event_Comm.hh" +// @(#)Input_Handler.cpp 1.1 10/18/96 + +#include "Notifier_Handler.h" +#include "Input_Handler.h" + +#if defined (ACE_HAS_ORBIX) + +int +Input_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + ACE_DEBUG ((LM_DEBUG, "closing down Supplier::Input_Handler\n")); + + Event_Comm::Notifier *notifier = this->notifier_->notifier (); + ACE_ASSERT (notifier != 0); + + ACE_OS::fclose (this->fp_); + + TRY { + // Disconnect all the consumers gracefully. + notifier->send_disconnect ("quit", IT_X); + } CATCHANY { + cerr << IT_X << endl; + } ENDTRY; + + // Don't execute a callback here otherwise we'll recurse indefinitely! + if (ACE_Service_Config::reactor ()->remove_handler (this, ACE_Event_Handler::READ_MASK + | ACE_Event_Handler::DONT_CALL) == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "remove_handler")); + + // *Must* be allocated dyanmically! + delete (void *) this; + return 0; +} + +Input_Handler::Input_Handler (Notifier_Handler *notifier, + ACE_HANDLE handle) // Use stdin by default. + : notifier_ (notifier), + handle_ (handle) +{ + // Register ourselves with the ACE_Reactor so that input events + // cause our handle_input() method to be dispatched automatically. + + if (ACE_Service_Config::reactor ()->register_handler (this, + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "register_handler")); + + this->fp_ = ACE_OS::fdopen (handle, "r"); + + if (this->fp_ == 0) + ACE_ERROR ((LM_ERROR, "%p\n", "fdopen")); +} + +Input_Handler::~Input_Handler (void) +{ + ACE_DEBUG ((LM_DEBUG, "closing down Input_Handler::~Input_Handler\n")); + this->handle_close (); +} + +ACE_HANDLE +Input_Handler::get_handle (void) const +{ + return this->handle_; +} + +// Frame input events and notify <Consumers>. + +int +Input_Handler::handle_input (ACE_HANDLE h) +{ + char buf[BUFSIZ]; + + // Read up to BUFSIZ worth of data from ACE_HANDLE h. + + if (ACE_OS::fgets (buf, sizeof buf - 1, this->fp_) == 0) + { + ACE_OS::strcpy (buf, "quit"); + ACE_DEBUG ((LM_DEBUG, "shutting down Input_Handler\n")); + } + else + { + size_t n = ACE_OS::strlen (buf); + + // Null terminate the buffer, replacing the '\n' with '\0'. + if (buf[n - 1] == '\n' || buf[n - 1] == EOF) + buf[n - 1] = '\0'; + else + buf[n] = '\0'; + ACE_DEBUG ((LM_DEBUG, "notifying for event %s\n", buf)); + } + + Event_Comm::Notifier *notifier = this->notifier_->notifier (); + ACE_ASSERT (notifier != 0); + + if (ACE_OS::strcmp (buf, "quit") == 0) + // Tell the main event loop to shutdown. + ACE_Service_Config::end_reactor_event_loop (); + else + { + // Use the notifier to notify Consumers. + TRY { + Event_Comm::Notification notification; + + // Pass the buf over in the tag field. + notification.tag_ = ACE_OS::strdup (buf); + + // This is where the "any" value goes or the object reference... + // notification.value_ = ... + + // Forward <Notification> to all <Notification_Receivers>. + notifier->send_notification (notification, IT_X); + } + CATCHANY { + cerr << "unexpected exception " << IT_X << endl; + } ENDTRY; + } + return 0; +} + +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/Supplier/Input_Handler.h b/apps/Orbix-Examples/Event_Comm/Supplier/Input_Handler.h new file mode 100644 index 00000000000..7bd05bbb5db --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Supplier/Input_Handler.h @@ -0,0 +1,70 @@ +/* -*- C++ -*- */ +// @(#)Input_Handler.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Input_Handler.h +// +// = DESCRIPTION +// Handle input from the keyboard. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_INPUT_HANDLER_H) +#define _INPUT_HANDLER_H + +#include "ace/Service_Config.h" + +#if defined (ACE_HAS_ORBIX) + +// Forward declaration. +class Notifier_Handler; + +class Input_Handler : public ACE_Service_Object + // = TITLE + // Handles input events generated from a keyboard. + // + // = DESCRIPTION + // The events are currently framed and forwarded to + // all Consumers. In the future, we will need to + // be more selective and only send to those Consumers + // whose filtering criteria matches! +{ +public: + Input_Handler (Notifier_Handler *, ACE_HANDLE = 0); // Use stdin by default. + + virtual int handle_input (ACE_HANDLE); + // Frame input events and notify <Consumers>. + + virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, + ACE_Reactor_Mask = ACE_Event_Handler::NULL_MASK); + // Close down the handler. + +protected: + virtual ACE_HANDLE get_handle (void) const; + + ACE_HANDLE handle_; + // ACE_HANDLE where the input comes from. + + Notifier_Handler *notifier_; + // Pointer to a <Notifier_Handler> that's used to inform + // Consumers that events of interest have occurred. + + FILE *fp_; + // Pointer to an input ACE_FILE. + +private: + ~Input_Handler (void); + // Ensure dynamic allocation. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _INPUT_HANDLER_H */ diff --git a/apps/Orbix-Examples/Event_Comm/Supplier/Makefile b/apps/Orbix-Examples/Event_Comm/Supplier/Makefile new file mode 100644 index 00000000000..4ded1a20e24 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Supplier/Makefile @@ -0,0 +1,164 @@ +#---------------------------------------------------------------------------- +# @(#)Makefile 1.1 10/18/96 +# +# Makefile for the Notifier. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +BIN = supplier + +FILES = Input_Handler \ + Notifier_Handler + +LSRC = $(addsuffix .cpp,$(FILES)) supplier.cpp +LOBJ = $(addsuffix .o,$(FILES)) +SHOBJ = $(addsuffix .so,$(FILES)) + +SRX = ../src/.obj + +LDLIBS = $(addprefix .shobj/,$(LOBJ)) ../src/libEvent_Comm.a + +VLDLIBS = $(LDLIBS:%=%$(VAR)) + +BUILD = $(VBIN) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.lib.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.bin.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +CPPFLAGS += -I../include +VLDLIBS += -lgen + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + +Input_Handler.o: Input_Handler.cpp ../include/Event_Comm.hh Notifier_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/CORBA_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + ../include/Event_Comm_i.h ../include/Notification_Receiver_i.h \ + ../include/Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + Input_Handler.h +Notifier_Handler.o: Notifier_Handler.cpp Notifier_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/CORBA_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + ../include/Event_Comm_i.h ../include/Notification_Receiver_i.h \ + ../include/Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + ../include/Event_Comm.hh +supplier.o: supplier.cpp \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + Notifier_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/CORBA_Handler.h \ + ../include/Event_Comm_i.h ../include/Notification_Receiver_i.h \ + ../include/Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + ../include/Event_Comm.hh Input_Handler.h + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/apps/Orbix-Examples/Event_Comm/Supplier/Notifier_Handler.cpp b/apps/Orbix-Examples/Event_Comm/Supplier/Notifier_Handler.cpp new file mode 100644 index 00000000000..84e9b3380bf --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Supplier/Notifier_Handler.cpp @@ -0,0 +1,66 @@ +#include "Notifier_Handler.h" +// @(#)Notifier_Handler.cpp 1.1 10/18/96 + + +#if defined (ACE_HAS_ORBIX) + +#if defined (ACE_HAS_MT_ORBIX) +typedef ACE_MT_CORBA_Handler CORBA_HANDLER; +#else +typedef ACE_ST_CORBA_Handler CORBA_HANDLER; +#endif /* ACE_HAS_MT_ORBIX */ + +int +Notifier_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + if (this->notifier_ != 0) + { + ACE_DEBUG ((LM_DEBUG, "closing down Notifier_Handler\n")); + CORBA_HANDLER::instance ()->deactivate_service (Event_Comm_Notifier_IMPL, + this->notifier_->_marker ()); + CORBA::release (this->notifier_); + this->notifier_ = 0; + // *Must* be allocated dyanmically! + delete this; + } + return 0; +} + +Event_Comm::Notifier * +Notifier_Handler::notifier (void) +{ + return this->notifier_; +} + +void +Notifier_Handler::notifier (Event_Comm::Notifier *notifier) +{ + if (this->notifier_ != notifier) + { + CORBA::release (this->notifier_); + this->notifier_ = notifier; + } +} + +// Create and initialize a Notifier target object. + +Notifier_Handler::Notifier_Handler (const char *service_location, + const char *marker, + int putit) +{ + CORBA_HANDLER::instance ()->activate_service (Event_Comm_Notifier_IMPL, + putit ? marker : 0, service_location); + + // Create a notifier object using the implementation class Notifier_i. + this->notifier_ = + new TIE_Event_Comm_Notifier (Notifier_i) (new Notifier_i, marker); +} + +// Destroy a Notifier target object. + +Notifier_Handler::~Notifier_Handler (void) +{ + this->handle_close (); +} + +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/Supplier/Notifier_Handler.h b/apps/Orbix-Examples/Event_Comm/Supplier/Notifier_Handler.h new file mode 100644 index 00000000000..5d0be45924c --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Supplier/Notifier_Handler.h @@ -0,0 +1,57 @@ +/* -*- C++ -*- */ +// @(#)Notifier_Handler.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notifier_Handler.h +// +// = DESCRIPTION +// Integrate CORBA with the ACE ACE_Reactor. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_NOTIFIER_HANDLER_H) +#define _NOTIFIER_HANDLER_H + +#include "ace/CORBA_Handler.h" +#include "Event_Comm_i.h" + +#if defined (ACE_HAS_ORBIX) + +class Notifier_Handler + // = TITLE + // Integrate CORBA with the ACE ACE_Reactor. + // + // = DESCRIPTION + // +{ +public: + Notifier_Handler (const char *service_location, + const char *marker = "notifier", + int putit = 1); // Default marker name. + + Event_Comm::Notifier *notifier (void); + void notifier (Event_Comm::Notifier *); + + virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, + ACE_Reactor_Mask = ACE_Event_Handler::NULL_MASK); + // Close down the handler. + +private: + ~Notifier_Handler (void); + // Ensure dynamic allocation. + + Event_Comm::Notifier *notifier_; + // Pointer to an a <Event_Comm::Notifier> object. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _NOTIFIER_HANDLER_H */ diff --git a/apps/Orbix-Examples/Event_Comm/Supplier/supplier.cpp b/apps/Orbix-Examples/Event_Comm/Supplier/supplier.cpp new file mode 100644 index 00000000000..927ab73a022 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/Supplier/supplier.cpp @@ -0,0 +1,116 @@ +/* -*- C++ -*- */ +// @(#)supplier.cpp 1.1 10/18/96 + +// Supplier driver for the Orbix Publish/Subscribe example. + +// The executable file generated from this code should be registered +// (under the name 'logger') using the 'putit' command. + +#include "ace/Service_Config.h" +#include "ace/Log_Msg.h" +#include "Notifier_Handler.h" +#include "Input_Handler.h" + +#if defined (ACE_HAS_ORBIX) + +class Supplier : public ACE_Event_Handler +{ +public: + Supplier (int argc, char *argv[]); + ~Supplier (void); + + void run (void); + // Execute the supplier. + +private: + virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); + + virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); + + Input_Handler *ih_; + // Handler for keyboard input. + + Notifier_Handler *nh_; + // Handler for CORBA Notifier. + + ACE_Service_Config daemon_; + // ACE server event-loop mechanism. +}; + +int +Supplier::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + ACE_DEBUG ((LM_DEBUG, "closing down Supplier\n")); + return 0; +} + +int +Supplier::handle_signal (int signum, siginfo_t *, ucontext_t *) +{ + ACE_DEBUG ((LM_DEBUG, "%S\n", signum)); + ACE_Service_Config::end_reactor_event_loop (); + return 0; +} + +void +Supplier::run (void) +{ + if (ACE_Service_Config::run_reactor_event_loop () == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "run_reactor_event_loop")); +} + +Supplier::Supplier (int argc, char *argv[]) + : ih_ (0), + nh_ (0) +{ + // Initialize the server. + if (this->daemon_.open (argc, argv) == -1) + { + if (errno == ENOENT) // There's no svc.conf file, so use static linking... + { + ACE_DEBUG ((LM_DEBUG, "no config file, using static binding\n")); + // The constructor registers the handlers... + int putit = argc > 1 ? 1 : 0; + + // Pass in program exec name to use a service_location! + this->nh_ = new Notifier_Handler (argv[0], "notifier", putit); + ACE_ASSERT (this->nh_ != 0); + this->ih_ = new Input_Handler (this->nh_); + ACE_ASSERT (this->ih_ != 0); + } + else + ACE_ERROR ((LM_ERROR, "%p\n%a", "open", 1)); + } + + ACE_DEBUG ((LM_DEBUG, "starting up server %s\n", + CORBA::Orbix.myImplementationName ())); + + if (ACE_Service_Config::reactor ()->register_handler (SIGINT, this) == -1) + ACE_ERROR ((LM_ERROR, "%p\n", "register_handler")); +} + +Supplier::~Supplier (void) +{ + // Free up the handlers if they were statically bound. + this->ih_->handle_close (); + this->nh_->handle_close (); +} + +int +main (int argc, char *argv[]) +{ + // Initialize server daemon. + Supplier supplier (argc, argv); + + // Loop forever handling events. + supplier.run (); + + return 0; +} +#else /* !defined ACE_HAS_ORBIX */ +int +main (int argc, char *argv[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, "you must have Orbix to run application %s\n", argv[0]), 1); +} +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/include/Event_Comm.hh b/apps/Orbix-Examples/Event_Comm/include/Event_Comm.hh new file mode 100644 index 00000000000..85ad256da2a --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/include/Event_Comm.hh @@ -0,0 +1,887 @@ + +#ifndef Event_Comm_hh +#define Event_Comm_hh + +#include <CORBA.h> + +#include <string.h> + +class Event_Comm { +public: + +#ifndef Event_Comm_Notification_defined +#define Event_Comm_Notification_defined + + struct Notification { + CORBA::String_mgr tag_; + + void encodeOp (CORBA::Request &IT_r) const; + void decodeOp (CORBA::Request &IT_r); + void decodeInOutOp (CORBA::Request &IT_r); + static void* IT_anySupport (CORBA::Request &IT_r, + void *&, void*, const CORBA::Flags&); + static const void *IT_fn; + }; + + static const CORBA::TypeCode_ptr _tc_Notification; + +#ifndef Event_Comm_NotificationVarH +#define Event_Comm_NotificationVarH + +#ifndef Event_Comm_NotificationvPtr +#define Event_Comm_NotificationvPtr +typedef Notification* Notification_vPtr; +#endif + +class Notification_var : public CORBA::_var +{ + public: + + Notification_var () { + _ptr = NULL; + } + + Notification_var (Notification *IT_p) { + _ptr = IT_p; + } + + Notification_var (const Notification_var &IT_s) { + if (!IT_s._ptr) { + _ptr = IT_s._ptr; + return; + } + _ptr = new Notification (*(IT_s._ptr)); + } + + Notification_var &operator= (Notification *IT_p) { + if (_ptr != IT_p) { + delete _ptr; + } + _ptr = IT_p; + return (*this); + } + + Notification_var &operator= (const Notification_var &IT_s) { + if (_ptr != IT_s._ptr) { + delete _ptr; + } + _ptr = new Notification (*(IT_s._ptr)); + return (*this); + } + + ~Notification_var () { + delete _ptr; + } + + Notification* operator-> () { + return _ptr; + } + + operator const Notification_vPtr () const { return _ptr;} + operator Notification_vPtr& () { return _ptr;} + operator Notification& () const { return * _ptr;} + + protected: + Notification *_ptr; + private: + Notification_var &operator= (const CORBA::_var &IT_s); + Notification_var (const CORBA::_var &IT_s); +}; + +#endif + + +#endif + + +#ifndef _Event_Comm_Notification_Receiver_defined +#define _Event_Comm_Notification_Receiver_defined +class Notification_Receiver_dispatch : public virtual CORBA::PPTR { +public: + + Notification_Receiver_dispatch (void *IT_p, CORBA::Object* IT_o, const char *IT_m, + CORBA::LoaderClass *IT_l, char *IT_i, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_l,IT_i,IT_im) {} + + + Notification_Receiver_dispatch (char *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notification_Receiver_dispatch () {} + + Notification_Receiver_dispatch (ObjectReference *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notification_Receiver_dispatch (void *IT_p, CORBA::Object *IT_o, const char *IT_m, + char *IT_i, CORBA::Object* IT_ob, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_i,IT_ob,IT_im) {} + + + virtual unsigned char dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void* IT_pp=NULL); + + +}; + +class Notification_Receiver; + +#ifndef Event_Comm_Notification_ReceiverPtr +#define Event_Comm_Notification_ReceiverPtr + + typedef Notification_Receiver* Notification_Receiver_ptr; + + typedef Notification_Receiver* Notification_ReceiverRef; + +#endif + + +#ifndef Event_Comm_Notification_ReceiverForwH +#define Event_Comm_Notification_ReceiverForwH +static CORBA::ObjectRef Notification_Receiver_getBase (void *); +static void Notification_Receiver_release (Notification_Receiver *, CORBA::Environment &IT_env); +static void Notification_Receiver_release (Notification_Receiver_ptr); +static Notification_Receiver* Notification_Receiver_duplicate (Notification_Receiver_ptr, CORBA::Environment &IT_env); +static Notification_Receiver* Notification_Receiver_duplicate (Notification_Receiver_ptr ); +static Notification_Receiver_ptr Notification_Receiver_nil (CORBA::Environment &IT_env); +static Notification_Receiver_ptr Notification_Receiver_nil (); +#endif +#define Event_Comm_Notification_Receiver_IMPL "Event_Comm_Notification_Receiver" + + +class Notification_Receiver; + + typedef Notification_Receiver Notification_ReceiverProxy; +#define Event_Comm_Notification_Receiver_IR "Event_Comm_Notification_Receiver" +#define Event_Comm_Notification_Receiver_IMPL "Event_Comm_Notification_Receiver" + +#ifndef Event_Comm_Notification_ReceiverPtr +#define Event_Comm_Notification_ReceiverPtr + + typedef Notification_Receiver* Notification_Receiver_ptr; + + typedef Notification_Receiver* Notification_ReceiverRef; + +#endif + +class Notification_Receiver: public virtual CORBA::Object { +public: + Notification_Receiver (char *IT_OR); + Notification_Receiver (ObjectReference *IT_OR); + Notification_Receiver () : CORBA::Object (1) {} +protected: + Notification_Receiver_ptr __duplicate( + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::Object::__duplicate (IT_env); + return this; + } +public: + static Notification_Receiver_ptr _duplicate( + Notification_Receiver_ptr obj, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + if (CORBA::is_nil(obj, IT_env)) { + IT_raise.maybeRaise (); + return (obj); + } + Notification_Receiver_ptr IT_obj = obj->__duplicate (IT_env); + IT_raise.maybeRaise(); + return IT_obj; + } +public: + static Notification_Receiver* _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notification_Receiver* _bind (CORBA::Environment &IT_env); + static Notification_Receiver* _bind (const char* IT_markerServer=NULL, const char* host=NULL, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notification_Receiver* _narrow (CORBA::Object* , CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notification_Receiver_ptr _nil (CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + IT_raise.maybeRaise(); + return (Notification_Receiver_ptr) CORBA::OBJECT_NIL;} + virtual void receive_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void disconnect (const char * reason, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); +}; + + static const CORBA::TypeCode_ptr _tc_Notification_Receiver; + + static const CORBA::TypeCode_ptr _tc_Notification_ReceiverRef; + +#ifndef Event_Comm_Notification_ReceiverVarH +#define Event_Comm_Notification_ReceiverVarH + +#ifndef Event_Comm_Notification_ReceivervPtr +#define Event_Comm_Notification_ReceivervPtr +typedef Notification_Receiver* Notification_Receiver_vPtr; +#endif + +class Notification_Receiver_var : public CORBA::_var +{ + public: + + Notification_Receiver_var () { + _ptr = Notification_Receiver_nil (); + } + + Notification_Receiver_var (Notification_Receiver *IT_p) { + _ptr = IT_p; + } + + Notification_Receiver_var (const Notification_Receiver_var &IT_s) { + _ptr = Notification_Receiver_duplicate (IT_s._ptr); + } + + Notification_Receiver_var &operator= (Notification_Receiver *IT_p) { + Notification_Receiver_release (_ptr); + _ptr = IT_p; + return (*this); + } + + Notification_Receiver_var &operator= (const Notification_Receiver_var &IT_s) { + Notification_Receiver_release (_ptr); + _ptr = Notification_Receiver_duplicate (IT_s._ptr); + return (*this); + } + + ~Notification_Receiver_var () { + Notification_Receiver_release (_ptr); + } + + Notification_Receiver* operator-> () { + return _ptr; + } + + operator const Notification_Receiver_vPtr () const { return _ptr;} + operator Notification_Receiver_vPtr& () { return _ptr;} + + protected: + Notification_Receiver *_ptr; + private: + Notification_Receiver_var &operator= (const CORBA::_var &IT_s); + Notification_Receiver_var (const CORBA::_var &IT_s); + Notification_Receiver_var &operator= (const CORBA::_mgr &IT_s); + Notification_Receiver_var &operator= (const CORBA::_SeqElem &IT_s); + Notification_Receiver_var (const CORBA::_mgr &IT_s); + Notification_Receiver_var (const CORBA::_SeqElem &IT_s); +}; + +#endif + + +#ifndef Event_Comm_Notification_ReceiverMgrH +#define Event_Comm_Notification_ReceiverMgrH + +class Notification_Receiver_mgr : public CORBA::_mgr +{ + public: + + Notification_Receiver_mgr () { + _ptr = Notification_Receiver_nil (); + _release = 1; + } + + Notification_Receiver_mgr (const Notification_Receiver_mgr &IT_s) { + _ptr = Notification_Receiver_duplicate (IT_s._ptr); + _release = 1; + } + + Notification_Receiver_mgr &operator= (Notification_Receiver *IT_p) { + if (_ptr && _release) + Notification_Receiver_release (_ptr); + _ptr = IT_p; + _release = 1; + return (*this); + } + + Notification_Receiver_mgr &operator= (const Notification_Receiver_mgr &IT_s) { + if (_ptr && _release) + Notification_Receiver_release (_ptr); + _ptr = Notification_Receiver_duplicate(IT_s._ptr); + _release = 1; + return (*this); + } + + Notification_Receiver_mgr &operator= (const Notification_Receiver_var &IT_s) { + if (_ptr && _release) + Notification_Receiver_release (_ptr); + _ptr = Notification_Receiver_duplicate(IT_s); + _release = 1; + return (*this); + } + + ~Notification_Receiver_mgr () { + if (_release) + Notification_Receiver_release (_ptr); + } + + unsigned char release () { + return _release; + } + + void release (unsigned char rel) { + _release = rel; + } + + operator int () const { + CORBA::Environment env; + CORBA::EnvExcRaiser IT_raise (&env); + return (!(CORBA::is_nil((CORBA::Object*) _ptr, env))); + } + + operator void* () const { + return _ptr; + } + + operator CORBA::Object * () const { + return (CORBA::Object *) _ptr; + } + + operator Notification_Receiver* () const { + return (Notification_Receiver*) _ptr; + } + + Notification_Receiver *_ptr; + + protected: + + unsigned char _release; +}; + +#endif + +#ifndef Event_Comm_Notification_ReceiverSeqElemH +#define Event_Comm_Notification_ReceiverSeqElemH + +class Notification_Receiver_SeqElem : public CORBA::_SeqElem +{ + public: + + Notification_Receiver_SeqElem (Event_Comm::Notification_Receiver_ptr* IT_p, unsigned char rel) { + _ptr = IT_p; + _release = rel; + } + + Notification_Receiver_SeqElem &operator= (Event_Comm::Notification_Receiver_ptr IT_p) { + if (!_ptr) + return (*this); + if (*(_ptr) && _release) + Notification_Receiver_release (*(_ptr)); + *(_ptr) = IT_p; + return (*this); + } + + Notification_Receiver_SeqElem &operator= (const Notification_Receiver_SeqElem &IT_s) { + if (!_ptr|| !IT_s._ptr) + return (*this); + if (*(_ptr) && _release) + Notification_Receiver_release (*(_ptr)); + *(_ptr) = Notification_Receiver_duplicate(*(IT_s._ptr)); + return (*this); + } + + operator Event_Comm::Notification_Receiver_ptr () const +{ + if (!_ptr) + return (Notification_Receiver_nil()); + return (Event_Comm::Notification_Receiver_ptr) (*_ptr); + } + + Notification_Receiver_ptr operator->() const { return *_ptr;} + + protected: + Event_Comm::Notification_Receiver_ptr *_ptr; + unsigned char _release; +}; + +#endif + + +#define TIE_Event_Comm_Notification_Receiver(X) Event_Comm_Notification_Receiver##X + +#define DEF_TIE_Event_Comm_Notification_Receiver(X) \ + class Event_Comm_Notification_Receiver##X : public virtual Event_Comm::Notification_Receiver { \ + X* m_obj; \ + public: \ + \ + Event_Comm_Notification_Receiver##X (X *objp, const char* m="", CORBA::LoaderClass *l=0)\ + : Event_Comm::Notification_Receiver(), CORBA::Object (), m_obj(objp) { \ + m_pptr = new Event_Comm::Notification_Receiver_dispatch \ + (( Event_Comm::Notification_Receiver*)this,(CORBA::Object*)this,m,l,Event_Comm_Notification_Receiver_IR,m_obj); \ + } \ + Event_Comm_Notification_Receiver##X (CORBA::Object *IT_p, const char* IT_m="", void *IT_q=0)\ + : Event_Comm::Notification_Receiver(), CORBA::Object () { \ + m_pptr = new Event_Comm::Notification_Receiver_dispatch \ + (( Event_Comm::Notification_Receiver*)this,(CORBA::Object*)this,IT_m,Event_Comm_Notification_Receiver_IR,IT_p,IT_q); \ + m_obj = (X*)(m_pptr->getImplObj ()); \ + } \ + \ + virtual ~Event_Comm_Notification_Receiver##X () { \ + if (_okToDeleteImpl ()) delete m_obj; } \ + \ + virtual void* _deref () { \ + return m_obj; } \ + \ + virtual void receive_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->receive_notification ( notification,IT_env);\ +}\ + \ + virtual void disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->disconnect ( reason,IT_env);\ +}\ + \ + }; + + +#define QUALS_Event_Comm_Notification_Receiver \ + virtual void receive_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->receive_notification ( notification,IT_env);\ +}\ + \ + virtual void disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->disconnect ( reason,IT_env);\ +}\ + + + + +class Notification_ReceiverProxyFactoryClass : public virtual CORBA::ObjectFactoryClass { +public: + Notification_ReceiverProxyFactoryClass (unsigned char IT_p=0) + : CORBA::ProxyFactory (Event_Comm_Notification_Receiver_IR, IT_p) {} + + virtual void* New (char *IT_OR, CORBA::Environment&); + + virtual void* New (ObjectReference *IT_OR, CORBA::Environment&); + + virtual void* New2 (); + + virtual void* IT_castUp (void *IT_p, char* IT_s); + + virtual CORBA::PPTR* pptr (void *IT_p); + + virtual void baseInterfaces (_IDL_SEQUENCE_string&); + + +}; + +static Notification_ReceiverProxyFactoryClass Notification_ReceiverProxyFactory; + + + +#endif + + +#ifndef _Event_Comm_Notifier_defined +#define _Event_Comm_Notifier_defined +class Notifier_dispatch : public virtual CORBA::PPTR { +public: + + Notifier_dispatch (void *IT_p, CORBA::Object* IT_o, const char *IT_m, + CORBA::LoaderClass *IT_l, char *IT_i, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_l,IT_i,IT_im) {} + + + Notifier_dispatch (char *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notifier_dispatch () {} + + Notifier_dispatch (ObjectReference *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notifier_dispatch (void *IT_p, CORBA::Object *IT_o, const char *IT_m, + char *IT_i, CORBA::Object* IT_ob, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_i,IT_ob,IT_im) {} + + + virtual unsigned char dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void* IT_pp=NULL); + + +}; + +class Notifier; + +#ifndef Event_Comm_NotifierPtr +#define Event_Comm_NotifierPtr + + typedef Notifier* Notifier_ptr; + + typedef Notifier* NotifierRef; + +#endif + + +#ifndef Event_Comm_NotifierForwH +#define Event_Comm_NotifierForwH +static CORBA::ObjectRef Notifier_getBase (void *); +static void Notifier_release (Notifier *, CORBA::Environment &IT_env); +static void Notifier_release (Notifier_ptr); +static Notifier* Notifier_duplicate (Notifier_ptr, CORBA::Environment &IT_env); +static Notifier* Notifier_duplicate (Notifier_ptr ); +static Notifier_ptr Notifier_nil (CORBA::Environment &IT_env); +static Notifier_ptr Notifier_nil (); +#endif +#define Event_Comm_Notifier_IMPL "Event_Comm_Notifier" + + +class Notifier; + + typedef Notifier NotifierProxy; +#define Event_Comm_Notifier_IR "Event_Comm_Notifier" +#define Event_Comm_Notifier_IMPL "Event_Comm_Notifier" + +#ifndef Event_Comm_NotifierPtr +#define Event_Comm_NotifierPtr + + typedef Notifier* Notifier_ptr; + + typedef Notifier* NotifierRef; + +#endif + +class Notifier: public virtual CORBA::Object { +public: + Notifier (char *IT_OR); + Notifier (ObjectReference *IT_OR); + Notifier () : CORBA::Object (1) {} +protected: + Notifier_ptr __duplicate( + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::Object::__duplicate (IT_env); + return this; + } +public: + static Notifier_ptr _duplicate( + Notifier_ptr obj, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + if (CORBA::is_nil(obj, IT_env)) { + IT_raise.maybeRaise (); + return (obj); + } + Notifier_ptr IT_obj = obj->__duplicate (IT_env); + IT_raise.maybeRaise(); + return IT_obj; + } +public: + static Notifier* _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notifier* _bind (CORBA::Environment &IT_env); + static Notifier* _bind (const char* IT_markerServer=NULL, const char* host=NULL, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notifier* _narrow (CORBA::Object* , CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notifier_ptr _nil (CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + IT_raise.maybeRaise(); + return (Notifier_ptr) CORBA::OBJECT_NIL;} + virtual void send_disconnect (const char * reason, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void send_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void subscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void unsubscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); +}; + + static const CORBA::TypeCode_ptr _tc_Notifier; + + static const CORBA::TypeCode_ptr _tc_NotifierRef; + +#ifndef Event_Comm_NotifierVarH +#define Event_Comm_NotifierVarH + +#ifndef Event_Comm_NotifiervPtr +#define Event_Comm_NotifiervPtr +typedef Notifier* Notifier_vPtr; +#endif + +class Notifier_var : public CORBA::_var +{ + public: + + Notifier_var () { + _ptr = Notifier_nil (); + } + + Notifier_var (Notifier *IT_p) { + _ptr = IT_p; + } + + Notifier_var (const Notifier_var &IT_s) { + _ptr = Notifier_duplicate (IT_s._ptr); + } + + Notifier_var &operator= (Notifier *IT_p) { + Notifier_release (_ptr); + _ptr = IT_p; + return (*this); + } + + Notifier_var &operator= (const Notifier_var &IT_s) { + Notifier_release (_ptr); + _ptr = Notifier_duplicate (IT_s._ptr); + return (*this); + } + + ~Notifier_var () { + Notifier_release (_ptr); + } + + Notifier* operator-> () { + return _ptr; + } + + operator const Notifier_vPtr () const { return _ptr;} + operator Notifier_vPtr& () { return _ptr;} + + protected: + Notifier *_ptr; + private: + Notifier_var &operator= (const CORBA::_var &IT_s); + Notifier_var (const CORBA::_var &IT_s); + Notifier_var &operator= (const CORBA::_mgr &IT_s); + Notifier_var &operator= (const CORBA::_SeqElem &IT_s); + Notifier_var (const CORBA::_mgr &IT_s); + Notifier_var (const CORBA::_SeqElem &IT_s); +}; + +#endif + + +#ifndef Event_Comm_NotifierMgrH +#define Event_Comm_NotifierMgrH + +class Notifier_mgr : public CORBA::_mgr +{ + public: + + Notifier_mgr () { + _ptr = Notifier_nil (); + _release = 1; + } + + Notifier_mgr (const Notifier_mgr &IT_s) { + _ptr = Notifier_duplicate (IT_s._ptr); + _release = 1; + } + + Notifier_mgr &operator= (Notifier *IT_p) { + if (_ptr && _release) + Notifier_release (_ptr); + _ptr = IT_p; + _release = 1; + return (*this); + } + + Notifier_mgr &operator= (const Notifier_mgr &IT_s) { + if (_ptr && _release) + Notifier_release (_ptr); + _ptr = Notifier_duplicate(IT_s._ptr); + _release = 1; + return (*this); + } + + Notifier_mgr &operator= (const Notifier_var &IT_s) { + if (_ptr && _release) + Notifier_release (_ptr); + _ptr = Notifier_duplicate(IT_s); + _release = 1; + return (*this); + } + + ~Notifier_mgr () { + if (_release) + Notifier_release (_ptr); + } + + unsigned char release () { + return _release; + } + + void release (unsigned char rel) { + _release = rel; + } + + operator int () const { + CORBA::Environment env; + CORBA::EnvExcRaiser IT_raise (&env); + return (!(CORBA::is_nil((CORBA::Object*) _ptr, env))); + } + + operator void* () const { + return _ptr; + } + + operator CORBA::Object * () const { + return (CORBA::Object *) _ptr; + } + + operator Notifier* () const { + return (Notifier*) _ptr; + } + + Notifier *_ptr; + + protected: + + unsigned char _release; +}; + +#endif + +#ifndef Event_Comm_NotifierSeqElemH +#define Event_Comm_NotifierSeqElemH + +class Notifier_SeqElem : public CORBA::_SeqElem +{ + public: + + Notifier_SeqElem (Event_Comm::Notifier_ptr* IT_p, unsigned char rel) { + _ptr = IT_p; + _release = rel; + } + + Notifier_SeqElem &operator= (Event_Comm::Notifier_ptr IT_p) { + if (!_ptr) + return (*this); + if (*(_ptr) && _release) + Notifier_release (*(_ptr)); + *(_ptr) = IT_p; + return (*this); + } + + Notifier_SeqElem &operator= (const Notifier_SeqElem &IT_s) { + if (!_ptr|| !IT_s._ptr) + return (*this); + if (*(_ptr) && _release) + Notifier_release (*(_ptr)); + *(_ptr) = Notifier_duplicate(*(IT_s._ptr)); + return (*this); + } + + operator Event_Comm::Notifier_ptr () const +{ + if (!_ptr) + return (Notifier_nil()); + return (Event_Comm::Notifier_ptr) (*_ptr); + } + + Notifier_ptr operator->() const { return *_ptr;} + + protected: + Event_Comm::Notifier_ptr *_ptr; + unsigned char _release; +}; + +#endif + + +#define TIE_Event_Comm_Notifier(X) Event_Comm_Notifier##X + +#define DEF_TIE_Event_Comm_Notifier(X) \ + class Event_Comm_Notifier##X : public virtual Event_Comm::Notifier { \ + X* m_obj; \ + public: \ + \ + Event_Comm_Notifier##X (X *objp, const char* m="", CORBA::LoaderClass *l=0)\ + : Event_Comm::Notifier(), CORBA::Object (), m_obj(objp) { \ + m_pptr = new Event_Comm::Notifier_dispatch \ + (( Event_Comm::Notifier*)this,(CORBA::Object*)this,m,l,Event_Comm_Notifier_IR,m_obj); \ + } \ + Event_Comm_Notifier##X (CORBA::Object *IT_p, const char* IT_m="", void *IT_q=0)\ + : Event_Comm::Notifier(), CORBA::Object () { \ + m_pptr = new Event_Comm::Notifier_dispatch \ + (( Event_Comm::Notifier*)this,(CORBA::Object*)this,IT_m,Event_Comm_Notifier_IR,IT_p,IT_q); \ + m_obj = (X*)(m_pptr->getImplObj ()); \ + } \ + \ + virtual ~Event_Comm_Notifier##X () { \ + if (_okToDeleteImpl ()) delete m_obj; } \ + \ + virtual void* _deref () { \ + return m_obj; } \ + \ + virtual void send_disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_disconnect ( reason,IT_env);\ +}\ + \ + virtual void send_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_notification ( notification,IT_env);\ +}\ + \ + virtual void subscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->subscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + \ + virtual void unsubscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->unsubscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + \ + }; + + +#define QUALS_Event_Comm_Notifier \ + virtual void send_disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_disconnect ( reason,IT_env);\ +}\ + \ + virtual void send_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_notification ( notification,IT_env);\ +}\ + \ + virtual void subscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->subscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + \ + virtual void unsubscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->unsubscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + + + + +class NotifierProxyFactoryClass : public virtual CORBA::ObjectFactoryClass { +public: + NotifierProxyFactoryClass (unsigned char IT_p=0) + : CORBA::ProxyFactory (Event_Comm_Notifier_IR, IT_p) {} + + virtual void* New (char *IT_OR, CORBA::Environment&); + + virtual void* New (ObjectReference *IT_OR, CORBA::Environment&); + + virtual void* New2 (); + + virtual void* IT_castUp (void *IT_p, char* IT_s); + + virtual CORBA::PPTR* pptr (void *IT_p); + + virtual void baseInterfaces (_IDL_SEQUENCE_string&); + + +}; + +static NotifierProxyFactoryClass NotifierProxyFactory; + + + +#endif + +}; + + +void operator<<= (CORBA::any &IT_a, Event_Comm::Notification_Receiver_ptr IT_t); +CORBA::Boolean operator>>= (const CORBA::any &IT_a, Event_Comm::Notification_Receiver_ptr& IT_t); + + +void operator<<= (CORBA::any &IT_a, Event_Comm::Notifier_ptr IT_t); +CORBA::Boolean operator>>= (const CORBA::any &IT_a, Event_Comm::Notifier_ptr& IT_t); + + +void operator<<= (CORBA::any &IT_a, const Event_Comm::Notification& IT_t); +CORBA::Boolean operator>>= (const CORBA::any &IT_a, Event_Comm::Notification*& IT_t); + + +#endif diff --git a/apps/Orbix-Examples/Event_Comm/include/Event_Comm_i.h b/apps/Orbix-Examples/Event_Comm/include/Event_Comm_i.h new file mode 100644 index 00000000000..49673abec84 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/include/Event_Comm_i.h @@ -0,0 +1,37 @@ +/* -*- C++ -*- */ +// @(#)Event_Comm_i.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Event_Comm_i.h +// +// = DESCRIPTION +// Class interface for the implementation of the distributed +// event notification mechanism. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_EVENT_COMM_I_H) +#define _EVENT_COMM_I_H + +#include "Notification_Receiver_i.h" +#include "Notifier_i.h" + +#if defined (ACE_HAS_ORBIX) + +// Tie the Notification_Receiver and Notifier implementation classes +// together with the IDL interface. + +DEF_TIE_Event_Comm_Notification_Receiver (Notification_Receiver_i) +DEF_TIE_Event_Comm_Notifier (Notifier_i) + +#endif /* ACE_HAS_ORBIX */ +#endif /* _EVENT_COMM_I_H */ diff --git a/apps/Orbix-Examples/Event_Comm/include/Notification_Receiver_i.h b/apps/Orbix-Examples/Event_Comm/include/Notification_Receiver_i.h new file mode 100644 index 00000000000..4f0bcc980e4 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/include/Notification_Receiver_i.h @@ -0,0 +1,48 @@ +/* -*- C++ -*- */ +// @(#)Notification_Receiver_i.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notification_Receiver__i.h +// +// = DESCRIPTION +// Class interface for the implementation of the <Notification_Receiver> +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_Notification_Receiver_i_H) +#define _Notification_Receiver_i_H + +#if defined (ACE_HAS_ORBIX) +#include "Event_Comm.hh" + +class Notification_Receiver_i + // = TITLE + // Defines the implementation class for event <Notification_Receivers>. + // + // = DESCRIPTION +{ +public: + Notification_Receiver_i (void); + ~Notification_Receiver_i (void); + + virtual void receive_notification (const Event_Comm::Notification ¬ification, + CORBA::Environment &IT_env); + // Pass the <Notification> to the <Notification_Receiver>. + + virtual void disconnect (const char *reason, + CORBA::Environment &IT_env); + // Disconnect the <Notification_Receiver> from the <Notifier>, + // giving it the <reason>. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _Notification_Receiver_i_H */ diff --git a/apps/Orbix-Examples/Event_Comm/include/Notifier_i.h b/apps/Orbix-Examples/Event_Comm/include/Notifier_i.h new file mode 100644 index 00000000000..379f96b8097 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/include/Notifier_i.h @@ -0,0 +1,82 @@ +/* -*- C++ -*- */ +// @(#)Notifier_i.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notifier_i.h +// +// = DESCRIPTION +// Class interface for the implementation of the <Notifier> +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_Notifier_i_H) +#define _Notifier_i_H + +#include "ace/Map_Manager.h" +#include "ace/Synch.h" +#include "ace/SString.h" +#include "Event_Comm.hh" + +#if defined (ACE_HAS_ORBIX) + +// Forward reference. +class Notification_Receiver_Entry; + +class Notifier_i + // = TITLE + // Defines the implementation class for event <Notifiers>. + // + // = DESCRIPTION +{ +public: + enum + { + DEFAULT_SIZE = 1024 // Default max number of Event_Comm::Notification_Receivers. + }; + + Notifier_i (size_t size_hint = Notifier_i::DEFAULT_SIZE); + // Initialize a Notifier_i object with the specified size hint. + + void send_disconnect (const char *reason, + CORBA::Environment &IT_env); + // Disconnect all the receivers, giving them the <reason>. + + void send_notification (const Event_Comm::Notification ¬ification, + CORBA::Environment &IT_env); + // Send the <Notification> to all the consumers who + // have subscribed and who match the filtering criteria. + + void subscribe (Event_Comm::Notification_Receiver *notification_receiver, + const char *filtering_criteria, + CORBA::Environment &IT_env); + // Subscribe the <Notification_Receiver> to receive events that + // match <filtering_criteria> applied by the <Notifier>. + + void unsubscribe (Event_Comm::Notification_Receiver *notification_receiver, + const char *filtering_criteria, + CORBA::Environment &IT_env); + // Unsubscribe the <Notification_Receiver>. + +private: + // The following implementation should be replaced + // by a standard container class from STL... + + typedef ACE_Map_Manager <ACE_SString, Notification_Receiver_Entry *, ACE_Null_Mutex> MAP_MANAGER; + typedef ACE_Map_Iterator <ACE_SString, Notification_Receiver_Entry *, ACE_Null_Mutex> MAP_ITERATOR; + typedef ACE_Map_Entry <ACE_SString, Notification_Receiver_Entry *> MAP_ENTRY; + + MAP_MANAGER map_; + // Table that maps a <Event_Comm::Notification_Receiver *> to a <Notification_Receiver_Entry *>. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _Notifier_i_H */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm.hh b/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm.hh new file mode 100644 index 00000000000..85ad256da2a --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm.hh @@ -0,0 +1,887 @@ + +#ifndef Event_Comm_hh +#define Event_Comm_hh + +#include <CORBA.h> + +#include <string.h> + +class Event_Comm { +public: + +#ifndef Event_Comm_Notification_defined +#define Event_Comm_Notification_defined + + struct Notification { + CORBA::String_mgr tag_; + + void encodeOp (CORBA::Request &IT_r) const; + void decodeOp (CORBA::Request &IT_r); + void decodeInOutOp (CORBA::Request &IT_r); + static void* IT_anySupport (CORBA::Request &IT_r, + void *&, void*, const CORBA::Flags&); + static const void *IT_fn; + }; + + static const CORBA::TypeCode_ptr _tc_Notification; + +#ifndef Event_Comm_NotificationVarH +#define Event_Comm_NotificationVarH + +#ifndef Event_Comm_NotificationvPtr +#define Event_Comm_NotificationvPtr +typedef Notification* Notification_vPtr; +#endif + +class Notification_var : public CORBA::_var +{ + public: + + Notification_var () { + _ptr = NULL; + } + + Notification_var (Notification *IT_p) { + _ptr = IT_p; + } + + Notification_var (const Notification_var &IT_s) { + if (!IT_s._ptr) { + _ptr = IT_s._ptr; + return; + } + _ptr = new Notification (*(IT_s._ptr)); + } + + Notification_var &operator= (Notification *IT_p) { + if (_ptr != IT_p) { + delete _ptr; + } + _ptr = IT_p; + return (*this); + } + + Notification_var &operator= (const Notification_var &IT_s) { + if (_ptr != IT_s._ptr) { + delete _ptr; + } + _ptr = new Notification (*(IT_s._ptr)); + return (*this); + } + + ~Notification_var () { + delete _ptr; + } + + Notification* operator-> () { + return _ptr; + } + + operator const Notification_vPtr () const { return _ptr;} + operator Notification_vPtr& () { return _ptr;} + operator Notification& () const { return * _ptr;} + + protected: + Notification *_ptr; + private: + Notification_var &operator= (const CORBA::_var &IT_s); + Notification_var (const CORBA::_var &IT_s); +}; + +#endif + + +#endif + + +#ifndef _Event_Comm_Notification_Receiver_defined +#define _Event_Comm_Notification_Receiver_defined +class Notification_Receiver_dispatch : public virtual CORBA::PPTR { +public: + + Notification_Receiver_dispatch (void *IT_p, CORBA::Object* IT_o, const char *IT_m, + CORBA::LoaderClass *IT_l, char *IT_i, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_l,IT_i,IT_im) {} + + + Notification_Receiver_dispatch (char *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notification_Receiver_dispatch () {} + + Notification_Receiver_dispatch (ObjectReference *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notification_Receiver_dispatch (void *IT_p, CORBA::Object *IT_o, const char *IT_m, + char *IT_i, CORBA::Object* IT_ob, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_i,IT_ob,IT_im) {} + + + virtual unsigned char dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void* IT_pp=NULL); + + +}; + +class Notification_Receiver; + +#ifndef Event_Comm_Notification_ReceiverPtr +#define Event_Comm_Notification_ReceiverPtr + + typedef Notification_Receiver* Notification_Receiver_ptr; + + typedef Notification_Receiver* Notification_ReceiverRef; + +#endif + + +#ifndef Event_Comm_Notification_ReceiverForwH +#define Event_Comm_Notification_ReceiverForwH +static CORBA::ObjectRef Notification_Receiver_getBase (void *); +static void Notification_Receiver_release (Notification_Receiver *, CORBA::Environment &IT_env); +static void Notification_Receiver_release (Notification_Receiver_ptr); +static Notification_Receiver* Notification_Receiver_duplicate (Notification_Receiver_ptr, CORBA::Environment &IT_env); +static Notification_Receiver* Notification_Receiver_duplicate (Notification_Receiver_ptr ); +static Notification_Receiver_ptr Notification_Receiver_nil (CORBA::Environment &IT_env); +static Notification_Receiver_ptr Notification_Receiver_nil (); +#endif +#define Event_Comm_Notification_Receiver_IMPL "Event_Comm_Notification_Receiver" + + +class Notification_Receiver; + + typedef Notification_Receiver Notification_ReceiverProxy; +#define Event_Comm_Notification_Receiver_IR "Event_Comm_Notification_Receiver" +#define Event_Comm_Notification_Receiver_IMPL "Event_Comm_Notification_Receiver" + +#ifndef Event_Comm_Notification_ReceiverPtr +#define Event_Comm_Notification_ReceiverPtr + + typedef Notification_Receiver* Notification_Receiver_ptr; + + typedef Notification_Receiver* Notification_ReceiverRef; + +#endif + +class Notification_Receiver: public virtual CORBA::Object { +public: + Notification_Receiver (char *IT_OR); + Notification_Receiver (ObjectReference *IT_OR); + Notification_Receiver () : CORBA::Object (1) {} +protected: + Notification_Receiver_ptr __duplicate( + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::Object::__duplicate (IT_env); + return this; + } +public: + static Notification_Receiver_ptr _duplicate( + Notification_Receiver_ptr obj, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + if (CORBA::is_nil(obj, IT_env)) { + IT_raise.maybeRaise (); + return (obj); + } + Notification_Receiver_ptr IT_obj = obj->__duplicate (IT_env); + IT_raise.maybeRaise(); + return IT_obj; + } +public: + static Notification_Receiver* _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notification_Receiver* _bind (CORBA::Environment &IT_env); + static Notification_Receiver* _bind (const char* IT_markerServer=NULL, const char* host=NULL, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notification_Receiver* _narrow (CORBA::Object* , CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notification_Receiver_ptr _nil (CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + IT_raise.maybeRaise(); + return (Notification_Receiver_ptr) CORBA::OBJECT_NIL;} + virtual void receive_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void disconnect (const char * reason, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); +}; + + static const CORBA::TypeCode_ptr _tc_Notification_Receiver; + + static const CORBA::TypeCode_ptr _tc_Notification_ReceiverRef; + +#ifndef Event_Comm_Notification_ReceiverVarH +#define Event_Comm_Notification_ReceiverVarH + +#ifndef Event_Comm_Notification_ReceivervPtr +#define Event_Comm_Notification_ReceivervPtr +typedef Notification_Receiver* Notification_Receiver_vPtr; +#endif + +class Notification_Receiver_var : public CORBA::_var +{ + public: + + Notification_Receiver_var () { + _ptr = Notification_Receiver_nil (); + } + + Notification_Receiver_var (Notification_Receiver *IT_p) { + _ptr = IT_p; + } + + Notification_Receiver_var (const Notification_Receiver_var &IT_s) { + _ptr = Notification_Receiver_duplicate (IT_s._ptr); + } + + Notification_Receiver_var &operator= (Notification_Receiver *IT_p) { + Notification_Receiver_release (_ptr); + _ptr = IT_p; + return (*this); + } + + Notification_Receiver_var &operator= (const Notification_Receiver_var &IT_s) { + Notification_Receiver_release (_ptr); + _ptr = Notification_Receiver_duplicate (IT_s._ptr); + return (*this); + } + + ~Notification_Receiver_var () { + Notification_Receiver_release (_ptr); + } + + Notification_Receiver* operator-> () { + return _ptr; + } + + operator const Notification_Receiver_vPtr () const { return _ptr;} + operator Notification_Receiver_vPtr& () { return _ptr;} + + protected: + Notification_Receiver *_ptr; + private: + Notification_Receiver_var &operator= (const CORBA::_var &IT_s); + Notification_Receiver_var (const CORBA::_var &IT_s); + Notification_Receiver_var &operator= (const CORBA::_mgr &IT_s); + Notification_Receiver_var &operator= (const CORBA::_SeqElem &IT_s); + Notification_Receiver_var (const CORBA::_mgr &IT_s); + Notification_Receiver_var (const CORBA::_SeqElem &IT_s); +}; + +#endif + + +#ifndef Event_Comm_Notification_ReceiverMgrH +#define Event_Comm_Notification_ReceiverMgrH + +class Notification_Receiver_mgr : public CORBA::_mgr +{ + public: + + Notification_Receiver_mgr () { + _ptr = Notification_Receiver_nil (); + _release = 1; + } + + Notification_Receiver_mgr (const Notification_Receiver_mgr &IT_s) { + _ptr = Notification_Receiver_duplicate (IT_s._ptr); + _release = 1; + } + + Notification_Receiver_mgr &operator= (Notification_Receiver *IT_p) { + if (_ptr && _release) + Notification_Receiver_release (_ptr); + _ptr = IT_p; + _release = 1; + return (*this); + } + + Notification_Receiver_mgr &operator= (const Notification_Receiver_mgr &IT_s) { + if (_ptr && _release) + Notification_Receiver_release (_ptr); + _ptr = Notification_Receiver_duplicate(IT_s._ptr); + _release = 1; + return (*this); + } + + Notification_Receiver_mgr &operator= (const Notification_Receiver_var &IT_s) { + if (_ptr && _release) + Notification_Receiver_release (_ptr); + _ptr = Notification_Receiver_duplicate(IT_s); + _release = 1; + return (*this); + } + + ~Notification_Receiver_mgr () { + if (_release) + Notification_Receiver_release (_ptr); + } + + unsigned char release () { + return _release; + } + + void release (unsigned char rel) { + _release = rel; + } + + operator int () const { + CORBA::Environment env; + CORBA::EnvExcRaiser IT_raise (&env); + return (!(CORBA::is_nil((CORBA::Object*) _ptr, env))); + } + + operator void* () const { + return _ptr; + } + + operator CORBA::Object * () const { + return (CORBA::Object *) _ptr; + } + + operator Notification_Receiver* () const { + return (Notification_Receiver*) _ptr; + } + + Notification_Receiver *_ptr; + + protected: + + unsigned char _release; +}; + +#endif + +#ifndef Event_Comm_Notification_ReceiverSeqElemH +#define Event_Comm_Notification_ReceiverSeqElemH + +class Notification_Receiver_SeqElem : public CORBA::_SeqElem +{ + public: + + Notification_Receiver_SeqElem (Event_Comm::Notification_Receiver_ptr* IT_p, unsigned char rel) { + _ptr = IT_p; + _release = rel; + } + + Notification_Receiver_SeqElem &operator= (Event_Comm::Notification_Receiver_ptr IT_p) { + if (!_ptr) + return (*this); + if (*(_ptr) && _release) + Notification_Receiver_release (*(_ptr)); + *(_ptr) = IT_p; + return (*this); + } + + Notification_Receiver_SeqElem &operator= (const Notification_Receiver_SeqElem &IT_s) { + if (!_ptr|| !IT_s._ptr) + return (*this); + if (*(_ptr) && _release) + Notification_Receiver_release (*(_ptr)); + *(_ptr) = Notification_Receiver_duplicate(*(IT_s._ptr)); + return (*this); + } + + operator Event_Comm::Notification_Receiver_ptr () const +{ + if (!_ptr) + return (Notification_Receiver_nil()); + return (Event_Comm::Notification_Receiver_ptr) (*_ptr); + } + + Notification_Receiver_ptr operator->() const { return *_ptr;} + + protected: + Event_Comm::Notification_Receiver_ptr *_ptr; + unsigned char _release; +}; + +#endif + + +#define TIE_Event_Comm_Notification_Receiver(X) Event_Comm_Notification_Receiver##X + +#define DEF_TIE_Event_Comm_Notification_Receiver(X) \ + class Event_Comm_Notification_Receiver##X : public virtual Event_Comm::Notification_Receiver { \ + X* m_obj; \ + public: \ + \ + Event_Comm_Notification_Receiver##X (X *objp, const char* m="", CORBA::LoaderClass *l=0)\ + : Event_Comm::Notification_Receiver(), CORBA::Object (), m_obj(objp) { \ + m_pptr = new Event_Comm::Notification_Receiver_dispatch \ + (( Event_Comm::Notification_Receiver*)this,(CORBA::Object*)this,m,l,Event_Comm_Notification_Receiver_IR,m_obj); \ + } \ + Event_Comm_Notification_Receiver##X (CORBA::Object *IT_p, const char* IT_m="", void *IT_q=0)\ + : Event_Comm::Notification_Receiver(), CORBA::Object () { \ + m_pptr = new Event_Comm::Notification_Receiver_dispatch \ + (( Event_Comm::Notification_Receiver*)this,(CORBA::Object*)this,IT_m,Event_Comm_Notification_Receiver_IR,IT_p,IT_q); \ + m_obj = (X*)(m_pptr->getImplObj ()); \ + } \ + \ + virtual ~Event_Comm_Notification_Receiver##X () { \ + if (_okToDeleteImpl ()) delete m_obj; } \ + \ + virtual void* _deref () { \ + return m_obj; } \ + \ + virtual void receive_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->receive_notification ( notification,IT_env);\ +}\ + \ + virtual void disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->disconnect ( reason,IT_env);\ +}\ + \ + }; + + +#define QUALS_Event_Comm_Notification_Receiver \ + virtual void receive_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->receive_notification ( notification,IT_env);\ +}\ + \ + virtual void disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->disconnect ( reason,IT_env);\ +}\ + + + + +class Notification_ReceiverProxyFactoryClass : public virtual CORBA::ObjectFactoryClass { +public: + Notification_ReceiverProxyFactoryClass (unsigned char IT_p=0) + : CORBA::ProxyFactory (Event_Comm_Notification_Receiver_IR, IT_p) {} + + virtual void* New (char *IT_OR, CORBA::Environment&); + + virtual void* New (ObjectReference *IT_OR, CORBA::Environment&); + + virtual void* New2 (); + + virtual void* IT_castUp (void *IT_p, char* IT_s); + + virtual CORBA::PPTR* pptr (void *IT_p); + + virtual void baseInterfaces (_IDL_SEQUENCE_string&); + + +}; + +static Notification_ReceiverProxyFactoryClass Notification_ReceiverProxyFactory; + + + +#endif + + +#ifndef _Event_Comm_Notifier_defined +#define _Event_Comm_Notifier_defined +class Notifier_dispatch : public virtual CORBA::PPTR { +public: + + Notifier_dispatch (void *IT_p, CORBA::Object* IT_o, const char *IT_m, + CORBA::LoaderClass *IT_l, char *IT_i, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_l,IT_i,IT_im) {} + + + Notifier_dispatch (char *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notifier_dispatch () {} + + Notifier_dispatch (ObjectReference *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + Notifier_dispatch (void *IT_p, CORBA::Object *IT_o, const char *IT_m, + char *IT_i, CORBA::Object* IT_ob, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_i,IT_ob,IT_im) {} + + + virtual unsigned char dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void* IT_pp=NULL); + + +}; + +class Notifier; + +#ifndef Event_Comm_NotifierPtr +#define Event_Comm_NotifierPtr + + typedef Notifier* Notifier_ptr; + + typedef Notifier* NotifierRef; + +#endif + + +#ifndef Event_Comm_NotifierForwH +#define Event_Comm_NotifierForwH +static CORBA::ObjectRef Notifier_getBase (void *); +static void Notifier_release (Notifier *, CORBA::Environment &IT_env); +static void Notifier_release (Notifier_ptr); +static Notifier* Notifier_duplicate (Notifier_ptr, CORBA::Environment &IT_env); +static Notifier* Notifier_duplicate (Notifier_ptr ); +static Notifier_ptr Notifier_nil (CORBA::Environment &IT_env); +static Notifier_ptr Notifier_nil (); +#endif +#define Event_Comm_Notifier_IMPL "Event_Comm_Notifier" + + +class Notifier; + + typedef Notifier NotifierProxy; +#define Event_Comm_Notifier_IR "Event_Comm_Notifier" +#define Event_Comm_Notifier_IMPL "Event_Comm_Notifier" + +#ifndef Event_Comm_NotifierPtr +#define Event_Comm_NotifierPtr + + typedef Notifier* Notifier_ptr; + + typedef Notifier* NotifierRef; + +#endif + +class Notifier: public virtual CORBA::Object { +public: + Notifier (char *IT_OR); + Notifier (ObjectReference *IT_OR); + Notifier () : CORBA::Object (1) {} +protected: + Notifier_ptr __duplicate( + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::Object::__duplicate (IT_env); + return this; + } +public: + static Notifier_ptr _duplicate( + Notifier_ptr obj, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + if (CORBA::is_nil(obj, IT_env)) { + IT_raise.maybeRaise (); + return (obj); + } + Notifier_ptr IT_obj = obj->__duplicate (IT_env); + IT_raise.maybeRaise(); + return IT_obj; + } +public: + static Notifier* _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notifier* _bind (CORBA::Environment &IT_env); + static Notifier* _bind (const char* IT_markerServer=NULL, const char* host=NULL, + CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notifier* _narrow (CORBA::Object* , CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()); + static Notifier_ptr _nil (CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) { + CORBA::EnvExcRaiser IT_raise (&IT_env); + IT_raise.maybeRaise(); + return (Notifier_ptr) CORBA::OBJECT_NIL;} + virtual void send_disconnect (const char * reason, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void send_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void subscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); + virtual void unsubscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env=CORBA::IT_chooseDefaultEnv ()) throw (CORBA::SystemException); +}; + + static const CORBA::TypeCode_ptr _tc_Notifier; + + static const CORBA::TypeCode_ptr _tc_NotifierRef; + +#ifndef Event_Comm_NotifierVarH +#define Event_Comm_NotifierVarH + +#ifndef Event_Comm_NotifiervPtr +#define Event_Comm_NotifiervPtr +typedef Notifier* Notifier_vPtr; +#endif + +class Notifier_var : public CORBA::_var +{ + public: + + Notifier_var () { + _ptr = Notifier_nil (); + } + + Notifier_var (Notifier *IT_p) { + _ptr = IT_p; + } + + Notifier_var (const Notifier_var &IT_s) { + _ptr = Notifier_duplicate (IT_s._ptr); + } + + Notifier_var &operator= (Notifier *IT_p) { + Notifier_release (_ptr); + _ptr = IT_p; + return (*this); + } + + Notifier_var &operator= (const Notifier_var &IT_s) { + Notifier_release (_ptr); + _ptr = Notifier_duplicate (IT_s._ptr); + return (*this); + } + + ~Notifier_var () { + Notifier_release (_ptr); + } + + Notifier* operator-> () { + return _ptr; + } + + operator const Notifier_vPtr () const { return _ptr;} + operator Notifier_vPtr& () { return _ptr;} + + protected: + Notifier *_ptr; + private: + Notifier_var &operator= (const CORBA::_var &IT_s); + Notifier_var (const CORBA::_var &IT_s); + Notifier_var &operator= (const CORBA::_mgr &IT_s); + Notifier_var &operator= (const CORBA::_SeqElem &IT_s); + Notifier_var (const CORBA::_mgr &IT_s); + Notifier_var (const CORBA::_SeqElem &IT_s); +}; + +#endif + + +#ifndef Event_Comm_NotifierMgrH +#define Event_Comm_NotifierMgrH + +class Notifier_mgr : public CORBA::_mgr +{ + public: + + Notifier_mgr () { + _ptr = Notifier_nil (); + _release = 1; + } + + Notifier_mgr (const Notifier_mgr &IT_s) { + _ptr = Notifier_duplicate (IT_s._ptr); + _release = 1; + } + + Notifier_mgr &operator= (Notifier *IT_p) { + if (_ptr && _release) + Notifier_release (_ptr); + _ptr = IT_p; + _release = 1; + return (*this); + } + + Notifier_mgr &operator= (const Notifier_mgr &IT_s) { + if (_ptr && _release) + Notifier_release (_ptr); + _ptr = Notifier_duplicate(IT_s._ptr); + _release = 1; + return (*this); + } + + Notifier_mgr &operator= (const Notifier_var &IT_s) { + if (_ptr && _release) + Notifier_release (_ptr); + _ptr = Notifier_duplicate(IT_s); + _release = 1; + return (*this); + } + + ~Notifier_mgr () { + if (_release) + Notifier_release (_ptr); + } + + unsigned char release () { + return _release; + } + + void release (unsigned char rel) { + _release = rel; + } + + operator int () const { + CORBA::Environment env; + CORBA::EnvExcRaiser IT_raise (&env); + return (!(CORBA::is_nil((CORBA::Object*) _ptr, env))); + } + + operator void* () const { + return _ptr; + } + + operator CORBA::Object * () const { + return (CORBA::Object *) _ptr; + } + + operator Notifier* () const { + return (Notifier*) _ptr; + } + + Notifier *_ptr; + + protected: + + unsigned char _release; +}; + +#endif + +#ifndef Event_Comm_NotifierSeqElemH +#define Event_Comm_NotifierSeqElemH + +class Notifier_SeqElem : public CORBA::_SeqElem +{ + public: + + Notifier_SeqElem (Event_Comm::Notifier_ptr* IT_p, unsigned char rel) { + _ptr = IT_p; + _release = rel; + } + + Notifier_SeqElem &operator= (Event_Comm::Notifier_ptr IT_p) { + if (!_ptr) + return (*this); + if (*(_ptr) && _release) + Notifier_release (*(_ptr)); + *(_ptr) = IT_p; + return (*this); + } + + Notifier_SeqElem &operator= (const Notifier_SeqElem &IT_s) { + if (!_ptr|| !IT_s._ptr) + return (*this); + if (*(_ptr) && _release) + Notifier_release (*(_ptr)); + *(_ptr) = Notifier_duplicate(*(IT_s._ptr)); + return (*this); + } + + operator Event_Comm::Notifier_ptr () const +{ + if (!_ptr) + return (Notifier_nil()); + return (Event_Comm::Notifier_ptr) (*_ptr); + } + + Notifier_ptr operator->() const { return *_ptr;} + + protected: + Event_Comm::Notifier_ptr *_ptr; + unsigned char _release; +}; + +#endif + + +#define TIE_Event_Comm_Notifier(X) Event_Comm_Notifier##X + +#define DEF_TIE_Event_Comm_Notifier(X) \ + class Event_Comm_Notifier##X : public virtual Event_Comm::Notifier { \ + X* m_obj; \ + public: \ + \ + Event_Comm_Notifier##X (X *objp, const char* m="", CORBA::LoaderClass *l=0)\ + : Event_Comm::Notifier(), CORBA::Object (), m_obj(objp) { \ + m_pptr = new Event_Comm::Notifier_dispatch \ + (( Event_Comm::Notifier*)this,(CORBA::Object*)this,m,l,Event_Comm_Notifier_IR,m_obj); \ + } \ + Event_Comm_Notifier##X (CORBA::Object *IT_p, const char* IT_m="", void *IT_q=0)\ + : Event_Comm::Notifier(), CORBA::Object () { \ + m_pptr = new Event_Comm::Notifier_dispatch \ + (( Event_Comm::Notifier*)this,(CORBA::Object*)this,IT_m,Event_Comm_Notifier_IR,IT_p,IT_q); \ + m_obj = (X*)(m_pptr->getImplObj ()); \ + } \ + \ + virtual ~Event_Comm_Notifier##X () { \ + if (_okToDeleteImpl ()) delete m_obj; } \ + \ + virtual void* _deref () { \ + return m_obj; } \ + \ + virtual void send_disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_disconnect ( reason,IT_env);\ +}\ + \ + virtual void send_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_notification ( notification,IT_env);\ +}\ + \ + virtual void subscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->subscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + \ + virtual void unsubscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->unsubscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + \ + }; + + +#define QUALS_Event_Comm_Notifier \ + virtual void send_disconnect (const char * reason, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_disconnect ( reason,IT_env);\ +}\ + \ + virtual void send_notification (const Event_Comm::Notification& notification, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->send_notification ( notification,IT_env);\ +}\ + \ + virtual void subscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->subscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + \ + virtual void unsubscribe (Event_Comm::Notification_Receiver_ptr notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) throw (CORBA::SystemException){\ + m_obj->unsubscribe ( notification_receiver, filtering_criteria,IT_env);\ +}\ + + + + +class NotifierProxyFactoryClass : public virtual CORBA::ObjectFactoryClass { +public: + NotifierProxyFactoryClass (unsigned char IT_p=0) + : CORBA::ProxyFactory (Event_Comm_Notifier_IR, IT_p) {} + + virtual void* New (char *IT_OR, CORBA::Environment&); + + virtual void* New (ObjectReference *IT_OR, CORBA::Environment&); + + virtual void* New2 (); + + virtual void* IT_castUp (void *IT_p, char* IT_s); + + virtual CORBA::PPTR* pptr (void *IT_p); + + virtual void baseInterfaces (_IDL_SEQUENCE_string&); + + +}; + +static NotifierProxyFactoryClass NotifierProxyFactory; + + + +#endif + +}; + + +void operator<<= (CORBA::any &IT_a, Event_Comm::Notification_Receiver_ptr IT_t); +CORBA::Boolean operator>>= (const CORBA::any &IT_a, Event_Comm::Notification_Receiver_ptr& IT_t); + + +void operator<<= (CORBA::any &IT_a, Event_Comm::Notifier_ptr IT_t); +CORBA::Boolean operator>>= (const CORBA::any &IT_a, Event_Comm::Notifier_ptr& IT_t); + + +void operator<<= (CORBA::any &IT_a, const Event_Comm::Notification& IT_t); +CORBA::Boolean operator>>= (const CORBA::any &IT_a, Event_Comm::Notification*& IT_t); + + +#endif diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm.idl b/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm.idl new file mode 100644 index 00000000000..26890129d70 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm.idl @@ -0,0 +1,92 @@ +/* -*- C++ -*- */ +// @(#)Event_Comm.idl 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Event_Comm.idl +// +// = DESCRIPTION +// The CORBA IDL module for distributed event notification. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#ifndef _EVENT_COMM_IDL +#define _EVENT_COMM_IDL + +module Event_Comm + // = TITLE + // The CORBA IDL module for distributed event notification. + // + // = DESCRIPTION +{ + struct Notification + // = TITLE + // Defines the interface for an event <Notification>. + // + // = This is the type passed by the Notifier to the Notification_Receiver. + // Since it contains an <any>, it can hold any values. Naturally, + // the consumer must understand how to interpret this! + { + string tag_; + // Tag for the notification. + + // any value_; + // A notification can contain anything. + +// Object object_ref_; + // Object reference for callbacks. + }; + + interface Notification_Receiver + // = TITLE + // Defines the interface for a <Notification_Receiver> of events. + // Note that all operations are <oneway> to avoid blocking. + // + // = DESCRIPTION + { + oneway void receive_notification (in Notification notification); + // Inform the <Notification_Receiver> that <event> has occurred. + + oneway void disconnect (in string reason); + // Disconnect the <Notification_Receiver> from the <Notifier>, + // giving it the <reason>. + }; + + interface Notifier + // = TITLE + // Defines the interface for a <Notifier> of events. + // + // = DESCRIPTION + { + oneway void send_disconnect (in string reason); + // Disconnect all the receivers, giving them the <reason>. + + oneway void send_notification (in Notification notification); + // Send the <Notification> to all the consumers who + // have subscribed and who match the filtering criteria. + + oneway void subscribe (in Notification_Receiver notification_receiver, + in string filtering_criteria); + // Subscribe the <Notification_Receiver> to receive events that + // match the regular expresssion <filtering_criteria> applied by + // the <Notifier>. If <filtering_criteria> is "" then all events + // are matched. + + oneway void unsubscribe (in Notification_Receiver notification_receiver, + in string filtering_criteria); + // Unsubscribe the <Notification_Receiver> that matches the + // filtering criteria. If <filtering_criteria> is "" then + // all <Notification_Receivers> with the matching object reference + // are removed. + }; +}; + +#endif /* _EVENT_COMM_IDL */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Event_CommC.cpp b/apps/Orbix-Examples/Event_Comm/libsrc/Event_CommC.cpp new file mode 100644 index 00000000000..eee25b11a72 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Event_CommC.cpp @@ -0,0 +1,351 @@ + +// @(#)Event_CommC.cpp 1.1 10/18/96 + +#include "Event_Comm.hh" + + +#ifndef Event_Comm_Notification_Ops +#define Event_Comm_Notification_Ops + +void Event_Comm::Notification:: encodeOp (CORBA::Request &IT_r) const { + IT_r.encodeStringOp (tag_); +} + +void Event_Comm::Notification:: decodeOp (CORBA::Request &IT_r) { + IT_r.decodeStringOp(tag_); +} + +void Event_Comm::Notification:: decodeInOutOp (CORBA::Request &IT_r) { + IT_r.decodeInOutStrOp(tag_, 0); +} + +void* Event_Comm::Notification:: IT_anySupport (CORBA::Request &IT_r, + void *& IT_v, void *IT_to, const CORBA::Flags& IT_f) { + Event_Comm::Notification* IT_l = (Event_Comm::Notification*)IT_v; + + if (IT_f.isSetAll (CORBA::ARG_INOUT)) { + if (!IT_l) + IT_l = new Event_Comm::Notification(); + IT_l -> decodeInOutOp (IT_r); + IT_v = IT_l; + } + else if (IT_f.isSet (CORBA::ARG_IN)) { + IT_l -> encodeOp (IT_r); + } + else if (IT_f.isSet (CORBA::ARG_OUT)) { + if (!IT_l) + IT_l = new Event_Comm::Notification(); + IT_l -> decodeOp (IT_r); + IT_v = IT_l; + } + else if (IT_f.isSet (CORBA::_ANY_ASSIGN)) { + Event_Comm::Notification*IT_s = IT_to ? (Event_Comm::Notification*)IT_to : new Event_Comm::Notification; + *IT_s = *IT_l; return IT_s; + } + else if (IT_f.isSet (CORBA::_ANY_DELETE)) { + if (IT_to) IT_l->Event_Comm::Notification::~Notification(); + else delete IT_l; + return NULL; + } + else if (IT_f.isSet (CORBA::_ANY_SIZEOF)) { + return (void*) (sizeof (Event_Comm::Notification)); + } + else if (IT_f.isNil ()) { + if (!IT_l) + IT_l = new Event_Comm::Notification(); + IT_l -> decodeOp (IT_r); + IT_v = IT_l; + } + return NULL; +} + +const void *Event_Comm::Notification:: IT_fn = +CORBA::anyTable.record ("Event_Comm::Notification", &Event_Comm::Notification:: IT_anySupport); + +Event_Comm::Notification &Event_Comm::Notification:: operator= (const Event_Comm::IONANC_Notification& IT_p) { + this->operator= (*(Event_Comm::Notification*) &IT_p); + return (*this); +} + +Event_Comm::Notification:: operator Event_Comm::IONANC_Notification () { + Event_Comm::IONANC_Notification tmp; + memset (&tmp, 0, sizeof(tmp)); + ((Event_Comm::Notification *) &tmp)->operator= (*this); + return tmp; +} + +Event_Comm::Notification:: operator const Event_Comm::IONANC_Notification () const { + Event_Comm::IONANC_Notification tmp; + memset (&tmp, 0, sizeof(tmp)); + ((Event_Comm::Notification *) &tmp)->operator= (*this); + return tmp; +} + +Event_Comm::Notification::~Notification () { + if (tag_) delete [] tag_; +} + +Event_Comm::Notification:: Notification (const Event_Comm::Notification &IT_s) + { + if (IT_s.tag_) { + tag_=new char [strlen(IT_s.tag_)+1]; + strcpy (tag_, IT_s.tag_); + } + else { + tag_ = NULL; + } +} + +Event_Comm::Notification:: Notification () { + tag_ = NULL; +} + +Event_Comm::Notification &Event_Comm::Notification:: operator= (const Event_Comm::Notification& IT_s) { + if (this == &IT_s) return *this; + if (tag_) delete [] tag_; + if (IT_s.tag_) { + tag_=new char [strlen(IT_s.tag_)+1]; + strcpy (tag_, IT_s.tag_); + } + else { + tag_ = NULL; + } + return *this; +} + +Event_Comm::IONANC_Notification:: operator Event_Comm::Notification () { + return (*((Event_Comm::Notification *) this)); +} + +Event_Comm::IONANC_Notification:: operator const Event_Comm::Notification () const { + return (*((const Event_Comm::Notification *) this)); +} + + +#endif +Event_Comm::Notification_Receiver::Notification_Receiver (char *IT_OR) { + m_pptr = new Notification_Receiver_dispatch (IT_OR, this,(CORBA::Object*)this); +} + +#ifndef Event_Comm_Notification_ReceiverForwC +#define Event_Comm_Notification_ReceiverForwC +CORBA::ObjectRef Event_Comm::Notification_Receiver_getBase(void *IT_p){ + return (Event_Comm::Notification_Receiver*)IT_p;} + +void Event_Comm::Notification_Receiver_release (void *IT_p, CORBA::Environment &IT_env) { + ((Event_Comm::Notification_Receiver*)IT_p)->_release(IT_env);} + +Event_Comm::Notification_Receiver* Event_Comm::Notification_Receiver_duplicate (void *IT_p, CORBA::Environment &IT_env) { + return ((Event_Comm::Notification_Receiver*)IT_p)->_duplicate(IT_env); } +#endif + + + +Event_Comm::Notification_Receiver* Event_Comm::Notification_Receiver:: _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env) { + Notification_Receiver*IT_p = + (Notification_Receiver*)CORBA::Factory.New (IT_markerServer, IT_env, IT_c, host, + Event_Comm_Notification_Receiver_IMPL, Event_Comm_Notification_Receiver_IR); + return IT_p ? IT_p->_duplicate () : NULL; } + + + +Event_Comm::Notification_Receiver* Event_Comm::Notification_Receiver:: _bind (CORBA::Environment &IT_env) { + return _bind (NULL,NULL,CORBA::Context(), IT_env); } + + +Event_Comm::Notification_Receiver* Event_Comm::Notification_Receiver:: _bind (const char* IT_markerServer, const char* host, + CORBA::Environment &IT_env) { + return _bind (IT_markerServer, host, CORBA::Context (), IT_env); } +Event_Comm::Notification_Receiver* Event_Comm::Notification_Receiver::_narrow (CORBA::Object* IT_obj, CORBA::Environment &IT_env) { + Event_Comm::Notification_Receiver* IT_p = (Event_Comm::Notification_Receiver*)CORBA::Object::_castDown (IT_obj, Event_Comm_Notification_Receiver_IR, IT_env); + return IT_p ? IT_p->_duplicate(IT_env) : NULL; + } + +void* Event_Comm::Notification_ReceiverProxyFactoryClass::New (char *IT_OR, CORBA::Environment&) { + return new Notification_Receiver(IT_OR);} + +void* Event_Comm::Notification_ReceiverProxyFactoryClass::New2 () { + return new Notification_Receiver();} + +void* Event_Comm::Notification_ReceiverProxyFactoryClass::IT_castUp (void *IT_p, char* IT_s) { + void *IT_l; + if (!CORBA::_interfaceCmp (IT_s,Event_Comm_Notification_Receiver_IR)) + return IT_p; + else if (IT_l=CORBA::ObjectFactoryClass::IT_castUp((CORBA::Object*)((Event_Comm::Notification_Receiver*)IT_p),IT_s)) + return IT_l; + else return NULL; + } + + +CORBA::PPTR* Event_Comm::Notification_ReceiverProxyFactoryClass::pptr (void *IT_p) { + return ((Event_Comm::Notification_Receiver*)IT_p)->_pptr ();} + +void Event_Comm::Notification_ReceiverProxyFactoryClass::baseInterfaces (_IDL_SEQUENCE_string& seq) { + add (seq, Event_Comm_Notification_Receiver_IR); + CORBA::ObjectFactoryClass::baseInterfaces (seq); +} + + void Event_Comm::Notification_Receiver:: receive_notification(const Event_Comm::Notification& notification, CORBA::Environment &IT_env) { + + if (IT_env || m_isNull) return ; + CORBA::Request IT_r (this, "receive_notification",IT_env,1,1); + if (!IT_r.isException (IT_env)) { + notification.encodeOp (IT_r); + } + + IT_r.invoke (CORBA::Flags(CORBA::INV_NO_RESPONSE), IT_env); + } + + void Event_Comm::Notification_Receiver:: disconnect(const char * reason, CORBA::Environment &IT_env) { + + if (IT_env || m_isNull) return ; + CORBA::Request IT_r (this, "disconnect",IT_env,1,1); + if (!IT_r.isException (IT_env)) { + IT_r.encodeStringOp (reason); + } + + IT_r.invoke (CORBA::Flags(CORBA::INV_NO_RESPONSE), IT_env); + } + + +Event_Comm::Notification_ReceiverProxyFactoryClass Event_Comm::Notification_ReceiverProxyFactory(1); + + +#ifndef Event_Comm_Notification_Receiver_dispatch_impl + +unsigned char Event_Comm::Notification_Receiver_dispatch::dispatch (CORBA::Request &IT_r, + unsigned char, void *) { + IT_r.makeRuntimeException1 ("Event_Comm::Notification_Receiver"); + return 0; +} + +#endif + +Event_Comm::Notifier::Notifier (char *IT_OR) { + m_pptr = new Notifier_dispatch (IT_OR, this,(CORBA::Object*)this); +} + +#ifndef Event_Comm_NotifierForwC +#define Event_Comm_NotifierForwC +CORBA::ObjectRef Event_Comm::Notifier_getBase(void *IT_p){ + return (Event_Comm::Notifier*)IT_p;} + +void Event_Comm::Notifier_release (void *IT_p, CORBA::Environment &IT_env) { + ((Event_Comm::Notifier*)IT_p)->_release(IT_env);} + +Event_Comm::Notifier* Event_Comm::Notifier_duplicate (void *IT_p, CORBA::Environment &IT_env) { + return ((Event_Comm::Notifier*)IT_p)->_duplicate(IT_env); } +#endif + + + +Event_Comm::Notifier* Event_Comm::Notifier:: _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env) { + Notifier*IT_p = + (Notifier*)CORBA::Factory.New (IT_markerServer, IT_env, IT_c, host, + Event_Comm_Notifier_IMPL, Event_Comm_Notifier_IR); + return IT_p ? IT_p->_duplicate () : NULL; } + + + +Event_Comm::Notifier* Event_Comm::Notifier:: _bind (CORBA::Environment &IT_env) { + return _bind (NULL,NULL,CORBA::Context(), IT_env); } + + +Event_Comm::Notifier* Event_Comm::Notifier:: _bind (const char* IT_markerServer, const char* host, + CORBA::Environment &IT_env) { + return _bind (IT_markerServer, host, CORBA::Context (), IT_env); } +Event_Comm::Notifier* Event_Comm::Notifier::_narrow (CORBA::Object* IT_obj, CORBA::Environment &IT_env) { + Event_Comm::Notifier* IT_p = (Event_Comm::Notifier*)CORBA::Object::_castDown (IT_obj, Event_Comm_Notifier_IR, IT_env); + return IT_p ? IT_p->_duplicate(IT_env) : NULL; + } + +void* Event_Comm::NotifierProxyFactoryClass::New (char *IT_OR, CORBA::Environment&) { + return new Notifier(IT_OR);} + +void* Event_Comm::NotifierProxyFactoryClass::New2 () { + return new Notifier();} + +void* Event_Comm::NotifierProxyFactoryClass::IT_castUp (void *IT_p, char* IT_s) { + void *IT_l; + if (!CORBA::_interfaceCmp (IT_s,Event_Comm_Notifier_IR)) + return IT_p; + else if (IT_l=CORBA::ObjectFactoryClass::IT_castUp((CORBA::Object*)((Event_Comm::Notifier*)IT_p),IT_s)) + return IT_l; + else return NULL; + } + + +CORBA::PPTR* Event_Comm::NotifierProxyFactoryClass::pptr (void *IT_p) { + return ((Event_Comm::Notifier*)IT_p)->_pptr ();} + +void Event_Comm::NotifierProxyFactoryClass::baseInterfaces (_IDL_SEQUENCE_string& seq) { + add (seq, Event_Comm_Notifier_IR); + CORBA::ObjectFactoryClass::baseInterfaces (seq); +} + + void Event_Comm::Notifier:: send_disconnect(const char * reason, CORBA::Environment &IT_env) { + + if (IT_env || m_isNull) return ; + CORBA::Request IT_r (this, "send_disconnect",IT_env,1,1); + if (!IT_r.isException (IT_env)) { + IT_r.encodeStringOp (reason); + } + + IT_r.invoke (CORBA::Flags(CORBA::INV_NO_RESPONSE), IT_env); + } + + void Event_Comm::Notifier:: send_notification(const Event_Comm::Notification& notification, CORBA::Environment &IT_env) { + + if (IT_env || m_isNull) return ; + CORBA::Request IT_r (this, "send_notification",IT_env,1,1); + if (!IT_r.isException (IT_env)) { + notification.encodeOp (IT_r); + } + + IT_r.invoke (CORBA::Flags(CORBA::INV_NO_RESPONSE), IT_env); + } + + void Event_Comm::Notifier:: subscribe(Event_Comm::Notification_Receiver* notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) { + + if (IT_env || m_isNull) return ; + CORBA::Request IT_r (this, "subscribe",IT_env,1,1); + if (!IT_r.isException (IT_env)) { + IT_r << (CORBA::Object*)notification_receiver; + + IT_r.encodeStringOp (filtering_criteria); + } + + IT_r.invoke (CORBA::Flags(CORBA::INV_NO_RESPONSE), IT_env); + } + + void Event_Comm::Notifier:: unsubscribe(Event_Comm::Notification_Receiver* notification_receiver, const char * filtering_criteria, CORBA::Environment &IT_env) { + + if (IT_env || m_isNull) return ; + CORBA::Request IT_r (this, "unsubscribe",IT_env,1,1); + if (!IT_r.isException (IT_env)) { + IT_r << (CORBA::Object*)notification_receiver; + + IT_r.encodeStringOp (filtering_criteria); + } + + IT_r.invoke (CORBA::Flags(CORBA::INV_NO_RESPONSE), IT_env); + } + + +Event_Comm::NotifierProxyFactoryClass Event_Comm::NotifierProxyFactory(1); + + +#ifndef Event_Comm_Notifier_dispatch_impl + +unsigned char Event_Comm::Notifier_dispatch::dispatch (CORBA::Request &IT_r, + unsigned char, void *) { + IT_r.makeRuntimeException1 ("Event_Comm::Notifier"); + return 0; +} + +#endif + diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Event_CommS.cpp b/apps/Orbix-Examples/Event_Comm/libsrc/Event_CommS.cpp new file mode 100644 index 00000000000..9adc4cb26d4 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Event_CommS.cpp @@ -0,0 +1,166 @@ + +// @(#)Event_CommS.cpp 1.1 10/18/96 + +#include "Event_Comm.hh" + + +#define Event_Comm_Notification_Receiver_dispatch_impl + +unsigned char Event_Comm::Notification_Receiver_dispatch::dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void *IT_pp) { + if (!IT_pp) + IT_pp = m_obj; + const char *IT_s = IT_r.getOperation (); + if (!strcmp(IT_s,"receive_notification")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~receive_notification~+notification{R~Event_Comm::Notification~tag_{0}},>{v},O{}\ +")) + return 1; + Event_Comm::Notification notification; + notification.decodeOp (IT_r); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((Event_Comm::Notification_Receiver*)IT_pp)->receive_notification ( notification, IT_env); + + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + return 1; + } + + else if (!strcmp(IT_s,"disconnect")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~disconnect~+reason{0},>{v},O{}\ +")) + return 1; + char * reason; + IT_r.decodeStringOp(reason); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((Event_Comm::Notification_Receiver*)IT_pp)->disconnect ( reason, IT_env); + + delete [] reason; + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + return 1; + } + + else if (IT_isTarget) + IT_r.makeRuntimeException2 (); + + return 0; +} + +#define Event_Comm_Notifier_dispatch_impl + +unsigned char Event_Comm::Notifier_dispatch::dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void *IT_pp) { + if (!IT_pp) + IT_pp = m_obj; + const char *IT_s = IT_r.getOperation (); + if (!strcmp(IT_s,"send_disconnect")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~send_disconnect~+reason{0},>{v},O{}\ +")) + return 1; + char * reason; + IT_r.decodeStringOp(reason); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((Event_Comm::Notifier*)IT_pp)->send_disconnect ( reason, IT_env); + + delete [] reason; + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + return 1; + } + + else if (!strcmp(IT_s,"send_notification")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~send_notification~+notification{R~Event_Comm::Notification~tag_{0}},>{v},O{}\ +")) + return 1; + Event_Comm::Notification notification; + notification.decodeOp (IT_r); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((Event_Comm::Notifier*)IT_pp)->send_notification ( notification, IT_env); + + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + return 1; + } + + else if (!strcmp(IT_s,"subscribe")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~subscribe~+notification_receiver{O~Event_Comm::Notification_Receiver},+filtering_criteria{0},>{v},O{}\ +")) + return 1; + Event_Comm::Notification_Receiver* notification_receiver; + notification_receiver = (Event_Comm::Notification_Receiver*) IT_r.decodeObjRef (Event_Comm_Notification_Receiver_IR); + if (notification_receiver) notification_receiver->_duplicate (); + + char * filtering_criteria; + IT_r.decodeStringOp(filtering_criteria); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((Event_Comm::Notifier*)IT_pp)->subscribe ( notification_receiver, filtering_criteria, IT_env); + + if (notification_receiver) notification_receiver->_release (); + + delete [] filtering_criteria; + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + + return 1; + } + + else if (!strcmp(IT_s,"unsubscribe")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~unsubscribe~+notification_receiver{O~Event_Comm::Notification_Receiver},+filtering_criteria{0},>{v},O{}\ +")) + return 1; + Event_Comm::Notification_Receiver* notification_receiver; + notification_receiver = (Event_Comm::Notification_Receiver*) IT_r.decodeObjRef (Event_Comm_Notification_Receiver_IR); + if (notification_receiver) notification_receiver->_duplicate (); + + char * filtering_criteria; + IT_r.decodeStringOp(filtering_criteria); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((Event_Comm::Notifier*)IT_pp)->unsubscribe ( notification_receiver, filtering_criteria, IT_env); + + if (notification_receiver) notification_receiver->_release (); + + delete [] filtering_criteria; + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + + return 1; + } + + else if (IT_isTarget) + IT_r.makeRuntimeException2 (); + + return 0; +} + +#include "Event_CommC.cpp" + diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm_i.h b/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm_i.h new file mode 100644 index 00000000000..2db73e2f616 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Event_Comm_i.h @@ -0,0 +1,38 @@ +/* -*- C++ -*- */ +// @(#)Event_Comm_i.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Event_Comm_i.h +// +// = DESCRIPTION +// Class interface for the implementation of the distributed +// event notification mechanism. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_EVENT_COMM_I_H) +#define _EVENT_COMM_I_H + +#include "Notification_Receiver_i.h" +#include "Notifier_i.h" + +#if defined (ACE_HAS_ORBIX) +#define nil 0 + +// Tie the Notification_Receiver and Notifier implementation classes +// together with the IDL interface. + +DEF_TIE_Event_Comm_Notification_Receiver (Notification_Receiver_i) +DEF_TIE_Event_Comm_Notifier (Notifier_i) + +#endif /* ACE_HAS_ORBIX */ +#endif /* _EVENT_COMM_I_H */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Makefile b/apps/Orbix-Examples/Event_Comm/libsrc/Makefile new file mode 100644 index 00000000000..add9fd31151 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Makefile @@ -0,0 +1,113 @@ +#---------------------------------------------------------------------------- +# @(#)Makefile 1.1 10/18/96 +# +# Makefile for the Event Communications library +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +LIB = libEvent_Comm.a +SHLIB = libEvent_Comm.so + +FILES = Event_CommS \ + Event_CommC \ + Notifier_i \ + Notification_Receiver_i + +LSRC = $(addsuffix .cpp,$(FILES)) +LOBJ = $(addsuffix .o,$(FILES)) +SHOBJ = $(addsuffix .so,$(FILES)) + +VLDLIBS = $(LDLIBS:%=%$(VAR)) + +BUILD = $(VLIB) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.lib.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Orbix related macros and target settings. +#---------------------------------------------------------------------------- + +ORBIX_BINDIR = $(ORBIX_ROOT)/bin +ORBIX_LIBDIR = $(ORBIX_ROOT)/lib +ORBIX_INCDIR = $(ORBIX_ROOT)/include + +CPPFLAGS += -DEXCEPTIONS -I$(ORBIX_INCDIR) -DWANT_ORBIX_FDS +LDFLAGS += -L$(ORBIX_LIBDIR) -R $(ORBIX_LIBDIR) + +IDLFLAGS = -A -s S.cpp -c C.cpp + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + +Event_CommS.o: Event_CommS.cpp Event_Comm.hh Event_CommC.cpp +Event_CommC.o: Event_CommC.cpp Event_Comm.hh +Notifier_i.o: Notifier_i.cpp \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + Notification_Receiver_i.h Notifier_i.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Map_Manager.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/SString.i \ + Event_Comm.hh +Notification_Receiver_i.o: Notification_Receiver_i.cpp \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/sysincludes.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Priority.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Record.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Log_Msg.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Time_Value.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Synch_T.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Specific.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Config.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Handle_Set.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Event_Handler.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Timer_Queue.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Signal.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Set.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Token.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Reactor.i \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Shared_Object.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Service_Record.h \ + /project/adaptive/ACE_wrappers/build/SunOS5.4/include/ace/Thread_Manager.h \ + Notification_Receiver_i.h + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notification.idl b/apps/Orbix-Examples/Event_Comm/libsrc/Notification.idl new file mode 100644 index 00000000000..ecfd5adb8e0 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notification.idl @@ -0,0 +1,42 @@ +/* -*- C++ -*- */ +// @(#)Notification.idl 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notification.idl +// +// = DESCRIPTION +// This is the CORBA IDL interface for the Event Communication <Notification>. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#ifndef _NOTIFICATION_IDL +#define _NOTIFICATION_IDL + +struct Notification + // = TITLE + // Defines the interface for an event <Notification>. + // + // = This is the type passed by the Notifier to the Notification_Receiver. + // Since it contains an <any>, it can hold any values. Naturally, + // the consumer must understand how to interpret this! +{ + string tag_; + // Tag for the notification. + +// any value_; + // A notification can contain anything. + + Object object_ref_; + // Object reference for callbacks. +}; + +#endif /* _NOTIFICATION_IDL */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver.idl b/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver.idl new file mode 100644 index 00000000000..222f18782f7 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver.idl @@ -0,0 +1,42 @@ +/* -*- C++ -*- */ +// @(#)Notification_Receiver.idl 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notification_Receiver.idl +// +// = DESCRIPTION +// The CORBA IDL interface for the Event Communication +// <Notification_Receiver> component. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#include "Notification.idl" + +#ifndef _Notification_Receiver_iDL +#define _Notification_Receiver_iDL + +interface Notification_Receiver + // = TITLE + // Defines the interface for a <Notification_Receiver> of events. + // Note that all operations are <oneway> to avoid blocking. + // + // = DESCRIPTION +{ + oneway void receive_notification (in Notification notification); + // Inform the <Notification_Receiver> that <event> has occurred. + + oneway void disconnect (in string reason); + // Disconnect the <Notification_Receiver> from the <Notifier>, + // giving it the <reason>. +}; + +#endif /* _Notification_Receiver_iDL */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver_i.cpp b/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver_i.cpp new file mode 100644 index 00000000000..337cf91e31e --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver_i.cpp @@ -0,0 +1,39 @@ +#include "ace/Log_Msg.h" +// @(#)Notification_Receiver_i.cpp 1.1 10/18/96 + +#include "ace/Service_Config.h" +#include "Notification_Receiver_i.h" + +#if defined (ACE_HAS_ORBIX) + +Notification_Receiver_i::Notification_Receiver_i (void) +{ +} + +Notification_Receiver_i::~Notification_Receiver_i (void) +{ +} + +// Inform the <Event_Comm::Notification_Receiver> that <event> has occurred. + +void +Notification_Receiver_i::receive_notification + (const Event_Comm::Notification ¬ification, + CORBA::Environment &IT_env) +{ + const char *tmpstr = notification.tag_; + + ACE_DEBUG ((LM_DEBUG, "**** got notification = %s\n", tmpstr)); +} + +// Disconnect the <Event_Comm::Notification_Receiver> from the <Event_Comm::Notifier>. + +void +Notification_Receiver_i::disconnect (const char *reason, + CORBA::Environment &IT_env) +{ + ACE_DEBUG ((LM_DEBUG, "**** got disconnected due to %s\n", reason)); + ACE_Service_Config::end_reactor_event_loop (); +} + +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver_i.h b/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver_i.h new file mode 100644 index 00000000000..4f0bcc980e4 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notification_Receiver_i.h @@ -0,0 +1,48 @@ +/* -*- C++ -*- */ +// @(#)Notification_Receiver_i.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notification_Receiver__i.h +// +// = DESCRIPTION +// Class interface for the implementation of the <Notification_Receiver> +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_Notification_Receiver_i_H) +#define _Notification_Receiver_i_H + +#if defined (ACE_HAS_ORBIX) +#include "Event_Comm.hh" + +class Notification_Receiver_i + // = TITLE + // Defines the implementation class for event <Notification_Receivers>. + // + // = DESCRIPTION +{ +public: + Notification_Receiver_i (void); + ~Notification_Receiver_i (void); + + virtual void receive_notification (const Event_Comm::Notification ¬ification, + CORBA::Environment &IT_env); + // Pass the <Notification> to the <Notification_Receiver>. + + virtual void disconnect (const char *reason, + CORBA::Environment &IT_env); + // Disconnect the <Notification_Receiver> from the <Notifier>, + // giving it the <reason>. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _Notification_Receiver_i_H */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notifier.idl b/apps/Orbix-Examples/Event_Comm/libsrc/Notifier.idl new file mode 100644 index 00000000000..75e738e0627 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notifier.idl @@ -0,0 +1,49 @@ +/* -*- C++ -*- */ +// @(#)Notifier.idl 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notifier.idl +// +// = DESCRIPTION +// This is the CORBA IDL interface for the Event Communication <Notifier>. +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#ifndef _Notifier_iDL +#define _Notifier_iDL + +#include "Notification.idl" +#include "Notification_Receiver.idl" + +interface Notifier + // = TITLE + // Defines the interface for a <Notifier> of events. + // + // = DESCRIPTION +{ + oneway void send_disconnect (in string reason); + // Disconnect all the receivers, giving them the <reason>. + + oneway void send_notification (in Notification notification); + // Send the <Notification> to all the consumers who + // have subscribed and who match the filtering criteria. + + oneway void subscribe (in Notification_Receiver notification_receiver, + in string filtering_criteria); + // Subscribe the <Notification_Receiver> to receive events that + // match <filtering_criteria> applied by the <Notifier>. + + oneway void unsubscribe (in Notification_Receiver notification_receiver); + // Unsubscribe the <Notification_Receiver>. +}; + +#endif /* _Notifier_iDL */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notifier_i.cpp b/apps/Orbix-Examples/Event_Comm/libsrc/Notifier_i.cpp new file mode 100644 index 00000000000..1edefc82a29 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notifier_i.cpp @@ -0,0 +1,324 @@ +#include "ace/Log_Msg.h" +// @(#)Notifier_i.cpp 1.1 10/18/96 + +#include "Notification_Receiver_i.h" +#include "Notifier_i.h" + +#if defined (ACE_HAS_ORBIX) + +class Notification_Receiver_Entry + // = TITLE + // Keeps track of context information associated with + // a <Event_Comm::Notification_Receiver> entry. + // + // = DESCRIPTION + // +{ +public: + Notification_Receiver_Entry (Event_Comm::Notification_Receiver *notification_receiver, + const char *filtering_criteria); + ~Notification_Receiver_Entry (void); + + // = Set/get filtering criteria. + void criteria (const char *criteria); + const char *criteria (void); + + // = Set/get Event_Comm::Notification_Receiver object reference. + Event_Comm::Notification_Receiver *receiver (void); + void receiver (Event_Comm::Notification_Receiver *); + + // = Set/get the compiled regular expression buffer. + const char *regexp (void); + void regexp (char *); + +private: + const char *filtering_criteria_; + // String containing the filtering criteria. + + char *compiled_regexp_; + // Compiled representation of the regular expression (see + // regexpr(3g)). + + Event_Comm::Notification_Receiver *receiver_; + // Object reference for the Event_Comm::Notification_Receiver. +}; + +// = Set/get filtering criteria. + +void +Notification_Receiver_Entry::criteria (const char *criteria) +{ + ACE_OS::free (ACE_MALLOC_T (this->filtering_criteria_)); + this->filtering_criteria_ = ACE_OS::strdup (criteria); +} + +const char * +Notification_Receiver_Entry::criteria (void) +{ + return this->filtering_criteria_; +} + +// = Set/get Event_Comm::Notification_Receiver object reference. + +Event_Comm::Notification_Receiver * +Notification_Receiver_Entry::receiver (void) +{ + return this->receiver_; +} + +void +Notification_Receiver_Entry::receiver (Event_Comm::Notification_Receiver *receiver) +{ + this->receiver_ = receiver; +} + +const char * +Notification_Receiver_Entry::regexp (void) +{ + return this->compiled_regexp_; +} + +void +Notification_Receiver_Entry::regexp (char *regexp) +{ + ACE_OS::free (ACE_MALLOC_T (this->compiled_regexp_)); + this->compiled_regexp_ = regexp; +} + +Notification_Receiver_Entry::Notification_Receiver_Entry (Event_Comm::Notification_Receiver *receiver, + const char *filtering_criteria) + : receiver_ (receiver), + filtering_criteria_ (0), + compiled_regexp_ (0) +{ + char *compile_buffer = 0; + + this->criteria (filtering_criteria); + ACE_ASSERT (this->criteria ()); + + // Check for wildcard case first. + if (ACE_OS::strcmp (filtering_criteria, "") == 0) + compile_buffer = ACE_OS::strdup (""); + else // Compile the regular expression (the 0's cause ACE_OS::compile to allocate space). + compile_buffer = ACE_OS::compile (filtering_criteria, 0, 0); + + // Should throw an exception here! + ACE_ASSERT (compile_buffer != 0); + + this->regexp (compile_buffer); + ACE_ASSERT (this->regexp ()); + + // Increment the reference count since we are keeping a copy of + // this... + this->receiver_->_duplicate (this->receiver_); +} + +Notification_Receiver_Entry::~Notification_Receiver_Entry (void) +{ + ACE_OS::free (this->filtering_criteria_); + ACE_OS::free (this->compiled_regexp_); + // Decrement the object reference count. + CORBA::release (this->receiver_); +} + +Notifier_i::Notifier_i (size_t size) + : map_ (size) +{ +} + +// Add a new receiver to the table, being careful to check for +// duplicate entries. A receiver is considered a duplicate under +// the following circumstances: +// 1. It has the same marker name and the same filtering criteria +// 2. It has the same marker name and its filtering criteria is "" (the wild card). + +void +Notifier_i::subscribe (Event_Comm::Notification_Receiver *receiver_ref, + const char *filtering_criteria, + CORBA::Environment &IT_env) +{ + ACE_DEBUG ((LM_DEBUG, + "in Notifier_i::subscribe for %s with filtering criteria \"%s\"\n", + receiver_ref->_marker (), filtering_criteria)); + ACE_SString key (receiver_ref->_marker ()); + MAP_ITERATOR mi (this->map_); + + // Try to locate an entry using its marker name (which should be + // unique across the system). If we don't find the entry, or if the + // filtering criteria is different that is good news since we + // currently don't allow duplicates... In particular, if @@ Should + // duplicates be allowed? + + for (MAP_ENTRY *me = 0; mi.next (me) != 0; mi.advance ()) + { + Notification_Receiver_Entry *nr_entry = me->int_id_; + + // Check for a duplicate entry. + if (key == me->ext_id_ + && (ACE_OS::strcmp (filtering_criteria, "") == 0 + || ACE_OS::strcmp (filtering_criteria, nr_entry->criteria ()) == 0)) + { + // Inform the caller that the + // Event_Comm::Notification_Receiver * is already being + // used. + + errno = EADDRINUSE; + ACE_ERROR ((LM_ERROR, + "duplicate entry for receiver %s with criteria \"%s\"", + receiver_ref->_marker (), filtering_criteria)); + // Raise exception here??? + return; + } + } + + // If we get this far then we didn't find a duplicate, so add the + // new entry! + Notification_Receiver_Entry *nr_entry = + new Notification_Receiver_Entry (receiver_ref, filtering_criteria); + + if (nr_entry == 0) + { + errno = ENOMEM; + ACE_ERROR ((LM_ERROR, "%p\n", "new failed")); + // Raise exception here... + } + // Try to add new <Notification_Receiver_Entry> to the map. + else if (this->map_.bind (key, nr_entry) == -1) + { + // Prevent memory leaks. + delete nr_entry; + // Raise exception here... + ACE_ERROR ((LM_ERROR, "%p\n", "bind failed")); + } +} + +// Remove a receiver from the table. + +void +Notifier_i::unsubscribe (Event_Comm::Notification_Receiver *receiver_ref, + const char *filtering_criteria, + CORBA::Environment &IT_env) +{ + ACE_DEBUG ((LM_DEBUG, "in Notifier_i::unsubscribe for %s\n", + receiver_ref->_marker ())); + Notification_Receiver_Entry *nr_entry = 0; + ACE_SString key; + MAP_ITERATOR mi (this->map_); + int found = 0; + + // Don't make a copy since we are deleting... + key.rep ((char *) receiver_ref->_marker ()); + + // Locate <Notification_Receiver_Entry> and free up resources. @@ + // Note, we don't properly handle deallocation of KEYS! + + for (MAP_ENTRY *me = 0; mi.next (me) != 0; mi.advance ()) + { + if (key == me->ext_id_ + && (ACE_OS::strcmp (filtering_criteria, "") == 0 + || ACE_OS::strcmp (filtering_criteria, nr_entry->criteria ()) == 0)) + { + ACE_DEBUG ((LM_DEBUG, "removed entry %s with criteria \"%s\"\n", + receiver_ref->_marker (), filtering_criteria)); + found = 1; + // @@ This is a hack, we need a better approach! + if (this->map_.unbind (key, nr_entry) == -1) + ACE_ERROR ((LM_ERROR, "unbind failed for %s\n", + receiver_ref->_marker ())); + else + delete nr_entry; + } + } + + if (found == 0) + ACE_ERROR ((LM_ERROR, "entry %s with criteria \"%s\" not found\n", + receiver_ref->_marker (), filtering_criteria)); +} + +// Disconnect all the receivers, giving them the <reason>. + +void +Notifier_i::send_disconnect (const char *reason, + CORBA::Environment &IT_env) +{ + ACE_DEBUG ((LM_DEBUG, "in Notifier_i::send_disconnect = %s\n", reason)); + + MAP_ITERATOR mi (this->map_); + int count = 0; + + // Notify all the receivers, taking into account the filtering criteria. + + for (MAP_ENTRY *me = 0; mi.next (me) != 0; mi.advance ()) + { + Event_Comm::Notification_Receiver *receiver_ref = me->int_id_->receiver (); + ACE_ASSERT (receiver_ref->_marker () != 0); + ACE_DEBUG ((LM_DEBUG, "disconnecting client %s\n", receiver_ref->_marker ())); + TRY { + receiver_ref->disconnect (reason, IT_X); + } + CATCHANY { + cerr << "Unexpected exception " << IT_X << endl; + } + ENDTRY; + delete me->int_id_; + delete me->ext_id_.rep (); + count++; + } + + this->map_.close (); + if (count == 1) + ACE_DEBUG ((LM_DEBUG, "there was 1 receiver\n")); + else + ACE_DEBUG ((LM_DEBUG, "there were %d receivers\n", count)); +} + +// Notify all receivers whose filtering criteria match the event. + +void +Notifier_i::send_notification (const Event_Comm::Notification ¬ification, + CORBA::Environment &IT_env) +{ + ACE_DEBUG ((LM_DEBUG, "in Notifier_i::send_notification = %s\n", + notification.tag_)); + MAP_ITERATOR mi (this->map_); + int count = 0; + + // Notify all the receivers. + // @@ Later on we need to consider the filtering_criteria! + + for (MAP_ENTRY *me = 0; mi.next (me) != 0; mi.advance ()) + { + Event_Comm::Notification_Receiver *receiver_ref = me->int_id_->receiver (); + ACE_ASSERT (receiver_ref->_marker () != 0); + const char *regexp = me->int_id_->regexp (); + const char *criteria = me->int_id_->criteria (); + ACE_ASSERT (regexp); + ACE_ASSERT (criteria); + + // Do a regular expression comparison to determine matching. + if (ACE_OS::strcmp ("", criteria) == 0 // Everything matches the wildcard. +// || ACE_OS::strcmp (notification.tag_, regexp) == 0) + || ACE_OS::step (notification.tag_, regexp) != 0) + { + ACE_DEBUG ((LM_DEBUG, "string %s matched regexp \"%s\" for client %s\n", + notification.tag_, me->int_id_->criteria (), + receiver_ref->_marker ())); + TRY { + receiver_ref->receive_notification (notification, IT_X); + } + CATCHANY { + cerr << "Unexpected exception " << IT_X << endl; + continue; + } + ENDTRY; + count++; + } + } + + if (count == 1) + ACE_DEBUG ((LM_DEBUG, "there was 1 receiver\n")); + else + ACE_DEBUG ((LM_DEBUG, "there were %d receivers\n", count)); +} + +#endif /* ACE_HAS_ORBIX */ diff --git a/apps/Orbix-Examples/Event_Comm/libsrc/Notifier_i.h b/apps/Orbix-Examples/Event_Comm/libsrc/Notifier_i.h new file mode 100644 index 00000000000..379f96b8097 --- /dev/null +++ b/apps/Orbix-Examples/Event_Comm/libsrc/Notifier_i.h @@ -0,0 +1,82 @@ +/* -*- C++ -*- */ +// @(#)Notifier_i.h 1.1 10/18/96 + + +// ============================================================================ +// +// = LIBRARY +// EventComm +// +// = FILENAME +// Notifier_i.h +// +// = DESCRIPTION +// Class interface for the implementation of the <Notifier> +// +// = AUTHOR +// Douglas C. Schmidt (schmidt@cs.wustl.edu) +// +// ============================================================================ + +#if !defined (_Notifier_i_H) +#define _Notifier_i_H + +#include "ace/Map_Manager.h" +#include "ace/Synch.h" +#include "ace/SString.h" +#include "Event_Comm.hh" + +#if defined (ACE_HAS_ORBIX) + +// Forward reference. +class Notification_Receiver_Entry; + +class Notifier_i + // = TITLE + // Defines the implementation class for event <Notifiers>. + // + // = DESCRIPTION +{ +public: + enum + { + DEFAULT_SIZE = 1024 // Default max number of Event_Comm::Notification_Receivers. + }; + + Notifier_i (size_t size_hint = Notifier_i::DEFAULT_SIZE); + // Initialize a Notifier_i object with the specified size hint. + + void send_disconnect (const char *reason, + CORBA::Environment &IT_env); + // Disconnect all the receivers, giving them the <reason>. + + void send_notification (const Event_Comm::Notification ¬ification, + CORBA::Environment &IT_env); + // Send the <Notification> to all the consumers who + // have subscribed and who match the filtering criteria. + + void subscribe (Event_Comm::Notification_Receiver *notification_receiver, + const char *filtering_criteria, + CORBA::Environment &IT_env); + // Subscribe the <Notification_Receiver> to receive events that + // match <filtering_criteria> applied by the <Notifier>. + + void unsubscribe (Event_Comm::Notification_Receiver *notification_receiver, + const char *filtering_criteria, + CORBA::Environment &IT_env); + // Unsubscribe the <Notification_Receiver>. + +private: + // The following implementation should be replaced + // by a standard container class from STL... + + typedef ACE_Map_Manager <ACE_SString, Notification_Receiver_Entry *, ACE_Null_Mutex> MAP_MANAGER; + typedef ACE_Map_Iterator <ACE_SString, Notification_Receiver_Entry *, ACE_Null_Mutex> MAP_ITERATOR; + typedef ACE_Map_Entry <ACE_SString, Notification_Receiver_Entry *> MAP_ENTRY; + + MAP_MANAGER map_; + // Table that maps a <Event_Comm::Notification_Receiver *> to a <Notification_Receiver_Entry *>. +}; + +#endif /* ACE_HAS_ORBIX */ +#endif /* _Notifier_i_H */ diff --git a/apps/Orbix-Examples/Logger/Logger.cpp b/apps/Orbix-Examples/Logger/Logger.cpp new file mode 100644 index 00000000000..de05360f606 --- /dev/null +++ b/apps/Orbix-Examples/Logger/Logger.cpp @@ -0,0 +1,131 @@ +#include <iostream.h> +// @(#)Logger.cpp 1.1 10/18/96 + +#include "Logger.h" + +Logger::~Logger (void) +{ + // Release and free up the object reference. + this->logref_->_release (); + + // Must use free since we used strdup(3C). + ACE_OS::free (ACE_MALLOC_T (this->server_)); +} + +// Constructor takes the name of the host where the server +// is located. If server == 0, then use the locator service. + +Logger::Logger (char *server, size_t max_message_size) + : server_ (server == 0 ? 0 : ACE_OS::strdup (server)), + ip_ (0), + pid_ (ACE_OS::getpid ()) +{ + struct utsname name; + +#if 0 + // Could also use sysinfo(2)... + + ACE_OS::sysinfo (SI_HOSTNAME, clienthost, MAXHOSTNAMELEN); +#endif + + ACE_OS::uname (&name); + hostent *hp = ACE_OS::gethostbyname (name.nodename); + + if (hp != 0) + memcpy ((void *) &this->ip_, (void *) hp->h_addr, hp->h_length); + + TRY { + // First bind to the logger object. + // argv[1] has the hostname (if any) of the target logger object; + // The default is the local host: + this->logref_ = profile_logger::_bind ("", this->server_, IT_X); + } CATCHANY { + // an error occurred while trying to bind to the logger object. + cerr << "Bind to object failed" << endl; + cerr << "Unexpected exception " << IT_X << endl; + } ENDTRY; + // Pre-assign certain values that don't change. + this->log_msg_.app_id = this->pid_; + this->log_msg_.host_addr = this->ip_; + this->log_msg_.msg_data._maximum = max_message_size; +} + +// Transmit the message to the logging server. + +int +Logger::log (logger::Log_Priority priority, char message[], int length) +{ + // The following values change with every logging operation. + this->log_msg_.type = priority; + this->log_msg_.time = ACE_OS::time (0); + this->log_msg_.msg_data._length = length; + this->log_msg_.msg_data._buffer = message; + + TRY { + // Try to log a message. + this->logref_->log (this->log_msg_, IT_X); + } CATCHANY { + // an error occurred while trying to read the height and width: + cerr << "call to log failed" << endl; + cerr << "Unexpected exception " << IT_X << endl; + return -1; + } ENDTRY; + // success. + return 0; +} + +// Get the value of verbose. + +int +Logger::verbose (void) +{ + int verbosity = 0; + + TRY { + verbosity = this->logref_->verbose (); + } CATCHANY { + return -1; + } ENDTRY; + return verbosity; +} + +// Set the value of verbose. + +int +Logger::verbose (int value) +{ + int verbosity = 0; + + TRY { + this->logref_->verbose (value); + } CATCHANY { + return -1; + } ENDTRY; + return 0; +} + +// Activate the timer. + +int +Logger::start_timer (void) +{ + TRY { + this->logref_->start_timer (); + } CATCHANY { + return -1; + } ENDTRY; + return 0; +} + +// Deactivate the timer and return the elapsed time. + +int +Logger::stop_timer (profile_logger::Elapsed_Time &et) +{ + TRY { + this->logref_->stop_timer (et); + } CATCHANY { + return -1; + } ENDTRY; + return 0; +} diff --git a/apps/Orbix-Examples/Logger/Logger.h b/apps/Orbix-Examples/Logger/Logger.h new file mode 100644 index 00000000000..fecae83cbf6 --- /dev/null +++ b/apps/Orbix-Examples/Logger/Logger.h @@ -0,0 +1,56 @@ +/* -*- C++ -*- */ +// @(#)Logger.h 1.1 10/18/96 + + +#if !defined (_LOGGER_H) +#define _LOGGER_H + +#include "ace/OS.h" +#include "logger.hh" + +class Logger + // = TITLE + // Wrapper class that uses CORBA object reference + // as the transport mechanism to simplify implementation. +{ +public: + Logger (char *server, size_t max_message_size); + // Constructor takes the name of the host where the server + // is located. If server == 0, then use the locator service. + + ~Logger (void); + // Destructor releases the object reference. + + int log (logger::Log_Priority prio, char msg[], int len); + // Log a <msg> of length <len> with priority <prio>. + + int verbose (void); + // Report current level of verbosity. + + int verbose (int verbosity); + // Set the level of verbosity (0 == no verbose, > 0 == verbose). + + int start_timer (void); + // Activate the timer. + + int stop_timer (profile_logger::Elapsed_Time &et); + // Deactivate the timer and return the elapsed time. + +private: + profile_logger *logref_; + // CORBA object reference proxy. + + int pid_; + // Process ID. + + u_long ip_; + // IP address of self. + + logger::Log_Record log_msg_; + // Cache certain non-changing values to avoid recomputing them. + + char *server_; + // Name of server that we are bound to. +}; + +#endif /* _LOGGER_H */ diff --git a/apps/Orbix-Examples/Logger/Makefile b/apps/Orbix-Examples/Logger/Makefile new file mode 100644 index 00000000000..7193cee9945 --- /dev/null +++ b/apps/Orbix-Examples/Logger/Makefile @@ -0,0 +1,63 @@ +#---------------------------------------------------------------------------- +# @(#)Makefile 1.1 10/18/96 +# +# Makefile for the Logger. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +SVR_OBJS = loggerS.o logger_i.o server.o +CLT_OBJS = loggerC.o client.o Logger.o + +LDLIBS = + +VLDLIBS = $(LDLIBS:%=%$(VAR)) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.lib.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.bin.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Orbix related macros and target settings. +#---------------------------------------------------------------------------- + +ORBIX_BINDIR = $(ORBIX_ROOT)/bin +ORBIX_LIBDIR = $(ORBIX_ROOT)/lib +ORBIX_INCDIR = $(ORBIX_ROOT)/include + +CPPFLAGS += -DEXCEPTIONS -I$(ORBIX_INCDIR) -DWANT_ORBIX_FDS +LDFLAGS += -L$(ORBIX_LIBDIR) -R $(ORBIX_LIBDIR) + +IDLFLAGS = -s S.cpp -c C.cpp -B + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +all: client server + +client: $(addprefix $(VDIR),$(CLT_OBJS)) + $(LINK.cc) -o client $(addprefix $(VDIR),$(CLT_OBJS)) $(LDFLAGS) -lITsrvmt $(VLDLIBS) + +server: $(addprefix $(VDIR),$(SVR_OBJS)) + $(LINK.cc) -o server $(addprefix $(VDIR),$(SVR_OBJS)) $(LDFLAGS) -lITsrvmt $(VLDLIBS) + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + + + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/apps/Orbix-Examples/Logger/Orbix.hostgroups b/apps/Orbix-Examples/Logger/Orbix.hostgroups new file mode 100644 index 00000000000..013636e79c4 --- /dev/null +++ b/apps/Orbix-Examples/Logger/Orbix.hostgroups @@ -0,0 +1 @@ +all:tango diff --git a/apps/Orbix-Examples/Logger/Orbix.hosts b/apps/Orbix-Examples/Logger/Orbix.hosts new file mode 100644 index 00000000000..2e11d889bed --- /dev/null +++ b/apps/Orbix-Examples/Logger/Orbix.hosts @@ -0,0 +1,3 @@ +profile_logger:tango: +logger:tango: +IT_daemon:tango: diff --git a/apps/Orbix-Examples/Logger/README b/apps/Orbix-Examples/Logger/README new file mode 100644 index 00000000000..19b1db681f2 --- /dev/null +++ b/apps/Orbix-Examples/Logger/README @@ -0,0 +1,35 @@ +The directory contains the source code that implements an Orbix +version of the distributed Logger. Other ACE versions of this code +appear in the ./apps/Logger directory. It is interesting to compare +and contrast the alternative implementations. + +RUNNING: + +The client is run as follows: + +client -h host -m max_message_size + +The -h host is optional if the locator service is properly configured. +The -m specifies the maximum number of kilobytes to be sent per log. This +is useful when redirecting messages to stdin. + +TIMING: + +I recommend timing the log's by specifying a max_message_size and +redirecting /usr/dict/words. This will give you several trials from +which to take an average. + +CLIENT: + +While using the client and typing in messages manually, capital Q and V +must be used to quit and toggle verbose respectively. This allows you +to redirect /usr/dict/words without quiting at the q's!! + +SERVER: + +To turn off message reporting on the server side, do a + +setenv NO_MESSAGES + +in the enviroment where the server will be run. If this is done, the server +will only report that a message was received, but not display the messages. diff --git a/apps/Orbix-Examples/Logger/a1.tex b/apps/Orbix-Examples/Logger/a1.tex new file mode 100644 index 00000000000..5d10042e26e --- /dev/null +++ b/apps/Orbix-Examples/Logger/a1.tex @@ -0,0 +1,232 @@ +\documentstyle[times,11pt,moretext] {article} +\input macros +\input widen +\input psfig + +\begin{document} +\centerline{\Large Washington University} +\centerline{\Large Department of Computer Science} +\bigskip +\centerline{\large CS523: Distributed Operating Systems} +%\smallskip +%\centerline{\large Spring 1995} +\bigskip +\centerline{\large Programming Project} +% \centerline{\large Due Tuesday, January $31^{st}$, 1995} + +\section{Overview} + +In this assignment, you will implement a distributed logging service +shown in Figure~\ref{logenv}. Applications use this service to log +information (such as error notifications, debugging traces, and status +updates) in a distributed environment. In this service, CORBA remote +operations are used to send logging records to a central logging +server. The logging server outputs the logging records to a console, +a printer, a file, or a network management database, etc. + +\section{Design and Implementation Issues} + +The distributed logging service will be designed as a client/server +pair, containing the objects shown in Figure~\ref{simplog}. + +\subsection{CORBA IDL Specification} +The following CORBA IDL specification defines the logging interface: + +{ +\small +\ls{0.9} +\begin{verbatim} +// IDL schema definition +interface Logger +{ + // Types of logging messages. + enum Log_Priority { + LM_DEBUG, // Debugging messages + LM_WARNING, // Warning messages + LM_ERROR, // Errors + LM_EMERG // A panic condition + }; + + // Format of the logging record. + struct Log_Record { + Log_Priority type; // Type of logging message. + long time; // Time stamp at sender. + long app_id; // Process ID of sender. + long host_addr; // IP address of the sender. + sequence<char> msg_data; // Sender-specific logging message. + }; + + // Transmit a Log_Record to the logging server. + oneway void log (in Log_Record log_rec); + + // Toggle verbose formatting + attribute char verbose; +}; +\end{verbatim}} + +\begin{figure} +\center{\ \psfig{figure=graphics/logsimp.eps,width=13cm}\ } +\vspace{-0.12in} +\caption{Distributed Logging Service} +\label{logenv} +\end{figure} + +You will use a CORBA IDL compiler to translate this specification into +client-side {\em stubs} and server-side {\em skeletons}. The client +application (which you must write) will use the stubs as a {\em proxy} +to access the logging services provided by the server. You must also +write the implementation of the server, which provides the logging +service. + +\subsection{Client and Server Functionality} +For the purposes of the assignment, you can make the client driver +program very simple. The client can read a line from its standard +input and send it to the logging server. The server can then format +and print the line on its standard output. For example, if you type +this line to the client: + +\begin{verbatim} +To boldly go where no one has gone before +\end{verbatim} + +\noindent Then the server should output something like this: + +\begin{verbatim} +Jan 24 14:50:28 1995@tango.cs.wustl.edu@18352@LM_DEBUG +::To boldly go where no one has gone before +\end{verbatim} + +\noindent Note that the server has printed out the logging message +timestamp, sender's hostname and process id, and the message priority, +followed by the logging message data. + +\begin{figure} +\center{\ \psfig{figure=graphics/simplog.eps,width=13cm}\ } +\vspace{-0.12in} +\caption{CORBA-based Logger Design} +\label{simplog} +\end{figure} + +Note that in order to pass the client's IP address (which is +represented as a 4-byte {\tt long}) in the logging message, you'll +need to learn about several other UNIX routines. On the client-side +you'll need to use {\tt uname(2)} and {\tt gethostbyname(2)} to +determine the IP address of the client host. On the server-side, +you'll need to use the {\tt gethostbyaddr(2)} function to convert the +4-byte IP host address into an ASCII version of the host name. I +recommend that you check the manual pages and read Richard Steven's +book ``UNIX Network Programming'' for more details on using these +functions. + +\subsection{Invoking the Client and Server} +Once the client and server components are written, compiled, and +linked together you will use the {\tt putit} command to register the +server with the Orbix daemon. You'll then need to start up a copy of +{\tt orbixd} (if there isn't already one running). {\tt orbixd} +serves as the Object Request Broker for the local endpoint. + +A client will bind to the {\tt Logger} interface via the generated +{\tt Logger::\_bind} method. There are two general ways to use this +method. The first is to explicitly pass in the name of the server +where {\tt orbixd} is running (your client should accept a +command-line argument that is the name of the server, {\em e.g.,} +``tango.cs.wustl.edu''). + +The second method is to use the CORBA locator service to get an object +reference for the logging service. You'll need to read the Orbix +documentation to learn how to set up a location file. This file will +enable you to omit the name of the server in the call to {\tt +Logger::\_bind}. By using the locator server, your clients can bind +to object's implicitly. Make sure that your solution will work for +either implicit or explicit service location. + +Once the client application has bound (either explicitly or +implicitly) to an object reference for the {\tt Logger}, it can log +messages by calling the {\tt log} method via the object reference +proxy. + +\subsection{Performance Measurement} + +An important part of developing distributed systems is understanding +the performance implications of different design approaches. In order +to measure the performance overhead of using CORBA to build the +Logger, you will write a simple extension to the original {\tt Logger} +interface, as follows: + +{ +\small +\ls{0.9} +\begin{verbatim} +// IDL schema definition +interface Profile_Logger + : Logger // Profile_Logger IS-A Logger +{ + // Stores the amount of time that has elapsed. + struct Elapsed_Time + { + double real_time; + double user_time; + double system_time; + }; + + // Activate the timer. + void start_timer (void); + + // Deactivate the timer and return the elapsed time. + void stop_timer (out Elapsed_Time et); +}; +\end{verbatim}} + +\noindent You will need to modify your client program so that it can +time a series of {\tt Logger::log} operations for various sizes of +logging messages. This will help us understand the performance +overhead of CORBA. + +The main benchmarking should take place within a loop in your client +program. Basically, your client call {\tt +Profile\_Logger::start\_timer} just before sending the first of the +logging messages. After a suitable number of iterations (defined on +the command-line), you client will call {\tt +Profile\_Logger::stop\_timer} to determine and report the elapsed time +to the user. You should print out the ``real'' time, as well as the +``system $+$ user'' times. Make sure that you print out the +throughput in terms of megabits/sec (rather than bytes/sec or +kbytes/sec). Be sure to include the fixed-sized {\tt Log\_Record} +object, as well as the variable-sized {\tt msg\_data} portion in your +computations. + +The number of iterations and the size of the messages sent by the +client should be parameterizable on the command-line. Make sure that +your timing tests are run between processes on two different machines +(rather than processes on the same machine). If possible, try to run +the client and server processes on two machines on the same subnet. + +When you are finished with your timing test, you should explain the +timing results and indicate trends that you observed. + +\section{Learning and Using CORBA} + +To help you learn how CORBA works, I will be making copies of the +Orbix programmer's manual available for a small reproduction fee. +This manual explains how to program in CORBA. I will announce in +class where this will be available. + +We will be using IONA's Orbix CORBA Object Request Broker (ORB) +implementation. The libraries, executables, CORBA IDL compiler, and +example demo applications are located in {\tt +/project/adaptive/Orbix}. Please note that this is an automounted +directory, so you will need to {\tt cd} directly to it in order to see +the contents. To configure Orbix for your environment, copy the {\tt +/project/adaptive/Orbix/Orbix.cfg} file to your account. You'll need +to set the environment variable {\tt IT\_CONFIG\_PATH} to the complete +path where this file is located. + +\section{Concluding Remarks} +In office hours and in class, we will discuss how to use C++ and CORBA +in order to develop your solutions. Note that this assignment will +teach you many skills required to become adept at network programming. +However, it also will require a great deal of thought and planning. +Please make sure you start early, come to office hours, and ask lots +of questions. + +\end{document} diff --git a/apps/Orbix-Examples/Logger/client.cpp b/apps/Orbix-Examples/Logger/client.cpp new file mode 100644 index 00000000000..aea23379488 --- /dev/null +++ b/apps/Orbix-Examples/Logger/client.cpp @@ -0,0 +1,142 @@ +// A client for the distributed logger example. This program reads +// @(#)client.cpp 1.1 10/18/96 + +// from either stdin or from a redirected file and sends all the +// contents to the logging server. It also computes how long it takes +// to send this stuff. + +#include "ace/Log_Msg.h" +#include "Logger.h" + +// maximum message size +static size_t max_message_size = BUFSIZ; + +// Default behavior is to use the locator service. +static char *hostname = 0; + +// Should we prompt the user? +static int user_prompt; + +static void +parse_args (int argc, char *argv[]) +{ + extern char *optarg; + extern int optind; + int c; + + ACE_LOG_MSG->open (argv[0]); + + // If a file has been redirected, don't activate user prompts + if (ACE_OS::isatty (0)) + user_prompt = 1; + else + user_prompt = 0; + + while ((c = ACE_OS::getopt (argc, argv, "m:h:")) != -1) + switch (c) + { + case 'm': + max_message_size = ACE_OS::atoi (optarg) * BUFSIZ; + break; + case 'h': + hostname = optarg; + break; + default: + ACE_ERROR ((LM_ERROR, "%n: -h host -m max_message_size (in kbytes)\n%a", 1)); + /* NOTREACHED */ + } +} + +// Enable/disable verbose logging. + +static int +toggle_verbose (Logger &logger) +{ + int verbose_value; + + verbose_value = logger.verbose (); + logger.verbose (!verbose_value); + return 0; +} + +// Transmit messages to the server. + +int +transmit (Logger &logger, char buf[], ACE_HANDLE handle = 0) +{ + if (user_prompt) + cout << "\nEnter message ('Q':quit,'V':toggle verbose):\n" << flush; + + ssize_t nbytes = ACE_OS::read (handle, buf, max_message_size); + + if (nbytes <= 0) + return nbytes; // End of file or error. + buf[nbytes] = '\0'; + + if (user_prompt) + { + if (buf[0] == 'Q' || buf[0] == 'q') + return 0; + // toggle verbose? + else if (buf[0] == 'V' || buf[0] == 'v') + toggle_verbose (logger); + } + + // send the message to the logger + if (logger.log (logger::LM_DEBUG, buf, nbytes) == -1) + return -1; + else + return nbytes; +} + +// Print the results of the tests. + +void +report_results (profile_logger::Elapsed_Time &et, size_t total_bytes) +{ + ACE_DEBUG ((LM_DEBUG, + "real time = %8.2f\n" + "user time = %8.2f\n" + "sys time = %8.2f\n" + "mbits sec = %8.2f\n", + et.real_time, et.user_time, et.system_time, + (total_bytes / et.real_time) * 8.0 / 1024.0 / 1024.0)); +} + +int +main (int argc, char **argv) +{ + parse_args (argc,argv); + + // Pointer to the logger object that will be used. + Logger logger (hostname, max_message_size); + char *buf = new char [max_message_size]; + size_t total_bytes = 0; + size_t nbytes = 0; + + logger.start_timer (); + + // Transmit logging records until user quits. + + for (int done = 0; done == 0;) + switch (nbytes = transmit (logger, buf)) + { + case -1: + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "transmit"), -1); + /* NOTREACHED */ + case 0: + done = 1; + break; + default: + total_bytes += nbytes; + break; + } + + profile_logger::Elapsed_Time et; + + if (logger.stop_timer (et) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "stop timer"), -1); + + report_results (et, total_bytes); + return 0; +} diff --git a/apps/Orbix-Examples/Logger/logger.hh b/apps/Orbix-Examples/Logger/logger.hh new file mode 100644 index 00000000000..0d0eeeca2f0 --- /dev/null +++ b/apps/Orbix-Examples/Logger/logger.hh @@ -0,0 +1,434 @@ + +#ifndef logger_hh +#define logger_hh + +#include <CORBA.h> + +#include <string.h> + + +#ifndef _IDL_SEQUENCE_char_defined +#define _IDL_SEQUENCE_char_defined + +struct IONANC__IDL_SEQUENCE_char; +struct _IDL_SEQUENCE_char { + unsigned long _maximum; + unsigned long _length; + char *_buffer; + + operator IONANC__IDL_SEQUENCE_char(); + operator const IONANC__IDL_SEQUENCE_char() const; + _IDL_SEQUENCE_char& operator= (const IONANC__IDL_SEQUENCE_char&); + + _IDL_SEQUENCE_char& operator= (const _IDL_SEQUENCE_char&); + _IDL_SEQUENCE_char (const _IDL_SEQUENCE_char&); + + _IDL_SEQUENCE_char (unsigned long IT_size = 0); + + ~_IDL_SEQUENCE_char () { if (_buffer) delete [] _buffer; } + + char& operator [] (unsigned long IT_i) const {return _buffer[IT_i]; } + + void encodeOp (CORBA::Request &IT_r) const; + void decodeOp (CORBA::Request &IT_r); + void decodeInOutOp (CORBA::Request &IT_r); +}; + +struct IONANC__IDL_SEQUENCE_char { + unsigned long _maximum; + unsigned long _length; + char *_buffer; + + char& operator [] (unsigned long IT_i) const; + + operator _IDL_SEQUENCE_char (); + + operator const _IDL_SEQUENCE_char () const; + +}; + + + +#endif + + +#ifndef _logger_defined +#define _logger_defined +class logger_dispatch : public virtual CORBA::PPTR { +public: + + logger_dispatch (void *IT_p, CORBA::Object* IT_o, const char *IT_m, + CORBA::LoaderClass *IT_l, char *IT_i, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_l,IT_i,IT_im) {} + + + logger_dispatch (char *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + logger_dispatch () {} + + logger_dispatch (void *IT_p, CORBA::Object *IT_o, const char *IT_m, + char *IT_i, CORBA::Object* IT_ob, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_i,IT_ob,IT_im) {} + + + virtual unsigned char dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void* IT_pp=NULL); + + +}; + +class logger; + + +#ifndef loggerForwH +#define loggerForwH +CORBA::ObjectRef logger_getBase (void *); +void logger_release (void *, CORBA::Environment &IT_env=CORBA::default_environment); +logger* logger_duplicate (void *, CORBA::Environment &IT_env=CORBA::default_environment); +#endif +#define logger_IMPL "logger" + + +class logger; +#define logger_IR "logger" +#define logger_IMPL "logger" + +typedef logger* loggerRef; +typedef logger* logger_ptr; +class logger: public virtual CORBA::Object { +public: + logger (char *IT_OR); + logger () : CORBA::Object (1) {} + logger* _duplicate( + CORBA::Environment &IT_env=CORBA::default_environment) { + CORBA::Object::_duplicate (IT_env); return this; } + static logger* _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env=CORBA::default_environment); + static logger* _bind (CORBA::Environment &IT_env); + static logger* _bind (const char* IT_markerServer=NULL, const char* host=NULL, + CORBA::Environment &IT_env=CORBA::default_environment); + static logger* _narrow (CORBA::Object* , CORBA::Environment &IT_env=CORBA::default_environment); +enum Log_Priority {LM_MESSAGE,LM_DEBUG,LM_WARNING,LM_ERROR,LM_EMERG}; + +#ifndef logger_Log_Record_defined +#define logger_Log_Record_defined + +struct IONANC_Log_Record; +struct Log_Record { + logger::Log_Priority type; + long time; + long app_id; + long host_addr; + _IDL_SEQUENCE_char msg_data; + + void encodeOp (CORBA::Request &IT_r) const; + void decodeOp (CORBA::Request &IT_r); + void decodeInOutOp (CORBA::Request &IT_r); + Log_Record(const Log_Record &); + Log_Record(); + operator logger::IONANC_Log_Record(); + operator const logger::IONANC_Log_Record() const; + Log_Record& operator= (const IONANC_Log_Record&); + ~Log_Record(); + Log_Record& operator= (const Log_Record&); +}; + +struct IONANC_Log_Record { + logger::Log_Priority type; + long time; + long app_id; + long host_addr; + IONANC__IDL_SEQUENCE_char msg_data; + operator logger::Log_Record (); + operator const logger::Log_Record () const; + }; + + +#endif + + virtual void log (const logger::Log_Record& log_rec, CORBA::Environment &IT_env=CORBA::default_environment); + virtual void verbose (char verbose, CORBA::Environment &IT_env=CORBA::default_environment); + virtual char verbose (CORBA::Environment &IT_env=CORBA::default_environment); +}; + + +#define TIE_logger(X) logger##X + +#define DEF_TIE_logger(X) \ + class logger##X : public virtual logger { \ + X* m_obj; \ + public: \ + \ + logger##X (X *objp, const char* m="", CORBA::LoaderClass *l=nil)\ + : logger(), CORBA::Object (), m_obj(objp) { \ + m_pptr = new logger_dispatch \ + (( logger*)this,(CORBA::Object*)this,m,l,logger_IR,m_obj); \ + } \ + logger##X (CORBA::Object *IT_p, const char* IT_m="", void *IT_q=nil)\ + : logger(), CORBA::Object () { \ + m_pptr = new logger_dispatch \ + (( logger*)this,(CORBA::Object*)this,IT_m,logger_IR,IT_p,IT_q); \ + m_obj = (X*)(m_pptr->getImplObj ()); \ + } \ + \ + virtual ~logger##X () { \ + if (_okToDeleteImpl ()) delete m_obj; } \ + \ + virtual void* _deref () { \ + return m_obj; } \ + \ + virtual void log (const logger::Log_Record& log_rec, CORBA::Environment &IT_env) {\ +m_obj->log ( log_rec,IT_env);\ +}\ + \ +virtual void verbose (char verbose, CORBA::Environment &IT_env) {\ + m_obj->verbose(verbose,IT_env); }\ + \ +virtual char verbose (CORBA::Environment &IT_env) {\ +return m_obj->verbose(IT_env); }\ + \ + }; + + +#define QUALS_logger \ + virtual void log (const logger::Log_Record& log_rec, CORBA::Environment &IT_env) {\ +m_obj->log ( log_rec,IT_env);\ +}\ + \ +virtual void verbose (char verbose, CORBA::Environment &IT_env) {\ + m_obj->verbose(verbose,IT_env); }\ + \ +virtual char verbose (CORBA::Environment &IT_env) {\ +return m_obj->verbose(IT_env); }\ + + + + +class loggerProxyFactoryClass : public virtual CORBA::ObjectFactoryClass { +public: + loggerProxyFactoryClass (unsigned char IT_p=0) + : CORBA::ProxyFactory (logger_IR, IT_p) {} + + virtual void* New (char *IT_OR, CORBA::Environment&); + + virtual void* New2 (); + + virtual void* IT_castUp (void *IT_p, char* IT_s); + + virtual CORBA::PPTR* pptr (void *IT_p); + + virtual void baseInterfaces (_IDL_SEQUENCE_string&); + + +}; + +extern loggerProxyFactoryClass loggerProxyFactory; + + + +class loggerBOAImpl : public virtual logger { +public: + loggerBOAImpl (const char *m="", CORBA::LoaderClass *l=NULL) { + if (CORBA::PPTR::isOK (m_pptr, logger_IR)) + m_pptr = new logger_dispatch ( (logger*)this, + (CORBA::Object*)this, m, l, logger_IR, this); +} + + virtual void log (const logger::Log_Record& log_rec, CORBA::Environment &IT_env=CORBA::default_environment) =0; + virtual void verbose (char verbose, CORBA::Environment &IT_env=CORBA::default_environment)=0; + virtual char verbose (CORBA::Environment &IT_env=CORBA::default_environment)=0; +}; + + +#endif + + +#ifndef _profile_logger_defined +#define _profile_logger_defined +class profile_logger_dispatch : public virtual logger_dispatch { +public: + + profile_logger_dispatch (void *IT_p, CORBA::Object* IT_o, const char *IT_m, + CORBA::LoaderClass *IT_l, char *IT_i, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_l,IT_i,IT_im) {} + + + profile_logger_dispatch (char *IT_OR, void *IT_p, CORBA::Object *IT_o) + : CORBA::PPTR (IT_OR,IT_p,IT_o) {} + + + profile_logger_dispatch () {} + + profile_logger_dispatch (void *IT_p, CORBA::Object *IT_o, const char *IT_m, + char *IT_i, CORBA::Object* IT_ob, void* IT_im) + : CORBA::PPTR (IT_p,IT_o,IT_m,IT_i,IT_ob,IT_im) {} + + + virtual unsigned char dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void* IT_pp=NULL); + + +}; + +class profile_logger; + + +#ifndef profile_loggerForwH +#define profile_loggerForwH +CORBA::ObjectRef profile_logger_getBase (void *); +void profile_logger_release (void *, CORBA::Environment &IT_env=CORBA::default_environment); +profile_logger* profile_logger_duplicate (void *, CORBA::Environment &IT_env=CORBA::default_environment); +#endif +#define profile_logger_IMPL "profile_logger" + + +class profile_logger; +#define profile_logger_IR "profile_logger" +#define profile_logger_IMPL "profile_logger" + +typedef profile_logger* profile_loggerRef; +typedef profile_logger* profile_logger_ptr; +class profile_logger: public virtual logger { +public: + profile_logger (char *IT_OR); + profile_logger () : CORBA::Object (1) {} + profile_logger* _duplicate( + CORBA::Environment &IT_env=CORBA::default_environment) { + CORBA::Object::_duplicate (IT_env); return this; } + static profile_logger* _bind (const char* IT_markerServer, const char* host, + const CORBA::Context &IT_c, + CORBA::Environment &IT_env=CORBA::default_environment); + static profile_logger* _bind (CORBA::Environment &IT_env); + static profile_logger* _bind (const char* IT_markerServer=NULL, const char* host=NULL, + CORBA::Environment &IT_env=CORBA::default_environment); + static profile_logger* _narrow (CORBA::Object* , CORBA::Environment &IT_env=CORBA::default_environment); + +#ifndef profile_logger_Elapsed_Time_defined +#define profile_logger_Elapsed_Time_defined + +struct Elapsed_Time { + double real_time; + double user_time; + double system_time; + + void encodeOp (CORBA::Request &IT_r) const; + void decodeOp (CORBA::Request &IT_r); + void decodeInOutOp (CORBA::Request &IT_r); +}; + + +#endif + + virtual void start_timer (CORBA::Environment &IT_env=CORBA::default_environment); + virtual void stop_timer (profile_logger::Elapsed_Time& et, CORBA::Environment &IT_env=CORBA::default_environment); +}; + + +#define TIE_profile_logger(X) profile_logger##X + +#define DEF_TIE_profile_logger(X) \ + class profile_logger##X : public virtual profile_logger { \ + X* m_obj; \ + public: \ + \ + profile_logger##X (X *objp, const char* m="", CORBA::LoaderClass *l=nil)\ + : profile_logger(), CORBA::Object (), m_obj(objp) { \ + m_pptr = new profile_logger_dispatch \ + (( profile_logger*)this,(CORBA::Object*)this,m,l,profile_logger_IR,m_obj); \ + } \ + profile_logger##X (CORBA::Object *IT_p, const char* IT_m="", void *IT_q=nil)\ + : profile_logger(), CORBA::Object () { \ + m_pptr = new profile_logger_dispatch \ + (( profile_logger*)this,(CORBA::Object*)this,IT_m,profile_logger_IR,IT_p,IT_q); \ + m_obj = (X*)(m_pptr->getImplObj ()); \ + } \ + \ + virtual ~profile_logger##X () { \ + if (_okToDeleteImpl ()) delete m_obj; } \ + \ + virtual void* _deref () { \ + return m_obj; } \ + \ + virtual void log (const logger::Log_Record& log_rec, CORBA::Environment &IT_env) {\ +m_obj->log ( log_rec,IT_env);\ +}\ + \ +virtual void verbose (char verbose, CORBA::Environment &IT_env) {\ + m_obj->verbose(verbose,IT_env); }\ + \ +virtual char verbose (CORBA::Environment &IT_env) {\ +return m_obj->verbose(IT_env); }\ + virtual void start_timer (CORBA::Environment &IT_env) {\ +m_obj->start_timer (IT_env);\ +}\ + \ + virtual void stop_timer (profile_logger::Elapsed_Time& et, CORBA::Environment &IT_env) {\ +m_obj->stop_timer ( et,IT_env);\ +}\ + \ + }; + + +#define QUALS_profile_logger \ + virtual void log (const logger::Log_Record& log_rec, CORBA::Environment &IT_env) {\ +m_obj->log ( log_rec,IT_env);\ +}\ + \ +virtual void verbose (char verbose, CORBA::Environment &IT_env) {\ + m_obj->verbose(verbose,IT_env); }\ + \ +virtual char verbose (CORBA::Environment &IT_env) {\ +return m_obj->verbose(IT_env); }\ + virtual void start_timer (CORBA::Environment &IT_env) {\ +m_obj->start_timer (IT_env);\ +}\ + \ + virtual void stop_timer (profile_logger::Elapsed_Time& et, CORBA::Environment &IT_env) {\ +m_obj->stop_timer ( et,IT_env);\ +}\ + + + + +class profile_loggerProxyFactoryClass : public virtual loggerProxyFactoryClass { +public: + profile_loggerProxyFactoryClass (unsigned char IT_p=0) + : CORBA::ProxyFactory (profile_logger_IR, IT_p) {} + + virtual void* New (char *IT_OR, CORBA::Environment&); + + virtual void* New2 (); + + virtual void* IT_castUp (void *IT_p, char* IT_s); + + virtual CORBA::PPTR* pptr (void *IT_p); + + virtual void baseInterfaces (_IDL_SEQUENCE_string&); + + +}; + +extern profile_loggerProxyFactoryClass profile_loggerProxyFactory; + + + +class profile_loggerBOAImpl : public virtual profile_logger { +public: + profile_loggerBOAImpl (const char *m="", CORBA::LoaderClass *l=NULL) { + if (CORBA::PPTR::isOK (m_pptr, profile_logger_IR)) + m_pptr = new profile_logger_dispatch ( (profile_logger*)this, + (CORBA::Object*)this, m, l, profile_logger_IR, this); +} + + virtual void start_timer (CORBA::Environment &IT_env=CORBA::default_environment) =0; + virtual void stop_timer (profile_logger::Elapsed_Time& et, CORBA::Environment &IT_env=CORBA::default_environment) =0; +}; + + +#endif + + +#endif diff --git a/apps/Orbix-Examples/Logger/logger.idl b/apps/Orbix-Examples/Logger/logger.idl new file mode 100644 index 00000000000..0fe673a84b9 --- /dev/null +++ b/apps/Orbix-Examples/Logger/logger.idl @@ -0,0 +1,56 @@ +/* -*- C++ -*- */ +// @(#)logger.idl 1.1 10/18/96 + +// logger.idl + +interface logger +// = TITLE +// This is the CORBA interface for the logger class. +{ + // = Types of logging messages. + enum Log_Priority + { + LM_MESSAGE, + LM_DEBUG, + LM_WARNING, + LM_ERROR, + LM_EMERG + }; + + // = Format of the logging record. + struct Log_Record + { + Log_Priority type; // Type of logging message. + long time; // Time stamp at sender. + long app_id; // Process ID of sender. + long host_addr; // IP address of the sender. + sequence<char> msg_data; // Sender-specific logging message. + }; + + oneway void log (in Log_Record log_rec); + // Transmit a Log_Record to the logging server. + + attribute char verbose; + // Toggle verbose formatting +}; + +interface profile_logger + : logger // Profile_Logger IS-A Logger +// = TITLE +// IDL Profile Logger definition that is used +// to compute statistics about the logging. +{ + // = Stores the amount of time that has elapsed. + struct Elapsed_Time + { + double real_time; + double user_time; + double system_time; + }; + + void start_timer (); + // Activate the timer. + + void stop_timer (out Elapsed_Time et); + // Deactivate the timer and return the elapsed time. +}; diff --git a/apps/Orbix-Examples/Logger/loggerS.cpp b/apps/Orbix-Examples/Logger/loggerS.cpp new file mode 100644 index 00000000000..b1210683886 --- /dev/null +++ b/apps/Orbix-Examples/Logger/loggerS.cpp @@ -0,0 +1,141 @@ + +// @(#)loggerS.cpp 1.1 10/18/96 + +#include "logger.hh" + + +#define logger_dispatch_impl + +unsigned char logger_dispatch::dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void *IT_pp) { + if (!IT_pp) + IT_pp = m_obj; + const char *IT_s = IT_r.getOperation (); + if (!strcmp(IT_s,"log")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~log~+log_rec{R~logger::Log_Record~type{E~logger::Log_Priority~LM_MESSAGE,LM_DEBUG,LM_WARNING,LM_ERROR,LM_EMERG},time{l},app_id{l},host_addr{l},msg_data{S{c},0}},>{v},O{}\ +")) + return 1; + logger::Log_Record log_rec; + log_rec.decodeOp (IT_r); + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((logger*)IT_pp)->log ( log_rec, IT_env); + + IT_r.replyNoResults (CORBA::Flags(CORBA::INV_NO_RESPONSE),IT_env); + return 1; + } + + else if (!strcmp (IT_s,"_get_verbose")) { + char verbose; + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~_get_verbose~>{c},N{}\ +")) + return 1; + if (IT_f) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + verbose = ((logger*)IT_pp)->verbose(IT_env); + + if (!IT_r.isException (IT_env)) { + if (!IT_r.convertToReply ("\ +c\ +", IT_env)) return 1; + IT_r << verbose; + } + else IT_r.makeSystemException (IT_env); + + return 1; + } + else if (!strcmp (IT_s,"_set_verbose")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (IT_r.tcAssert ("\ +Ro~_set_verbose~+{c},>{v},N{}\ +")) { + char verbose; + IT_r >> verbose; + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((logger*)IT_pp)->verbose(verbose, IT_env); + } + IT_r.replyNoResults (IT_env); + return 1; + } + + else if (IT_isTarget) + IT_r.makeRuntimeException2 (); + + return 0; +} + +#define profile_logger_dispatch_impl + +unsigned char profile_logger_dispatch::dispatch (CORBA::Request &IT_r, + unsigned char IT_isTarget, void *IT_pp) { + if (!IT_pp) + IT_pp = m_obj; + const char *IT_s = IT_r.getOperation (); + if (!strcmp(IT_s,"start_timer")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~start_timer~>{v},N{}\ +")) + return 1; + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((profile_logger*)IT_pp)->start_timer (IT_env); + + IT_r.replyNoResults (IT_env); + return 1; + } + + else if (!strcmp(IT_s,"stop_timer")) { + CORBA::Environment IT_env (IT_r); + CORBA::Filter* IT_f = CORBA::Orbix.getFilter (); + if (!IT_r.tcAssert ("\ +Ro~stop_timer~-et{R~profile_logger::Elapsed_Time~real_time{d},user_time{d},system_time{d}},>{v},N{}\ +")) + return 1; + profile_logger::Elapsed_Time et; + + if (IT_f && !IT_r.isException (IT_env)) + IT_f->inRequestPostM (IT_r, IT_env); + if (!IT_r.isException (IT_env)) + ((profile_logger*)IT_pp)->stop_timer ( et, IT_env); + + + if (!IT_r.isException (IT_env)) { + if (!IT_r.convertToReply ("\ +v\ +", IT_env)) return 1; + et.encodeOp (IT_r); + } + + else IT_r.makeSystemException (IT_env); + return 1; + } + + else if (logger_dispatch::dispatch (IT_r, 0, + (logger*)((profile_logger*)IT_pp))) { + return 1; + } + + else if (IT_isTarget) + IT_r.makeRuntimeException2 (); + + return 0; +} + +#include "loggerC.cpp" + diff --git a/apps/Orbix-Examples/Logger/logger_i.cpp b/apps/Orbix-Examples/Logger/logger_i.cpp new file mode 100644 index 00000000000..cfd5a5b0d8b --- /dev/null +++ b/apps/Orbix-Examples/Logger/logger_i.cpp @@ -0,0 +1,120 @@ +// Implementation of the logger object. +// @(#)logger_i.cpp 1.1 10/18/96 + + +#include "ace/OS.h" +#include <iostream.h> +#include "logger_i.h" + +// Select non-verbose logging by default. + +logger_i::logger_i (int verbose) + : verbose_value_ (verbose) +{ + if (ACE_OS::getenv ("NO_MESSAGES") == 0) + this->verbose_message_ = 1; + else + this->verbose_message_ = 0; +} + +// Implement the log method. + +void +logger_i::log (const logger::Log_Record &log_rec, CORBA::Environment &IT_env) +{ + if (this->verbose_value_) // If verbose mode is on + { + char *tm; + + // Convert time + if ((tm = ACE_OS::ctime (&log_rec.time)) == 0) + cerr << "ctime failed" << endl; + else + { + hostent *hp; + + /* 01234567890123456789012345 */ + /* Wed Oct 18 14:25:36 1989n0 */ + tm[24] = '@'; + cout << tm; + + // Get host name of client + + if ((hp = gethostbyaddr((char *) &log_rec.host_addr, + sizeof log_rec.host_addr, AF_INET)) == NULL) + { + cerr << "server: error in calling gethostbyaddr" << endl; + cerr << "h_errno = " << h_errno << endl; + return; + } + else // Output client hostname. + cout << hp->h_name << "@"; + + // Output PID of client + cout << log_rec.app_id << "@"; + + // Output priority + + switch (log_rec.type) + { + case logger::LM_DEBUG: + cout << "LM_DEBUG"; + break; + case logger::LM_WARNING: + cout << "LM_WARNING"; + break; + case logger::LM_ERROR: + cout << "LM_ERROR"; + break; + case logger::LM_EMERG: + cout << "LM_EMERG"; + break; + } + } + } + if (this->verbose_message_) + { + cout << "::"; + // Output message + cout.write (log_rec.msg_data._buffer, log_rec.msg_data._length) << flush; + } +} + +// Enable/disable verbosity. + +void +logger_i::verbose (char verbose, CORBA::Environment &IT_env) +{ + this->verbose_value_ = verbose; +} + +// Report current verbosity level. + +char +logger_i::verbose (CORBA::Environment &IT_env) +{ + return this->verbose_value_; +} + +// Profile_Logger_i + +void +profile_logger_i::start_timer (CORBA::Environment &IT_env) +{ + this->pt_.start (); +} + +void +profile_logger_i::stop_timer (profile_logger::Elapsed_Time& et, + CORBA::Environment &IT_env) +{ + this->pt_.stop (); + + ACE_Profile_Timer::ACE_Elapsed_Time e; + + this->pt_.elapsed_time (e); + + et.real_time = e.real_time; + et.user_time = e.user_time; + et.system_time = e.system_time; +} diff --git a/apps/Orbix-Examples/Logger/logger_i.h b/apps/Orbix-Examples/Logger/logger_i.h new file mode 100644 index 00000000000..65253527370 --- /dev/null +++ b/apps/Orbix-Examples/Logger/logger_i.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// @(#)logger_i.h 1.1 10/18/96 + + +#include "ace/Profile_Timer.h" +#define EXCEPTIONS +#include "logger.hh" + +class logger_i +#if defined (USE_BOA_IMPL) + : virtual public loggerBOAImpl +#endif /* USE_BOA_IMPL */ + // = TITLE + // Implementation of the logger interface. + // + // = DESCRIPTION + // Uses either the BOAImpl or the DEF_TIE approach, + // depending on the #ifdef +{ +public: + logger_i (int verbose = 0); + // Select non-verbose logging by default. + + virtual void log (const logger::Log_Record &log_rec, CORBA::Environment &IT_env); + // Implement the log method. + + virtual void verbose (char verbose, CORBA::Environment &IT_env); + // Enable/disable verbosity. + + virtual char verbose (CORBA::Environment &IT_env); + // Report current verbosity level. + +private: + unsigned char verbose_value_; + // Indicate if we are using verbose logging or not. + + unsigned char verbose_message_; + // Indicate if we outputting the messages (turn off if you + // want to conduct timing tests that just measure throughput). +}; + +class profile_logger_i : +#if defined (USE_BOA_IMPL) + public virtual profile_loggerBOAImpl, + public virtual Logger_i +#else /* USE_TIE */ + public logger_i +#endif /* USE_BOA_IMPL */ + // = TITLE + // Implementation of the profiler logger interface. + // + // = DESCRIPTION + // Uses the BOAImpl approach. +{ +public: + virtual void start_timer (CORBA::Environment &env); + // Activate the timer. + + virtual void stop_timer (profile_logger::Elapsed_Time &et, + CORBA::Environment &env); + // Deactivate the timer and return the elapsed time. + +private: + ACE_Profile_Timer pt_; + // Object that keeps track of the user and system execution time. +}; + +#if !defined (USE_BOA_IMPL) +// Indicate that the C++ classes logger_i and profile_logger_i implement +// the IDL interface logger and profile_logger, respectively: + +DEF_TIE_logger (logger_i) +DEF_TIE_profile_logger (profile_logger_i) + +#endif /* USE_BOA_IMPL */ diff --git a/apps/Orbix-Examples/Logger/server.cpp b/apps/Orbix-Examples/Logger/server.cpp new file mode 100644 index 00000000000..c41aa474dcf --- /dev/null +++ b/apps/Orbix-Examples/Logger/server.cpp @@ -0,0 +1,40 @@ +// server.C +// @(#)server.cpp 1.1 10/18/96 + + +// The server for the logger example. +// This uses the TRY,CATCHANY,ENDTRY macros for error testing. + +// The executable file generated from this code should be registered +// (under the name 'logger') using the 'putit' command. + +#include <iostream.h> +#include "logger_i.h" + +int +main (int, char *[]) +{ + // Tell the server not to hang up while clients are connected. + CORBA::Orbix.setNoHangup (1); + + // create a logger object - using the implementation class logger_i +#if defined (USE_BOA_IMPL) + profile_logger_i profile_logger; +#else + TIE_profile_logger (profile_logger_i) profile_logger (new profile_logger_i); +#endif /* USE_BOA_IMPL */ + + TRY { + // tell Orbix that we have completed the server's initialisation: + CORBA::Orbix.impl_is_ready (profile_logger_IMPL, IT_X); + } CATCHANY { + // an error occured calling impl_is_ready () - output the error. + cout << IT_X << endl; + } ENDTRY; + + // impl_is_ready() returns only when Orbix times-out an idle server + // (or an error occurs). + cerr << "server exiting" << endl; + + return 0; +} diff --git a/apps/Orbix-Examples/Makefile b/apps/Orbix-Examples/Makefile new file mode 100644 index 00000000000..723a4dce7c3 --- /dev/null +++ b/apps/Orbix-Examples/Makefile @@ -0,0 +1,25 @@ +#---------------------------------------------------------------------------- +# @(#)Makefile 1.1 10/18/96 +# +# Makefile for the Orbix applications +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +INFO = README + +DIRS = Event_Comm \ + Logger + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nested.GNU +include $(WRAPPER_ROOT)/include/makeinclude/rules.nolocal.GNU + |