Restore build on FreeBSD.
[getmangos.git] / dep / ACE_wrappers / ace / Module.h
blob29690a5f3db98326c363477a8d5918956aa937f9
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file Module.h
7 * $Id: Module.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
11 //==========================================================================
13 #ifndef ACE_MODULE_H
14 #define ACE_MODULE_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/ACE_export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/Task_T.h"
25 #include "ace/os_include/os_dirent.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 /**
30 * @class ACE_Module_Base
32 * @brief Workaround HP/C++ compiler bug with enums in templates.
34 * Certain C++ compilers, e.g., the HP/UX 10.x and 9.x compilers,
35 * seem to fail if enums are defined inside a template, hence we
36 * have to move them into a base class.
38 class ACE_Export ACE_Module_Base
40 public:
41 enum
43 /// Indicates that the flags have not been set
44 M_FLAGS_NOT_SET = 0,
46 /// Indicates that <close> should delete the writer Task.
47 M_DELETE_READER = 1,
49 /// Indicates that <close> should delete the reader Task.
50 M_DELETE_WRITER = 2,
52 /// Indicates that <close> deletes the Tasks.
53 /**
54 * Don't change this value without updating the same enum in class
55 * ACE_Stream...
56 * The <M_DELETE_READER> and <M_DELETE_WRITER> flags may be or'ed
57 * together.
59 M_DELETE = 3,
61 /// Indicates that <close> should not delete any Tasks.
62 M_DELETE_NONE = 4
66 /**
67 * @class ACE_Module
69 * @brief An abstraction for managing a bi-directional flow of messages.
71 * This is based on the Module concept in System V Streams,
72 * which contains a pair of Tasks, one for handling upstream
73 * processing, one for handling downstream processing. In
74 * general, you shouldn't subclass from this class, but instead
75 * subclass from the ACE_Task.
77 template <ACE_SYNCH_DECL>
78 class ACE_Module : public ACE_Module_Base
80 public:
81 // = Initialization and termination methods.
82 /// Create an empty Module.
83 ACE_Module (void);
85 /// Shutdown the Module.
86 virtual ~ACE_Module (void);
88 /// Create an initialized module with @a module_name as its identity
89 /// and @a reader and @a writer as its tasks.
90 ACE_Module (const ACE_TCHAR *module_name,
91 ACE_Task<ACE_SYNCH_USE> *writer = 0,
92 ACE_Task<ACE_SYNCH_USE> *reader = 0,
93 void *args = 0,
94 int flags = M_DELETE);
96 /**
97 * Initialize the module with <module_name> as its identity
98 * and <reader> and <writer> as its tasks. Previously register
99 * reader or writers or closed down and deleted according to the
100 * value of flags_. Should not be called from within
101 * <ACE_Task::module_closed>.
103 int open (const ACE_TCHAR *module_name,
104 ACE_Task<ACE_SYNCH_USE> *writer = 0,
105 ACE_Task<ACE_SYNCH_USE> *reader = 0,
106 void *a = 0,
107 int flags = M_DELETE);
110 * Close down the module and its tasks. The flags argument can be
111 * used to override the default behaviour, which depends on previous
112 * @a flags values in calls to c'tor, <open>, <reader>, and <writer>.
113 * A previous value M_DELETE[_XXX] can not be overridden. Should
114 * not be called from within <ACE_Task::module_closed>.
116 int close (int flags = M_DELETE_NONE);
118 // = ACE_Task manipulation routines
119 /// Get the writer task.
120 ACE_Task<ACE_SYNCH_USE> *writer (void);
123 * Set the writer task. @a flags can be used to indicate that the
124 * module should delete the writer during a call to close or to the
125 * destructor. If a previous writer exists, it is closed. It may
126 * also be deleted, depending on the old flags_ value. Should not
127 * be called from within <ACE_Task::module_closed>.
129 void writer (ACE_Task<ACE_SYNCH_USE> *q, int flags = M_DELETE_WRITER);
131 /// Get the reader task.
132 ACE_Task<ACE_SYNCH_USE> *reader (void);
135 * Set the reader task. @a flags can be used to indicate that the
136 * module should delete the reader during a call to close or to the
137 * destructor. If a previous reader exists, it is closed. It may
138 * also be deleted, depending on the old flags_ value. Should not
139 * be called from within <ACE_Task::module_closed>.
141 void reader (ACE_Task<ACE_SYNCH_USE> *q, int flags = M_DELETE_READER);
143 /// Set and get pointer to sibling ACE_Task in an ACE_Module
144 ACE_Task<ACE_SYNCH_USE> *sibling (ACE_Task<ACE_SYNCH_USE> *orig);
146 // = Identify the module
147 /// Get the module name.
148 const ACE_TCHAR *name (void) const;
150 /// Set the module name.
151 void name (const ACE_TCHAR *);
153 // = Argument to the Tasks.
154 /// Get the argument passed to the tasks.
155 void *arg (void) const;
157 /// Set the argument passed to the tasks.
158 void arg (void *);
160 /// Link to other modules in the ustream stack
161 void link (ACE_Module<ACE_SYNCH_USE> *m);
163 /// Get the next pointer to the module above in the stream.
164 ACE_Module<ACE_SYNCH_USE> *next (void);
166 /// Set the next pointer to the module above in the stream.
167 void next (ACE_Module<ACE_SYNCH_USE> *m);
169 /// Dump the state of an object.
170 void dump (void) const;
172 /// Declare the dynamic allocation hooks.
173 ACE_ALLOC_HOOK_DECLARE;
175 private:
176 /// Implements the close operation for either the reader or the
177 /// writer task (depending on <which>).
178 int close_i (int which, int flags);
180 /// Pair of Tasks that form the "read-side" and "write-side" of the
181 /// ACE_Module partitioning.
182 ACE_Task<ACE_SYNCH_USE> *q_pair_[2];
184 /// Name of the ACE_Module.
185 ACE_TCHAR name_[MAXPATHLEN + 1];
187 /// Next ACE_Module in the stack.
188 ACE_Module<ACE_SYNCH_USE> *next_;
190 /// Argument passed through to the reader and writer task when they
191 /// are opened.
192 void *arg_;
194 /// Holds flags which are used to determine if the reader and writer
195 /// task have to be deleted on exit
196 int flags_;
199 ACE_END_VERSIONED_NAMESPACE_DECL
201 #if defined (__ACE_INLINE__)
202 #include "ace/Module.inl"
203 #endif /* __ACE_INLINE__ */
205 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
206 #include "ace/Module.cpp"
207 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
209 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
210 #pragma implementation ("Module.cpp")
211 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
213 #include /**/ "ace/post.h"
215 #endif /* ACE_MODULE_H */