summaryrefslogtreecommitdiff
path: root/TAO/tao/Environment.h
blob: d3641c158f664137fc6077bfa9def84130c86603 (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
// This may look like C, but it's really -*- C++ -*-
// $Id$

// ============================================================================
//
// = LIBRARY
//   TAO
//
// = FILENAME
//   Environment.h
//
// = DESCRIPTION
//   Declare the CORBA_Environment class.  Note that this header file
//   only requires a few forward declarations of CORBA classes, this
//   is *very* important because even the ORB needs to know about it;
//   make your changes with care.  It is also a good idea trying to
//   minimize cross dependencies between header files.
//
// = AUTHOR
//   Carlos O'Ryan <coryan@cs.wustl.edu>
//
// ============================================================================

#ifndef TAO_ENVIRONMENT_H
#define TAO_ENVIRONMENT_H

#include "tao/corbafwd.h"

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

class TAO_ORB_Core;

class TAO_Export CORBA_Environment
{
  // = TITLE
  //   CORBA_Environment
  //
  // = DESCRIPTION
  //   A CORBA_Environment is a way to automagically ensure that
  //   exception data is freed -- the "var" class for Exceptions.  It
  //   adds just a bit of convenience function support, helping
  //   classify exceptions as well as reducing memory leakage.
  //
  //   The thread has a default environment to simplify porting
  //   between platforms that support native C++ exceptions and those
  //   that don't. This is a TSS resource (always), but with a twist:
  //   if the user creates a new environment the old one is "pushed"
  //   (actually the new one remembers it), eventually the new
  //   environment destructor pops itself from the stack and we
  //   recover the old environment.  This means that if the user
  //   create a new environment and somebody calls a function using
  //   the default one the exception will still be received in the
  //   environment created by the user.  The only drawback is that
  //   environments life time must nest properly, this shouldn't be a
  //   problem because environments are usually created on the stack,
  //   but, the spec allows their creation on the heap and/or as class
  //   members; we need to investigate the tradeoffs and take a
  //   decision.
public:
  // = Initialization and termination methods.
  CORBA_Environment (void);
  // The default constructor, the environment will hold no exceptions.

  CORBA_Environment (const CORBA_Environment &ACE_TRY_ENV);
  // Copy constructor.

  CORBA_Environment &operator=(const CORBA_Environment &ACE_TRY_ENV);
  // Assingment.

  ~CORBA_Environment (void);
  // Destructor, release the exception.

  static CORBA_Environment * _duplicate (CORBA_Environment *);
  static CORBA_Environment * _nil (void);
  // Some static methods that need to be defined in every pseudo object

  CORBA_Exception* exception (void) const;
  // Return the exception.  Caller must call <_incr_refcnf> in order
  // to keep the ptr.

  void exception (CORBA_Exception *ex);
  // Set the exception to <ex>, taking a reference on it.

  int exception_type (void) const;
  // Return if the exception is a user exception or a system
  // exception.

  const char *exception_id (void) const;
  // return the repository ID for the exception.

  void clear (void);
  // Clear the exception.

  void print_exception (const char *info,
                        FILE *f=stdout) const;
  // Print the exception to output determined by f.  This function is
  // not CORBA compliant.

  // = Obtain a default environment to use with TAO.
  static CORBA_Environment &default_environment (void);

  // = Reference counting.
  CORBA::ULong _incr_refcnt (void);
  CORBA::ULong _decr_refcnt (void);

#if !defined(__GNUC__) || __GNUC__ > 2 || __GNUC_MINOR__ >= 8
  typedef CORBA_Environment_ptr _ptr_type;
  typedef CORBA_Environment_var _var_type;
#endif /* __GNUC__ */
  // Useful for template programming.

private:

  friend class TAO_ORB_Core;
  CORBA_Environment (TAO_ORB_Core *orb_core);
  // Initialize using a well known ORB Core; this is intended for the
  // bootstraping of the ORB_Core, not for general consumption.

  CORBA_Exception *exception_;
  // Pointer to the exception object contained in the environment.

  CORBA_Environment *previous_;
  // The previous environment on the "default environment stack".

  CORBA::ULong refcount_;
  // Reference counting.

  ACE_SYNCH_MUTEX refcount_lock_;
  // Protect the reference count.
};

class TAO_Export CORBA_Environment_var
{
  // = TITLE
  //   CORBA_Environment_var
  //
  // = DESCRIPTION
  //   Provide for automatic storage deallocation on going out of
  //   scope.
public:
  CORBA_Environment_var (void);
  // default constructor
  CORBA_Environment_var (CORBA_Environment_ptr);
  CORBA_Environment_var (const CORBA_Environment_var &);
  // copy constructor
  ~CORBA_Environment_var (void);
  // destructor

  CORBA_Environment_var &operator= (CORBA_Environment_ptr);
  CORBA_Environment_var &operator= (const CORBA_Environment_var &);
  CORBA_Environment_ptr operator-> (void) const;

  operator const CORBA_Environment_ptr &() const;
  operator CORBA_Environment_ptr &();
  // in, inout, out, _retn
  CORBA_Environment_ptr in (void) const;
  CORBA_Environment_ptr &inout (void);
  CORBA_Environment_ptr &out (void);
  CORBA_Environment_ptr _retn (void);
  CORBA_Environment_ptr ptr (void) const;

private:
  CORBA_Environment_ptr ptr_;
};

class TAO_Export CORBA_Environment_out
{
  // = TITLE
  //   CORBA_Environment_out
  //
  // = DESCRIPTION
  //   The _out class for CORBA_Environment. This is used to help in
  //   managing the out parameters.
public:
  CORBA_Environment_out (CORBA_Environment_ptr &);
  CORBA_Environment_out (CORBA_Environment_var &);
  CORBA_Environment_out (const CORBA_Environment_out &);
  CORBA_Environment_out &operator= (const CORBA_Environment_out &);
  CORBA_Environment_out &operator= (CORBA_Environment_ptr);
  operator CORBA_Environment_ptr &();
  CORBA_Environment_ptr &ptr (void);
  CORBA_Environment_ptr operator-> (void);

private:
  CORBA_Environment_ptr &ptr_;

  CORBA_Environment_out &operator= (const CORBA_Environment_var &);
  // Assignment from _var not allowed.
};

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

#endif /* TAO_ENVIRONMENT_H */