00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000-2003 by the OpenSG Forum * 00006 * * 00007 * www.opensg.org * 00008 * * 00009 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00010 * * 00011 \*---------------------------------------------------------------------------*/ 00012 /*---------------------------------------------------------------------------*\ 00013 * License * 00014 * * 00015 * This library is free software; you can redistribute it and/or modify it * 00016 * under the terms of the GNU Library General Public License as published * 00017 * by the Free Software Foundation, version 2. * 00018 * * 00019 * This library is distributed in the hope that it will be useful, but * 00020 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the Free Software * 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00027 * * 00028 \*---------------------------------------------------------------------------*/ 00029 /*---------------------------------------------------------------------------*\ 00030 * Changes * 00031 * * 00032 * * 00033 * * 00034 * * 00035 * * 00036 * * 00037 \*---------------------------------------------------------------------------*/ 00038 00039 #ifndef _OSGSHAREDOBJECTHANDLER_H_ 00040 #define _OSGSHAREDOBJECTHANDLER_H_ 00041 #ifdef __sgi 00042 #pragma once 00043 #endif 00044 00045 00050 //--------------------------------------------------------------------------- 00051 // Includes 00052 //--------------------------------------------------------------------------- 00053 00054 #include "OSGBaseTypes.h" 00055 #include "OSGMemoryObject.h" 00056 00057 #include <map> 00058 #include <vector> 00059 00060 OSG_BEGIN_NAMESPACE 00061 00062 //--------------------------------------------------------------------------- 00063 // Forward References 00064 //--------------------------------------------------------------------------- 00065 00066 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00067 00068 class SharedObjectHandler; 00069 class SharedObject; 00070 00071 class CompileConfig; 00072 00073 #endif 00074 00075 //--------------------------------------------------------------------------- 00076 // Types 00077 //--------------------------------------------------------------------------- 00078 00079 #ifdef WIN32 00080 typedef HMODULE SharedHandle; 00081 #else 00082 typedef void *SharedHandle; 00083 #endif 00084 00085 typedef void *AnonSymbolHandle; 00086 00087 //--------------------------------------------------------------------------- 00088 // Class 00089 //--------------------------------------------------------------------------- 00090 00094 typedef OSG::SharedObject *SharedObjectP; 00095 00099 class OSG_BASE_DLLMAPPING SharedObject : public MemoryObject 00100 { 00101 public: 00102 00103 //----------------------------------------------------------------------- 00104 // constants 00105 //----------------------------------------------------------------------- 00106 00107 //----------------------------------------------------------------------- 00108 // enums 00109 //----------------------------------------------------------------------- 00110 00111 enum SharedObjectType 00112 { 00113 Invalid = 0x0000, 00114 Application = 0x0001, 00115 SharedLibrary = 0x0002 00116 }; 00117 00118 //----------------------------------------------------------------------- 00119 // types 00120 //----------------------------------------------------------------------- 00121 00122 private: 00123 00124 //----------------------------------------------------------------------- 00125 // enums 00126 //----------------------------------------------------------------------- 00127 00128 //----------------------------------------------------------------------- 00129 // types 00130 //----------------------------------------------------------------------- 00131 00132 typedef MemoryObject Inherited; 00133 00134 //----------------------------------------------------------------------- 00135 // friend classes 00136 //----------------------------------------------------------------------- 00137 00138 friend class SharedObjectHandler; 00139 00140 //----------------------------------------------------------------------- 00141 // friend functions 00142 //----------------------------------------------------------------------- 00143 00144 //----------------------------------------------------------------------- 00145 // class variables 00146 //----------------------------------------------------------------------- 00147 00148 //----------------------------------------------------------------------- 00149 // class functions 00150 //----------------------------------------------------------------------- 00151 00152 //----------------------------------------------------------------------- 00153 // instance variables 00154 //----------------------------------------------------------------------- 00155 00156 //----------------------------------------------------------------------- 00157 // instance functions 00158 //----------------------------------------------------------------------- 00159 00160 // prohibit default functions (move to 'public' if you need one) 00161 SharedObject(const SharedObject &source); 00162 // prohibit default functions (move to 'public' if you need one) 00163 void operator =(const SharedObject &source); 00164 00165 protected: 00166 00167 //----------------------------------------------------------------------- 00168 // enums 00169 //----------------------------------------------------------------------- 00170 00171 //----------------------------------------------------------------------- 00172 // types 00173 //----------------------------------------------------------------------- 00174 00175 //----------------------------------------------------------------------- 00176 // class variables 00177 //----------------------------------------------------------------------- 00178 00179 static Char8 _szApplicationObjectName[]; 00180 00181 //----------------------------------------------------------------------- 00182 // class functions 00183 //----------------------------------------------------------------------- 00184 00185 //----------------------------------------------------------------------- 00186 // instance variables 00187 //----------------------------------------------------------------------- 00188 00189 std::string _szName; 00190 SharedHandle _pHandle; 00191 00192 SharedObjectType _type; 00193 00194 //----------------------------------------------------------------------- 00195 // instance functions 00196 //----------------------------------------------------------------------- 00197 00198 SharedObject(const Char8 *szName); 00199 00200 virtual ~SharedObject(void); 00201 00202 bool close(void); 00203 00204 public : 00205 00206 //----------------------------------------------------------------------- 00207 // class functions 00208 //----------------------------------------------------------------------- 00209 00210 //----------------------------------------------------------------------- 00211 // instance functions 00212 //----------------------------------------------------------------------- 00213 00214 /*------------------------- your_category -------------------------------*/ 00215 00216 bool open ( void ); 00217 AnonSymbolHandle getSymbol(const Char8 *szSymbolName); 00218 00219 bool isOpen ( void ); 00220 00221 bool reOpen ( void ); 00222 00223 const std::string &getName ( void ); 00224 const Char8 *getCName ( void ); 00225 00226 /*------------------------- your_operators ------------------------------*/ 00227 00228 /*------------------------- assignment ----------------------------------*/ 00229 00230 void dump(void); 00231 00232 /*------------------------- comparison ----------------------------------*/ 00233 }; 00234 00235 //--------------------------------------------------------------------------- 00236 // Class 00237 //--------------------------------------------------------------------------- 00238 00239 00243 typedef OSG::SharedObjectHandler *SharedObjectHandlerP; 00244 00248 class OSG_BASE_DLLMAPPING SharedObjectHandler 00249 { 00250 public: 00251 00252 //----------------------------------------------------------------------- 00253 // constants 00254 //----------------------------------------------------------------------- 00255 00256 //----------------------------------------------------------------------- 00257 // enums 00258 //----------------------------------------------------------------------- 00259 00260 //----------------------------------------------------------------------- 00261 // types 00262 //----------------------------------------------------------------------- 00263 00264 typedef std::map<std::string, SharedObjectP> SharedObjectMap; 00265 00266 typedef SharedObjectMap::iterator SharedObjectMapIt; 00267 00268 typedef SharedObjectMap::const_iterator SharedObjectMapConstIt; 00269 00270 00271 typedef std::vector<std::string> NameStore; 00272 typedef std::vector<std::string>::iterator NameStoreIt; 00273 typedef std::vector<std::string>::const_iterator NameStoreConstIt; 00274 00275 private: 00276 00277 //----------------------------------------------------------------------- 00278 // enums 00279 //----------------------------------------------------------------------- 00280 00281 //----------------------------------------------------------------------- 00282 // types 00283 //----------------------------------------------------------------------- 00284 00285 //----------------------------------------------------------------------- 00286 // friend classes 00287 //----------------------------------------------------------------------- 00288 00289 //----------------------------------------------------------------------- 00290 // friend functions 00291 //----------------------------------------------------------------------- 00292 00293 OSG_BASE_DLLMAPPING 00294 friend bool osgInit(Int32 argc, Char8 **argv, 00295 UInt16 major, UInt16 minor, UInt16 release, 00296 bool debug, bool dll, bool mt); 00297 00298 OSG_BASE_DLLMAPPING 00299 friend bool osgExit(void); 00300 00301 //----------------------------------------------------------------------- 00302 // class variables 00303 //----------------------------------------------------------------------- 00304 00305 //----------------------------------------------------------------------- 00306 // class functions 00307 //----------------------------------------------------------------------- 00308 00309 //----------------------------------------------------------------------- 00310 // instance variables 00311 //----------------------------------------------------------------------- 00312 00313 //----------------------------------------------------------------------- 00314 // instance functions 00315 //----------------------------------------------------------------------- 00316 00317 // prohibit default functions (move to 'public' if you need one) 00318 SharedObjectHandler(const SharedObjectHandler &source); 00319 // prohibit default functions (move to 'public' if you need one) 00320 void operator =(const SharedObjectHandler &source); 00321 00322 protected: 00323 00324 //----------------------------------------------------------------------- 00325 // enums 00326 //----------------------------------------------------------------------- 00327 00328 //----------------------------------------------------------------------- 00329 // types 00330 //----------------------------------------------------------------------- 00331 00332 //----------------------------------------------------------------------- 00333 // class variables 00334 //----------------------------------------------------------------------- 00335 00336 static SharedObjectHandlerP _the; 00337 00338 //----------------------------------------------------------------------- 00339 // class functions 00340 //----------------------------------------------------------------------- 00341 00342 //----------------------------------------------------------------------- 00343 // instance variables 00344 //----------------------------------------------------------------------- 00345 00346 SharedObjectMap _mSharedObjects; 00347 00348 NameStore _vLoadedNames; 00349 00350 //----------------------------------------------------------------------- 00351 // instance functions 00352 //----------------------------------------------------------------------- 00353 00354 SharedObjectHandler(void); 00355 00356 virtual ~SharedObjectHandler(void); 00357 00358 bool initialize(void); 00359 void terminate (void); 00360 00361 public : 00362 00363 //----------------------------------------------------------------------- 00364 // class functions 00365 //----------------------------------------------------------------------- 00366 00367 static SharedObjectHandlerP the(void); 00368 00369 //----------------------------------------------------------------------- 00370 // instance functions 00371 //----------------------------------------------------------------------- 00372 00373 SharedObjectP getSharedObject (const Char8 *szName ); 00374 SharedObjectP getOSGSharedObject(const Char8 *szName ); 00375 SharedObjectP findSharedObject (const Char8 *szName ) const; 00376 00377 void removeSharedObject(const Char8 *szName ); 00378 void removeSharedObject( SharedObjectP pObject); 00379 00380 /*------------------------- your_category -------------------------------*/ 00381 00382 void registerLoadedObject(const Char8 *szName); 00383 00384 /*------------------------- your_operators ------------------------------*/ 00385 00386 /*------------------------- assignment ----------------------------------*/ 00387 00388 /*------------------------- comparison ----------------------------------*/ 00389 00390 void dump(void); 00391 00392 /*------------------------- comparison ----------------------------------*/ 00393 }; 00394 00395 OSG_END_NAMESPACE 00396 00397 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00398 00399 #define OSGSHAREDOBJECTHANDLER_HEADER_CVSID "@(#)$Id: $" 00400 00401 #endif 00402 00403 #endif /* _OSGSHAREDOBJECTHANDLER_H_ */
1.5.5