Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Module.h

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

Generated on Mon Jun 16 11:20:26 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002