summaryrefslogtreecommitdiff
path: root/TAO/IIOP/lib/except.hh
blob: 0dacdfb09008ec46363de5b55fb3aa56919f79a7 (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
//
// Header file for Win32 C/C++/COM interface to a CORBA ORB.
//
// This file defines way in which CORBA exceptions are reported.
//

//
// CORBA2-specified exception hierarchy.
//
// 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.
//
extern const IID	IID_CORBA_Exception;
extern const IID	IID_CORBA_UserException;
extern const IID	IID_CORBA_SystemException;

class _EXPCLASS CORBA_Exception : public IUnknown {
  public:
				CORBA_Exception (const CORBA_Exception &src);
    CORBA_Exception		&operator = (const CORBA_Exception &src);

    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); }


    const CORBA_String		id () const;
    const CORBA_TypeCode_ptr	type () const;

    //
    // Stuff required for COM IUnknown support
    //
    ULONG __stdcall		AddRef ();
    ULONG __stdcall		Release ();
    HRESULT __stdcall           QueryInterface (
				    REFIID	riid,
				    void	**ppv
				);

				CORBA_Exception (
				    CORBA_TypeCode_ptr	type
				);
				virtual ~CORBA_Exception ();
  private:
    CORBA_TypeCode_ptr		_type;
    unsigned			_refcnt;
};
typedef CORBA_Exception *CORBA_Exception_ptr;

//
// User exceptions are those defined by application developers
// using OMG-IDL.
//
class _EXPCLASS CORBA_UserException : public CORBA_Exception {
  public:
			    CORBA_UserException (CORBA_TypeCode_ptr tc);
			    ~CORBA_UserException ();
  protected:
			    // copy and assignment operators
};

//
// System exceptions are those defined in the CORBA spec; OMG-IDL
// defines these.
//
enum CORBA_CompletionStatus {
    COMPLETED_YES,		// successful or exceptional completion
    COMPLETED_NO,		// didn't change any state; retry is OK
    COMPLETED_MAYBE		// can't say what happened; retry unsafe
};

class _EXPCLASS CORBA_SystemException : public CORBA_Exception {
  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 ();

    CORBA_ULong			minor () const { return _minor; }
    void			minor (CORBA_ULong m) { _minor = m; }

    CORBA_CompletionStatus	completion () 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 SYSEX(name) \
extern CORBA_TypeCode_ptr		_tc_CORBA_ ## name ; \
class _EXPCLASS CORBA_ ## name : public CORBA_SystemException { \
  public: \
			    CORBA_ ## name ( \
				CORBA_CompletionStatus	completed, \
				CORBA_ULong		code = 0xffff0000L \
			    ) : CORBA_SystemException ( \
				    _tc_CORBA_ ## name, \
				    code, completed) { } }

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

#undef	SYSEX

//
// 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.
//
enum CORBA_ExceptionType {
    NO_EXCEPTION,
    SYSTEM_EXCEPTION,
    USER_EXCEPTION
};

class CORBA_Environment {
  public:
				CORBA_Environment () : _exception (0) { }
				~CORBA_Environment () { clear (); }

    CORBA_Exception_ptr		exception () const { return _exception; }
    void			exception (CORBA_Exception *ex)
				{ clear (); _exception = ex; }

    CORBA_ExceptionType		exception_type () const;
    const CORBA_String		exception_id () const;

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

  private:
    CORBA_Exception_ptr		_exception;

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