summaryrefslogtreecommitdiff
path: root/ace/Module.h
blob: d2bd2c608f03898ab1c7b2c4ae8b325999fcea77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    ace
// 
// = FILENAME
//    Module.h
//
// = AUTHOR
//    Doug Schmidt 
// 
// ============================================================================

#if !defined (ACE_MODULE_H)
#define ACE_MODULE_H

#include "ace/ACE.h"
#include "ace/Task.h"

// Forward decl.
// template <ACE_SYNCH_1> class ACE_Task;

template <ACE_SYNCH_1>
class ACE_Module
  // = TITLE
  //     An abstraction for managing a bi-directional flow of messages.
  // 
  // = DESCRIPTION
  //     This is based on the Module concept in System V Streams,
  //     which contains a pair of Tasks, one for handling upstream
  //     processing, one for handling downstream processing.
{
  friend class ACE_Shutup_GPlusPlus;  // Turn off g++ warning
public:
  enum
  {
    M_DELETE_NONE = 0,
    // Indicates that close() should not delete any tasks.

    M_DELETE_READER = 1,
    // Indicates that close() should delete the writer thread.

    M_DELETE_WRITER = 2,
    // Indicates that close() should delete the reader thread.

    M_DELETE = 3 
    // Indicates that close() deletes the Tasks.  Don't change this
    // value without updating the same enum in class ACE_Stream...
    // The <M_DELETE_READER> and <M_DELETE_WRITER> flags may be or'ed
    // together.
  };

  // = Initialization and termination methods.
  ACE_Module (void);
  // Create an empty Module.

  ~ACE_Module (void);		
  // Shutdown the Module.

  ACE_Module (const char *module_name, 
	      ACE_Task<ACE_SYNCH_2> *writer = 0, 
	      ACE_Task<ACE_SYNCH_2> *reader = 0, 
	      void *args = 0,
	      int flags = M_DELETE);
  // Create an initialized module with <module_name> as its identity
  // and <reader> and <writer> as its tasks.

  int open (const char *module_name, 
	    ACE_Task<ACE_SYNCH_2> *writer = 0, 
	    ACE_Task<ACE_SYNCH_2> *reader = 0, 
	    void *a = 0,
	    int flags = M_DELETE);
  // Create an initialized module with <module_name> as its identity
  // and <reader> and <writer> as its tasks.  Previously register
  // reader or writers or closed down and deleted according to the
  // value of flags_.  Should not be called from within
  // ACE_Task::module_closed().

  int close (int flags = M_DELETE_NONE);
  // Close down the Module and its Tasks.  The flags argument can be
  // used to override the default behaviour, which depends on previous
  // <flags> values in calls to c'tor(), open(), reader() and
  // writer().  A previous value M_DELETE[_XXX] can not be overridden.
  // Should not be called from within ACE_Task::module_closed().
  
  // = ACE_Task manipulation routines 
  ACE_Task<ACE_SYNCH_2> *writer (void);
  // Get the writer task.

  void writer (ACE_Task<ACE_SYNCH_2> *q, int flags = M_DELETE_WRITER);
  // Set the writer task. <flags> can be used to indicate that the
  // module should delete the writer during a call to close or to the
  // destructor. If a previous writer exists, it is closed.  It may
  // also be deleted, depending on the old flags_ value.  Should not
  // be called from within ACE_Task::module_closed().

  ACE_Task<ACE_SYNCH_2> *reader (void);
  // Get the reader task.

  void reader (ACE_Task<ACE_SYNCH_2> *q, int flags = M_DELETE_READER);
  // Set the reader task. <flags> can be used to indicate that the
  // module should delete the reader during a call to close or to the
  // destructor. If a previous reader exists, it is closed.  It may
  // also be deleted, depending on the old flags_ value.  Should not
  // be called from within ACE_Task::module_closed()

  ACE_Task<ACE_SYNCH_2> *sibling (ACE_Task<ACE_SYNCH_2> *orig); 
  // Set and get pointer to sibling ACE_Task in ACE_Module.

  // = Identify the module 
  const char *name (void) const;
  // Get the module name.
  void name (const char *);
  // Set the module name.

  // = Argument to the Tasks. 
  void *arg (void) const;
  // Get the argument passed to the tasks.

  void arg (void *);
  // Set the argument passed to the tasks.

  void link (ACE_Module<ACE_SYNCH_2> *m);
  // Link to other modules in the ustream stack 

  ACE_Module<ACE_SYNCH_2> *next (void);
  // Get the next pointer to the module above in the stream.

  void next (ACE_Module<ACE_SYNCH_2> *m);
  // Set the next pointer to the module above in the stream.

  void dump (void) const;
  // Dump the state of an object.

  ACE_ALLOC_HOOK_DECLARE;
  // Declare the dynamic allocation hooks.

private:
  int close_i (int which, int flags);
  // Implements the close operation for either the reader or the
  // writer task (depending on <which>).

  ACE_Task<ACE_SYNCH_2> *q_pair_[2];   
  // Pair of Tasks that form the "read-side" and "write-side" of the
  // ACE_Module partitioning.

  char name_[MAXNAMLEN + 1];
  // Name of the ACE_Module.

  ACE_Module<ACE_SYNCH_2> *next_;
  // Next ACE_Module in the stack.

  void *arg_;
  // Argument passed through to the reader and writer task when they
  // are opened.

  int flags_;
  // Holds flags which are used to determine if the reader and writer
  // task have to be deleted on exit
};

#if defined (__ACE_INLINE__)
#include "ace/Module.i"
#endif /* __ACE_INLINE__ */

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Module.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Module.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* ACE_MODULE_H */