source: trunk/nom/class_c/nomobj.c

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

Replaced forward class declarations in idl files by includes for the respective class idl files.

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