1 // -*- Mode: C++; -*-
2 //                            Package   : omniORB
3 // GIOP_S.h                   Created on: 05/01/2001
4 //                            Author    : Sai Lai Lo (sll)
5 //
6 //    Copyright (C) 2005-2013 Apasphere Ltd
7 //    Copyright (C) 2001      AT&T Laboratories Cambridge
8 //
9 //    This file is part of the omniORB library
10 //
11 //    The omniORB library is free software; you can redistribute it and/or
12 //    modify it under the terms of the GNU Lesser General Public
13 //    License as published by the Free Software Foundation; either
14 //    version 2.1 of the License, or (at your option) any later version.
15 //
16 //    This library is distributed in the hope that it will be useful,
17 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 //    Lesser General Public License for more details.
20 //
21 //    You should have received a copy of the GNU Lesser General Public
22 //    License along with this library. If not, see http://www.gnu.org/licenses/
23 //
24 //
25 // Description:
26 //	*** PROPRIETARY INTERFACE ***
27 //
28 
29 #ifndef __GIOP_S_H__
30 #define __GIOP_S_H__
31 
32 #include <omniORB4/IOP_S.h>
33 
34 #ifdef _core_attr
35 # error "A local CPP macro _core_attr has already been defined."
36 #endif
37 
38 #if defined(_OMNIORB_LIBRARY)
39 #     define _core_attr
40 #else
41 #     define _core_attr _OMNIORB_NTDLL_IMPORT
42 #endif
43 
44 class omniCallDescriptor;
45 
OMNI_NAMESPACE_BEGIN(omni)46 OMNI_NAMESPACE_BEGIN(omni)
47 
48 class giopWorker;
49 
50 class GIOP_S : public IOP_S, public giopStream, public giopStreamList {
51  public:
52 
53 
54   GIOP_S(giopStrand*);
55   GIOP_S(const GIOP_S&);
56   ~GIOP_S();
57 
58   virtual void* ptrToClass(int* cptr);
59   static inline GIOP_S* downcast(cdrStream* s) {
60     return (GIOP_S*)s->ptrToClass(&_classid);
61   }
62   static _core_attr int _classid;
63 
64   CORBA::Boolean dispatcher();
65   // This function do not raise an exception.
66   // Returns TRUE(1) if the dispatch has been successful.
67   // Returns FALSE(0) if a terminate error was encountered and no
68   // more dispatch should be done.
69   // XXX remember to catch all the system exceptions and
70   //     giopStream::CommFailure.
71 
72 
73   void ReceiveRequest(omniCallDescriptor&);
74   // override IOP_S
75 
76   void SkipRequestBody();
77   // override IOP_S
78 
79   void SendReply();
80   // override IOP_S
81 
82   void SendException(CORBA::Exception*);
83   // override IOP_S
84 
85   void notifyCommFailure(CORBA::Boolean heldlock,
86 			 CORBA::ULong& minor,
87 			 CORBA::Boolean& retry);
88   // override giopStream member
89 
90   _CORBA_ULong completion();
91   // override cdrStream member.
92 
93   cdrStream& getStream() { return *this; }
94 
95   //////////////////////////////////////////////////////////////////
96   IOP_S::State state() const { return pd_state; }
97   void state(IOP_S::State s) { pd_state = s; }
98 
99   //////////////////////////////////////////////////////////////////
100   omniCallDescriptor* calldescriptor() { return pd_calldescriptor; }
101   void calldescriptor(omniCallDescriptor* c) { pd_calldescriptor = c; }
102 
103   //////////////////////////////////////////////////////////////////
104   GIOP::MsgType requestType() const { return pd_requestType; }
105   void requestType(GIOP::MsgType m) { pd_requestType = m; }
106 
107 
108   //////////////////////////////////////////////////////////////////
109   inline CORBA::Boolean response_expected() const {
110     return pd_response_expected;
111   }
112   inline void response_expected(CORBA::Boolean v) {
113     pd_response_expected = v;
114   }
115 
116   //////////////////////////////////////////////////////////////////
117   inline void result_expected(CORBA::Boolean v) {
118       pd_result_expected = v;
119   }
120   inline CORBA::Boolean result_expected() const {
121     return pd_result_expected;
122   }
123 
124   //////////////////////////////////////////////////////////////////
125   inline int keysize() const { return pd_key.size(); }
126   inline CORBA::Octet* key() const { return (CORBA::Octet*)pd_key.key(); }
127   inline void keysize(int sz) { pd_key.set_size((int)sz); }
128   inline void resetKey() { pd_key.set_size(-1); }
129   inline omniObjKey& keyobj() { return pd_key; }
130 
131   //////////////////////////////////////////////////////////////////
132   inline GIOP::IORAddressingInfo& targetAddress() {
133       return pd_target_address;
134   }
135   void unmarshalIORAddressingInfo();
136 
137 
138 # define GIOP_S_INLINE_BUF_SIZE 32
139 
140   //////////////////////////////////////////////////////////////////
141   inline char* operation() const { return pd_operation; }
142   inline void  set_operation_size(CORBA::ULong sz) {
143     if (pd_operation != pd_op_buffer) {
144       delete [] pd_operation;
145       pd_operation = pd_op_buffer;
146     }
147     if (sz > GIOP_S_INLINE_BUF_SIZE) {
148       pd_operation = new char[sz];
149     }
150   }
151 
152   const char* operation_name() const;
153 
154   //////////////////////////////////////////////////////////////////
155   inline CORBA::Octet* principal() const { return pd_principal; }
156   inline CORBA::ULong principal_size() const { return pd_principal_len; }
157   inline void set_principal_size(CORBA::ULong sz) {
158     if (pd_principal != pd_pr_buffer) {
159       delete [] pd_principal;
160       pd_principal = pd_pr_buffer;
161     }
162     if (sz > GIOP_S_INLINE_BUF_SIZE) {
163       pd_principal = new _CORBA_Octet[sz];
164     }
165     pd_principal_len = sz;
166   }
167 
168   //////////////////////////////////////////////////////////////////
169   inline IOP::ServiceContextList& service_contexts() {
170     return pd_service_contexts;
171   }
172 
173   //////////////////////////////////////////////////////////////////
174   // terminateProcessing may be thrown by the GIOP implementations in
175   // response to a CancelRequest message.
176   class terminateProcessing {
177   public:
178     terminateProcessing() {}
179     ~terminateProcessing() {}
180   };
181 
182   inline void worker(giopWorker* w) { pd_worker = w; }
183   inline giopWorker* worker() { return pd_worker; }
184 
185 private:
186   IOP_S::State             pd_state;
187   giopWorker*              pd_worker;
188   omniCallDescriptor*      pd_calldescriptor;
189   const char* const*       pd_user_excns;
190   int                      pd_n_user_excns;
191   GIOP::MsgType            pd_requestType;
192 
193   omniObjKey               pd_key;
194   // If pd_key.size() < 0, pd_target_address contains the
195   // full IOR that the client has sent. Only used in GIOP 1.2.
196   GIOP::IORAddressingInfo  pd_target_address;
197 
198   char*                    pd_operation;
199   char                     pd_op_buffer[GIOP_S_INLINE_BUF_SIZE];
200 
201   CORBA::Octet*            pd_principal;
202   CORBA::Octet             pd_pr_buffer[GIOP_S_INLINE_BUF_SIZE];
203   CORBA::ULong             pd_principal_len;
204 
205   CORBA::Boolean           pd_response_expected;
206   CORBA::Boolean           pd_result_expected;
207 
208   IOP::ServiceContextList  pd_service_contexts;
209 
210   CORBA::Boolean handleRequest();
211   CORBA::Boolean handleLocateRequest();
212 
213 public:
214   CORBA::Boolean handleCancelRequest();
215 
216 private:
217   GIOP_S();
218   GIOP_S& operator=(const GIOP_S&);
219 
220 # undef GIOP_S_INLINE_BUF_SIZE
221 
222 };
223 
224 
225 ////////////////////////////////////////////////////////////////////////
226 ////////////////////////////////////////////////////////////////////////
227 class GIOP_S_Holder {
228 public:
229   GIOP_S_Holder(giopStrand*, giopWorker*);
230   ~GIOP_S_Holder();
231 
232   GIOP_S* operator->() { return pd_iop_s; }
233 
234   operator GIOP_S& () { return *pd_iop_s; }
235 
236 private:
237   giopStrand*  pd_strand;
238   GIOP_S*      pd_iop_s;
239 
240 };
241 
242 OMNI_NAMESPACE_END(omni)
243 
244 #undef _core_attr
245 
246 #endif // __GIOP_S_H__
247