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

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

More types...

File size: 9.8 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 "nomtst.h"
51 #include "nomtst2.h" */
52#include <nomclassmanager.h>
53/* Garbage collector */
54#include <gc.h>
55
56/* Undef if you want debugging msg from somEnvironmentNew() */
57#define DEBUG_NOMENVNEW
58
59/********************************************************/
60/********************************************************/
61PNOM_ENV pGlobalNomEnv;
62/* Global class manager object */
63NOMClassMgr* NOMClassMgrObject; /* Referenced from different files */
64
65/********************************************************/
66/* Toolkit functions, exported */
67/********************************************************/
68
69
70/*
71 Some of these functions should be moved to other source files...
72 */
73
74NOMEXTERN gboolean NOMLINK nomIsObj(gpointer nomObj)
75{
76 if(!nomObj)
77 return FALSE;
78
79 return TRUE;
80}
81
82NOMEXTERN int NOMLINK nomPrintf(string chrFormat, ...)
83{
84 long rc;
85
86 va_list arg_ptr;
87
88 va_start (arg_ptr, chrFormat);
89 rc=vprintf( chrFormat, arg_ptr);
90 va_end (arg_ptr);
91 return rc;
92}
93
94
95
96/*
97 This function is called to initialize the NOM runtime.
98 It creates NOMObject, NOMClass and NOMClassMgr classes and the global
99 NOMClassMgrObject.
100*/
101NOMEXTERN NOMClassMgr * NOMLINK nomEnvironmentNew (void)
102{
103 NOMClassPriv* ncPriv;
104 NOMClass* nomCls;
105 NOMObject *nomObj;
106#if 0
107 NOMTest* nomTst;
108 NOMTest* nomTstObj;
109 NOMTest* nomTst2Obj;
110#endif
111
112#ifdef DEBUG_NOMENVNEW
113 nomPrintf("Entering %s to initialize NOM runtime.\n\n", __FUNCTION__);
114 nomPrintf("**** Building NOMObject class...\n");
115#endif
116 nomCls=NOMObjectNewClass(NOMObject_MajorVersion, NOMObject_MinorVersion);
117
118#ifdef DEBUG_NOMENVNEW
119 nomPrintf("NOMObject class: %x\n", nomCls);
120 nomPrintf("\n**** Building NOMClass class...\n");
121#endif
122
123 nomCls=NOMClassNewClass(NOMClass_MajorVersion, NOMClass_MinorVersion);
124#ifdef DEBUG_NOMENVNEW
125 nomPrintf("NOMClass class: %x\n", nomCls);
126 nomPrintf("\n**** Building NOMClassMgr class and NOMClassMgrObject...\n");
127#endif
128 NOMClassMgrObject=NOMClassMgrNew();
129 if(!NOMClassMgrObject)
130 g_error("Can't create the NOMClassMgr class object!\n");
131
132#ifdef DEBUG_NOMENVNEW
133 nomPrintf("%s: NOMClassMgrObject: %x \n", __FUNCTION__, NOMClassMgrObject);
134#endif
135
136 /* Now register the classes we already have */
137 // _nomRegisterClass(NOMClassMgrObject, pGlobalNomEnv->defaultMetaClass->mtab, NULLHANDLE); //NOMClass
138 _nomClassReady(pGlobalNomEnv->defaultMetaClass, NULLHANDLE); //NOMClass
139 //_nomRegisterClass(NOMClassMgrObject, NOMClassMgrObject->mtab, NULLHANDLE); //NOMClassMgr
140 _nomClassReady( _NOMClassMgr, NULLHANDLE); //NOMClassMgr
141 ncPriv=(NOMClassPriv*)pGlobalNomEnv->nomObjectMetaClass->mtab->nomClsInfo;
142
143 /* Do not register the NOMObject metaclass here. It's already registered because it's
144 NOMClass in fact. */
145 //_nomRegisterClass(NOMClassMgrObject, pGlobalNomEnv->nomObjectMetaClass->mtab, NULLHANDLE); //NOMObject
146 //_nomRegisterClass(NOMClassMgrObject, pGlobalNomEnv->ncpNOMObject->mtab, NULLHANDLE); //NOMObject
147 _nomClassReady(_NOMObject, NULLHANDLE); //NOMObject
148
149
150#if 0
151 nomPrintf("\n**** Building NOMTest class...\n");
152 nomTst=NOMTestNewClass(NOMTest_MajorVersion, NOMTest_MinorVersion);
153 nomPrintf("NOMTest class: %x\n", nomTst);
154
155 nomPrintf("Now building a NOMTest object from %x...\n", _NOMTest);
156 nomTstObj= NOMTestNew();
157 nomPrintf("NOMTest object: %x\n", nomTstObj);
158#endif
159
160#if 0
161 nomPrintf("Calling _nomTestFunc() 1\n", nomTstObj);
162 _nomTestFunc(nomTstObj, NULLHANDLE);
163 nomPrintf("Calling _nomTestFuncString() 1\n", nomTstObj);
164 nomPrintf("--> %s\n",_nomTestFuncString(nomTstObj, NULLHANDLE));
165
166 nomPrintf("Calling _nomTestFunc() 2\n", nomTstObj);
167 _nomTestFunc(nomTstObj, NULLHANDLE);
168 nomPrintf("Calling _nomTestFuncString() 2\n", nomTstObj);
169 nomPrintf("--> %s\n",_nomTestFuncString(nomTstObj, NULLHANDLE));
170#endif
171
172#if 0
173 //#if 0
174 nomPrintf("\n**** Building NOMTest2 class...\n");
175 nomPrintf("\nNow building a NOMTest2 object...\n");
176 // NOMTest2NewClass(NOMTest2_MajorVersion, NOMTest2_MinorVersion);
177 nomTst2Obj= NOMTest2New();
178 nomPrintf("NOMTest2 object: %x\n", nomTst2Obj);
179 //#endif
180
181
182 nomPrintf("\nCalling _nomTestFunc_NOMTest2() 1\n", nomTst2Obj);
183 _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
184 nomPrintf("\nCalling _nomTestFuncString_NOMTest2() 1\n", nomTst2Obj);
185 nomPrintf("--> %s\n",_nomTestFuncString_NOMTest2(nomTst2Obj, NULLHANDLE));
186 nomPrintf("\nCalling _nomTestFunc_NOMTest2() 2\n", nomTst2Obj);
187 _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
188
189 nomPrintf("\nCalling _nomTestFunc() with NOMTest2 object: %x\n", nomTst2Obj);
190 _nomTestFunc(nomTst2Obj, NULLHANDLE);
191 nomPrintf("\nCalling _nomTestFuncString() with NOMTest2: %x\n", nomTst2Obj);
192 nomPrintf("--> %s\n",_nomTestFuncString(nomTst2Obj, NULLHANDLE));
193 nomPrintf("\n");
194 _nomTestFunc(nomTst2Obj, NULLHANDLE);
195 _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
196#endif
197
198#if 0
199 _dumpMtab(nomTstObj->mtab);
200 _dumpMtab(nomTst2Obj->mtab);
201 // _dumpMtab(NOMClassMgrObject->mtab);
202 // _dumpClasses();
203 _nomTestFunc(nomTstObj, NULLHANDLE);
204 _nomTestFunc(nomTst2Obj, NULLHANDLE);
205 _nomTestFunc(nomTstObj, NULLHANDLE);
206 _nomTestFunc(nomTst2Obj, NULLHANDLE);
207#endif
208
209#if 0
210 nomPrintf("NOMTest object: %x, %x\n", nomTstObj, NOMTestClassData.classObject);
211 nomTstObj=_nomNew((_NOMTest ? _NOMTest : NOMTestNewClass(NOMTest_MajorVersion, NOMTest_MinorVersion)), (void*) 0);
212 nomPrintf("NOMTest object: %x\n", nomTstObj);
213 nomTstObj= NOMTestNew();
214 nomPrintf("NOMTest object: %x\n", nomTstObj);
215#endif
216
217 return NOMClassMgrObject;
218}
219
220
221
222NOMEXTERN PNOM_ENV NOMLINK nomTkInit(void)
223{
224
225
226 PVOID memPtr;
227 PVOID memPool;
228
229 nomPrintf("Entering %s...\n", __FUNCTION__);
230 nomPrintf("*************************************\n");
231 nomPrintf("!! This function must be rewritten !!\n");
232 nomPrintf("!! It's using OS/2 only memory !!\n");
233 nomPrintf("!! functions. !!\n");
234 nomPrintf("*************************************\n");
235
236 /* Check if we already allocated our shared mem */
237 if(NO_ERROR==DosGetNamedSharedMem(&memPtr,SOMTK_SHARED_MEM_NAME_ROOT , PAG_EXECUTE|PAG_READ|PAG_WRITE)) {
238 nomPrintf("%s: Found root shared mem: %x.\n", __FUNCTION__, memPtr);
239 /* Give process access to memory pool*/
240 DosGetSharedMem( ((PNOM_ENV)memPtr)->pMemPool, PAG_READ|PAG_WRITE|PAG_EXECUTE);
241 if(NO_ERROR!=DosSubSetMem(((PNOM_ENV)memPtr)->pMemPool, DOSSUB_SPARSE_OBJ|DOSSUB_SERIALIZE, SOMTK_SHARED_MEM_SIZE_POOL)) {
242 DosFreeMem(memPool);
243 DosFreeMem(memPtr);
244 return NULL;
245 }
246 pGlobalNomEnv=(PNOM_ENV)memPtr;
247 return (PNOM_ENV)memPtr;
248 }
249 nomPrintf("%s: No root memory yet\n", __FUNCTION__);
250
251 /* Get the mem for the root structure in a shared memory area */
252 if(NO_ERROR!=DosAllocSharedMem(&memPtr, SOMTK_SHARED_MEM_NAME_ROOT, SOMTK_SHARED_MEM_SIZE_ROOT,
253 PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE))
254 return NULL;
255
256 nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
257
258 /* Get our shared memory pool */
259 if(NO_ERROR!=DosAllocSharedMem(&memPool, NULL, SOMTK_SHARED_MEM_SIZE_POOL,OBJ_GETTABLE | PAG_EXECUTE|PAG_READ|PAG_WRITE)) {
260 DosFreeMem(memPtr);
261 return NULL;
262 }
263 nomPrintf("%s: Got shared memory pool: %x\n", __FUNCTION__, memPool);
264
265 /* Now init the structure */
266 memset(memPtr, 0, 1 /*SOMTK_SHARED_MEM_SIZE_ROOT*/);
267 nomPrintf("%s: zeroed memory\n", __FUNCTION__);
268
269 ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
270 /* Init memory pool */
271 if(NO_ERROR!=DosSubSetMem(memPool, DOSSUB_INIT|DOSSUB_SPARSE_OBJ|DOSSUB_SERIALIZE, SOMTK_SHARED_MEM_SIZE_POOL)) {
272 DosFreeMem(memPool);
273 DosFreeMem(memPtr);
274 return NULL;
275 }
276 ((PNOM_ENV)memPtr)->pMemPool=memPool;
277 if(NO_ERROR!=DosCreateMutexSem(NULL, &((PNOM_ENV)memPtr)->hmtx, DC_SEM_SHARED, FALSE))
278 {
279 DosFreeMem(memPool);
280 DosFreeMem(memPtr);
281 return NULL;
282 }
283 pGlobalNomEnv=(PNOM_ENV)memPtr;
284
285 return (PNOM_ENV)memPtr;
286}
287
288
289
290
291
292
293
294
295
296
297
Note: See TracBrowser for help on using the repository browser.