Module.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Module.h
00006  *
00007  *  Module.h,v 4.38 2006/01/17 20:28:29 jwillemsen Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //==========================================================================
00012 
00013 #ifndef ACE_MODULE_H
00014 #define ACE_MODULE_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/ACE_export.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "ace/Task_T.h"
00025 #include "ace/os_include/os_dirent.h"
00026 
00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 /**
00030  * @class ACE_Module_Base
00031  *
00032  * @brief Workaround HP/C++ compiler bug with enums in templates.
00033  *
00034  * Certain C++ compilers, e.g., the HP/UX 10.x and 9.x compilers,
00035  * seem to fail if enums are defined inside a template, hence we
00036  * have to move them into a base class.
00037  */
00038 class ACE_Export ACE_Module_Base
00039 {
00040 public:
00041   enum
00042   {
00043     /// Indicates that <close> should not delete any Tasks.
00044     M_DELETE_NONE = 0,
00045 
00046     /// Indicates that <close> should delete the writer Task.
00047     M_DELETE_READER = 1,
00048 
00049     /// Indicates that <close> should delete the reader Task.
00050     M_DELETE_WRITER = 2,
00051 
00052     /// Indicates that <close> deletes the Tasks.
00053     /**
00054      * Don't change this value without updating the same enum in class
00055      * ACE_Stream...
00056      * The <M_DELETE_READER> and <M_DELETE_WRITER> flags may be or'ed
00057      * together.
00058      */
00059     M_DELETE = 3
00060   };
00061 };
00062 
00063 /**
00064  * @class ACE_Module
00065  *
00066  * @brief An abstraction for managing a bi-directional flow of messages.
00067  *
00068  * This is based on the Module concept in System V Streams,
00069  * which contains a pair of Tasks, one for handling upstream
00070  * processing, one for handling downstream processing.  In
00071  * general, you shouldn't subclass from this class, but instead
00072  * subclass from the <ACE_Task>.
00073  */
00074 template <ACE_SYNCH_DECL>
00075 class ACE_Module : public ACE_Module_Base
00076 {
00077 public:
00078   // = Initialization and termination methods.
00079   /// Create an empty Module.
00080   ACE_Module (void);
00081 
00082   /// Shutdown the Module.
00083   virtual ~ACE_Module (void);
00084 
00085   /// Create an initialized module with @a module_name as its identity
00086   /// and @a reader and @a writer as its tasks.
00087   ACE_Module (const ACE_TCHAR *module_name,
00088               ACE_Task<ACE_SYNCH_USE> *writer = 0,
00089               ACE_Task<ACE_SYNCH_USE> *reader = 0,
00090               void *args = 0,
00091               int flags = M_DELETE);
00092 
00093   /**
00094    * Initialize the module with <module_name> as its identity
00095    * and <reader> and <writer> as its tasks.  Previously register
00096    * reader or writers or closed down and deleted according to the
00097    * value of flags_.  Should not be called from within
00098    * <ACE_Task::module_closed>.
00099    */
00100   int open (const ACE_TCHAR *module_name,
00101             ACE_Task<ACE_SYNCH_USE> *writer = 0,
00102             ACE_Task<ACE_SYNCH_USE> *reader = 0,
00103             void *a = 0,
00104             int flags = M_DELETE);
00105 
00106   /**
00107    * Close down the module and its tasks.  The flags argument can be
00108    * used to override the default behaviour, which depends on previous
00109    * <flags> values in calls to c'tor, <open>, <reader>, and <writer>.
00110    * A previous value M_DELETE[_XXX] can not be overridden.  Should
00111    * not be called from within <ACE_Task::module_closed>.
00112    */
00113   int close (int flags = M_DELETE_NONE);
00114 
00115   // = ACE_Task manipulation routines
00116   /// Get the writer task.
00117   ACE_Task<ACE_SYNCH_USE> *writer (void);
00118 
00119   /**
00120    * Set the writer task. @a flags can be used to indicate that the
00121    * module should delete the writer during a call to close or to the
00122    * destructor. If a previous writer exists, it is closed.  It may
00123    * also be deleted, depending on the old flags_ value.  Should not
00124    * be called from within <ACE_Task::module_closed>.
00125    */
00126   void writer (ACE_Task<ACE_SYNCH_USE> *q, int flags = M_DELETE_WRITER);
00127 
00128   /// Get the reader task.
00129   ACE_Task<ACE_SYNCH_USE> *reader (void);
00130 
00131   /**
00132    * Set the reader task. @a flags can be used to indicate that the
00133    * module should delete the reader during a call to close or to the
00134    * destructor. If a previous reader exists, it is closed.  It may
00135    * also be deleted, depending on the old flags_ value.  Should not
00136    * be called from within <ACE_Task::module_closed>.
00137    */
00138   void reader (ACE_Task<ACE_SYNCH_USE> *q, int flags = M_DELETE_READER);
00139 
00140   /// Set and get pointer to sibling ACE_Task in an ACE_Module
00141   ACE_Task<ACE_SYNCH_USE> *sibling (ACE_Task<ACE_SYNCH_USE> *orig);
00142 
00143   // = Identify the module
00144   /// Get the module name.
00145   const ACE_TCHAR *name (void) const;
00146 
00147   /// Set the module name.
00148   void name (const ACE_TCHAR *);
00149 
00150   // = Argument to the Tasks.
00151   /// Get the argument passed to the tasks.
00152   void *arg (void) const;
00153 
00154   /// Set the argument passed to the tasks.
00155   void arg (void *);
00156 
00157   /// Link to other modules in the ustream stack
00158   void link (ACE_Module<ACE_SYNCH_USE> *m);
00159 
00160   /// Get the next pointer to the module above in the stream.
00161   ACE_Module<ACE_SYNCH_USE> *next (void);
00162 
00163   /// Set the next pointer to the module above in the stream.
00164   void next (ACE_Module<ACE_SYNCH_USE> *m);
00165 
00166   /// Dump the state of an object.
00167   void dump (void) const;
00168 
00169   /// Declare the dynamic allocation hooks.
00170   ACE_ALLOC_HOOK_DECLARE;
00171 
00172 private:
00173   /// Implements the close operation for either the reader or the
00174   /// writer task (depending on <which>).
00175   int close_i (int which, int flags);
00176 
00177   /// Pair of Tasks that form the "read-side" and "write-side" of the
00178   /// ACE_Module partitioning.
00179   ACE_Task<ACE_SYNCH_USE> *q_pair_[2];
00180 
00181   /// Name of the ACE_Module.
00182   ACE_TCHAR name_[MAXPATHLEN + 1];
00183 
00184   /// Next ACE_Module in the stack.
00185   ACE_Module<ACE_SYNCH_USE> *next_;
00186 
00187   /// Argument passed through to the reader and writer task when they
00188   /// are opened.
00189   void *arg_;
00190 
00191   /// Holds flags which are used to determine if the reader and writer
00192   /// task have to be deleted on exit
00193   int flags_;
00194 };
00195 
00196 ACE_END_VERSIONED_NAMESPACE_DECL
00197 
00198 #if defined (__ACE_INLINE__)
00199 #include "ace/Module.inl"
00200 #endif /* __ACE_INLINE__ */
00201 
00202 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00203 #include "ace/Module.cpp"
00204 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00205 
00206 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00207 #pragma implementation ("Module.cpp")
00208 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00209 
00210 #include /**/ "ace/post.h"
00211 
00212 #endif /* ACE_MODULE_H */

Generated on Thu Nov 9 09:41:56 2006 for ACE by doxygen 1.3.6