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

Last change on this file since 255 was 255, checked in by cinc, 18 years ago

Parameter checking for object pointer working.

File size: 6.7 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#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/********************************************************/
59PNOM_ENV pGlobalNomEnv;
60/* Global class manager object */
61NOMClassMgr* NOMClassMgrObject=NULLHANDLE; /* Referenced from different files */
62
63gboolean fInitialized=FALSE;
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/*
75 This function asks the NOMClassMgrObject to search in the internal lists
76 for the mtab of the given object. If that mtab is found the pointer points to a
77 valid object.
78 */
79NOMEXTERN gboolean NOMLINK nomIsObj(gpointer nomObj)
80{
81 if(NOMClassMgrObject)
82 return NOMClassMgr_nomIsObject(NOMClassMgrObject, (PNOMObject)nomObj, NULLHANDLE);
83
84 if(!nomObj)
85 return FALSE;
86
87 /* We assume that here... */
88 return TRUE;
89}
90
91NOMEXTERN int NOMLINK nomPrintf(string chrFormat, ...)
92{
93 long rc;
94
95 va_list arg_ptr;
96
97 va_start (arg_ptr, chrFormat);
98 rc=vprintf( chrFormat, arg_ptr);
99 va_end (arg_ptr);
100 return rc;
101}
102
103
104NOMEXTERN PNOM_ENV NOMLINK nomTkInit(void)
105{
106 PVOID memPtr;
107
108 if(pGlobalNomEnv)
109 return pGlobalNomEnv; /* Already done */
110
111 nomPrintf("Entering %s...\n", __FUNCTION__);
112
113 memPtr=g_malloc(sizeof(NOM_ENV)); /* g_malloc() can't fail... */
114
115 nomPrintf("%s: Got root memory: %x\n", __FUNCTION__, memPtr);
116
117 /* Now init the structure */
118 /* GC memory is zeroed... */
119 ((PNOM_ENV)memPtr)->cbSize=sizeof(NOM_ENV);
120 pGlobalNomEnv=(PNOM_ENV)memPtr;
121
122 return (PNOM_ENV)memPtr;
123}
124
125
126/*
127 This function is called to initialize the NOM runtime.
128 It creates NOMObject, NOMClass and NOMClassMgr classes and the global
129 NOMClassMgrObject.
130*/
131NOMEXTERN NOMClassMgr * NOMLINK nomEnvironmentNew (void)
132{
133 NOMClassPriv* ncPriv;
134 NOMClass* nomCls;
135 // NOMClassMgr *NOMClassMgrObject_priv;
136#if 0
137 NOMObject *nomObj;
138 NOMTest* nomTst;
139 NOMTest* nomTstObj;
140 NOMTest* nomTst2Obj;
141#endif
142
143
144#ifdef DEBUG_NOMENVNEW
145 nomPrintf("Entering %s to initialize NOM runtime.\n\n", __FUNCTION__);
146 nomPrintf("**** Building NOMObject class...\n");
147#endif
148 nomTkInit();
149
150 nomCls=NOMObjectNewClass(NOMObject_MajorVersion, NOMObject_MinorVersion);
151
152#ifdef DEBUG_NOMENVNEW
153 nomPrintf("NOMObject class: %x\n", nomCls);
154 nomPrintf("\n**** Building NOMClass class...\n");
155#endif
156
157 nomCls=NOMClassNewClass(NOMClass_MajorVersion, NOMClass_MinorVersion);
158#ifdef DEBUG_NOMENVNEW
159 nomPrintf("NOMClass class: %x\n", nomCls);
160 nomPrintf("\n**** Building NOMClassMgr class and NOMClassMgrObject...\n");
161#endif
162 NOMClassMgrObject=NOMClassMgrNew();
163 if(!NOMClassMgrObject)
164 g_error("Can't create the NOMClassMgr class object!\n");
165
166#ifdef DEBUG_NOMENVNEW
167 nomPrintf("%s: NOMClassMgrObject: %x (%x)\n", __FUNCTION__, NOMClassMgrObject, pGlobalNomEnv->defaultMetaClass);
168#endif
169
170 /* Now register the classes we already have */
171 _nomClassReady(pGlobalNomEnv->defaultMetaClass, NULLHANDLE); //NOMClass
172 _nomClassReady( _NOMClassMgr, NULLHANDLE); //NOMClassMgr
173 ncPriv=(NOMClassPriv*)pGlobalNomEnv->nomObjectMetaClass->mtab->nomClsInfo;
174
175 /* Do not register the NOMObject metaclass here. It's already registered because it's
176 NOMClass in fact. */
177 _nomClassReady(_NOMObject, NULLHANDLE); //NOMObject
178
179
180#if 0
181 nomPrintf("\n**** Building NOMTest2 class...\n");
182 nomPrintf("\nNow building a NOMTest2 object...\n");
183 nomTst2Obj= NOMTest2New();
184 nomPrintf("NOMTest2 object: %x\n", nomTst2Obj);
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 /* This must be done last! */
202 // NOMClassMgrObject=NOMClassMgrObject_priv;
203
204 fInitialized=TRUE;
205
206 return NOMClassMgrObject;
207}
208
209
210NOMEXTERN void NOMLINK nomTkUnInit(gpointer pReserved)
211{
212 /* Nothing yet...*/
213}
214
215NOMEXTERN void NOMLINK nomEnvironmentEnd (void)
216{
217 nomTkUnInit(NULL);
218}
219
220
221
222
223
224
225
226
227
228
Note: See TracBrowser for help on using the repository browser.