source: trunk/nom/class_c/nomobj.c@ 354

Last change on this file since 354 was 354, checked in by cinc, 17 years ago

nomGetMethodList() improvements

File size: 8.5 KB
Line 
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 nomobj.idl
35
36 Implementation file for the NOM class NOMObject.
37*/
38
39#ifndef NOM_NOMObject_IMPLEMENTATION_FILE
40#define NOM_NOMObject_IMPLEMENTATION_FILE
41#endif
42
43#ifdef __OS2__
44# define INCL_DOS
45# include <os2.h>
46#endif /* __OS2__ */
47
48#include <string.h>
49/* #include <gtk/gtk.h> - why? */
50
51#include "nom.h"
52#include "nomtk.h"
53
54#include "nomobj.ih"
55
56#include "nomstring.h"
57#include "nommethod.h"
58#include "nomarray.h"
59#include "gc.h"
60
61/**
62 \brief This function implements the method nomInit() of class NOMObject.
63 */
64NOM_Scope void NOMLINK impl_NOMObject_nomInit(NOMObject *nomSelf, CORBA_Environment *ev)
65{
66
67}
68
69/**
70 \brief This function implements the method nomUnInit() of class NOMObject.
71 */
72NOM_Scope void NOMLINK impl_NOMObject_nomUnInit(NOMObject *nomSelf, CORBA_Environment *ev)
73{
74 /* NOMObjectData *nomThis = NOMObjectGetData(nomSelf); */
75
76 nomPrintf(" Entering %s (%x) with nomSelf: 0x%x. SomSelf is: %s.\n",
77 __FUNCTION__, impl_NOMObject_nomUnInit, nomSelf , nomSelf->mtab->nomClassName);
78}
79
80/**
81 \brief This function implements the method nomGetSize() of class NOMObject.
82 */
83NOM_Scope CORBA_long NOMLINK impl_NOMObject_nomGetSize(NOMObject* nomSelf, CORBA_Environment *ev)
84{
85 //nomPrintf(" Entering %s (%x) with nomSelf: 0x%x. nomSelf is: %s.\n",
86 // __FUNCTION__, impl_NOMObject_nomGetSize, nomSelf , nomSelf->mtab->nomClassName);
87
88 if(!nomSelf) {
89 return 0;
90 }
91
92 return nomSelf->mtab->ulInstanceSize;
93}
94
95/**
96 \brief This function implements the method delete() of class NOMObject.
97
98 It calls nomUnInit() to give the object a chance of freeing system resources. Afterwards
99 the memory occupied by the object is given back to the system and the object is not
100 accessible anymore.
101 */
102NOM_Scope void NOMLINK impl_NOMObject_delete(NOMObject* nomSelf, CORBA_Environment *ev)
103{
104/* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
105 GC_PTR oldData;
106 GC_finalization_proc oldFinalizerFunc;
107 NOMClassPriv *ncp;
108
109 /* Unregister finalizer if the class uses nomUnInit. This is done so nomUnInit isn't
110 called again when the memory is eventually collected by the GC. */
111 ncp=(NOMClassPriv*)nomSelf->mtab->nomClsInfo;
112 if(ncp->ulClassFlags & NOM_FLG_NOMUNINIT_OVERRIDEN){
113 /* A NULL finalizer function removes the finalizer */
114 GC_register_finalizer(nomSelf, NULL, NULL, &oldFinalizerFunc, &oldData);
115 }
116
117 /* Give object the chance to free resources */
118 _nomUnInit(nomSelf, NULL);
119
120 /* And now delete the object */
121 /*
122 FIXME: we should probably call a class function here, so the
123 class can keep track of objects.
124 */
125 NOMFree(nomSelf);
126}
127
128/**
129 \brief This function implements the method nomQueryClass() of class NOMObject.
130 It returns a pointer to the class object of this object.
131
132 \param nomSelf The pointer to the object.
133 \param ev Environment pointer or NULL.
134 \retval PNOMClass A pointer to the class object for this object. This can never be NULL.
135 */
136NOM_Scope PNOMClass NOMLINK impl_NOMObject_nomQueryClass(NOMObject* nomSelf, CORBA_Environment *ev)
137{
138/* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
139
140 return nomSelf->mtab->nomClassObject;
141}
142
143/**
144
145 \brief This function implements the method new() of class NOMObject.
146
147 Create a new class of the kind the caller is. This method ensures that subclassing
148 is properly handled without the need to override this method in every subclass.
149
150 This method will get the class object of nomSelf () which may be any subclass
151 of NOMObject) and call nomNew() on it creating
152 a new object which has exactly the same class hierarchy as nomSelf.
153 */
154NOM_Scope PNOMObject NOMLINK impl_NOMObject_new(NOMObject* nomSelf, CORBA_Environment *ev)
155{
156/* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
157 NOMClass* nomCls;
158
159 /* We don't know which class we're actually. So we can't just create a new object using
160 <CkassName>New() here.
161 It is possible that we are called by a subclass. So get the class object and let the
162 class object create the correct class. */
163 nomCls=NOMObject_nomQueryClass(nomSelf, NULL);
164 return NOMClass_nomNew(nomCls, NULL);
165}
166
167
168
169NOM_Scope CORBA_boolean NOMLINK impl_NOMObject_nomIsA(NOMObject* nomSelf, const PNOMClass nomClass, CORBA_Environment *ev)
170{
171 /* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
172
173 if(!nomIsObj(nomClass)){
174 g_warning("%s: class object pointer nomClass does not point to an object.", __FUNCTION__);
175 return FALSE;
176 }
177
178 return _nomIsANoClsCheck(nomSelf, nomClass, ev);
179}
180
181
182NOM_Scope CORBA_boolean NOMLINK impl_NOMObject_nomIsANoClsCheck(NOMObject* nomSelf, const PNOMClass nomClass,
183 CORBA_Environment *ev)
184{
185 /* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
186 NOMClassPriv* ncp;
187 nomMethodTabs mtabs; /* List of mtabs */
188
189 /* Check if we have the class in our list of classes */
190 ncp=(NOMClassPriv*)nomSelf->mtab->nomClsInfo;
191 mtabs=&ncp->mtabList;
192 while(mtabs)
193 {
194 if(nomClass==mtabs->mtab->nomClassObject)
195 return TRUE;
196
197 mtabs=mtabs->next;
198 }
199 return FALSE;
200}
201
202NOM_Scope CORBA_boolean NOMLINK impl_NOMObject_nomIsInstanceOf(NOMObject* nomSelf, const PNOMClass nomClass, CORBA_Environment *ev)
203{
204 /* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
205
206 if(!nomIsObj(nomClass)){
207 g_warning("%s: class object pointer nomClass does not point to an object.", __FUNCTION__);
208 return FALSE;
209 }
210
211 if(nomClass==_nomQueryClass(nomSelf, NULL))
212 return TRUE;
213
214 return FALSE;
215}
216
217/**
218 Function which implements the nomGetClassName() method of NOMObject.
219*/
220NOM_Scope CORBA_string NOMLINK impl_NOMObject_nomGetClassName(NOMObject* nomSelf, CORBA_Environment *ev)
221{
222 /* NOMObjectData* nomThis=NOMObjectGetData(nomSelf); */
223 return nomSelf->mtab->nomClassName;
224}
225
226/*
227 Create a new NOMArray holding NOMMethod objects.
228 */
229NOMDLLEXPORT NOM_Scope NOMObject* NOMLINK impl_NOMObject_nomGetMethodList(NOMObject* nomSelf,
230 const CORBA_boolean bIncludingParents,
231 CORBA_Environment *ev)
232{
233 NOMClassPriv* ncPriv;
234 NOMArray*nomArray=NOMArrayNew();
235
236 /* NOMObjectData* nomThis = NOMObjectGetData(nomSelf); */
237
238 if(TRUE==bIncludingParents)
239 g_message("Flag ˚bIncludeParents˚ not supported yet");
240
241 ncPriv=(NOMClassPriv*)_nomGetObjectCreateInfo(_nomQueryClass(nomSelf, NULL), NULL);
242
243 if(ncPriv){
244 gulong a, ulNumIntroducedMethods;
245
246 ulNumIntroducedMethods=ncPriv->sci->ulNumStaticMethods;
247 for(a=0;a< ulNumIntroducedMethods;a++)
248 {
249 NOMMethod* nMethod=NOMMethodNew();
250
251 _initData(nMethod, (gpointer) &ncPriv->sci->nomSMethods[a], NULL);
252
253 NOMArray_append(nomArray, nMethod, NULL);
254 }
255 }
256 return nomArray;
257}
258
Note: See TracBrowser for help on using the repository browser.