Studierstube 4 Documentation Project

   Main Page       Modules       Class Hierarchy       Alphabetical List       Compound List       File List       Compound Members       Related Pages   

OS.cxx

Go to the documentation of this file.
00001 /* ========================================================================
00002 * Copyright (C) 2005  Graz University of Technology
00003 *
00004 * This framework is free software; you can redistribute it and/or modify
00005 * it under the terms of the GNU General Public License as published by
00006 * the Free Software Foundation; either version 2 of the License, or
00007 * (at your option) any later version.
00008 *
00009 * This framework is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this framework; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 *
00018 * For further information please contact Dieter Schmalstieg under
00019 * <schmalstieg@icg.tu-graz.ac.at> or write to Dieter Schmalstieg,
00020 * Graz University of Technology, Inffeldgasse 16a, A8010 Graz,
00021 * Austria.
00022 * ========================================================================
00023 * PROJECT: Studierstube
00024 * ======================================================================== */
00031 /* ======================================================================= */
00032 
00033 
00034 #include <stb/base/fixWinCEIssues.h>
00035 #include <stb/base/OS.h>
00036 #include <stb/base/fixWinXPIssues.h>
00037 #include <ace/OS.h>
00038 
00039 #ifndef __APPLE__
00040 #include <GL/gl.h>
00041 #else
00042 #include <OpenGL/gl.h>
00043 #endif
00044 #include <cstdio>
00045 #include <sstream>
00046 #include <iostream>
00047 #include <assert.h>
00048 
00049 
00050 BEGIN_NAMESPACE_STB
00051 
00052 
00053 //---------------------------------------
00056 hModule 
00057 os_LoadLibrary(stb::string fileName)
00058 {
00059 #ifdef STB_IS_WINDOWS
00060     //ostringstream name;
00061     //name  << fileName;
00062     //#ifdef _DEBUG
00063     //    name << "d";
00064     //#endif
00065     //    name <<".dll";
00066 
00067     //FILE* fp = fopen(name.str().c_str(), "rb");
00068     //if(!fp)
00069     //{
00070     //    printf("can't open %s\n",name.str().c_str());
00071     //    return NULL;
00072     //}
00073 
00074         std::string fName = fileName;
00075         fName += ".dll";
00076 
00077         const char* libNameStr = fName.c_str();
00078         assert(libNameStr);
00079 
00080         return ::LoadLibrary(ACE_TEXT_CHAR_TO_TCHAR(libNameStr));
00081 #else 
00082     using namespace std;
00083     stb::string pathName, libName;
00084     stb::string::size_type pos = fileName.rfind('/');
00085 
00086     if(pos != stb::string::npos) {
00087         ++pos;
00088         pathName = fileName.substr(0, pos);
00089         fileName = fileName.substr(pos, fileName.length() - pos);
00090     }
00091 
00092 #ifndef __APPLE__
00093     libName = pathName + "lib" + fileName + ".so";
00094 #else
00095     libName = pathName + "lib" + fileName + ".dylib";
00096 #endif 
00097     cerr << "  Dynamically loading >" << libName << "< ...";
00098     
00099     // load the library
00100     hModule p = dlopen(libName.c_str(), RTLD_LAZY);
00101     if (!p) {
00102         cerr << "  failed: cannot load library: " << dlerror() << '\n';
00103         return 0;
00104     }
00105     cerr << "  done." << endl;
00106     return p;
00107 #endif
00108 }
00109 
00110 //----------------------------------------
00113 int*
00114 os_GetProcAddress(hModule moduleHandle,const char*   procName)
00115 {
00116 #ifdef STB_IS_WINDOWS
00117     return (int*)GetProcAddress(moduleHandle, ACE_TEXT_CHAR_TO_TCHAR(procName));
00118 #else
00119     return (int*)dlsym(moduleHandle, procName);
00120 #endif
00121 }
00122 
00123 bool    
00124 os_FreeLibrary(hModule libHandle)
00125 {
00126 #ifdef STB_IS_WINDOWS
00127     if(FreeLibrary(libHandle))//if else to avoid warning C4800:forcing value to bool 'true' or 'false' 
00128         return true;
00129     else 
00130         return false;
00131 #else
00132     dlclose(libHandle);
00133     return true;
00134 #endif
00135 }
00136 
00137 
00138 bool
00139 os_correctModuleName(stb::string& fileName, bool nMakeDebug, bool nMakeES)
00140 {
00141 
00142         // only WinXP uses '_es' to mark OpenGL ES version...
00143         //
00144 #if defined(_IS_KLIMTES_) && defined(STB_IS_WINXP)
00145         if(nMakeES)
00146                 fileName += "_es";
00147 #endif
00148 
00149         // Windows debug DLLs are post-fixed with a 'd'
00150         //
00151 #if defined(STB_IS_WINDOWS) && defined(STB_IS_DEBUG)
00152         if(nMakeDebug)
00153                 fileName += "d";
00154 #endif
00155 
00156         return true;
00157 }
00158 
00159 
00160 END_NAMESPACE_STB
00161 
00162 
00163 /* ========================================================================
00164  * End of file
00165  * ========================================================================
00166  * Local Variables:
00167  * mode: c++
00168  * c-basic-offset: 4
00169  * eval: (c-set-offset 'substatement-open 0)
00170  * eval: (c-set-offset 'case-label '+)
00171  * eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00172  * eval: (setq indent-tabs-mode nil)
00173  * End:
00174  * ========================================================================
00175  */
00176 
 This page was generated at Wed Oct 27 13:00:09 2010 for Studierstube 4 by Doxygen.
 If you have any comments, please send a message to schmalstieg#icg.tu-graz.ac.at.
www.studierstube.org