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

Last change on this file since 326 was 326, checked in by cinc, 17 years ago

Portability patches for Windows, Linux, Darwin by Bird.

File size: 6.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-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#ifdef __OS2__
36# define INCL_DOS
37# define INCL_DOSERRORS
38# define INCL_DOSMEMMGR
39# include <os2.h>
40#endif /* __OS2__ */
41
42#include <stdarg.h>
43#include <stdio.h>
44#include <string.h>
45
46
47/* For nomToken etc. */
48#include <nom.h>
49#include "nomtk.h"
50#include "nomobj.h"
51#include "nomcls.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=NULL; /* Referenced from different files */
64
65gboolean fInitialized=FALSE;
66
67/********************************************************/
68/* Toolkit functions, exported */
69/********************************************************/
70
71
72/*
73 Some of these functions should be moved to other source files...
74 */
75
76/*
77 This function asks the NOMClassMgrObject to search in the internal lists
78 for the mtab of the given object. If that mtab is found the pointer points to a
79 valid object.
80 */
81NOMEXTERN gboolean NOMLINK nomIsObj(gpointer nomObj)
82{
83 if(NOMClassMgrObject)
84 return NOMClassMgr_nomIsObject(NOMClassMgrObject, (PNOMObject)nomObj, NULL);
85
86 if(!nomObj)
87 return FALSE;
88
89 /* We assume that here... */
90 return TRUE;
91}
92
93NOMEXTERN int NOMLINK nomPrintf(string chrFormat, ...)
94{
95 long rc;
96
97 va_list arg_ptr;
98
99 va_start (arg_ptr, chrFormat);
100 rc=vprintf( chrFormat, arg_ptr);
101 va_end (arg_ptr);
102 return rc;
103}
104
105
106NOMEXTERN PNOM_ENV NOMLINK nomTkInit(void)
107{
108 void *memPtr;
109
110 if(pGlobalNomEnv)
111 return pGlobalNomEnv; /* Already done */
112
113 nomPrintf("Entering %s...\n", __FUNCTION__);
114
115 memPtr=g_malloc(sizeof(NOM_ENV)); /* g_malloc() can't fail... */
116
117 nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
118
119 /* Now init the structure */
120 /* GC memory is zeroed... */
121 ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
122 pGlobalNomEnv=(PNOM_ENV)memPtr;
123
124 return (PNOM_ENV)memPtr;
125}
126
127
128/*
129 This function is called to initialize the NOM runtime.
130 It creates NOMObject, NOMClass and NOMClassMgr classes and the global
131 NOMClassMgrObject.
132*/
133NOMEXTERN NOMClassMgr * NOMLINK nomEnvironmentNew (void)
134{
135 NOMClassPriv* ncPriv;
136 NOMClass* nomCls;
137 // NOMClassMgr *NOMClassMgrObject_priv;
138#if 0
139 NOMObject *nomObj;
140 NOMTest* nomTst;
141 NOMTest* nomTstObj;
142 NOMTest* nomTst2Obj;
143#endif
144
145
146#ifdef DEBUG_NOMENVNEW
147 nomPrintf("Entering %s to initialize NOM runtime.\n\n", __FUNCTION__);
148 nomPrintf("**** Building NOMObject class...\n");
149#endif
150 nomTkInit();
151
152 nomCls=NOMObjectNewClass(NOMObject_MajorVersion, NOMObject_MinorVersion);
153
154#ifdef DEBUG_NOMENVNEW
155 nomPrintf("NOMObject class: %x\n", nomCls);
156 nomPrintf("\n**** Building NOMClass class...\n");
157#endif
158
159 nomCls=NOMClassNewClass(NOMClass_MajorVersion, NOMClass_MinorVersion);
160#ifdef DEBUG_NOMENVNEW
161 nomPrintf("NOMClass class: %x\n", nomCls);
162 nomPrintf("\n**** Building NOMClassMgr class and NOMClassMgrObject...\n");
163#endif
164 NOMClassMgrObject=NOMClassMgrNew();
165
166 if(!NOMClassMgrObject)
167 g_error("Can't create the NOMClassMgr class object!\n");
168
169#ifdef DEBUG_NOMENVNEW
170 nomPrintf("%s: NOMClassMgrObject: %x (%x)\n", __FUNCTION__, NOMClassMgrObject, pGlobalNomEnv->defaultMetaClass);
171#endif
172
173 /* Now register the classes we already have */
174 _nomClassReady(pGlobalNomEnv->defaultMetaClass, NULL); //NOMClass
175 _nomClassReady( _NOMClassMgr, NULL); //NOMClassMgr
176 ncPriv=(NOMClassPriv*)pGlobalNomEnv->nomObjectMetaClass->mtab->nomClsInfo;
177
178 /* Do not register the NOMObject metaclass here. It's already registered because it's
179 NOMClass in fact. */
180 _nomClassReady(_NOMObject, NULL); //NOMObject
181
182
183#if 0
184 nomPrintf("\n**** Building NOMTest2 class...\n");
185 nomPrintf("\nNow building a NOMTest2 object...\n");
186 nomTst2Obj= NOMTest2New();
187 nomPrintf("NOMTest2 object: %x\n", nomTst2Obj);
188
189 nomPrintf("\nCalling _nomTestFunc_NOMTest2() 1\n", nomTst2Obj);
190 _nomTestFunc_NOMTest2(nomTst2Obj, NULL);
191 nomPrintf("\nCalling _nomTestFuncString_NOMTest2() 1\n", nomTst2Obj);
192 nomPrintf("--> %s\n",_nomTestFuncString_NOMTest2(nomTst2Obj, NULL));
193 nomPrintf("\nCalling _nomTestFunc_NOMTest2() 2\n", nomTst2Obj);
194 _nomTestFunc_NOMTest2(nomTst2Obj, NULL);
195
196 nomPrintf("\nCalling _nomTestFunc() with NOMTest2 object: %x\n", nomTst2Obj);
197 _nomTestFunc(nomTst2Obj, NULL);
198 nomPrintf("\nCalling _nomTestFuncString() with NOMTest2: %x\n", nomTst2Obj);
199 nomPrintf("--> %s\n",_nomTestFuncString(nomTst2Obj, NULL));
200 nomPrintf("\n");
201 _nomTestFunc(nomTst2Obj, NULL);
202 _nomTestFunc_NOMTest2(nomTst2Obj, NULL);
203#endif
204 /* This must be done last! */
205 // NOMClassMgrObject=NOMClassMgrObject_priv;
206
207 fInitialized=TRUE;
208
209 return NOMClassMgrObject;
210}
211
212
213NOMEXTERN void NOMLINK nomTkUnInit(gpointer pReserved)
214{
215 /* Nothing yet...*/
216}
217
218NOMEXTERN void NOMLINK nomEnvironmentEnd (void)
219{
220 nomTkUnInit(NULL);
221}
222
223
224
225
226
227
228
229
230
231
Note: See TracBrowser for help on using the repository browser.