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-2007
|
---|
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 | NOMEXTERN PNOM_ENV NOMLINK nomTkInit(void)
|
---|
103 | {
|
---|
104 | PVOID memPtr;
|
---|
105 |
|
---|
106 | if(pGlobalNomEnv)
|
---|
107 | return pGlobalNomEnv; /* Already done */
|
---|
108 |
|
---|
109 | nomPrintf("Entering %s...\n", __FUNCTION__);
|
---|
110 |
|
---|
111 | memPtr=g_malloc(sizeof(NOM_ENV)); /* g_malloc() can't fail... */
|
---|
112 |
|
---|
113 | nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
|
---|
114 |
|
---|
115 | /* Now init the structure */
|
---|
116 | /* GC memory is zeroed... */
|
---|
117 | ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
|
---|
118 | pGlobalNomEnv=(PNOM_ENV)memPtr;
|
---|
119 |
|
---|
120 | return (PNOM_ENV)memPtr;
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /*
|
---|
125 | This function is called to initialize the NOM runtime.
|
---|
126 | It creates NOMObject, NOMClass and NOMClassMgr classes and the global
|
---|
127 | NOMClassMgrObject.
|
---|
128 | */
|
---|
129 | NOMEXTERN NOMClassMgr * NOMLINK nomEnvironmentNew (void)
|
---|
130 | {
|
---|
131 | NOMClassPriv* ncPriv;
|
---|
132 | NOMClass* nomCls;
|
---|
133 | #if 0
|
---|
134 | NOMObject *nomObj;
|
---|
135 | NOMTest* nomTst;
|
---|
136 | NOMTest* nomTstObj;
|
---|
137 | NOMTest* nomTst2Obj;
|
---|
138 | #endif
|
---|
139 |
|
---|
140 |
|
---|
141 | #ifdef DEBUG_NOMENVNEW
|
---|
142 | nomPrintf("Entering %s to initialize NOM runtime.\n\n", __FUNCTION__);
|
---|
143 | nomPrintf("**** Building NOMObject class...\n");
|
---|
144 | #endif
|
---|
145 | nomTkInit();
|
---|
146 |
|
---|
147 | nomCls=NOMObjectNewClass(NOMObject_MajorVersion, NOMObject_MinorVersion);
|
---|
148 |
|
---|
149 | #ifdef DEBUG_NOMENVNEW
|
---|
150 | nomPrintf("NOMObject class: %x\n", nomCls);
|
---|
151 | nomPrintf("\n**** Building NOMClass class...\n");
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | nomCls=NOMClassNewClass(NOMClass_MajorVersion, NOMClass_MinorVersion);
|
---|
155 | #ifdef DEBUG_NOMENVNEW
|
---|
156 | nomPrintf("NOMClass class: %x\n", nomCls);
|
---|
157 | nomPrintf("\n**** Building NOMClassMgr class and NOMClassMgrObject...\n");
|
---|
158 | #endif
|
---|
159 | NOMClassMgrObject=NOMClassMgrNew();
|
---|
160 | if(!NOMClassMgrObject)
|
---|
161 | g_error("Can't create the NOMClassMgr class object!\n");
|
---|
162 |
|
---|
163 | #ifdef DEBUG_NOMENVNEW
|
---|
164 | nomPrintf("%s: NOMClassMgrObject: %x \n", __FUNCTION__, NOMClassMgrObject);
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | /* Now register the classes we already have */
|
---|
168 | _nomClassReady(pGlobalNomEnv->defaultMetaClass, NULLHANDLE); //NOMClass
|
---|
169 | _nomClassReady( _NOMClassMgr, NULLHANDLE); //NOMClassMgr
|
---|
170 | ncPriv=(NOMClassPriv*)pGlobalNomEnv->nomObjectMetaClass->mtab->nomClsInfo;
|
---|
171 |
|
---|
172 | /* Do not register the NOMObject metaclass here. It's already registered because it's
|
---|
173 | NOMClass in fact. */
|
---|
174 | _nomClassReady(_NOMObject, NULLHANDLE); //NOMObject
|
---|
175 |
|
---|
176 |
|
---|
177 | #if 0
|
---|
178 | nomPrintf("\n**** Building NOMTest2 class...\n");
|
---|
179 | nomPrintf("\nNow building a NOMTest2 object...\n");
|
---|
180 | nomTst2Obj= NOMTest2New();
|
---|
181 | nomPrintf("NOMTest2 object: %x\n", nomTst2Obj);
|
---|
182 |
|
---|
183 | nomPrintf("\nCalling _nomTestFunc_NOMTest2() 1\n", nomTst2Obj);
|
---|
184 | _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
|
---|
185 | nomPrintf("\nCalling _nomTestFuncString_NOMTest2() 1\n", nomTst2Obj);
|
---|
186 | nomPrintf("--> %s\n",_nomTestFuncString_NOMTest2(nomTst2Obj, NULLHANDLE));
|
---|
187 | nomPrintf("\nCalling _nomTestFunc_NOMTest2() 2\n", nomTst2Obj);
|
---|
188 | _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
|
---|
189 |
|
---|
190 | nomPrintf("\nCalling _nomTestFunc() with NOMTest2 object: %x\n", nomTst2Obj);
|
---|
191 | _nomTestFunc(nomTst2Obj, NULLHANDLE);
|
---|
192 | nomPrintf("\nCalling _nomTestFuncString() with NOMTest2: %x\n", nomTst2Obj);
|
---|
193 | nomPrintf("--> %s\n",_nomTestFuncString(nomTst2Obj, NULLHANDLE));
|
---|
194 | nomPrintf("\n");
|
---|
195 | _nomTestFunc(nomTst2Obj, NULLHANDLE);
|
---|
196 | _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | return NOMClassMgrObject;
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | NOMEXTERN void NOMLINK nomTkUnInit(gpointer pReserved)
|
---|
204 | {
|
---|
205 | /* Nothing yet...*/
|
---|
206 | }
|
---|
207 |
|
---|
208 | NOMEXTERN void NOMLINK nomEnvironmentEnd (void)
|
---|
209 | {
|
---|
210 | nomTkUnInit(NULL);
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 |
|
---|
215 |
|
---|
216 |
|
---|
217 |
|
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|