lib/client/global.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "global.h"
00019 #include "nodeFactory.h"
00020 #include "pluginRegistry.h"
00021
00022 #include <eq/base/fileSearch.h>
00023 #include <eq/net/global.h>
00024
00025 #include <algorithm>
00026
00027 #ifdef WIN32_API
00028 # include <direct.h>
00029 # define getcwd _getcwd
00030 # ifndef MAXPATHLEN
00031 # define MAXPATHLEN 1024
00032 # endif
00033 #endif
00034
00035
00036 namespace eq
00037 {
00038 NodeFactory* Global::_nodeFactory = 0;
00039 PluginRegistry Global::_pluginRegistry;
00040 std::string Global::_server;
00041 #ifdef WIN32
00042 std::string Global::_configFile = "../examples/configs/4-window.all.eqc";
00043 #else
00044 std::string Global::_configFile = "examples/configs/4-window.all.eqc";
00045 #endif
00046 StringVector Global::_pluginDirectories = _initPluginDirectories();
00047
00048 #ifdef AGL
00049 static base::Lock _carbonLock;
00050 #endif
00051
00052
00053 void Global::setServer( const std::string& server )
00054 {
00055 _server = server;
00056 }
00057
00058 const std::string& Global::getServer()
00059 {
00060 return _server;
00061 }
00062
00063 void Global::setConfigFile( const std::string& configFile )
00064 {
00065 _configFile = configFile;
00066 }
00067
00068 const std::string& Global::getConfigFile()
00069 {
00070 return _configFile;
00071 }
00072
00073 void Global::enterCarbon()
00074 {
00075 #ifdef AGL
00076 _carbonLock.set();
00077 #endif
00078 }
00079
00080 void Global::leaveCarbon()
00081 {
00082 #ifdef AGL
00083 _carbonLock.unset();
00084 #endif
00085 }
00086
00087
00088 EQ_EXPORT const StringVector& Global::getPluginDirectories()
00089 {
00090 return _pluginDirectories;
00091 }
00092
00093 void Global::addPluginDirectory( const std::string& path )
00094 {
00095 _pluginDirectories.push_back( path );
00096 }
00097
00098 void Global::removePluginDirectory( const std::string& path )
00099 {
00100
00101 StringVector::iterator i = find(_pluginDirectories.begin(), _pluginDirectories.end(), path);
00102
00103 if( i != _pluginDirectories.end( ))
00104 _pluginDirectories.erase( i );
00105 }
00106
00107
00108 StringVector Global::_initPluginDirectories()
00109 {
00110 StringVector pluginDirectories;
00111
00112 char* env = getenv("EQ_PLUGIN_PATH") ;
00113 std::string envString( env ? env : "" );
00114
00115 if( envString.empty( ))
00116 {
00117 pluginDirectories.push_back( "/usr/local/share/Equalizer/plugins" );
00118 pluginDirectories.push_back( ".eqPlugins" );
00119
00120 char cwd[MAXPATHLEN];
00121 pluginDirectories.push_back( getcwd( cwd, MAXPATHLEN ));
00122
00123 #ifdef WIN32
00124 if( GetModuleFileName( 0, cwd, MAXPATHLEN ) > 0 )
00125 {
00126 pluginDirectories.push_back( base::getDirname( cwd ));
00127 }
00128 #endif
00129
00130 #ifdef Darwin
00131 env = getenv( "DYLD_LIBRARY_PATH" );
00132 #else
00133 env = getenv( "LD_LIBRARY_PATH" );
00134 #endif
00135 if( env )
00136 envString = env;
00137 }
00138
00139 #ifdef WIN32
00140 const char separator = ';';
00141 #else
00142 const char separator = ':';
00143 #endif
00144
00145 while( !envString.empty( ))
00146 {
00147 size_t nextPos = envString.find( separator );
00148 if ( nextPos == std::string::npos )
00149 nextPos = envString.size();
00150
00151 std::string path = envString.substr( 0, nextPos );
00152 if ( nextPos == envString.size())
00153 envString = "";
00154 else
00155 envString = envString.substr( nextPos + 1, envString.size() );
00156
00157 if( !path.empty( ))
00158 pluginDirectories.push_back( path );
00159 }
00160
00161 return pluginDirectories;
00162 }
00163
00164 PluginRegistry& Global::getPluginRegistry()
00165 {
00166 return _pluginRegistry;
00167 }
00168
00169 EQ_EXPORT std::ostream& operator << ( std::ostream& os,
00170 const IAttrValue value )
00171 {
00172 if( value > ON )
00173 os << static_cast<int>( value );
00174 else
00175 os << ( value == UNDEFINED ? "UNDEFINED" :
00176 value == OFF ? "OFF" :
00177 value == ON ? "ON" :
00178 value == AUTO ? "AUTO" :
00179 value == NICEST ? "NICEST" :
00180 value == QUAD ? "QUAD" :
00181 value == ANAGLYPH ? "ANAGLYPH" :
00182 value == VERTICAL ? "VERTICAL" :
00183 value == WINDOW ? "window" :
00184 value == PBUFFER ? "pbuffer" :
00185 value == FBO ? "FBO" :
00186 value == RGBA16F ? "RGBA16F" :
00187 value == RGBA32F ? "RGBA32F" :
00188 value == ASYNC ? "ASYNC" :
00189 value == DRAW_SYNC ? "DRAW_SYNC" :
00190 value == LOCAL_SYNC ? "LOCAL_SYNC" :
00191 "ERROR" );
00192 return os;
00193 }
00194 }