PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SystemImpl.h * 00003 * 00004 * Copyright (C) 2002-2011 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 * Reads an environment variable 00201 * 00202 * @param[in] sName 00203 * Name of the environment variable to read 00204 * 00205 * @return 00206 * Content of the variable 00207 */ 00208 virtual String GetEnvironmentVariable(const String &sName) const = 0; 00209 00210 /** 00211 * @brief 00212 * Writes an environment variable 00213 * 00214 * @param[in] sName 00215 * Name of the environment variable to write 00216 * @param[in] sValue 00217 * Value to write into the variable 00218 * 00219 * @return 00220 * 'true' if the variable has been set successfully, else 'false' 00221 */ 00222 virtual bool SetEnvironmentVariable(const String &sName, const String &sValue) const = 0; 00223 00224 /** 00225 * @brief 00226 * Deletes an environment variable 00227 * 00228 * @param[in] sName 00229 * Name of the environment variable to delete 00230 */ 00231 virtual void DeleteEnvironmentVariable(const String &sName) const = 0; 00232 00233 /** 00234 * @brief 00235 * Executes a system command (create a new process) 00236 * 00237 * @param[in] sCommand 00238 * Command to execute 00239 * @param[in] sParameters 00240 * Parameters to pass to the command 00241 * @param[in] sWorkingDir 00242 * Working directory in which to execute the command 00243 * 00244 * @return 00245 * 'true' if the command has been executed successfully, else 'false' 00246 */ 00247 virtual bool Execute(const String &sCommand, const String &sParameters, const String &sWorkingDir) const = 0; 00248 00249 /** 00250 * @brief 00251 * Returns the current program locale language information 00252 * 00253 * @return 00254 * The current program locale language information 00255 */ 00256 virtual String GetLocaleLanguage() const = 0; 00257 00258 /** 00259 * @brief 00260 * Returns the current directory 00261 * 00262 * @return 00263 * Path to the current directory as the OS provided it (native path style) 00264 * 00265 * @note 00266 * - On Windows for example "C:\Programs\App" 00267 */ 00268 virtual String GetCurrentDir() const = 0; 00269 00270 /** 00271 * @brief 00272 * Sets the current directory 00273 * 00274 * @param[in] sPath 00275 * Path to the current directory 00276 * 00277 * @return 00278 * 'true', if all went fine, else 'false' 00279 */ 00280 virtual bool SetCurrentDir(const String &sPath) = 0; 00281 00282 /** 00283 * @brief 00284 * Returns a pointer to the current thread 00285 * 00286 * @return 00287 * Current thread, a null pointer on main thread or error 00288 */ 00289 virtual Thread *GetCurrentThread() const = 0; 00290 00291 /** 00292 * @brief 00293 * Exit the application immediately 00294 * 00295 * @param[in] nReturn 00296 * Return value 00297 */ 00298 virtual void Exit(int nReturn) = 0; 00299 00300 /** 00301 * @brief 00302 * Returns the console instance 00303 * 00304 * @return 00305 * The console instance 00306 */ 00307 virtual const Console &GetConsole() const = 0; 00308 00309 /** 00310 * @brief 00311 * Primitive way (e.g. by using a message box) to be able to tell the user that something went terrible wrong 00312 * 00313 * @param[in] sMessage 00314 * Message to show 00315 * 00316 * @remarks 00317 * Do not misuse this method in order to communicate with the user on a regular basis. This method does only 00318 * exist to be able to tell the user that something went terrible wrong. There are situations were one can't 00319 * use a log file, command line or something like this. Even when using e.g. a log file to write out error 00320 * information - an application may e.g. just close directly after it's start without any further information 00321 * and the user may even think that the application didn't start in the first place for an unknown reason. 00322 * In such a situation, it's polite to inform the user that something went terrible wrong and providing 00323 * a short hint how the issue may be solved. This method wasn't named "MessageBox()" by intend - because 00324 * such a feature may not be available on the used platform or is handled in another way as a normal MS Windows 00325 * message box. 00326 */ 00327 virtual void UrgentMessage(const String &sMessage) const = 0; 00328 00329 //[-------------------------------------------------------] 00330 //[ Time functions ] 00331 //[-------------------------------------------------------] 00332 /** 00333 * @brief 00334 * Returns the current date and time 00335 * 00336 * @return 00337 * Date and time string 00338 */ 00339 virtual Time GetTime() const = 0; 00340 00341 /** 00342 * @brief 00343 * Returns the number of milliseconds since the system was started 00344 * 00345 * @return 00346 * Number of milliseconds elapsed since the system was started 00347 */ 00348 virtual uint64 GetMilliseconds() const = 0; 00349 00350 /** 00351 * @brief 00352 * Retrieves the number of microseconds since the system was started 00353 * 00354 * @return 00355 * Number of microseconds elapsed since the system was started 00356 */ 00357 virtual uint64 GetMicroseconds() const = 0; 00358 00359 /** 00360 * @brief 00361 * Suspend the current thread for a specified time period 00362 * 00363 * @param[in] nMilliseconds 00364 * Number of milliseconds to sleep 00365 */ 00366 virtual void Sleep(uint64 nMilliseconds) const = 0; 00367 00368 /** 00369 * @brief 00370 * Yields the rest of the current threads time slice 00371 */ 00372 virtual void Yield() const = 0; 00373 00374 //[-------------------------------------------------------] 00375 //[ Memory functions ] 00376 //[-------------------------------------------------------] 00377 /** 00378 * @brief 00379 * Returns an approximation of the percentage of used physical memory (0.0-100.0) 00380 * 00381 * @return 00382 * An approximation of the percentage of used physical memory 00383 */ 00384 virtual float GetPercentageOfUsedPhysicalMemory() const = 0; 00385 00386 /** 00387 * @brief 00388 * Returns the total physical memory in bytes 00389 * 00390 * @return 00391 * The total physical memory in bytes 00392 */ 00393 virtual uint64 GetTotalPhysicalMemory() const = 0; 00394 00395 /** 00396 * @brief 00397 * Returns the current free physical memory in bytes 00398 * 00399 * @return 00400 * The current free physical memory in bytes 00401 */ 00402 virtual uint64 GetFreePhysicalMemory() const = 0; 00403 00404 /** 00405 * @brief 00406 * Returns the total virtual memory in bytes 00407 * 00408 * @return 00409 * The total virtual memory in bytes 00410 */ 00411 virtual uint64 GetTotalVirtualMemory() const = 0; 00412 00413 /** 00414 * @brief 00415 * Returns the current free virtual memory in bytes 00416 * 00417 * @return 00418 * The current free virtual memory in bytes 00419 */ 00420 virtual uint64 GetFreeVirtualMemory() const = 0; 00421 00422 00423 }; 00424 00425 00426 //[-------------------------------------------------------] 00427 //[ Namespace ] 00428 //[-------------------------------------------------------] 00429 } // PLCore 00430 00431 00432 #endif // __PLCORE_SYSTEM_IMPL_H__
|