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