Correct feature names
[ACE_TAO.git] / ACE / ace / Module.h
blob40d619185953c75666f4820c53221e902d4b87ec
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file Module.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //==========================================================================
11 #ifndef ACE_MODULE_H
12 #define ACE_MODULE_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Task_T.h"
23 #include "ace/os_include/os_dirent.h"
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 /**
28 * @class ACE_Module_Base
30 * @brief Workaround HP/C++ compiler bug with enums in templates.
32 * Certain C++ compilers, e.g., the HP/UX 10.x and 9.x compilers,
33 * seem to fail if enums are defined inside a template, hence we
34 * have to move them into a base class.
36 class ACE_Export ACE_Module_Base
38 public:
39 enum
41 /// Indicates that the flags have not been set
42 M_FLAGS_NOT_SET = 0,
44 /// Indicates that close() should delete the writer Task.
45 M_DELETE_READER = 1,
47 /// Indicates that close() should delete the reader Task.
48 M_DELETE_WRITER = 2,
50 /// Indicates that close() deletes the Tasks.
51 /**
52 * Don't change this value without updating the same enum in class
53 * ACE_Stream...
54 * The M_DELETE_READER and M_DELETE_WRITER flags may be or'ed
55 * together.
57 M_DELETE = 3,
59 /// Indicates that close() should not delete any Tasks.
60 M_DELETE_NONE = 4
64 /**
65 * @class ACE_Module
67 * @brief An abstraction for managing a bi-directional flow of messages.
69 * This is based on the Module concept in System V Streams,
70 * which contains a pair of Tasks, one for handling upstream
71 * processing, one for handling downstream processing. In
72 * general, you shouldn't subclass from this class, but instead
73 * subclass from the ACE_Task.
75 template <ACE_SYNCH_DECL, class TIME_POLICY = ACE_System_Time_Policy>
76 class ACE_Module : public ACE_Module_Base
78 public:
79 /// Create an empty Module.
80 ACE_Module (void);
82 /// Shutdown the Module.
83 virtual ~ACE_Module (void);
85 /// Create an initialized module with @a module_name as its identity
86 /// and @a reader and @a writer as its tasks.
87 ACE_Module (const ACE_TCHAR *module_name,
88 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *writer = 0,
89 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *reader = 0,
90 void *args = 0,
91 int flags = M_DELETE);
93 /**
94 * Initialize the module with @a module_name as its identity
95 * and @a reader> and @a writer as its tasks. Previously register
96 * reader or writers or closed down and deleted according to the
97 * value of flags_. Should not be called from within
98 * <ACE_Task::module_closed>.
100 int open (const ACE_TCHAR *module_name,
101 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *writer = 0,
102 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *reader = 0,
103 void *a = 0,
104 int flags = M_DELETE);
107 * Close down the module and its tasks. The flags argument can be
108 * used to override the default behaviour, which depends on previous
109 * @a flags values in calls to c'tor, <open>, <reader>, and <writer>.
110 * A previous value M_DELETE[_XXX] can not be overridden. Should
111 * not be called from within <ACE_Task::module_closed>.
113 int close (int flags = M_DELETE_NONE);
115 // = ACE_Task manipulation routines
116 /// Get the writer task.
117 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *writer (void);
120 * Set the writer task. @a flags can be used to indicate that the
121 * module should delete the writer during a call to close or to the
122 * destructor. If a previous writer exists, it is closed. It may
123 * also be deleted, depending on the old flags_ value. Should not
124 * be called from within <ACE_Task::module_closed>.
126 void writer (ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *q, int flags = M_DELETE_WRITER);
128 /// Get the reader task.
129 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *reader (void);
132 * Set the reader task. @a flags can be used to indicate that the
133 * module should delete the reader during a call to close or to the
134 * destructor. If a previous reader exists, it is closed. It may
135 * also be deleted, depending on the old flags_ value. Should not
136 * be called from within <ACE_Task::module_closed>.
138 void reader (ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *q, int flags = M_DELETE_READER);
140 /// Set and get pointer to sibling ACE_Task in an ACE_Module
141 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *sibling (ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *orig);
143 // = Identify the module
144 /// Get the module name.
145 const ACE_TCHAR *name (void) const;
147 /// Set the module name.
148 void name (const ACE_TCHAR *);
150 // = Argument to the Tasks.
151 /// Get the argument passed to the tasks.
152 void *arg (void) const;
154 /// Set the argument passed to the tasks.
155 void arg (void *);
157 /// Link to other modules in the ustream stack
158 void link (ACE_Module<ACE_SYNCH_USE, TIME_POLICY> *m);
160 /// Get the next pointer to the module above in the stream.
161 ACE_Module<ACE_SYNCH_USE, TIME_POLICY> *next (void);
163 /// Set the next pointer to the module above in the stream.
164 void next (ACE_Module<ACE_SYNCH_USE, TIME_POLICY> *m);
166 /// Dump the state of an object.
167 void dump (void) const;
169 /// Declare the dynamic allocation hooks.
170 ACE_ALLOC_HOOK_DECLARE;
172 private:
173 /// Implements the close operation for either the reader or the
174 /// writer task (depending on @a which).
175 int close_i (int which, int flags);
177 /// Pair of Tasks that form the "read-side" and "write-side" of the
178 /// ACE_Module partitioning.
179 ACE_Task<ACE_SYNCH_USE, TIME_POLICY> *q_pair_[2];
181 /// Name of the ACE_Module.
182 ACE_TCHAR name_[MAXPATHLEN + 1];
184 /// Next ACE_Module in the stack.
185 ACE_Module<ACE_SYNCH_USE, TIME_POLICY> *next_;
187 /// Argument passed through to the reader and writer task when they
188 /// are opened.
189 void *arg_;
191 /// Holds flags which are used to determine if the reader and writer
192 /// task have to be deleted on exit
193 int flags_;
196 ACE_END_VERSIONED_NAMESPACE_DECL
198 #if defined (__ACE_INLINE__)
199 #include "ace/Module.inl"
200 #endif /* __ACE_INLINE__ */
202 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
203 #include "ace/Module.cpp"
204 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
206 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
207 #pragma implementation ("Module.cpp")
208 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
210 #include /**/ "ace/post.h"
212 #endif /* ACE_MODULE_H */