summaryrefslogtreecommitdiff
path: root/ACE/ace/FlReactor
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2008-03-04 14:51:23 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2008-03-04 14:51:23 +0000
commit99aa8c60282c7b8072eb35eb9ac815702f5bf586 (patch)
treebda96bf8c3a4c2875a083d7b16720533c8ffeaf4 /ACE/ace/FlReactor
parentc4078c377d74290ebe4e66da0b4975da91732376 (diff)
downloadATCD-99aa8c60282c7b8072eb35eb9ac815702f5bf586.tar.gz
undoing accidental deletion
Diffstat (limited to 'ACE/ace/FlReactor')
-rw-r--r--ACE/ace/FlReactor/ACE_FlReactor.pc.in11
-rw-r--r--ACE/ace/FlReactor/ACE_FlReactor_export.h58
-rw-r--r--ACE/ace/FlReactor/FlReactor.cpp330
-rw-r--r--ACE/ace/FlReactor/FlReactor.h110
4 files changed, 509 insertions, 0 deletions
diff --git a/ACE/ace/FlReactor/ACE_FlReactor.pc.in b/ACE/ace/FlReactor/ACE_FlReactor.pc.in
new file mode 100644
index 00000000000..c284481585d
--- /dev/null
+++ b/ACE/ace/FlReactor/ACE_FlReactor.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: ACE_FlReactor
+Description: ACE FlReactor Library
+Requires: ACE
+Version: @VERSION@
+Libs: -L${libdir} -lACE_FlReactor
+Cflags: -I${includedir}
diff --git a/ACE/ace/FlReactor/ACE_FlReactor_export.h b/ACE/ace/FlReactor/ACE_FlReactor_export.h
new file mode 100644
index 00000000000..f46b66cb3f7
--- /dev/null
+++ b/ACE/ace/FlReactor/ACE_FlReactor_export.h
@@ -0,0 +1,58 @@
+
+// -*- C++ -*-
+// $Id$
+// Definition for Win32 Export directives.
+// This file is generated automatically by generate_export_file.pl -s ACE_FlReactor
+// ------------------------------
+#ifndef ACE_FLREACTOR_EXPORT_H
+#define ACE_FLREACTOR_EXPORT_H
+
+#include /**/ "ace/config-all.h"
+
+#if defined (ACE_AS_STATIC_LIBS) && !defined (ACE_FLREACTOR_HAS_DLL)
+# define ACE_FLREACTOR_HAS_DLL 0
+#endif /* ACE_AS_STATIC_LIBS && ACE_FLREACTOR_HAS_DLL */
+
+#if !defined (ACE_FLREACTOR_HAS_DLL)
+# define ACE_FLREACTOR_HAS_DLL 1
+#endif /* ! ACE_FLREACTOR_HAS_DLL */
+
+#if defined (ACE_FLREACTOR_HAS_DLL) && (ACE_FLREACTOR_HAS_DLL == 1)
+# if defined (ACE_FLREACTOR_BUILD_DLL)
+# define ACE_FlReactor_Export ACE_Proper_Export_Flag
+# define ACE_FLREACTOR_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
+# define ACE_FLREACTOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# else /* ACE_FLREACTOR_BUILD_DLL */
+# define ACE_FlReactor_Export ACE_Proper_Import_Flag
+# define ACE_FLREACTOR_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
+# define ACE_FLREACTOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# endif /* ACE_FLREACTOR_BUILD_DLL */
+#else /* ACE_FLREACTOR_HAS_DLL == 1 */
+# define ACE_FlReactor_Export
+# define ACE_FLREACTOR_SINGLETON_DECLARATION(T)
+# define ACE_FLREACTOR_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+#endif /* ACE_FLREACTOR_HAS_DLL == 1 */
+
+// Set ACE_FLREACTOR_NTRACE = 0 to turn on library specific tracing even if
+// tracing is turned off for ACE.
+#if !defined (ACE_FLREACTOR_NTRACE)
+# if (ACE_NTRACE == 1)
+# define ACE_FLREACTOR_NTRACE 1
+# else /* (ACE_NTRACE == 1) */
+# define ACE_FLREACTOR_NTRACE 0
+# endif /* (ACE_NTRACE == 1) */
+#endif /* !ACE_FLREACTOR_NTRACE */
+
+#if (ACE_FLREACTOR_NTRACE == 1)
+# define ACE_FLREACTOR_TRACE(X)
+#else /* (ACE_FLREACTOR_NTRACE == 1) */
+# if !defined (ACE_HAS_TRACE)
+# define ACE_HAS_TRACE
+# endif /* ACE_HAS_TRACE */
+# define ACE_FLREACTOR_TRACE(X) ACE_TRACE_IMPL(X)
+# include "ace/Trace.h"
+#endif /* (ACE_FLREACTOR_NTRACE == 1) */
+
+#endif /* ACE_FLREACTOR_EXPORT_H */
+
+// End of auto generated file.
diff --git a/ACE/ace/FlReactor/FlReactor.cpp b/ACE/ace/FlReactor/FlReactor.cpp
new file mode 100644
index 00000000000..611b9a14a19
--- /dev/null
+++ b/ACE/ace/FlReactor/FlReactor.cpp
@@ -0,0 +1,330 @@
+// $Id$
+
+#include "ace/FlReactor/FlReactor.h"
+
+ACE_RCSID(ace, FlReactor, "$Id$")
+
+#include /**/ <FL/Fl.h>
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+ACE_ALLOC_HOOK_DEFINE (ACE_FlReactor)
+
+// Must be called with lock held
+ACE_FlReactor::ACE_FlReactor (size_t size,
+ int restart,
+ ACE_Sig_Handler *h)
+ : ACE_Select_Reactor (size, restart, h)
+{
+ // When the ACE_Select_Reactor is constructed it creates the notify
+ // pipe and registers it with the register_handler_i() method. The
+ // FlReactor overloads this method BUT because the
+ // register_handler_i occurs when constructing the base class
+ // ACE_Select_Reactor, the ACE_Select_Reactor register_handler_i()
+ // is called not the FlReactor register_handler_i(). This means
+ // that the notify pipe is registered with the ACE_Select_Reactor
+ // event handling code not the FlReactor and so notfications don't
+ // work. To get around this we simply close and re-opened the
+ // notification handler in the constructor of the FlReactor.
+
+#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
+ this->notify_handler_->close ();
+ this->notify_handler_->open (this, 0);
+#endif /* ACE_MT_SAFE */
+}
+
+ACE_FlReactor::~ACE_FlReactor (void)
+{
+}
+
+// This is just the <wait_for_multiple_events> from ace/Reactor.cpp
+// but we use the Fl functions to wait for an event, not <select>
+
+int
+ACE_FlReactor::wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &handle_set,
+ ACE_Time_Value *max_wait_time)
+{
+ ACE_TRACE ("ACE_FlReactor::wait_for_multiple_events");
+ int nfound;
+
+ do
+ {
+ max_wait_time = this->timer_queue_->calculate_timeout (max_wait_time);
+
+ size_t width = this->handler_rep_.max_handlep1 ();
+ handle_set.rd_mask_ = this->wait_set_.rd_mask_;
+ handle_set.wr_mask_ = this->wait_set_.wr_mask_;
+ handle_set.ex_mask_ = this->wait_set_.ex_mask_;
+
+ // Check to make sure our handle's are all usable.
+ ACE_Select_Reactor_Handle_Set temp_set = handle_set;
+
+ ACE_Time_Value zero = ACE_Time_Value::zero;
+ if (ACE_OS::select (width,
+ temp_set.rd_mask_,
+ temp_set.wr_mask_,
+ temp_set.ex_mask_,
+ &zero) == -1)
+ return -1; // Bad file arguments...
+
+ // Instead of waiting using <select>, just use the Fl mechanism
+ // to wait for one or more events...
+
+ // Wait for something to happen.
+ double t = 0;
+ if (max_wait_time != 0)
+ t = max_wait_time->sec () + max_wait_time->usec () / 1000000.0F;
+
+ while (t > 0) {
+ t = Fl::wait (t);
+ }
+
+ // Reset the width, in case it changed during the upcalls.
+ width = this->handler_rep_.max_handlep1 ();
+
+ // Now actually read the result needed by the <Select_Reactor>
+ // using <select>.
+ zero = ACE_Time_Value::zero;
+ nfound = ACE_OS::select (width,
+ handle_set.rd_mask_,
+ handle_set.wr_mask_,
+ handle_set.ex_mask_,
+ &zero);
+
+ } while (nfound == -1 && this->handle_error () > 0);
+
+ if (nfound > 0)
+ {
+#if !defined (ACE_WIN32)
+ handle_set.rd_mask_.sync (this->handler_rep_.max_handlep1 ());
+ handle_set.wr_mask_.sync (this->handler_rep_.max_handlep1 ());
+ handle_set.ex_mask_.sync (this->handler_rep_.max_handlep1 ());
+#endif /* ACE_WIN32 */
+ }
+ return nfound; // Timed out or input available
+}
+
+void
+ACE_FlReactor::fl_io_proc (int fd, void* reactor)
+{
+ ACE_FlReactor *self = static_cast<ACE_FlReactor *> (reactor);
+ ACE_HANDLE handle = (ACE_HANDLE)fd; //reinterpret_cast<ACE_HANDLE> (fd);
+
+ // my copy isn't const.
+ ACE_Time_Value zero = ACE_Time_Value::zero;
+
+ ACE_Select_Reactor_Handle_Set wait_set;
+
+ // Deal with one file event.
+
+ // - read which kind of event
+ if (self->wait_set_.rd_mask_.is_set (handle))
+ wait_set.rd_mask_.set_bit (handle);
+ if (self->wait_set_.wr_mask_.is_set (handle))
+ wait_set.wr_mask_.set_bit (handle);
+ if (self->wait_set_.ex_mask_.is_set (handle))
+ wait_set.ex_mask_.set_bit (handle);
+
+ int result = ACE_OS::select (fd + 1,
+ wait_set.rd_mask_,
+ wait_set.wr_mask_,
+ wait_set.ex_mask_, &zero);
+
+ ACE_Select_Reactor_Handle_Set dispatch_set;
+
+ // - Use only that one file event (removes events for other files).
+ if (result > 0)
+ {
+ if (wait_set.rd_mask_.is_set (handle))
+ dispatch_set.rd_mask_.set_bit (handle);
+ if (wait_set.wr_mask_.is_set (handle))
+ dispatch_set.wr_mask_.set_bit (handle);
+ if (wait_set.ex_mask_.is_set (handle))
+ dispatch_set.ex_mask_.set_bit (handle);
+
+ self->dispatch (1, dispatch_set);
+ }
+}
+
+void
+ACE_FlReactor::fl_timeout_proc (void* reactor)
+{
+ ACE_FlReactor *self = static_cast<ACE_FlReactor *> (reactor);
+
+ // Deal with any timer events
+ ACE_Select_Reactor_Handle_Set handle_set;
+ self->dispatch (0, handle_set);
+ self->reset_timeout ();
+}
+
+
+int
+ACE_FlReactor::register_handler_i (ACE_HANDLE handle,
+ ACE_Event_Handler *handler,
+ ACE_Reactor_Mask mask)
+{
+ ACE_TRACE ("ACE_FlReactor::register_handler_i");
+
+ int result = ACE_Select_Reactor::register_handler_i (handle,
+ handler, mask);
+ if (result == -1)
+ return -1;
+
+ int condition = 0;
+
+ if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK))
+ ACE_SET_BITS (condition, FL_READ);
+ if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::WRITE_MASK))
+ ACE_SET_BITS (condition, FL_WRITE);
+ if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK))
+ ACE_SET_BITS (condition, FL_EXCEPT);
+ if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK))
+ ACE_SET_BITS (condition, FL_READ);
+ if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
+ {
+ ACE_SET_BITS (condition, FL_WRITE); // connected, you may write
+ ACE_SET_BITS (condition, FL_READ); // connected, you have data/err
+ }
+
+ if (condition != 0)
+ {
+ Fl::add_fd ((int)handle, // reinterpret_cast<int> (handle),
+ ACE_FlReactor::fl_io_proc,
+ this);
+ }
+ return 0;
+}
+
+int
+ACE_FlReactor::register_handler_i (const ACE_Handle_Set &handles,
+ ACE_Event_Handler *handler,
+ ACE_Reactor_Mask mask)
+{
+ return ACE_Select_Reactor::register_handler_i (handles,
+ handler,
+ mask);
+}
+
+int
+ACE_FlReactor::remove_handler_i (ACE_HANDLE handle,
+ ACE_Reactor_Mask mask)
+{
+ ACE_TRACE ("ACE_FlReactor::remove_handler_i");
+
+ // In the registration phase we registered first with
+ // ACE_Select_Reactor and then with X. Now we are now doing things
+ // in reverse order.
+
+ // First clean up the corresponding X11Input.
+ Fl::remove_fd ((int)handle); // reinterpret_cast<int> (handle);
+
+ // Now let the reactor do its work.
+ return ACE_Select_Reactor::remove_handler_i (handle,
+ mask);
+}
+
+int
+ACE_FlReactor::remove_handler_i (const ACE_Handle_Set &handles,
+ ACE_Reactor_Mask mask)
+{
+ return ACE_Select_Reactor::remove_handler_i (handles,
+ mask);
+}
+
+// The following function ensures there's an Fl timeout for the first
+// timeout in the Reactor's Timer_Queue.
+
+void
+ACE_FlReactor::reset_timeout (void)
+{
+ ACE_Time_Value *max_wait_time =
+ this->timer_queue_->calculate_timeout (0);
+
+ if (max_wait_time != 0)
+ {
+ float t = max_wait_time->sec ()
+ + max_wait_time->usec () / 1000000.0F;
+ Fl::add_timeout (t,
+ ACE_FlReactor::fl_timeout_proc,
+ this);
+ }
+}
+
+int
+ACE_FlReactor::reset_timer_interval
+ (long timer_id,
+ const ACE_Time_Value &interval)
+{
+ ACE_TRACE ("ACE_FlReactor::reset_timer_interval");
+ ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token, ace_mon, this->token_, -1));
+
+ int result =
+ ACE_Select_Reactor::reset_timer_interval (timer_id,
+ interval);
+
+ if (result == -1)
+ return -1;
+ else
+ {
+ this->reset_timeout ();
+ return result;
+ }
+}
+
+long
+ACE_FlReactor::schedule_timer (ACE_Event_Handler *event_handler,
+ const void *arg,
+ const ACE_Time_Value &delay,
+ const ACE_Time_Value &interval)
+{
+ ACE_TRACE ("ACE_FlReactor::schedule_timer");
+ ACE_MT (ACE_GUARD_RETURN (ACE_Select_Reactor_Token, ace_mon, this->token_, -1));
+
+ long result = ACE_Select_Reactor::schedule_timer (event_handler,
+ arg,
+ delay,
+ interval);
+ if (result == -1)
+ return -1;
+ else
+ {
+ this->reset_timeout ();
+ return result;
+ }
+}
+
+int
+ACE_FlReactor::cancel_timer (ACE_Event_Handler *handler,
+ int dont_call_handle_close)
+{
+ ACE_TRACE ("ACE_FlReactor::cancel_timer");
+
+ if (ACE_Select_Reactor::cancel_timer (handler,
+ dont_call_handle_close) == -1)
+ return -1;
+ else
+ {
+ this->reset_timeout ();
+ return 0;
+ }
+}
+
+int
+ACE_FlReactor::cancel_timer (long timer_id,
+ const void **arg,
+ int dont_call_handle_close)
+{
+ ACE_TRACE ("ACE_FlReactor::cancel_timer");
+
+ if (ACE_Select_Reactor::cancel_timer (timer_id,
+ arg,
+ dont_call_handle_close) == -1)
+ return -1;
+ else
+ {
+ this->reset_timeout ();
+ return 0;
+ }
+}
+
+ACE_END_VERSIONED_NAMESPACE_DECL
diff --git a/ACE/ace/FlReactor/FlReactor.h b/ACE/ace/FlReactor/FlReactor.h
new file mode 100644
index 00000000000..c2e3c64df06
--- /dev/null
+++ b/ACE/ace/FlReactor/FlReactor.h
@@ -0,0 +1,110 @@
+/* -*- C++ -*- */
+
+//=============================================================================
+/**
+ * @file FlReactor.h
+ *
+ * $Id$
+ *
+ * @author Carlos O'Ryan <coryan@cs.wustl.edu>
+ * @author Based in part in the ACE_XtReactor implementation by
+ * @author Eric C. Newton's <ecn@clark.net>
+ * @author Kirill Rybaltchenko <Kirill.Rybaltchenko@cern.ch>
+ * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
+ */
+//=============================================================================
+
+
+#ifndef ACE_FLREACTOR_H
+#define ACE_FLREACTOR_H
+#include /**/ "ace/pre.h"
+
+#include /**/ "ace/config-all.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/FlReactor/ACE_FlReactor_export.h"
+#include "ace/Select_Reactor.h"
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+/**
+ * @class ACE_FlReactor
+ *
+ * @brief A Reactor implementation that uses the Fast-Light (FL) toolkit
+ * for event demultiplexing. This will let us integrate the FL
+ * toolkit with ACE and/or TAO.
+ *
+ * As many other GUI toolkits FL supports a minimal set of
+ * callbacks to handle event demultiplexing, namely simple methods
+ * to add file descriptors to the event demuxing set or timeout
+ * events. This class adapts this simple mechanisms so they are
+ * compatible with ACE's Reactor.
+ */
+class ACE_FlReactor_Export ACE_FlReactor : public ACE_Select_Reactor
+{
+
+public:
+ // = Initialization and termination methods.
+ ACE_FlReactor (size_t size = DEFAULT_SIZE,
+ int restart = 0,
+ ACE_Sig_Handler * = 0);
+ virtual ~ACE_FlReactor (void);
+
+ // = Timer operations.
+ virtual long schedule_timer (ACE_Event_Handler *event_handler,
+ const void *arg,
+ const ACE_Time_Value &delay,
+ const ACE_Time_Value &interval);
+ virtual int reset_timer_interval (long timer_id,
+ const ACE_Time_Value &interval);
+ virtual int cancel_timer (ACE_Event_Handler *handler,
+ int dont_call_handle_close = 1);
+ virtual int cancel_timer (long timer_id,
+ const void **arg = 0,
+ int dont_call_handle_close = 1);
+
+protected:
+ // = Register timers/handles with Fl.
+ /// Register a single @a handler.
+ virtual int register_handler_i (ACE_HANDLE handle,
+ ACE_Event_Handler *handler,
+ ACE_Reactor_Mask mask);
+
+ /// Register a set of <handlers>.
+ virtual int register_handler_i (const ACE_Handle_Set &handles,
+ ACE_Event_Handler *handler,
+ ACE_Reactor_Mask mask);
+
+ /// Remove the <handler> associated with this @a handle.
+ virtual int remove_handler_i (ACE_HANDLE handle,
+ ACE_Reactor_Mask mask);
+
+ /// Remove a set of <handles>.
+ virtual int remove_handler_i (const ACE_Handle_Set &handles,
+ ACE_Reactor_Mask);
+
+ /// Wait for events to occur.
+ virtual int wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &,
+ ACE_Time_Value *);
+
+private:
+ /// This method ensures there's an Fl timeout for the first timeout
+ /// in the Reactor's Timer_Queue.
+ void reset_timeout (void);
+
+ // = Integrate with the FL callback function mechanism.
+ static void fl_io_proc (int fd, void*);
+ static void fl_timeout_proc (void*);
+
+ /// Deny access since member-wise won't work...
+ ACE_FlReactor (const ACE_FlReactor &);
+ ACE_FlReactor &operator = (const ACE_FlReactor &);
+};
+
+ACE_END_VERSIONED_NAMESPACE_DECL
+
+#include /**/ "ace/post.h"
+#endif /* ACE_FLREACTOR_H */