summaryrefslogtreecommitdiff
path: root/TAO/tao/default_resource.h
blob: 5e2a3d49c09c62b33b276890dc9cc01ecfbbb766 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// -*- C++ -*-
// $Id$

// ============================================================================
//
// = LIBRARY
//   TAO
//
// = FILENAME
//   default_resource.h
//
// = AUTHOR
//   Chris Cleeland
//   Carlos O'Ryan
//
// ============================================================================

#ifndef TAO_DEFAULT_RESOURCE_H
#define TAO_DEFAULT_RESOURCE_H

#include "ace/Strategies_T.h"
#include "ace/Singleton.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/Resource_Factory.h"
#include "tao/IIOP_Acceptor.h"
#include "tao/POA.h"

// ****************************************************************

class TAO_Default_Reactor : public ACE_Reactor
{
  // = TITLE
  //
  //   Force TAO to use Select Reactor.
public:
  TAO_Default_Reactor (int nolock = 0);
  virtual ~TAO_Default_Reactor (void);
};

// ****************************************************************

class TAO_Export TAO_Allocated_Resources
{
  // = TITLE
  //   Container for the resources allocated by the factory.
  //
  // = DESCRIPTION
  //
public:
  TAO_Allocated_Resources (void);
  // Constructor necessary because we have pointers.  It's inlined
  // here rather than in the .i file because it's easier than trying
  // to re-order header files in corba.h to eliminate the "used
  // before declared inline" warnings/errors on certain compilers.

  ~TAO_Allocated_Resources (void);
  // Destructor is also necessary because we now allocate some of
  // the objects held here.

  // = Resources

  ACE_Thread_Manager tm_;
  // The Thread Manager

  TAO_NULL_CREATION_STRATEGY null_creation_strategy_;
  // This no-op creation strategy is necessary for using the
  // <Strategy_Connector> with the <Cached_Connect_Strategy>.

  TAO_NULL_ACTIVATION_STRATEGY null_activation_strategy_;
  // This no-op activation strategy prevents the cached connector from
  // calling the service handler's <open> method multiple times.

  TAO_IIOP_Acceptor a_;
  // The Acceptor

  TAO_IIOP_Connector c_;
  // The Connector, HACK to create the first connector which happens
  // to be IIOP.

  TAO_Connector_Registry cr_;
  // The Connector Registry!

  TAO_Default_Reactor *r_;
  // The Reactor.

  TAO_Object_Adapter *object_adapter_;
  // Object Adapter.

  TAO_CACHED_CONNECT_STRATEGY *cached_connect_strategy_;
  // The Cached Connect Strategy

  TAO_POA *poa_;
  // Pointer to application-created POA.

  ACE_Allocator *input_cdr_dblock_allocator_;
  ACE_Allocator *input_cdr_buffer_allocator_;
  // The allocators for the input CDR streams.

  ACE_Allocator *output_cdr_dblock_allocator_;
  ACE_Allocator *output_cdr_buffer_allocator_;
  // The allocators for the output CDR streams.
};

// ****************************************************************

class TAO_Default_Resource_Factory : public TAO_Resource_Factory
{
  // = TITLE
  //   TAO's default resource factory
  //
  // = DESCRIPTION
  //   Using a <{resource source specifier}> as a discriminator, the
  //   factory can return resource instances which are, e.g., global,
  //   stored in thread-specific storage, stored in shared memory,
  //   etc.
  //
public:
  // = Initialization and termination methods.
  TAO_Default_Resource_Factory (void);
  // Constructor.

  virtual ~TAO_Default_Resource_Factory (void);
  // Destructor.

  // = Service Configurator hooks.
  virtual int init (int argc, char* argv[]);
  // Dynamic linking hook

  int parse_args (int argc, char* argv[]);
  // Parse svc.conf arguments

  // = Member Accessors
  enum
  {
    TAO_GLOBAL,
    TAO_TSS
  };

  // = Type of Reactor
  enum
  {
    TAO_TOKEN,     // Use ACE_Token as Select_Reactor's internal lock
    TAO_NULL_LOCK  // Use ACE_Noop_Token as Select_Reactor's internal lock
  };

  // = Range of values for <{resource source specifier}>.
  virtual void resource_source (int which_source);
  // Set the resource source specifier.
  virtual int resource_source (void);
  // Get the resource source specifier.

  virtual void poa_source (int which_source);
  // Set the POA source specifier.
  virtual int poa_source (void);
  // Get the POA source specifier.

  int cdr_allocator_source (void);
  // Modify and get the source for the CDR allocators

  // = Resource Retrieval
  virtual ACE_Reactor *get_reactor (void);
  virtual ACE_Thread_Manager *get_thr_mgr (void);
  virtual TAO_Connector *get_connector (void);
  virtual TAO_Connector_Registry *get_connector_registry (void);
  virtual TAO_CACHED_CONNECT_STRATEGY *get_cached_connect_strategy (void);
  virtual TAO_NULL_CREATION_STRATEGY *get_null_creation_strategy (void);
  virtual TAO_NULL_ACTIVATION_STRATEGY *get_null_activation_strategy (void);
  virtual TAO_Acceptor *get_acceptor (void);
  virtual TAO_POA *get_root_poa (void);
  virtual TAO_Object_Adapter *object_adapter (void);
  virtual TAO_GLOBAL_Collocation_Table *get_global_collocation_table (void);
  virtual int reactor_lock (void);
  virtual ACE_Allocator* input_cdr_dblock_allocator (void);
  virtual ACE_Allocator* input_cdr_buffer_allocator (void);
  virtual ACE_Allocator* output_cdr_dblock_allocator (void);
  virtual ACE_Allocator* output_cdr_buffer_allocator (void);
  virtual ACE_Data_Block *create_input_cdr_data_block (size_t size);

protected:

  int resource_source_;
  // Flag indicating whether resources should be global or
  // thread-specific.

  int poa_source_;
  // Flag indicating whether the POA should be global or
  // thread-specific.  If not set specifically, this takes on the
  // value of <resource_source_>.

  int collocation_table_source_;
  // Flag indicating whether the collocation table should be global
  // thread-specific.  It defaults to TAO_GLOBAL if not set
  // specifically.

  int reactor_lock_;
  // Flag indicating wether we should provide a lock-freed reactor
  // or not.

  int cdr_allocator_source_;
  // The source for the CDR allocator. Even with a TSS resource
  // factory the user may be interested in global allocators for the
  // CDR streams, for instance to keep the buffers around after the
  // upcall and/or pass them to another thread.

  // = Typedefs for the singleton types used to store our orb core
  // information.
  typedef ACE_Singleton<TAO_Allocated_Resources, ACE_SYNCH_MUTEX>
          GLOBAL_ALLOCATED;
  typedef ACE_TSS_Singleton<TAO_Allocated_Resources, ACE_SYNCH_MUTEX>
          TSS_ALLOCATED;

  typedef ACE_Singleton<TAO_GLOBAL_Collocation_Table, ACE_SYNCH_MUTEX>
          GLOBAL_Collocation_Table;
};

#if defined (__ACE_INLINE__)
#include "tao/default_resource.i"
#endif /* __ACE_INLINE__ */

ACE_STATIC_SVC_DECLARE (TAO_Default_Resource_Factory)
ACE_FACTORY_DECLARE (TAO, TAO_Default_Resource_Factory)

#endif /* TAO_DEFAULT_CLIENT_H */