source: trunk/nom/src/nomtkinit.c@ 195

Last change on this file since 195 was 195, checked in by cinc, 19 years ago

Class DLLs register themselves with the garbage collector now. Some clean ups.

File size: 6.7 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-2006
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#define INCL_DOS
36#define INCL_DOSERRORS
37#define INCL_DOSMEMMGR
38#include <os2.h>
39
40#include <stdarg.h>
41#include <stdio.h>
42#include <string.h>
43
44
45/* For nomToken etc. */
46#include <nom.h>
47#include "nomtk.h"
48#include "nomobj.h"
49#include "nomcls.h"
50#include <nomclassmanager.h>
51/* Garbage collector */
52#include <gc.h>
53
54/* Undef if you want debugging msg from somEnvironmentNew() */
55#define DEBUG_NOMENVNEW
56
57/********************************************************/
58/********************************************************/
59PNOM_ENV pGlobalNomEnv;
60/* Global class manager object */
61NOMClassMgr* NOMClassMgrObject=NULLHANDLE; /* Referenced from different files */
62
63/********************************************************/
64/* Toolkit functions, exported */
65/********************************************************/
66
67
68/*
69 Some of these functions should be moved to other source files...
70 */
71
72/*
73 This function asks the NOMClassMgrObject to search in the internal lists
74 for the mtab of the given object. If that mtab is found the pointer points to a
75 valid object.
76 */
77NOMEXTERN gboolean NOMLINK nomIsObj(gpointer nomObj)
78{
79 if(NOMClassMgrObject)
80 return NOMClassMgr_nomIsObject(NOMClassMgrObject, (PNOMObject)nomObj, NULLHANDLE);
81
82 if(!nomObj)
83 return FALSE;
84
85 /* We assume that here... */
86 return TRUE;
87}
88
89NOMEXTERN int NOMLINK nomPrintf(string chrFormat, ...)
90{
91 long rc;
92
93 va_list arg_ptr;
94
95 va_start (arg_ptr, chrFormat);
96 rc=vprintf( chrFormat, arg_ptr);
97 va_end (arg_ptr);
98 return rc;
99}
100
101
102
103/*
104 This function is called to initialize the NOM runtime.
105 It creates NOMObject, NOMClass and NOMClassMgr classes and the global
106 NOMClassMgrObject.
107*/
108NOMEXTERN NOMClassMgr * NOMLINK nomEnvironmentNew (void)
109{
110 NOMClassPriv* ncPriv;
111 NOMClass* nomCls;
112#if 0
113 NOMObject *nomObj;
114 NOMTest* nomTst;
115 NOMTest* nomTstObj;
116 NOMTest* nomTst2Obj;
117#endif
118
119#ifdef DEBUG_NOMENVNEW
120 nomPrintf("Entering %s to initialize NOM runtime.\n\n", __FUNCTION__);
121 nomPrintf("**** Building NOMObject class...\n");
122#endif
123 nomCls=NOMObjectNewClass(NOMObject_MajorVersion, NOMObject_MinorVersion);
124
125#ifdef DEBUG_NOMENVNEW
126 nomPrintf("NOMObject class: %x\n", nomCls);
127 nomPrintf("\n**** Building NOMClass class...\n");
128#endif
129
130 nomCls=NOMClassNewClass(NOMClass_MajorVersion, NOMClass_MinorVersion);
131#ifdef DEBUG_NOMENVNEW
132 nomPrintf("NOMClass class: %x\n", nomCls);
133 nomPrintf("\n**** Building NOMClassMgr class and NOMClassMgrObject...\n");
134#endif
135 NOMClassMgrObject=NOMClassMgrNew();
136 if(!NOMClassMgrObject)
137 g_error("Can't create the NOMClassMgr class object!\n");
138
139#ifdef DEBUG_NOMENVNEW
140 nomPrintf("%s: NOMClassMgrObject: %x \n", __FUNCTION__, NOMClassMgrObject);
141#endif
142
143 /* Now register the classes we already have */
144 // _nomRegisterClass(NOMClassMgrObject, pGlobalNomEnv->defaultMetaClass->mtab, NULLHANDLE); //NOMClass
145 _nomClassReady(pGlobalNomEnv->defaultMetaClass, NULLHANDLE); //NOMClass
146 //_nomRegisterClass(NOMClassMgrObject, NOMClassMgrObject->mtab, NULLHANDLE); //NOMClassMgr
147 _nomClassReady( _NOMClassMgr, NULLHANDLE); //NOMClassMgr
148 ncPriv=(NOMClassPriv*)pGlobalNomEnv->nomObjectMetaClass->mtab->nomClsInfo;
149
150 /* Do not register the NOMObject metaclass here. It's already registered because it's
151 NOMClass in fact. */
152 //_nomRegisterClass(NOMClassMgrObject, pGlobalNomEnv->nomObjectMetaClass->mtab, NULLHANDLE); //NOMObject
153 _nomClassReady(_NOMObject, NULLHANDLE); //NOMObject
154
155
156#if 0
157 nomPrintf("\n**** Building NOMTest2 class...\n");
158 nomPrintf("\nNow building a NOMTest2 object...\n");
159 nomTst2Obj= NOMTest2New();
160 nomPrintf("NOMTest2 object: %x\n", nomTst2Obj);
161
162 nomPrintf("\nCalling _nomTestFunc_NOMTest2() 1\n", nomTst2Obj);
163 _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
164 nomPrintf("\nCalling _nomTestFuncString_NOMTest2() 1\n", nomTst2Obj);
165 nomPrintf("--> %s\n",_nomTestFuncString_NOMTest2(nomTst2Obj, NULLHANDLE));
166 nomPrintf("\nCalling _nomTestFunc_NOMTest2() 2\n", nomTst2Obj);
167 _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
168
169 nomPrintf("\nCalling _nomTestFunc() with NOMTest2 object: %x\n", nomTst2Obj);
170 _nomTestFunc(nomTst2Obj, NULLHANDLE);
171 nomPrintf("\nCalling _nomTestFuncString() with NOMTest2: %x\n", nomTst2Obj);
172 nomPrintf("--> %s\n",_nomTestFuncString(nomTst2Obj, NULLHANDLE));
173 nomPrintf("\n");
174 _nomTestFunc(nomTst2Obj, NULLHANDLE);
175 _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
176#endif
177
178 return NOMClassMgrObject;
179}
180
181
182NOMEXTERN PNOM_ENV NOMLINK nomTkInit(void)
183{
184 PVOID memPtr;
185 //PVOID memPool;
186
187 nomPrintf("Entering %s...\n", __FUNCTION__);
188
189 memPtr=g_malloc(sizeof(NOM_ENV)); /* g_malloc() can't fail... */
190
191 nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
192
193 /* Now init the structure */
194 /* GC memory is zeroed... */
195 ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
196 pGlobalNomEnv=(PNOM_ENV)memPtr;
197
198#if 0
199 if(NO_ERROR!=DosCreateMutexSem(NULL, &((PNOM_ENV)memPtr)->hmtx, DC_SEM_SHARED, FALSE))
200 {
201 g_free(memPtr);
202 return NULL;
203 }
204#endif
205
206 return (PNOM_ENV)memPtr;
207}
208
209
210
211
212
213
214
215
216
217
218
Note: See TracBrowser for help on using the repository browser.