1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: CDDL 1.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
---|
6 | * this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at http://www.sun.com/cddl/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is "NOM" Netlabs Object Model
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2005-2007
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | *
|
---|
23 | * Alternatively, the contents of this file may be used under the terms of
|
---|
24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
---|
25 | * case the provisions of the LGPL are applicable instead of those above. If
|
---|
26 | * you wish to allow use of your version of this file only under the terms of
|
---|
27 | * the LGPL, and not to allow others to use your version of this file under
|
---|
28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
---|
29 | * above and replace them with the notice and other provisions required by the
|
---|
30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
---|
31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
---|
32 | *
|
---|
33 | * ***** END LICENSE BLOCK ***** */
|
---|
34 | /*
|
---|
35 | * And remember, phase 3 is near...
|
---|
36 | */
|
---|
37 | /** \file nomobj.idl
|
---|
38 |
|
---|
39 | Implementation file for the NOM class NOMClassMgr.
|
---|
40 | */
|
---|
41 |
|
---|
42 | #ifndef NOM_NOMClassMgr_IMPLEMENTATION_FILE
|
---|
43 | #define NOM_NOMClassMgr_IMPLEMENTATION_FILE
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #ifdef __OS2__
|
---|
47 | # define INCL_DOS
|
---|
48 | # include <os2.h>
|
---|
49 | #endif /* __OS2__ */
|
---|
50 |
|
---|
51 | #include <string.h>
|
---|
52 | #ifdef NOM_WITH_GTK
|
---|
53 | # include <gtk/gtk.h>
|
---|
54 | #endif
|
---|
55 |
|
---|
56 |
|
---|
57 | #include "nom.h"
|
---|
58 | #include "nomtk.h"
|
---|
59 |
|
---|
60 | #include "nomclassmanager.ih"
|
---|
61 |
|
---|
62 |
|
---|
63 | /**
|
---|
64 | \brief Function which implements the nomFindClassFromID() method of NOMClassMgr.
|
---|
65 |
|
---|
66 | \remark This method isn't implemented yet.
|
---|
67 | */
|
---|
68 | NOM_Scope NOMClass* NOMLINK impl_NOMClassMgr_nomFindClassFromId(NOMClassMgr* nomSelf,
|
---|
69 | const gulong classId,
|
---|
70 | const gulong ulMajorVersion,
|
---|
71 | const gulong ulMinorVersion,
|
---|
72 | CORBA_Environment *ev)
|
---|
73 | {
|
---|
74 | /* NOMClassMgrData *nomThis = NOMClassMgrGetData(nomSelf); */
|
---|
75 | CORBA_Object nomRetval;
|
---|
76 |
|
---|
77 | nomPrintf("%s: %s not implemented yet (line %d)\n", __FILE__, __FUNCTION__, __LINE__);
|
---|
78 | nomRetval=NULL;
|
---|
79 | return nomRetval;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | \brief Function which implements the nomFindClassFromName() method of NOMClassMgr.
|
---|
84 | */
|
---|
85 | NOM_Scope NOMClass* NOMLINK impl_NOMClassMgr_nomFindClassFromName(NOMClassMgr* nomSelf,
|
---|
86 | const CORBA_char * className,
|
---|
87 | const CORBA_long ulMajorVersion,
|
---|
88 | const CORBA_long ulMinorVersion,
|
---|
89 | CORBA_Environment *ev)
|
---|
90 | {
|
---|
91 | CORBA_Object nomRetval=NULL;
|
---|
92 | nomMethodTab * mtab;
|
---|
93 | NOMClassMgrData *nomThis = NOMClassMgrGetData(nomSelf);
|
---|
94 |
|
---|
95 | /* This is only for NOMClass objects */
|
---|
96 | if(strchr(className, ':'))
|
---|
97 | return NULL;
|
---|
98 |
|
---|
99 | mtab=g_datalist_get_data(&_gdataClassList, className);
|
---|
100 |
|
---|
101 | if(mtab){
|
---|
102 | NOMClassPriv* ncPriv;
|
---|
103 | ncPriv=(NOMClassPriv*)mtab->nomClsInfo;
|
---|
104 | nomRetval=(CORBA_Object)ncPriv->sci->nomCds->nomClassObject;
|
---|
105 | }
|
---|
106 | return nomRetval;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | This function is called when a class is (accidently) removed from our class list.
|
---|
111 | This may happen e.g. when a class is registered again using the same name. The old
|
---|
112 | registration is removed then and the new inserted (which may be the very same data).
|
---|
113 | When this happens this is presumably a bug:
|
---|
114 | */
|
---|
115 | static void
|
---|
116 | priv_handleClassRemove(gpointer data)
|
---|
117 | {
|
---|
118 | nomMethodTab* mtab;
|
---|
119 | mtab=(nomMethodTab*)data;
|
---|
120 | if(mtab)
|
---|
121 | g_warning("%s: supposed to remove class %s mtab: %lx. This is probably a bug.\n",
|
---|
122 | __FUNCTION__, mtab->nomClassName, (long)mtab);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | \brief Function which implements the nomRegisterClass() method of NOMClassMgr.
|
---|
127 |
|
---|
128 | We register mtabs as unique pointers to classes. It's possible to get every
|
---|
129 | information from an mtab.
|
---|
130 | */
|
---|
131 | NOM_Scope void NOMLINK impl_NOMClassMgr_nomRegisterClass(NOMClassMgr* nomSelf, const gpointer classMtab,
|
---|
132 | CORBA_Environment *ev)
|
---|
133 | {
|
---|
134 | nomMethodTab* mtab;
|
---|
135 | NOMClassMgrData *nomThis = NOMClassMgrGetData(nomSelf);
|
---|
136 |
|
---|
137 | mtab=(nomMethodTab*) classMtab;
|
---|
138 |
|
---|
139 | g_datalist_set_data_full(&_gdataClassList, mtab->nomClassName, classMtab, priv_handleClassRemove);
|
---|
140 | g_tree_insert(_pClassListTree, mtab, mtab->nomClassName); /* key is the mtab because we want to use
|
---|
141 | this tree for fast lookup of mtabs to
|
---|
142 | check for valid objects. */
|
---|
143 |
|
---|
144 | //nomPrintf("%s: registering %lx, %s classList: %lx ID: %ld\n", __FUNCTION__,
|
---|
145 | // classMtab, mtab->nomClassName, _gdataClassList, g_quark_try_string(mtab->nomClassName));
|
---|
146 | mtab->classNomId=g_quark_try_string(mtab->nomClassName);
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | /**
|
---|
151 | \brief Function which implements the nomGetClassList() method of NOMClassMgr.
|
---|
152 | */
|
---|
153 | NOM_Scope gpointer NOMLINK impl_NOMClassMgr_nomGetClassList(NOMClassMgr* nomSelf, CORBA_Environment *ev)
|
---|
154 | {
|
---|
155 | NOMClassMgrData *nomThis = NOMClassMgrGetData(nomSelf);
|
---|
156 |
|
---|
157 | return (gpointer) _gdataClassList;
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | NOM_Scope gpointer NOMLINK impl_NOMClassMgr_nomGetClassInfoPtrFromName(NOMClassMgr* nomSelf,
|
---|
162 | const CORBA_char * className,
|
---|
163 | CORBA_Environment *ev)
|
---|
164 | {
|
---|
165 | nomMethodTab * mtab;
|
---|
166 | NOMClassMgrData *nomThis = NOMClassMgrGetData(nomSelf);
|
---|
167 |
|
---|
168 | /* This is only for NOMClassPriv objects */
|
---|
169 | if(strchr(className, ':'))
|
---|
170 | return NULL;
|
---|
171 |
|
---|
172 | mtab=g_datalist_get_data(&_gdataClassList, className);
|
---|
173 | if(mtab)
|
---|
174 | return mtab->nomClsInfo;
|
---|
175 | else
|
---|
176 | return NULL;
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | /**
|
---|
181 | This function is called when a method is (accidently) removed from our list.
|
---|
182 | This may happen e.g. when a class is registered again using the same name. The old
|
---|
183 | registration is removed then and the new inserted (which may be the very same data).
|
---|
184 | When this happens this is presumably a bug:
|
---|
185 | */
|
---|
186 | static void
|
---|
187 | priv_handleMethodRemoveFromList(gpointer data)
|
---|
188 | {
|
---|
189 | nomMethodTab* mtab;
|
---|
190 | mtab=(nomMethodTab*)data;
|
---|
191 | if(mtab)
|
---|
192 | g_warning("%s: supposed to remove method mtab: %lx. This is probably a bug.\n",
|
---|
193 | __FUNCTION__, (long)mtab);
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | \brief Function which implements the nomRegisterMethod() method of NOMClassMgr.
|
---|
198 | */
|
---|
199 | NOM_Scope void NOMLINK impl_NOMClassMgr_nomRegisterMethod(NOMClassMgr* nomSelf,
|
---|
200 | const gpointer classMtab,
|
---|
201 | const CORBA_char * chrMethodName,
|
---|
202 | CORBA_Environment *ev)
|
---|
203 | {
|
---|
204 | nomMethodTab* mtab;
|
---|
205 | NOMClassMgrData *nomThis = NOMClassMgrGetData(nomSelf);
|
---|
206 |
|
---|
207 | mtab=(nomMethodTab*) classMtab;
|
---|
208 |
|
---|
209 | g_datalist_set_data_full(&_gdataMethodList, chrMethodName, classMtab, priv_handleMethodRemoveFromList);
|
---|
210 | }
|
---|
211 |
|
---|
212 | /**
|
---|
213 | \brief Function which implements the nomIsObject() method of NOMClassMgr.
|
---|
214 | */
|
---|
215 | NOM_Scope CORBA_boolean NOMLINK impl_NOMClassMgr_nomIsObject(NOMClassMgr* nomSelf, const PNOMObject nomObject,
|
---|
216 | CORBA_Environment *ev)
|
---|
217 | {
|
---|
218 | NOMClassMgrData* nomThis=NOMClassMgrGetData(nomSelf);
|
---|
219 |
|
---|
220 | if(NULL==nomObject)
|
---|
221 | return FALSE;
|
---|
222 |
|
---|
223 | return (g_tree_lookup(_pClassListTree, nomObject->mtab)!= NULL);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /**
|
---|
227 | \brief Function which implements the nomSubstituteClass() method of NOMClassMgr.
|
---|
228 | */
|
---|
229 | NOM_Scope CORBA_boolean NOMLINK impl_NOMClassMgr_nomSubstituteClass(NOMClassMgr* nomSelf,
|
---|
230 | const CORBA_char * oldClass,
|
---|
231 | const CORBA_char * replacementClass,
|
---|
232 | CORBA_Environment *ev)
|
---|
233 | {
|
---|
234 | /* NOMClassMgrData* nomThis=NOMClassMgrGetData(nomSelf); */
|
---|
235 | NOMClass* oClass;
|
---|
236 | NOMClass* rClass;
|
---|
237 | NOMClassPriv* ncp;
|
---|
238 |
|
---|
239 | /* This returns a meta class */
|
---|
240 | if((oClass=_nomFindClassFromName( nomSelf, oldClass, 0, 0, NULL))==NULL)
|
---|
241 | return FALSE;
|
---|
242 |
|
---|
243 | if((rClass=_nomFindClassFromName( nomSelf, replacementClass, 0, 0, NULL))==NULL)
|
---|
244 | return FALSE;
|
---|
245 |
|
---|
246 | /* Check if the class is a direct child */
|
---|
247 | ncp=(NOMClassPriv*)_nomGetObjectCreateInfo(rClass, NULL);
|
---|
248 |
|
---|
249 | if(strcmp(ncp->parentMtabStruct.next->mtab->nomClassName, oldClass))
|
---|
250 | return FALSE;
|
---|
251 |
|
---|
252 | /* Save old class object pointer. Hmm, maybe not it's still in the old parentMtab */
|
---|
253 |
|
---|
254 | /* Change the class object pointer in the nomClassDataStructure */
|
---|
255 |
|
---|
256 | /* Reregister old class with new mtab in the internal list. Make sure we don't get
|
---|
257 | a warning by GLib */
|
---|
258 |
|
---|
259 | return FALSE;
|
---|
260 | }
|
---|
261 |
|
---|
262 | NOM_Scope CORBA_string NOMLINK impl_NOMClassMgr_nomQueryDLLForClass(NOMClassMgr* nomSelf,
|
---|
263 | const CORBA_char * chrClassName,
|
---|
264 | CORBA_Environment *ev)
|
---|
265 | {
|
---|
266 | /* NOMClassMgrData* nomThis=NOMClassMgrGetData(nomSelf); */
|
---|
267 | #if 0
|
---|
268 | /* We have a circular reference here to the voyfcls.dll containing NOMPath, which needs nomtk.a
|
---|
269 | to be built. */
|
---|
270 | NOMPath* thePath;
|
---|
271 |
|
---|
272 | if(!chrClassName)
|
---|
273 | return NULL;
|
---|
274 |
|
---|
275 | if((thePath=NOMPathNew())==NULL)
|
---|
276 | return NULL;
|
---|
277 |
|
---|
278 | /* We probably use the home dir later */
|
---|
279 | thePath=NOMPath_assignCString(thePath, g_get_current_dir(), NULL);
|
---|
280 | thePath=NOMPath_appendCString(thePath, "classlist.ini", NULL);
|
---|
281 | #endif
|
---|
282 |
|
---|
283 | return NULL;
|
---|
284 | }
|
---|
285 |
|
---|
286 |
|
---|
287 | static
|
---|
288 | int nomClassMgrCompareFunc(gconstpointer a, gconstpointer b)
|
---|
289 | {
|
---|
290 | if(a < b )
|
---|
291 | return -1;
|
---|
292 | if(a > b )
|
---|
293 | return 1;
|
---|
294 | return 0;
|
---|
295 | }
|
---|
296 | /**
|
---|
297 | \brief Function which implements the nomInit() override NOMClassMgr.
|
---|
298 | */
|
---|
299 | NOM_Scope void NOMLINK impl_NOMClassMgr_nomInit(NOMClassMgr* nomSelf, CORBA_Environment *ev)
|
---|
300 | {
|
---|
301 | NOMClassMgrData* nomThis=NOMClassMgrGetData(nomSelf);
|
---|
302 |
|
---|
303 | g_message("In %s", __FUNCTION__);
|
---|
304 | NOMClassMgr_nomInit_parent((NOMObject*)nomSelf, ev);
|
---|
305 |
|
---|
306 | g_datalist_init(&_gdataMethodList);
|
---|
307 | g_datalist_init(&_gdataClassList);
|
---|
308 |
|
---|
309 | /* This balanced binary tree holds the objects in this folder. We create a tree
|
---|
310 | which may be searched using the name of the file/directory */
|
---|
311 |
|
---|
312 | _pClassListTree=g_tree_new((GCompareFunc)nomClassMgrCompareFunc);
|
---|
313 |
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 |
|
---|
318 |
|
---|
319 |
|
---|
320 |
|
---|
321 |
|
---|
322 |
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 |
|
---|