OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / mico / boa_impl.h
1 // -*- c++ -*-
2 /*
3  *  MICO --- an Open Source CORBA implementation
4  *  Copyright (c) 1997-2001 by The Mico Team
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  *  For more information, visit the MICO Home Page at
21  *  http://www.mico.org/
22  */
23
24 #ifndef __mico_boa_impl_h__
25 #define __mico_boa_impl_h__
26
27 namespace MICO {
28
29 class BOAServImpl;
30
31 enum BOAState {
32     BOAActive,
33     BOAShutdown,
34     BOAInactive
35 };
36
37 class ObjectRecord {
38     CORBA::BOA::ReferenceData _id;
39     CORBA::ImplementationDef * _impl;
40     CORBA::InterfaceDef * _iface;
41     CORBA::Object_ptr _local_obj;
42     CORBA::Object_ptr _remote_obj;
43     CORBA::ImplementationBase *_skel;
44     CORBA::Boolean _save;
45     // changed for CDK
46     BOAState _state;
47     CORBA::Boolean _persistent;
48 public:
49
50     ObjectRecord (CORBA::Object_ptr local, const CORBA::BOA::ReferenceData &,
51                   CORBA::InterfaceDef *, CORBA::ImplementationDef *,
52                   CORBA::ImplementationBase * = NULL);
53     ObjectRecord (CORBA::Object_ptr local, CORBA::Object_ptr remote,
54                   const CORBA::BOA::ReferenceData &,
55                   CORBA::InterfaceDef *, CORBA::ImplementationDef *,
56                   CORBA::ImplementationBase * = NULL);
57     ~ObjectRecord ();
58
59     CORBA::BOA::ReferenceData *id ();
60
61     CORBA::ImplementationDef *impl ();
62     void impl (CORBA::ImplementationDef *);
63
64     CORBA::InterfaceDef *iface ();
65     void iface (CORBA::InterfaceDef *);
66
67     CORBA::Object_ptr local_obj ();
68     CORBA::Object_ptr remote_obj ();
69
70     CORBA::ImplementationBase *skel ();
71     void skel (CORBA::ImplementationBase *);
72
73     void save (CORBA::Boolean);
74     CORBA::Boolean save () const;
75
76     void persistent (CORBA::Boolean);
77     CORBA::Boolean persistent () const;
78
79     void state (BOAState);
80     BOAState state () const;
81 };
82
83 struct BOAObjKey {
84     const CORBA::Octet *key;
85     CORBA::Long len;
86
87     BOAObjKey (CORBA::Object_ptr o)
88     {
89         key = o->_ior()->profile()->objectkey (len);
90     }
91     BOAObjKey ()
92     {
93     }
94 };
95
96 class BOAImpl : public CORBA::BOA, public CORBA::ObjectAdapter {
97     struct objcomp : std::binary_function<const BOAObjKey &, const BOAObjKey &, bool> {
98         bool operator() (const BOAObjKey &k1, const BOAObjKey &k2) const
99         {
100             if (k1.len != k2.len)
101                 return k1.len < k2.len;
102             return mico_key_compare (k1.key, k2.key, k1.len) < 0;
103         }
104     };
105     typedef std::map<BOAObjKey, ObjectRecord *, objcomp> MapObjRec;
106     typedef std::list<MICO::SharedLib *> ListShlib;
107
108     MapObjRec _lobjs, _robjs;
109     ListShlib _shlibs;
110     CORBA::ORB_ptr _orb;
111     CORBA::ULong _theid;
112     CORBA::OAMediator *_oamed;
113     CORBA::OAServer *_oasrv;
114     CORBA::OAMediator::ServerId _oasrv_id;
115     CORBA::Object_ptr _active_obj;
116     CORBA::ImplementationDef::ActivationMode _amode;
117     std::string _impl_name;
118     CORBA::Boolean _restoring;
119     BOAState _state;
120     CORBA::Environment_ptr _curr_environ;
121     MICO::RequestQueue _queue;
122     CORBA::Long _queue_count;
123     CORBA::Octet _id_template[11];
124
125     void queue ();
126     void unqueue ();
127     CORBA::Boolean must_queue (CORBA::ORBMsgId);
128     CORBA::ImplementationDef *find_impl ();
129     CORBA::Object_ptr find_obj ();
130     void add_record (ObjectRecord *);
131     ObjectRecord *get_record (CORBA::Object_ptr);
132     void del_record (CORBA::Object_ptr);
133     void del_all_records ();
134     void unique_id (std::vector<CORBA::Octet> &id);
135     CORBA::Boolean is_builtin_invoke (const char *opname);
136 #ifdef USE_CSL2
137     CORBA::Principal_ptr get_principal (CORBA::Object_ptr);
138 #endif /* USE_CSL2  */
139     void builtin_invoke (CORBA::Object_ptr,
140                          CORBA::ServerRequest_ptr,
141                          CORBA::Principal_ptr);
142     CORBA::Boolean activate (const char *repoid);
143     void shutdown_obj (CORBA::Object_ptr);
144     void shutdown_impl ();
145     void restore_internal (CORBA::Object_ptr);
146
147     CORBA::Boolean dobind (CORBA::ORBMsgId, const char *repoid,
148                            const CORBA::ORB::ObjectTag &,
149                            CORBA::Address *addr);
150
151     CORBA::Boolean is_active_object (CORBA::Object_ptr obj);
152 public:
153     BOAImpl (CORBA::ORB_ptr, int &argc, char **argv);
154     ~BOAImpl ();
155
156     CORBA::Object_ptr create (const ReferenceData &,
157                               CORBA::InterfaceDef *,
158                               CORBA::ImplementationDef *,
159                               CORBA::ImplementationBase * = NULL,
160                               const char *repoid = 0);
161     // begin-mico-extension
162     CORBA::Boolean restoring ();
163     CORBA::Object_ptr restore (CORBA::Object_ptr,
164                                const ReferenceData &,
165                                CORBA::InterfaceDef *,
166                                CORBA::ImplementationDef *,
167                                CORBA::ImplementationBase *);
168     CORBA::ORB_ptr orb ();
169     const char *impl_name ();
170     void save_objects ();
171     void save_object (ObjectRecord *rec);
172     void dispose_objects ();
173     void dispose_object (ObjectRecord *rec);
174     CORBA::Boolean load_object (ObjectRecord *rec);
175     void answer_invoke (CORBA::ORBMsgId, CORBA::Object_ptr,
176                         CORBA::ORBRequest *,
177                         CORBA::InvokeStatus);
178     // end-mico-extension
179     void dispose (CORBA::Object_ptr);
180     ReferenceData *get_id (CORBA::Object_ptr);
181     void change_implementation (CORBA::Object_ptr,
182                                 CORBA::ImplementationDef *);
183     CORBA::Principal_ptr get_principal (CORBA::Object_ptr,
184                                         CORBA::Environment_ptr);
185     
186     void impl_is_ready (CORBA::ImplementationDef *);
187     void deactivate_impl (CORBA::ImplementationDef *);
188     void obj_is_ready (CORBA::Object_ptr, CORBA::ImplementationDef *);
189     void deactivate_obj (CORBA::Object_ptr);
190     
191     
192     const char *get_oaid () const;
193     CORBA::Boolean has_object (CORBA::Object_ptr);
194     CORBA::Boolean is_local () const;
195     
196     CORBA::ImplementationDef *get_impl (CORBA::Object_ptr);
197     CORBA::InterfaceDef *get_iface (CORBA::Object_ptr);
198     
199     CORBA::Boolean invoke (CORBA::ORBMsgId, CORBA::Object_ptr,
200                            CORBA::ORBRequest *,
201                            CORBA::Principal_ptr,
202                            CORBA::Boolean response_exp = TRUE);
203     CORBA::Boolean bind (CORBA::ORBMsgId, const char *repoid,
204                          const CORBA::ORB::ObjectTag &,
205                          CORBA::Address *addr);
206     CORBA::Boolean locate (CORBA::ORBMsgId, CORBA::Object_ptr);
207     CORBA::Object_ptr skeleton (CORBA::Object_ptr);
208     void cancel (CORBA::ORBMsgId);
209     void shutdown (CORBA::Boolean wait_for_completion);
210
211     friend class BOAServImpl;
212 };
213
214 class BOAServImpl : virtual public CORBA::OAServer_skel {
215     BOAImpl *_boa;
216 public:
217     BOAServImpl (BOAImpl *boa);
218     ~BOAServImpl ();
219
220     void restore_request (const CORBA::OAServer::ObjSeq &objs);
221     void obj_inactive (CORBA::Object_ptr obj);
222     void impl_inactive ();
223 };
224
225 }
226
227 #endif // __mico_boa_impl_h__