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

// ============================================================================
//
// = LIBRARY
//    TAO
//
// = FILENAME
//    except.h
//
// = DESCRTION
//     This file defines way in which CORBA exceptions are reported.
//
// = AUTHOR
//     Copyright 1994-1995 by Sun Microsystems Inc.
//
// ============================================================================

#if !defined (TAO_EXCEPT_H)
#  define TAO_EXCEPT_H

class TAO_Export CORBA_Exception : public IUnknown
  // = TITLE
  //   CORBA2-specified exception hierarchy.
  //
  // = DESCRIPTION
  //   All exceptions have a type (represented by a TypeCode) and a
  //   widely scoped type ID (in the TypeCode) that generated by any
  //   OMG-IDL compiler and available through the Interface
  //   Repositories.  Think of it as a "globally scoped" name
  //   distinguishing each exception.
{
public:
  CORBA_Exception (const CORBA_Exception &src);
  CORBA_Exception &operator = (const CORBA_Exception &src);

  // @@ All these inline methods should be split off into a *.i file.
  void *operator new (size_t, const void *p)
  { return (void *) p; }
  void *operator new (size_t s)
  { return ::operator new (s); }
  void operator delete (void *p)
  { ::operator delete (p); }

  TAO_CONST CORBA::String id (void) const;
  TAO_CONST CORBA::TypeCode_ptr type (void) const;

  // = Methods required for COM IUnknown support

  ULONG __stdcall AddRef (void);
  ULONG __stdcall Release (void);
  HRESULT __stdcall QueryInterface (REFIID riid,
				    void **ppv);

  CORBA_Exception (CORBA::TypeCode_ptr type);
  virtual ~CORBA_Exception (void);

private:
  CORBA::TypeCode_ptr _type;
  // Type of the Exception.

  u_int refcount_;
  // Reference count to avoid copying overhead.

  ACE_SYNCH_MUTEX lock_;
  // Serialize access to reference count.
};

class TAO_Export CORBA_UserException : public CORBA_Exception
  // = TITLE
  //   User exceptions are those defined by application developers
  //   using OMG-IDL.
{
public:
  CORBA_UserException (CORBA::TypeCode_ptr tc);
  ~CORBA_UserException (void);

protected:
  // Copy and assignment operators.
};

class TAO_Export CORBA_SystemException : public CORBA_Exception
  // = TITLE
  //   System exceptions are those defined in the CORBA spec; OMG-IDL
  //   defines these.
{
public:
  // 94-9-14 also sez:  public copy constructor
  // and assignment operator.

  CORBA_SystemException (CORBA::TypeCode_ptr tc,
			 CORBA::ULong code,
			 CORBA::CompletionStatus completed);

  ~CORBA_SystemException (void);

  CORBA::ULong minor (void) const { return _minor; }
  void minor (CORBA::ULong m) { _minor = m; }

  CORBA::CompletionStatus completion (void) const { return _completed; }

  void completion (CORBA::CompletionStatus c)
  { _completed = c; }

private:
  CORBA::ULong _minor;
  CORBA::CompletionStatus _completed;
};

// Declarations for all of the CORBA standard exceptions.
//
// XXX shouldn't have a default minor code, at least for code that's
// inside the ORB.  All minor codes should be symbolically catalogued.

#define TAO_SYSTEM_EXCEPTION(name) \
class TAO_Export CORBA_ ## name : public CORBA_SystemException { \
public: \
  CORBA_ ## name (CORBA::CompletionStatus completed, \
                  CORBA::ULong code = 0xffff0000L) \
    : CORBA_SystemException (CORBA::_tc_ ## name, code, completed) \
    { } \
}

TAO_SYSTEM_EXCEPTION(UNKNOWN);
TAO_SYSTEM_EXCEPTION(BAD_PARAM);
TAO_SYSTEM_EXCEPTION(NO_MEMORY);
TAO_SYSTEM_EXCEPTION(IMP_LIMIT);
TAO_SYSTEM_EXCEPTION(COMM_FAILURE);
TAO_SYSTEM_EXCEPTION(INV_OBJREF);
TAO_SYSTEM_EXCEPTION(OBJECT_NOT_EXIST);
TAO_SYSTEM_EXCEPTION(NO_PERMISSION);
TAO_SYSTEM_EXCEPTION(INTERNAL);
TAO_SYSTEM_EXCEPTION(MARSHAL);
TAO_SYSTEM_EXCEPTION(INITIALIZE);
TAO_SYSTEM_EXCEPTION(NO_IMPLEMENT);
TAO_SYSTEM_EXCEPTION(BAD_TYPECODE);
TAO_SYSTEM_EXCEPTION(BAD_OPERATION);
TAO_SYSTEM_EXCEPTION(NO_RESOURCES);
TAO_SYSTEM_EXCEPTION(NO_RESPONSE);
TAO_SYSTEM_EXCEPTION(PERSIST_STORE);
TAO_SYSTEM_EXCEPTION(BAD_INV_ORDER);
TAO_SYSTEM_EXCEPTION(TRANSIENT);
TAO_SYSTEM_EXCEPTION(FREE_MEM);
TAO_SYSTEM_EXCEPTION(INV_IDENT);
TAO_SYSTEM_EXCEPTION(INV_FLAG);
TAO_SYSTEM_EXCEPTION(INTF_REPOS);
TAO_SYSTEM_EXCEPTION(BAD_CONTEXT);
TAO_SYSTEM_EXCEPTION(OBJ_ADAPTER);
TAO_SYSTEM_EXCEPTION(DATA_CONVERSION);

#undef	TAO_SYSTEM_EXCEPTION

class TAO_Export CORBA_Environment
{
  // = TITLE
  // 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.
public:
  CORBA_Environment (void) : _exception (0) { }
  ~CORBA_Environment (void) { clear (); }

  CORBA::Exception_ptr exception (void) const { return _exception; }

  void exception (CORBA::Exception *ex)
  { clear (); _exception = ex; }

  CORBA::ExceptionType exception_type (void) const;
  TAO_CONST CORBA::String exception_id (void) const;

  void clear (void)
  {
    if (_exception)
      {
	_exception->Release ();
	_exception = 0;	// XXX
      }
  }

  void print_exception (const char *info,
                        FILE *f=stdout) const;
  // print the exception to output determined by f

private:
  CORBA::Exception_ptr _exception;

  // = These are not provided.
  CORBA_Environment (const CORBA_Environment &src);
  CORBA_Environment &operator = (const CORBA_Environment &src);
};

#endif /* TAO_EXCEPT_H */