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 | /********************************************************/
|
---|
59 | PNOM_ENV pGlobalNomEnv;
|
---|
60 | /* Global class manager object */
|
---|
61 | NOMClassMgr* 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 | */
|
---|
77 | NOMEXTERN 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 |
|
---|
89 | NOMEXTERN 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 | */
|
---|
108 | NOMEXTERN 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 |
|
---|
182 |
|
---|
183 | NOMEXTERN PNOM_ENV NOMLINK nomTkInit(void)
|
---|
184 | {
|
---|
185 | PVOID memPtr;
|
---|
186 | //PVOID memPool;
|
---|
187 |
|
---|
188 | nomPrintf("Entering %s...\n", __FUNCTION__);
|
---|
189 |
|
---|
190 | memPtr=g_malloc(sizeof(NOM_ENV)); /* g_malloc() can't fail... */
|
---|
191 |
|
---|
192 | nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
|
---|
193 |
|
---|
194 | /* Now init the structure */
|
---|
195 | /* GC memory is zeroed... */
|
---|
196 | ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
|
---|
197 | pGlobalNomEnv=(PNOM_ENV)memPtr;
|
---|
198 | if(NO_ERROR!=DosCreateMutexSem(NULL, &((PNOM_ENV)memPtr)->hmtx, DC_SEM_SHARED, FALSE))
|
---|
199 | {
|
---|
200 | g_free(memPtr);
|
---|
201 | return NULL;
|
---|
202 | }
|
---|
203 |
|
---|
204 | return (PNOM_ENV)memPtr;
|
---|
205 |
|
---|
206 | #if 0
|
---|
207 | nomPrintf("*************************************\n");
|
---|
208 | nomPrintf("!! This function must be rewritten !!\n");
|
---|
209 | nomPrintf("!! It's using OS/2 only memory !!\n");
|
---|
210 | nomPrintf("!! functions. !!\n");
|
---|
211 | nomPrintf("*************************************\n");
|
---|
212 |
|
---|
213 | /* Check if we already allocated our shared mem */
|
---|
214 | if(NO_ERROR==DosGetNamedSharedMem(&memPtr,SOMTK_SHARED_MEM_NAME_ROOT , PAG_EXECUTE|PAG_READ|PAG_WRITE)) {
|
---|
215 | nomPrintf("%s: Found root shared mem: %x.\n", __FUNCTION__, memPtr);
|
---|
216 | /* Give process access to memory pool*/
|
---|
217 | DosGetSharedMem( ((PNOM_ENV)memPtr)->pMemPool, PAG_READ|PAG_WRITE|PAG_EXECUTE);
|
---|
218 | if(NO_ERROR!=DosSubSetMem(((PNOM_ENV)memPtr)->pMemPool, DOSSUB_SPARSE_OBJ|DOSSUB_SERIALIZE, SOMTK_SHARED_MEM_SIZE_POOL)) {
|
---|
219 | DosFreeMem(memPool);
|
---|
220 | DosFreeMem(memPtr);
|
---|
221 | return NULL;
|
---|
222 | }
|
---|
223 | pGlobalNomEnv=(PNOM_ENV)memPtr;
|
---|
224 | return (PNOM_ENV)memPtr;
|
---|
225 | }
|
---|
226 | nomPrintf("%s: No root memory yet\n", __FUNCTION__);
|
---|
227 |
|
---|
228 | /* Get the mem for the root structure in a shared memory area */
|
---|
229 | if(NO_ERROR!=DosAllocSharedMem(&memPtr, SOMTK_SHARED_MEM_NAME_ROOT, SOMTK_SHARED_MEM_SIZE_ROOT,
|
---|
230 | PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE))
|
---|
231 | return NULL;
|
---|
232 |
|
---|
233 | nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
|
---|
234 |
|
---|
235 | /* Get our shared memory pool */
|
---|
236 | if(NO_ERROR!=DosAllocSharedMem(&memPool, NULL, SOMTK_SHARED_MEM_SIZE_POOL,OBJ_GETTABLE | PAG_EXECUTE|PAG_READ|PAG_WRITE)) {
|
---|
237 | DosFreeMem(memPtr);
|
---|
238 | return NULL;
|
---|
239 | }
|
---|
240 | nomPrintf("%s: Got shared memory pool: %x\n", __FUNCTION__, memPool);
|
---|
241 |
|
---|
242 | /* Now init the structure */
|
---|
243 | memset(memPtr, 0, 1 /*SOMTK_SHARED_MEM_SIZE_ROOT*/);
|
---|
244 | nomPrintf("%s: zeroed memory\n", __FUNCTION__);
|
---|
245 |
|
---|
246 | ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
|
---|
247 | /* Init memory pool */
|
---|
248 | if(NO_ERROR!=DosSubSetMem(memPool, DOSSUB_INIT|DOSSUB_SPARSE_OBJ|DOSSUB_SERIALIZE, SOMTK_SHARED_MEM_SIZE_POOL)) {
|
---|
249 | DosFreeMem(memPool);
|
---|
250 | DosFreeMem(memPtr);
|
---|
251 | return NULL;
|
---|
252 | }
|
---|
253 | ((PNOM_ENV)memPtr)->pMemPool=memPool;
|
---|
254 | if(NO_ERROR!=DosCreateMutexSem(NULL, &((PNOM_ENV)memPtr)->hmtx, DC_SEM_SHARED, FALSE))
|
---|
255 | {
|
---|
256 | DosFreeMem(memPool);
|
---|
257 | DosFreeMem(memPtr);
|
---|
258 | return NULL;
|
---|
259 | }
|
---|
260 | pGlobalNomEnv=(PNOM_ENV)memPtr;
|
---|
261 |
|
---|
262 | return (PNOM_ENV)memPtr;
|
---|
263 | #endif
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 |
|
---|
269 |
|
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|