Changeset 6040 for sandbox_light/src/libraries/core
- Timestamp:
- Nov 5, 2009, 10:15:05 PM (15 years ago)
- Location:
- sandbox_light
- Files:
-
- 4 deleted
- 6 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
sandbox_light
- Property svn:mergeinfo changed
-
sandbox_light/src/libraries/core/CMakeLists.txt
r5789 r6040 19 19 20 20 SET_SOURCE_FILES(CORE_SRC_FILES 21 Clock.cc 22 CommandLine.cc 21 CommandLineParser.cc 23 22 Core.cc 24 23 LuaState.cc 24 PathConfig.cc 25 25 ) 26 26 -
sandbox_light/src/libraries/core/Core.cc
r5789 r6040 37 37 38 38 #include <cassert> 39 #include <fstream> 40 #include <cstdlib> 41 #include <cstdio> 42 #include <boost/version.hpp> 43 #include <boost/filesystem.hpp> 39 #include <ctime> 40 #include <vector> 44 41 45 42 #ifdef ORXONOX_PLATFORM_WINDOWS … … 50 47 # undef min 51 48 # undef max 52 #elif defined(ORXONOX_PLATFORM_APPLE) 53 # include <sys/param.h> 54 # include <mach-o/dyld.h> 55 #else /* Linux */ 56 # include <sys/types.h> 57 # include <unistd.h> 58 #endif 59 60 #include "SpecialConfig.h" 49 #endif 50 51 #include "util/Clock.h" 61 52 #include "util/Debug.h" 62 53 #include "util/Exception.h" 63 54 #include "util/SignalHandler.h" 64 #include " Clock.h"65 #include "CommandLine .h"55 #include "PathConfig.h" 56 #include "CommandLineParser.h" 66 57 #include "LuaState.h" 67 68 // Boost 1.36 has some issues with deprecated functions that have been omitted69 #if (BOOST_VERSION == 103600)70 # define BOOST_LEAF_FUNCTION filename71 #else72 # define BOOST_LEAF_FUNCTION leaf73 #endif74 58 75 59 namespace orxonox … … 78 62 Core* Core::singletonPtr_s = 0; 79 63 80 SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");81 64 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); 82 65 #ifdef ORXONOX_PLATFORM_WINDOWS … … 151 134 int softDebugLevelShell_; //!< The debug level for the ingame shell 152 135 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 153 154 //! Path to the parent directory of the ones above if program was installed with relativ pahts155 boost::filesystem::path rootPath_;156 boost::filesystem::path executablePath_; //!< Path to the executable157 boost::filesystem::path dataPath_; //!< Path to the data file folder158 boost::filesystem::path configPath_; //!< Path to the config file folder159 boost::filesystem::path logPath_; //!< Path to the log file folder160 136 }; 161 137 … … 164 140 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) 165 141 : configuration_(new CoreConfiguration()) // Don't yet create config values! 166 , bDevRun_(false)167 142 { 168 143 // Set the hard coded fixed paths 169 this-> setFixedPaths();144 this->pathConfig_.reset(new PathConfig()); 170 145 171 146 // Parse command line arguments AFTER the modules have been loaded (static code!) 172 CommandLine ::parseCommandLine(cmdLine);147 CommandLineParser::parseCommandLine(cmdLine); 173 148 174 149 // Set configurable paths like log, config and media 175 this-> setConfigurablePaths();150 this->pathConfig_->setConfigurablePaths(); 176 151 177 152 // create a signal handler (only active for linux) 178 153 // This call is placed as soon as possible, but after the directories are set 179 154 this->signalHandler_.reset(new SignalHandler()); 180 this->signalHandler_->doCatch( configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log");155 this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log"); 181 156 182 157 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 183 OutputHandler::getOutStream().setLogPath( Core::getLogPathString());158 OutputHandler::getOutStream().setLogPath(PathConfig::getLogPathString()); 184 159 185 160 // Parse additional options file now that we know its path 186 CommandLine ::parseFile();161 CommandLineParser::parseFile(); 187 162 188 163 #ifdef ORXONOX_PLATFORM_WINDOWS … … 190 165 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through 191 166 // the timer though). 192 int limitToCPU = CommandLine ::getValue("limitToCPU");167 int limitToCPU = CommandLineParser::getValue("limitToCPU"); 193 168 if (limitToCPU > 0) 194 169 setThreadAffinity(static_cast<unsigned int>(limitToCPU)); … … 250 225 } 251 226 252 /*static*/ const boost::filesystem::path& Core::getDataPath()253 {254 return getInstance().configuration_->dataPath_;255 }256 /*static*/ std::string Core::getDataPathString()257 {258 return getInstance().configuration_->dataPath_.string() + '/';259 }260 261 /*static*/ const boost::filesystem::path& Core::getConfigPath()262 {263 return getInstance().configuration_->configPath_;264 }265 /*static*/ std::string Core::getConfigPathString()266 {267 return getInstance().configuration_->configPath_.string() + '/';268 }269 270 /*static*/ const boost::filesystem::path& Core::getLogPath()271 {272 return getInstance().configuration_->logPath_;273 }274 /*static*/ std::string Core::getLogPathString()275 {276 return getInstance().configuration_->logPath_.string() + '/';277 }278 279 /*static*/ const boost::filesystem::path& Core::getRootPath()280 {281 return getInstance().configuration_->rootPath_;282 }283 /*static*/ std::string Core::getRootPathString()284 {285 return getInstance().configuration_->rootPath_.string() + '/';286 }287 288 227 /** 289 228 @note … … 331 270 #endif 332 271 } 333 334 /**335 @brief336 Retrievs the executable path and sets all hard coded fixed path (currently only the module path)337 Also checks for "orxonox_dev_build.keep_me" in the executable diretory.338 If found it means that this is not an installed run, hence we339 don't write the logs and config files to ~/.orxonox340 @throw341 GeneralException342 */343 void Core::setFixedPaths()344 {345 //////////////////////////346 // FIND EXECUTABLE PATH //347 //////////////////////////348 349 #ifdef ORXONOX_PLATFORM_WINDOWS350 // get executable module351 TCHAR buffer[1024];352 if (GetModuleFileName(NULL, buffer, 1024) == 0)353 ThrowException(General, "Could not retrieve executable path.");354 355 #elif defined(ORXONOX_PLATFORM_APPLE)356 char buffer[1024];357 unsigned long path_len = 1023;358 if (_NSGetExecutablePath(buffer, &path_len))359 ThrowException(General, "Could not retrieve executable path.");360 361 #else /* Linux */362 /* written by Nicolai Haehnle <prefect_@gmx.net> */363 364 /* Get our PID and build the name of the link in /proc */365 char linkname[64]; /* /proc/<pid>/exe */366 if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)367 {368 /* This should only happen on large word systems. I'm not sure369 what the proper response is here.370 Since it really is an assert-like condition, aborting the371 program seems to be in order. */372 assert(false);373 }374 375 /* Now read the symbolic link */376 char buffer[1024];377 int ret;378 ret = readlink(linkname, buffer, 1024);379 /* In case of an error, leave the handling up to the caller */380 if (ret == -1)381 ThrowException(General, "Could not retrieve executable path.");382 383 /* Ensure proper NUL termination */384 buffer[ret] = 0;385 #endif386 387 configuration_->executablePath_ = boost::filesystem::path(buffer);388 #ifndef ORXONOX_PLATFORM_APPLE389 configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name390 #endif391 392 /////////////////////393 // SET MODULE PATH //394 /////////////////////395 396 if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me"))397 {398 COUT(1) << "Running from the build tree." << std::endl;399 Core::bDevRun_ = true;400 }401 else402 {403 404 #ifdef INSTALL_COPYABLE // --> relative paths405 406 // Also set the root path407 boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath);408 configuration_->rootPath_ = configuration_->executablePath_;409 while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_)410 && !configuration_->rootPath_.empty())411 configuration_->rootPath_ = configuration_->rootPath_.branch_path();412 if (configuration_->rootPath_.empty())413 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");414 415 #endif416 }417 }418 419 /**420 @brief421 Sets config, log and media path and creates folders if necessary.422 @throws423 GeneralException424 */425 void Core::setConfigurablePaths()426 {427 if (Core::isDevelopmentRun())428 {429 configuration_->dataPath_ = specialConfig::dataDevDirectory;430 configuration_->configPath_ = specialConfig::configDevDirectory;431 configuration_->logPath_ = specialConfig::logDevDirectory;432 }433 else434 {435 436 #ifdef INSTALL_COPYABLE // --> relative paths437 438 // Using paths relative to the install prefix, complete them439 configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath;440 configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;441 configuration_->logPath_ = configuration_->rootPath_ / specialConfig::defaultLogPath;442 443 #else444 445 configuration_->dataPath_ = specialConfig::dataInstallDirectory;446 447 // Get user directory448 # ifdef ORXONOX_PLATFORM_UNIX /* Apple? */449 char* userDataPathPtr(getenv("HOME"));450 # else451 char* userDataPathPtr(getenv("APPDATA"));452 # endif453 if (userDataPathPtr == NULL)454 ThrowException(General, "Could not retrieve user data path.");455 boost::filesystem::path userDataPath(userDataPathPtr);456 userDataPath /= ".orxonox";457 458 configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath;459 configuration_->logPath_ = userDataPath / specialConfig::defaultLogPath;460 461 #endif462 463 }464 465 // Option to put all the config and log files in a separate folder466 if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue())467 {468 std::string directory(CommandLine::getValue("writingPathSuffix").getString());469 configuration_->configPath_ = configuration_->configPath_ / directory;470 configuration_->logPath_ = configuration_->logPath_ / directory;471 }472 473 // Create directories to avoid problems when opening files in non existent folders.474 std::vector<std::pair<boost::filesystem::path, std::string> > directories;475 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config"));476 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->logPath_), "log"));477 478 for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();479 it != directories.end(); ++it)480 {481 if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first))482 {483 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \484 Please remove " + it->first.string());485 }486 if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?)487 {488 COUT(4) << "Created " << it->second << " directory" << std::endl;489 }490 }491 }492 272 } -
sandbox_light/src/libraries/core/Core.h
r5789 r6040 28 28 */ 29 29 30 /**31 @file32 @brief33 Declaration of the Core class.34 @details35 The Core class is a singleton, only used to configure some variables36 in the core through the config-file.37 */38 39 30 #ifndef _Core_H__ 40 31 #define _Core_H__ … … 55 46 @brief 56 47 The Core class is a singleton used to configure the program basics. 57 @details58 The class provides information about the data, config and log path.59 It determines those by the use of platform specific functions.60 48 @remark 61 49 You should only create this singleton once because it destroys the identifiers! … … 82 70 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 83 71 84 //! Returns the path to the data files as boost::filesystem::path85 static const boost::filesystem::path& getDataPath();86 //! Returns the path to the config files as boost::filesystem::path87 static const boost::filesystem::path& getConfigPath();88 //! Returns the path to the log files as boost::filesystem::path89 static const boost::filesystem::path& getLogPath();90 //! Returns the path to the root folder as boost::filesystem::path91 static const boost::filesystem::path& getRootPath();92 //! Returns the path to the data files as std::string93 static std::string getDataPathString();94 //! Returns the path to the config files as std::string95 static std::string getConfigPathString();96 //! Returns the path to the log files as std::string97 static std::string getLogPathString();98 //! Returns the path to the root folder as std::string99 static std::string getRootPathString();100 101 static bool isDevelopmentRun() { return getInstance().bDevRun_; }102 103 72 private: 104 73 Core(const Core&); //!< Don't use (undefined symbol) 105 74 106 void setFixedPaths();107 void setConfigurablePaths();108 75 void setThreadAffinity(int limitToCPU); 109 76 110 77 // Mind the order for the destruction! 78 scoped_ptr<PathConfig> pathConfig_; 111 79 scoped_ptr<SignalHandler> signalHandler_; 112 80 scoped_ptr<CoreConfiguration> configuration_; 113 114 bool bDevRun_; //!< True for runs in the build directory (not installed)115 81 116 82 static Core* singletonPtr_s; -
sandbox_light/src/libraries/core/CorePrereqs.h
r5738 r6040 28 28 29 29 /** 30 @file 31 @brief Contains all the necessary forward declarations for all classes and structs. 30 @file 31 @brief 32 Shared library macros, enums, constants and forward declarations for the core library 32 33 */ 33 34 … … 40 41 // Shared library settings 41 42 //----------------------------------------------------------------------- 43 42 44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD ) 43 45 # ifdef CORE_SHARED_BUILD … … 56 58 #endif 57 59 58 59 //----------------------------------------------------------------------- 60 // Forward declarations 61 //----------------------------------------------------------------------- 60 //----------------------------------------------------------------------- 61 // Constants 62 //----------------------------------------------------------------------- 63 64 namespace orxonox 65 { 66 static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1); 67 } 68 69 //----------------------------------------------------------------------- 70 // Enums 71 //----------------------------------------------------------------------- 72 62 73 namespace orxonox 63 74 { … … 66 77 enum Mode 67 78 { 79 NOP, 68 80 LoadObject, 69 81 SaveObject, 70 82 ExpandObject 71 83 }; 72 84 } 73 85 74 86 namespace KeybindMode … … 82 94 }; 83 95 }; 84 96 } 97 98 //----------------------------------------------------------------------- 99 // Forward declarations 100 //----------------------------------------------------------------------- 101 102 namespace orxonox 103 { 85 104 typedef std::string LanguageEntryLabel; 86 105 87 106 class ArgumentCompleter; 88 107 class ArgumentCompletionListElement; 89 class BaseFactory;90 class BaseMetaObjectListElement;91 108 class BaseObject; 92 109 template <class T> … … 98 115 class ClassTreeMaskNode; 99 116 class ClassTreeMaskObjectIterator; 100 class Clock;101 117 class CommandEvaluation; 102 class CommandExecutor; 103 class CommandLine; 118 class CommandLineParser; 104 119 class CommandLineArgument; 105 120 class ConfigFile; … … 109 124 class ConfigFileManager; 110 125 class ConfigFileSection; 126 struct ConfigFileType; 111 127 class ConfigValueContainer; 112 128 class ConsoleCommand; … … 115 131 class DynLibManager; 116 132 struct Event; 117 class Event Container;133 class EventState; 118 134 class Executor; 119 135 template <class T> … … 125 141 class FunctorMember; 126 142 class FunctorStatic; 143 class Game; 144 class GameState; 145 struct GameStateInfo; 146 struct GameStateTreeNode; 127 147 class GraphicsManager; 128 148 class GUIManager; … … 131 151 template <class T> 132 152 class Iterator; 133 class IteratorBase;134 153 class Language; 135 class LanguageEntry;136 class Loader;137 154 class LuaState; 138 155 class MemoryArchive; … … 152 169 class OgreWindowEventListener; 153 170 class OrxonoxClass; 171 class PathConfig; 154 172 struct ResourceInfo; 155 173 class Shell; 156 174 class ShellListener; 157 175 template <class T> 176 class SmartPtr; 177 template <class T> 158 178 class SubclassIdentifier; 159 179 class TclBind; … … 163 183 class TclThreadManager; 164 184 class Template; 185 class Thread; 186 class ThreadPool; 187 template <class T> 188 class WeakPtr; 165 189 class WindowEventListener; 166 190 class XMLFile; … … 173 197 class XMLPortParamContainer; 174 198 175 // game states 176 class Game; 177 class GameState; 178 struct GameStateInfo; 179 struct GameStateTreeNode; 180 181 // input 199 // Input 182 200 class BaseCommand; 183 201 class BufferedParamCommand; 184 202 class Button; 185 class CalibratorCallback;186 203 class HalfAxis; 187 204 class InputBuffer; … … 192 209 class InputManager; 193 210 class InputState; 211 struct InputStatePriority; 212 class JoyStickQuantityListener; 194 213 class JoyStick; 214 class KeyBinder; 215 class KeyBinderManager; 216 class Keyboard; 217 class KeyDetector; 218 class KeyEvent; 195 219 class Mouse; 196 class Keyboard;197 class KeyBinder;198 class KeyDetector;199 220 class ParamCommand; 200 221 class SimpleCommand; 201 202 203 // multithreading204 class Thread;205 class ThreadPool;206 222 } 207 223 … … 282 298 namespace orxonox 283 299 { 284 using ticpp::Document;285 300 using ticpp::Element; 286 using ticpp::Declaration; 287 using ticpp::StylesheetReference; 288 using ticpp::Text; 289 using ticpp::Comment; 290 using ticpp::Attribute; 291 } 292 301 } 293 302 294 303 #endif /* _CorePrereqs_H__ */ -
sandbox_light/src/libraries/core/LuaState.cc
r5782 r6040 38 38 39 39 #include "util/Debug.h" 40 #include " Core.h"40 #include "PathConfig.h" 41 41 #include "ToluaBindCore.h" 42 42 … … 106 106 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename) 107 107 { 108 boost::filesystem::path filepath = Core::getDataPath() / "lua" / filename;108 boost::filesystem::path filepath = PathConfig::getDataPath() / "lua" / filename; 109 109 if (boost::filesystem::exists(filepath)) 110 110 { -
sandbox_light/src/libraries/core/PathConfig.cc
r6039 r6040 75 75 : rootPath_(*(new bf::path())) 76 76 , executablePath_(*(new bf::path())) 77 , modulePath_(*(new bf::path()))78 77 , dataPath_(*(new bf::path())) 79 78 , configPath_(*(new bf::path())) … … 136 135 COUT(1) << "Running from the build tree." << std::endl; 137 136 PathConfig::bDevRun_ = true; 138 modulePath_ = specialConfig::moduleDevDirectory;139 137 } 140 138 else … … 151 149 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?"); 152 150 153 // Module path is fixed as well154 modulePath_ = rootPath_ / specialConfig::defaultModulePath;155 156 151 #else 157 152 158 153 // There is no root path, so don't set it at all 159 // Module path is fixed as well160 modulePath_ = specialConfig::moduleInstallDirectory;161 154 162 155 #endif … … 168 161 delete &rootPath_; 169 162 delete &executablePath_; 170 delete &modulePath_;171 163 delete &dataPath_; 172 164 delete &configPath_; … … 242 234 } 243 235 244 std::vector<std::string> PathConfig::getModulePaths()245 {246 std::vector<std::string> modulePaths;247 248 // We search for helper files with the following extension249 std::string moduleextension = specialConfig::moduleExtension;250 size_t moduleextensionlength = moduleextension.size();251 252 // Add that path to the PATH variable in case a module depends on another one253 std::string pathVariable = getenv("PATH");254 putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + modulePath_.string()).c_str()));255 256 // Make sure the path exists, otherwise don't load modules257 if (!boost::filesystem::exists(modulePath_))258 return modulePaths;259 260 boost::filesystem::directory_iterator file(modulePath_);261 boost::filesystem::directory_iterator end;262 263 // Iterate through all files264 while (file != end)265 {266 std::string filename = file->BOOST_LEAF_FUNCTION();267 268 // Check if the file ends with the exension in question269 if (filename.size() > moduleextensionlength)270 {271 if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)272 {273 // We've found a helper file274 std::string library = filename.substr(0, filename.size() - moduleextensionlength);275 modulePaths.push_back((modulePath_ / library).file_string());276 }277 }278 ++file;279 }280 281 return modulePaths;282 }283 284 236 /*static*/ std::string PathConfig::getRootPathString() 285 237 { … … 306 258 return getInstance().logPath_.string() + '/'; 307 259 } 308 309 /*static*/ std::string PathConfig::getModulePathString()310 {311 return getInstance().modulePath_.string() + '/';312 }313 260 } -
sandbox_light/src/libraries/core/PathConfig.h
r6039 r6040 42 42 The PathConfig class is a singleton used to configure different paths. 43 43 @details 44 The class provides information about the data, config, log, executable ,45 root and modulepath.44 The class provides information about the data, config, log, executable 45 and root path. 46 46 It determines those by the use of platform specific functions. 47 47 @remarks … … 83 83 static const boost::filesystem::path& getLogPath() 84 84 { return getInstance().logPath_; } 85 //! Returns the path to the modules as boost::filesystem::path86 static const boost::filesystem::path& getModulePath()87 { return getInstance().modulePath_; }88 85 89 86 //! Returns the path to the root folder as std::string … … 97 94 //! Returns the path to the log files as std::string 98 95 static std::string getLogPathString(); 99 //! Returns the path to the modules as std::string100 static std::string getModulePathString();101 96 102 97 //! Return trrue for runs in the build directory (not installed) … … 113 108 */ 114 109 void setConfigurablePaths(); 115 //! Returns a list with all modules declared by a *.module file in the module folder.116 std::vector<std::string> getModulePaths();117 110 118 111 //! Path to the parent directory of the ones above if program was installed with relativ paths 119 112 boost::filesystem::path& rootPath_; 120 113 boost::filesystem::path& executablePath_; //!< Path to the executable 121 boost::filesystem::path& modulePath_; //!< Path to the modules122 114 boost::filesystem::path& dataPath_; //!< Path to the data files folder 123 115 boost::filesystem::path& configPath_; //!< Path to the config files folder
Note: See TracChangeset
for help on using the changeset viewer.