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

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

Initial NOM checkin

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