PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SystemImpl.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_SYSTEM_IMPL_H__ 00024 #define __PLCORE_SYSTEM_IMPL_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Tools/Time.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Forward declarations ] 00042 //[-------------------------------------------------------] 00043 class Thread; 00044 class Console; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * Abstract base class for platform specific 'System' implementations 00053 * 00054 * @note 00055 * - Implementation of the bridge design pattern, this class is the implementor of the 'System' abstraction 00056 */ 00057 class SystemImpl { 00058 00059 00060 //[-------------------------------------------------------] 00061 //[ Friends ] 00062 //[-------------------------------------------------------] 00063 friend class System; 00064 00065 00066 //[-------------------------------------------------------] 00067 //[ Protected functions ] 00068 //[-------------------------------------------------------] 00069 protected: 00070 /** 00071 * @brief 00072 * Constructor 00073 */ 00074 SystemImpl(); 00075 00076 /** 00077 * @brief 00078 * Destructor 00079 */ 00080 virtual ~SystemImpl(); 00081 00082 00083 //[-------------------------------------------------------] 00084 //[ Protected virtual SystemImpl functions ] 00085 //[-------------------------------------------------------] 00086 protected: 00087 /** 00088 * @brief 00089 * Returns the name of the platform 00090 * 00091 * @return 00092 * Platform string (for instance 'Windows' for Windows, 'Linux' for Linux and so on) 00093 */ 00094 virtual String GetPlatform() const = 0; 00095 00096 /** 00097 * @brief 00098 * Returns the name and version of the operating system 00099 * 00100 * @return 00101 * OS information string (for instance 'Windows 7 Service Pack 1 (Build 7601)') 00102 */ 00103 virtual String GetOS() const = 0; 00104 00105 /** 00106 * @brief 00107 * Returns the directory separator used by the operation system 00108 * 00109 * @return 00110 * The directory separator used by the operation system (e.g. '/' on Linux, '\' on Windows) 00111 */ 00112 virtual char GetSeparator() const = 0; 00113 00114 /** 00115 * @brief 00116 * Returns the shared library filename prefix used by the operation system 00117 * 00118 * @return 00119 * The shared library filename prefix used by the operation system (e.g. 'lib' as in 'libPLCore.so' on Linux, no prefix as in 'PLCore.dll' on Windows) 00120 */ 00121 virtual String GetSharedLibraryPrefix() const = 0; 00122 00123 /** 00124 * @brief 00125 * Returns the shared library file extension used by the operation system 00126 * 00127 * @return 00128 * The shared library file extension used by the operation system (e.g. 'so' on Linux, 'dll' on Windows) 00129 */ 00130 virtual String GetSharedLibraryExtension() const = 0; 00131 00132 /** 00133 * @brief 00134 * Get the CPU MHz 00135 * 00136 * @return 00137 * CPU MHz 00138 */ 00139 virtual uint32 GetCPUMhz() const = 0; 00140 00141 /** 00142 * @brief 00143 * Returns the name of the computer 00144 * 00145 * @return 00146 * Computer name 00147 */ 00148 virtual String GetComputerName() const = 0; 00149 00150 /** 00151 * @brief 00152 * Returns the current user name 00153 * 00154 * @return 00155 * User name 00156 */ 00157 virtual String GetUserName() const = 0; 00158 00159 /** 00160 * @brief 00161 * Get home directory of the current user 00162 * 00163 * @return 00164 * The home directory of the current user (native path style) 00165 */ 00166 virtual String GetUserHomeDir() const = 0; 00167 00168 /** 00169 * @brief 00170 * Get data directory of the current user 00171 * 00172 * @return 00173 * The data directory of the current user (native path style) 00174 */ 00175 virtual String GetUserDataDir() const = 0; 00176 00177 /** 00178 * @brief 00179 * Get name of data directory for given application name 00180 * 00181 * @param[in] sName 00182 * Application name 00183 * 00184 * @return 00185 * Name of data directory in native style of used OS 00186 */ 00187 virtual String GetDataDirName(const String &sName) const = 0; 00188 00189 /** 00190 * @brief 00191 * Get absolute path of application executable 00192 * 00193 * @return 00194 * Path to executable (native path style, e.g. on Windows: 'C:\MyApplication\Test.exe') 00195 */ 00196 virtual String GetExecutableFilename() const = 0; 00197 00198 /** 00199 * @brief 00200 * Returns the absolute filename of the shared library or executable a given memory address is located in 00201 * 00202 * @param[in] pMemoryAddress 00203 * Memory address ("memory anchor") inside the shared library or executable from which the absolute filename 00204 * should be returned from, can be a null pointer in which case the result will be an empty string 00205 * 00206 * @return 00207 * Absolute filename of the shared library or executable the given memory address is located in (native path style), 00208 * or an empty string in case it was impossible to determine the filename 00209 * 00210 * @note 00211 * - Result example on Windows: 'C:\MyApplication\PLCore.dll' or 'C:\MyApplication\Test.exe' 00212 */ 00213 virtual String GetModuleFilenameByMemoryAddress(const void *pMemoryAddress) const = 0; 00214 00215 /** 00216 * @brief 00217 * Reads an environment variable 00218 * 00219 * @param[in] sName 00220 * Name of the environment variable to read 00221 * 00222 * @return 00223 * Content of the variable 00224 */ 00225 virtual String GetEnvironmentVariable(const String &sName) const = 0; 00226 00227 /** 00228 * @brief 00229 * Writes an environment variable 00230 * 00231 * @param[in] sName 00232 * Name of the environment variable to write 00233 * @param[in] sValue 00234 * Value to write into the variable 00235 * 00236 * @return 00237 * 'true' if the variable has been set successfully, else 'false' 00238 */ 00239 virtual bool SetEnvironmentVariable(const String &sName, const String &sValue) const = 0; 00240 00241 /** 00242 * @brief 00243 * Deletes an environment variable 00244 * 00245 * @param[in] sName 00246 * Name of the environment variable to delete 00247 */ 00248 virtual void DeleteEnvironmentVariable(const String &sName) const = 0; 00249 00250 /** 00251 * @brief 00252 * Executes a system command (create a new process) 00253 * 00254 * @param[in] sCommand 00255 * Command to execute 00256 * @param[in] sParameters 00257 * Parameters to pass to the command 00258 * @param[in] sWorkingDir 00259 * Working directory in which to execute the command 00260 * 00261 * @return 00262 * 'true' if the command has been executed successfully, else 'false' 00263 */ 00264 virtual bool Execute(const String &sCommand, const String &sParameters, const String &sWorkingDir) const = 0; 00265 00266 /** 00267 * @brief 00268 * Returns the current program locale language information 00269 * 00270 * @return 00271 * The current program locale language information 00272 */ 00273 virtual String GetLocaleLanguage() const = 0; 00274 00275 /** 00276 * @brief 00277 * Returns the current directory 00278 * 00279 * @return 00280 * Path to the current directory as the OS provided it (native path style) 00281 * 00282 * @note 00283 * - On Windows for example "C:\Programs\App" 00284 */ 00285 virtual String GetCurrentDir() const = 0; 00286 00287 /** 00288 * @brief 00289 * Sets the current directory 00290 * 00291 * @param[in] sPath 00292 * Path to the current directory 00293 * 00294 * @return 00295 * 'true', if all went fine, else 'false' 00296 */ 00297 virtual bool SetCurrentDir(const String &sPath) = 0; 00298 00299 /** 00300 * @brief 00301 * Returns a pointer to the current thread 00302 * 00303 * @return 00304 * Current thread, a null pointer on main thread or error 00305 */ 00306 virtual Thread *GetCurrentThread() const = 0; 00307 00308 /** 00309 * @brief 00310 * Exit the application immediately 00311 * 00312 * @param[in] nReturn 00313 * Return value 00314 */ 00315 virtual void Exit(int nReturn) = 0; 00316 00317 /** 00318 * @brief 00319 * Returns the console instance 00320 * 00321 * @return 00322 * The console instance 00323 */ 00324 virtual const Console &GetConsole() const = 0; 00325 00326 /** 00327 * @brief 00328 * Primitive way (e.g. by using a message box) to be able to tell the user that something went terrible wrong 00329 * 00330 * @param[in] sMessage 00331 * Message to show 00332 * 00333 * @remarks 00334 * Do not misuse this method in order to communicate with the user on a regular basis. This method does only 00335 * exist to be able to tell the user that something went terrible wrong. There are situations were one can't 00336 * use a log file, command line or something like this. Even when using e.g. a log file to write out error 00337 * information - an application may e.g. just close directly after it's start without any further information 00338 * and the user may even think that the application didn't start in the first place for an unknown reason. 00339 * In such a situation, it's polite to inform the user that something went terrible wrong and providing 00340 * a short hint how the issue may be solved. This method wasn't named "MessageBox()" by intend - because 00341 * such a feature may not be available on the used platform or is handled in another way as a normal MS Windows 00342 * message box. 00343 */ 00344 virtual void UrgentMessage(const String &sMessage) const = 0; 00345 00346 //[-------------------------------------------------------] 00347 //[ Time functions ] 00348 //[-------------------------------------------------------] 00349 /** 00350 * @brief 00351 * Returns the current date and time 00352 * 00353 * @return 00354 * Date and time string 00355 */ 00356 virtual Time GetTime() const = 0; 00357 00358 /** 00359 * @brief 00360 * Returns the number of milliseconds since the system was started 00361 * 00362 * @return 00363 * Number of milliseconds elapsed since the system was started 00364 */ 00365 virtual uint64 GetMilliseconds() const = 0; 00366 00367 /** 00368 * @brief 00369 * Retrieves the number of microseconds since the system was started 00370 * 00371 * @return 00372 * Number of microseconds elapsed since the system was started 00373 */ 00374 virtual uint64 GetMicroseconds() const = 0; 00375 00376 /** 00377 * @brief 00378 * Suspend the current thread for a specified time period 00379 * 00380 * @param[in] nMilliseconds 00381 * Number of milliseconds to sleep 00382 */ 00383 virtual void Sleep(uint64 nMilliseconds) const = 0; 00384 00385 /** 00386 * @brief 00387 * Yields the rest of the current threads time slice 00388 */ 00389 virtual void Yield() const = 0; 00390 00391 //[-------------------------------------------------------] 00392 //[ Memory functions ] 00393 //[-------------------------------------------------------] 00394 /** 00395 * @brief 00396 * Returns an approximation of the percentage of used physical memory (0.0-100.0) 00397 * 00398 * @return 00399 * An approximation of the percentage of used physical memory 00400 */ 00401 virtual float GetPercentageOfUsedPhysicalMemory() const = 0; 00402 00403 /** 00404 * @brief 00405 * Returns the total physical memory in bytes 00406 * 00407 * @return 00408 * The total physical memory in bytes 00409 */ 00410 virtual uint64 GetTotalPhysicalMemory() const = 0; 00411 00412 /** 00413 * @brief 00414 * Returns the current free physical memory in bytes 00415 * 00416 * @return 00417 * The current free physical memory in bytes 00418 */ 00419 virtual uint64 GetFreePhysicalMemory() const = 0; 00420 00421 /** 00422 * @brief 00423 * Returns the total virtual memory in bytes 00424 * 00425 * @return 00426 * The total virtual memory in bytes 00427 */ 00428 virtual uint64 GetTotalVirtualMemory() const = 0; 00429 00430 /** 00431 * @brief 00432 * Returns the current free virtual memory in bytes 00433 * 00434 * @return 00435 * The current free virtual memory in bytes 00436 */ 00437 virtual uint64 GetFreeVirtualMemory() const = 0; 00438 00439 00440 }; 00441 00442 00443 //[-------------------------------------------------------] 00444 //[ Namespace ] 00445 //[-------------------------------------------------------] 00446 } // PLCore 00447 00448 00449 #endif // __PLCORE_SYSTEM_IMPL_H__
|