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 | /** \file noncls.c
|
---|
35 |
|
---|
36 | Implementation file for the NOMClass class.
|
---|
37 | */
|
---|
38 | #ifndef NOM_NOMClass_IMPLEMENTATION_FILE
|
---|
39 | #define NOM_NOMClass_IMPLEMENTATION_FILE
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #ifdef __OS2__
|
---|
43 | # define INCL_DOS
|
---|
44 | # include <os2.h>
|
---|
45 | #endif /* __OS2__ */
|
---|
46 |
|
---|
47 | #include <string.h>
|
---|
48 | #include <stdlib.h>
|
---|
49 | #ifdef NOM_WITH_GTK
|
---|
50 | # include <gtk/gtk.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 |
|
---|
54 | #include "nom.h"
|
---|
55 | #include "nomtk.h"
|
---|
56 |
|
---|
57 | #include "nomcls.ih"
|
---|
58 | #include "nomclassmanager.h"
|
---|
59 |
|
---|
60 | #include "gc.h"
|
---|
61 |
|
---|
62 | extern NOMClassMgr* NOMClassMgrObject;
|
---|
63 |
|
---|
64 | static void nomObjectFinalizer(GC_PTR obj, GC_PTR client_data)
|
---|
65 | {
|
---|
66 | NOMObject* nObj;
|
---|
67 | nObj=(NOMObject*)obj;
|
---|
68 |
|
---|
69 | if(nomIsObj(nObj)){
|
---|
70 | //nomPrintf("Finalizing 0x%x: %s \n", nObj, nObj->mtab->nomClassName);
|
---|
71 | _nomUnInit(nObj, NULL);
|
---|
72 | }
|
---|
73 | //else
|
---|
74 | //nomPrintf("Finalizing 0x%x: no object! \n", nObj);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | \brief Function which implements the nomNew() method of NOMClass.
|
---|
79 | */
|
---|
80 | NOM_Scope PNOMObject NOMLINK impl_NOMClass_nomNew(NOMClass* nomSelf, CORBA_Environment *ev)
|
---|
81 | {
|
---|
82 | NOMClassData* nomThis=NOMClassGetData(nomSelf);
|
---|
83 | NOMClassPriv *ncp;
|
---|
84 | gchar* nObj;
|
---|
85 |
|
---|
86 | if(!_ncpObject)
|
---|
87 | return NULL;
|
---|
88 |
|
---|
89 | ncp=(NOMClassPriv*)_ncpObject;
|
---|
90 |
|
---|
91 | /* Allocate memory big enough to hold an object. This means the size is that of the
|
---|
92 | mtab pointer and all instance variables. */
|
---|
93 | if((nObj=_nomAllocate(nomSelf, ncp->mtab->ulInstanceSize, NULL))==NULL)
|
---|
94 | return NULL;
|
---|
95 |
|
---|
96 | /* _nomInit() is called in _nomRenew() */
|
---|
97 | return _nomRenew(nomSelf, (CORBA_Object)nObj, NULL); /* This will also init the object */
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | \brief Function which implements the nomRenewNoInit() method of NOMClass.
|
---|
102 | */
|
---|
103 | NOM_Scope PNOMObject NOMLINK impl_NOMClass_nomRenewNoInit(NOMClass* nomSelf,
|
---|
104 | const gpointer nomObj,
|
---|
105 | CORBA_Environment *ev)
|
---|
106 | {
|
---|
107 | NOMClassPriv *ncp;
|
---|
108 | NOMClassData *nomThis = NOMClassGetData(nomSelf);
|
---|
109 | GC_PTR oldData;
|
---|
110 | GC_finalization_proc oldFinalizerFunc;
|
---|
111 |
|
---|
112 | ncp=(NOMClassPriv*)_ncpObject;
|
---|
113 |
|
---|
114 | /* Docs say the memory is first zeroed */
|
---|
115 | memset(nomObj, 0, ncp->mtab->ulInstanceSize);
|
---|
116 |
|
---|
117 | /* Set mtab so it's an object */
|
---|
118 | ((NOMObject*)nomObj)->mtab=ncp->mtab;
|
---|
119 |
|
---|
120 | /* Register finalizer if the class uses nomUnInit */
|
---|
121 | ncp=(NOMClassPriv*)ncp->mtab->nomClsInfo;
|
---|
122 | if(ncp->ulClassFlags & NOM_FLG_NOMUNINIT_OVERRIDEN){
|
---|
123 | //nomPrintf("Registering finalizer for %s\n", ((NOMObject*)nomObj)->mtab->nomClassName);
|
---|
124 | GC_register_finalizer(nomObj, nomObjectFinalizer, NULL, &oldFinalizerFunc, &oldData);
|
---|
125 | }
|
---|
126 | /* NO call to _nomInit() */
|
---|
127 |
|
---|
128 | /* Return statement to be customized: */
|
---|
129 | return nomObj;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | \brief Function which implements the nomRenew() method of NOMClass.
|
---|
134 | */
|
---|
135 | NOM_Scope PNOMObject NOMLINK impl_NOMClass_nomRenew(NOMClass* nomSelf, const gpointer nomObj,
|
---|
136 | CORBA_Environment *ev)
|
---|
137 | {
|
---|
138 | #if 0
|
---|
139 | CORBA_Environment tempEnv={0};
|
---|
140 | tempEnv.fFlags=NOMENV_FLG_DONT_CHECK_OBJECT;
|
---|
141 | #endif
|
---|
142 | _nomRenewNoInit(nomSelf, nomObj, NULL);
|
---|
143 |
|
---|
144 | /* And now give the object the possibility to initialize... */
|
---|
145 | /* Make sure the object is not checked. */
|
---|
146 | //_nomInit((NOMObject*)nomObj, &tempEnv);
|
---|
147 | _nomInit((NOMObject*)nomObj, NULL);
|
---|
148 |
|
---|
149 | return nomObj;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | \brief Function which implements the nomAllocate() method of NOMClass.
|
---|
155 | */
|
---|
156 | NOM_Scope gpointer NOMLINK impl_NOMClass_nomAllocate(NOMClass* nomSelf, const CORBA_long ulSize,
|
---|
157 | CORBA_Environment *ev)
|
---|
158 | {
|
---|
159 | /* NOMClassData *nomThis = NOMClassGetData(nomSelf); */
|
---|
160 |
|
---|
161 | return NOMMalloc(ulSize);
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | Function which implements the nomGetCreatedClassName() method of NOMClass.
|
---|
166 | */
|
---|
167 | NOM_Scope CORBA_string NOMLINK impl_NOMClass_nomGetCreatedClassName(NOMClass* nomSelf, CORBA_Environment *ev)
|
---|
168 | {
|
---|
169 | NOMClassPriv* ncp;
|
---|
170 |
|
---|
171 | /* The private struct characterizing the objects this meta class can create. */
|
---|
172 | ncp=_nomGetObjectCreateInfo(nomSelf, NULL);
|
---|
173 |
|
---|
174 | if(!ncp)
|
---|
175 | return ""; /* That can not happen but anyway... */
|
---|
176 |
|
---|
177 | // return nomSelf->mtab->nomClassName;
|
---|
178 | return ncp->mtab->nomClassName;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /**
|
---|
183 | \brief Function which implements the nomDeallocate() method of NOMClass.
|
---|
184 | */
|
---|
185 | NOM_Scope void NOMLINK impl_NOMClass_nomDeallocate(NOMClass* nomSelf, const gpointer memptr, CORBA_Environment *ev)
|
---|
186 | {
|
---|
187 | NOMFree((nomToken)memptr);
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | /**
|
---|
192 | \brief Function which implements the nomSetObjectCreateInfo() method of NOMClass.
|
---|
193 | */
|
---|
194 | NOM_Scope void NOMLINK impl_NOMClass_nomSetObjectCreateInfo(NOMClass* nomSelf, const gpointer ncpObject,
|
---|
195 | CORBA_Environment *ev)
|
---|
196 | {
|
---|
197 | NOMClassData* nomThis=NOMClassGetData(nomSelf);
|
---|
198 |
|
---|
199 | _ncpObject=ncpObject;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /**
|
---|
203 | \brief Function which implements the nomGetObjectCreateInfo() method of NOMClass.
|
---|
204 | */
|
---|
205 | NOM_Scope gpointer NOMLINK impl_NOMClass_nomGetObjectCreateInfo(NOMClass* nomSelf, CORBA_Environment *ev)
|
---|
206 | {
|
---|
207 | NOMClassData* nomThis=NOMClassGetData(nomSelf);
|
---|
208 |
|
---|
209 | return _ncpObject;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /**
|
---|
213 | \brief Function which implements the nomClassReady() method of NOMClass.
|
---|
214 | */
|
---|
215 | NOM_Scope void NOMLINK impl_NOMClass_nomClassReady(NOMClass* nomSelf, CORBA_Environment *ev)
|
---|
216 | {
|
---|
217 | CORBA_Environment tempEnv={0};
|
---|
218 | tempEnv.fFlags=NOMENV_FLG_DONT_CHECK_OBJECT;
|
---|
219 |
|
---|
220 | nomPrintf(" Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n",
|
---|
221 | __FUNCTION__, nomSelf, nomSelf->mtab->nomClassName);
|
---|
222 |
|
---|
223 | /* Register the class object if not alread done */
|
---|
224 | if(NULL!=NOMClassMgrObject)
|
---|
225 | {
|
---|
226 | /* First check if this class is already in the list. This is important
|
---|
227 | because there may be several classes having the same metaclass (usually NOMClass).
|
---|
228 | The only difference of these metaclasses are different object templates for creating
|
---|
229 | the instances. So to prevent unnecessary growth of the list just insert one class
|
---|
230 | of each type. This should be sufficient for now and the future.
|
---|
231 |
|
---|
232 | We insert the mtab pointer which is an anchor to all other class info we may
|
---|
233 | be interested in. */
|
---|
234 |
|
---|
235 | /* FIXME: no use of version information, yet. */
|
---|
236 |
|
---|
237 | //The following was used before changing nomGetname()
|
---|
238 | //if(!_nomFindClassFromName(NOMClassMgrObject, _nomGetName(nomSelf, NULL),
|
---|
239 | // 0, 0, NULL))
|
---|
240 | if(!_nomFindClassFromName(NOMClassMgrObject, _nomGetClassName(nomSelf, &tempEnv),
|
---|
241 | 0, 0, &tempEnv))
|
---|
242 |
|
---|
243 | {
|
---|
244 | NOMClassPriv* ncPriv;
|
---|
245 | gulong a, ulNumIntroducedMethods;
|
---|
246 |
|
---|
247 | nomPrintf("%s: Metaclass not registered yet.\n", __FUNCTION__);
|
---|
248 |
|
---|
249 | /* No, not in the list, so register it */
|
---|
250 | ncPriv=(NOMClassPriv*)nomSelf->mtab->nomClsInfo;
|
---|
251 | //ncPriv->ulIsMetaClass=1; /* Mark that we are a metaclass */
|
---|
252 | ncPriv->ulClassFlags|=NOM_FLG_IS_METACLASS; /* Mark that we are a metaclass */
|
---|
253 | _nomRegisterClass(NOMClassMgrObject, nomSelf->mtab, NULL);
|
---|
254 | /* Register all the methods this class introduces */
|
---|
255 | ulNumIntroducedMethods=ncPriv->sci->ulNumStaticMethods;
|
---|
256 | for(a=0;a<ulNumIntroducedMethods;a++)
|
---|
257 | {
|
---|
258 | if(*ncPriv->sci->nomSMethods[a].chrMethodDescriptor)
|
---|
259 | _nomRegisterMethod(NOMClassMgrObject, nomSelf->mtab,
|
---|
260 | *ncPriv->sci->nomSMethods[a].chrMethodDescriptor, NULL);
|
---|
261 | }
|
---|
262 | /* Metaclass is registered. Register the object class this
|
---|
263 | metaclass may create. */
|
---|
264 | ncPriv=(NOMClassPriv*)_nomGetObjectCreateInfo(nomSelf, NULL);//nomSelf->mtab->nomClsInfo;
|
---|
265 | if(ncPriv){
|
---|
266 | #ifndef _MSC_VER
|
---|
267 | #warning !!!!! NOMClass does not have this pointer, this is a bug !!!!!
|
---|
268 | #endif
|
---|
269 | //ncPriv->ulIsMetaClass=0; /* Mark that we are not a metaclass (should be 0 already) */
|
---|
270 | ncPriv->ulClassFlags&=~NOM_FLG_IS_METACLASS; /* Mark that we are not a metaclass (should be 0 already) */
|
---|
271 | _nomRegisterClass(NOMClassMgrObject, ncPriv->mtab, NULL);
|
---|
272 |
|
---|
273 | /* Register all the methods this class introduces */
|
---|
274 | ulNumIntroducedMethods=ncPriv->sci->ulNumStaticMethods;
|
---|
275 | for(a=0;a<ulNumIntroducedMethods;a++)
|
---|
276 | {
|
---|
277 | if(*ncPriv->sci->nomSMethods[a].chrMethodDescriptor)
|
---|
278 | _nomRegisterMethod(NOMClassMgrObject, ncPriv->mtab,
|
---|
279 | *ncPriv->sci->nomSMethods[a].chrMethodDescriptor, NULL);
|
---|
280 | }/* for(a) */
|
---|
281 | }/* ncPriv */
|
---|
282 | }
|
---|
283 | else{
|
---|
284 | NOMClassPriv* ncPriv;
|
---|
285 | /* Metaclass is already registered. Register the object class this
|
---|
286 | metaclass may create. */
|
---|
287 |
|
---|
288 | nomPrintf("%s (%d): Metaclass already registered, registering normal object class now.\n", __FUNCTION__, __LINE__);
|
---|
289 |
|
---|
290 | ncPriv=(NOMClassPriv*)_nomGetObjectCreateInfo(nomSelf, NULL);//nomSelf->mtab->nomClsInfo;
|
---|
291 |
|
---|
292 | if(ncPriv){
|
---|
293 | gulong a, ulNumIntroducedMethods;
|
---|
294 |
|
---|
295 | // ncPriv->ulIsMetaClass=0; /* Mark that we are not a metaclass (should be 0 already) */
|
---|
296 | ncPriv->ulClassFlags&=~NOM_FLG_IS_METACLASS; /* Mark that we are not a metaclass (should be 0 already) */
|
---|
297 |
|
---|
298 | if(_nomFindClassFromName(NOMClassMgrObject, ncPriv->mtab->nomClassName,
|
---|
299 | 0, 0, &tempEnv))
|
---|
300 | nomPrintf("%s: %s already registered\n", __FUNCTION__, ncPriv->mtab->nomClassName);
|
---|
301 |
|
---|
302 | /* Register all the methods this class introduces */
|
---|
303 | ulNumIntroducedMethods=ncPriv->sci->ulNumStaticMethods;
|
---|
304 | for(a=0;a<ulNumIntroducedMethods;a++)
|
---|
305 | {
|
---|
306 | if(*ncPriv->sci->nomSMethods[a].chrMethodDescriptor)
|
---|
307 | _nomRegisterMethod(NOMClassMgrObject, ncPriv->mtab,
|
---|
308 | *ncPriv->sci->nomSMethods[a].chrMethodDescriptor, NULL);
|
---|
309 | }
|
---|
310 | //nomPrintf("%s %s %s \n", __FUNCTION__, nomSelf->mtab->nomClassName, ncPriv->mtab->nomClassName);
|
---|
311 | _nomRegisterClass(NOMClassMgrObject, ncPriv->mtab, NULL);
|
---|
312 | }
|
---|
313 | }
|
---|
314 | }
|
---|
315 | else
|
---|
316 | nomPrintf("%s: no NOMClassMgrObject yet.\n", __FUNCTION__);
|
---|
317 |
|
---|
318 | }
|
---|
319 |
|
---|
320 | NOM_Scope void NOMLINK impl_NOMClass_nomInit(NOMClass* nomSelf, CORBA_Environment *ev)
|
---|
321 | {
|
---|
322 | /* NOMClassData* nomThis=NOMClassGetData(nomSelf); */
|
---|
323 | #if 0
|
---|
324 | CORBA_Environment tempEnv={0};
|
---|
325 | tempEnv.fFlags=NOMENV_FLG_DONT_CHECK_OBJECT;
|
---|
326 | #endif
|
---|
327 | // nomPrintf(" Entering %s with nomSelf: 0x%x. nomSelf is: %s.\n",
|
---|
328 | // __FUNCTION__, nomSelf, nomSelf->mtab->nomClassName);
|
---|
329 |
|
---|
330 | /* Don't check object pointer. We are just created but not yet registered as a class. */
|
---|
331 | // NOMClass_nomInit_parent(nomSelf, &tempEnv);
|
---|
332 | NOMClass_nomInit_parent(nomSelf, NULL);
|
---|
333 | }
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 |
|
---|