PixelLightAPI  .
Runtime.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Runtime.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_RUNTIME_H__
00024 #define __PLCORE_RUNTIME_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Tools/Version.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    PixelLight framework runtime class
00046 *
00047 *  @note
00048 *    - There can be a local and system runtime at the same time, although this is not recommended
00049 *    - On Windows 64 bit it's possible to have a 32 bit and a 64 bit PixelLight runtime version
00050 *      installed at the same time (even in the PATH environment variable, the OS will automatically pick the correct dll)
00051 */
00052 class Runtime {
00053 
00054 
00055     //[-------------------------------------------------------]
00056     //[ Definitions                                           ]
00057     //[-------------------------------------------------------]
00058     public:
00059         /**
00060         *  @brief
00061         *    Runtime installation type
00062         */
00063         enum EType {
00064             StaticInstallation, /**< The running process is using the static linked version of PLCore */
00065             LocalInstallation,  /**< The PixelLight runtime is in the same directory as the running process, making this to a local installation */
00066             SystemInstallation  /**< The PixelLight runtime is registered within the system, making this to a system installation */
00067         };
00068 
00069 
00070     //[-------------------------------------------------------]
00071     //[ Public static functions                               ]
00072     //[-------------------------------------------------------]
00073     public:
00074         //[-------------------------------------------------------]
00075         //[ Passive information                                   ]
00076         //[-------------------------------------------------------]
00077         /**
00078         *  @brief
00079         *    Get used PixelLight installation type
00080         *
00081         *  @return
00082         *    Used PixelLight installation type the running process is using
00083         */
00084         static PLCORE_API EType GetType();
00085 
00086         /**
00087         *  @brief
00088         *    Get PixelLight version
00089         *
00090         *  @return
00091         *    Version of this PixelLight installation the running process is using
00092         */
00093         static PLCORE_API Version GetVersion();
00094 
00095         /**
00096         *  @brief
00097         *    Return whether or not this is a debug version of PixelLight
00098         *
00099         *  @return
00100         *    'true' if the running process is using a debug version of PixelLight, else 'false'
00101         */
00102         static inline bool IsDebugVersion();
00103 
00104         /**
00105         *  @brief
00106         *    Get PixelLight suffix
00107         *
00108         *  @return
00109         *    Suffix of this PixelLight installation the running process is using
00110         */
00111         static PLCORE_API String GetSuffix();
00112 
00113         /**
00114         *  @brief
00115         *    Try to find the local PixelLight runtime directory
00116         *
00117         *  @return
00118         *    Path to the local PixelLight runtime directory (e.g. "file://C:/MyApplication/x86" on Windows), or ""
00119         */
00120         static inline String GetLocalDirectory();
00121 
00122         /**
00123         *  @brief
00124         *    Try to find the local PixelLight runtime data directory
00125         *
00126         *  @return
00127         *    Path to the local PixelLight runtime data directory (e.g. "file://C:/MyApplication/Data" on Windows), or ""
00128         */
00129         static PLCORE_API String GetLocalDataDirectory();
00130 
00131         /**
00132         *  @brief
00133         *    Try to find the system PixelLight runtime directory
00134         *
00135         *  @return
00136         *    Path to the system PixelLight runtime directory (e.g. "file://C:/PixelLight/Runtime/x86" on Windows), or ""
00137         */
00138         static PLCORE_API String GetSystemDirectory();
00139 
00140         /**
00141         *  @brief
00142         *    Try to find the system PixelLight runtime data directory
00143         *
00144         *  @return
00145         *    Path to the system PixelLight runtime data directory (e.g. "file://C:/PixelLight/Runtime/Data" on Windows), or ""
00146         */
00147         static PLCORE_API String GetSystemDataDirectory();
00148 
00149         /**
00150         *  @brief
00151         *    Try to find the system PixelLight runtime directory by reading the registry
00152         *
00153         *  @return
00154         *    Path to the system PixelLight runtime directory (e.g. "file://C:/PixelLight/Runtime/x86" on Windows), or ""
00155         *
00156         *  @remarks
00157         *    For this method, you also need to add a key to the registry (or environment, depending on the used OS, in here
00158         *    the MS Windows terminology is used), so that the path to the build PixelLight runtime can be found during runtime.
00159         *    This means that there's a high probability that this registry key does not exist or it's configuration is invalid.
00160         *    So, if you don't really need this method, try to avoid using it to reduce possible errors. When e.g. using a static
00161         *    build of PLCore, this registry method has to be used in order to be able to find the system PixelLight runtime directory.
00162         *
00163         *    On MS Windows, this key has to be at "HKEY_LOCAL_MACHINE/SOFTWARE/PixelLight/PixelLight-SDK/Runtime" (or at
00164         *    "HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/PixelLight/PixelLight-SDK/Runtime" if you are using a 32 bit PixelLight
00165         *    SDK on a 64 bit MS Windows). This "Runtime"-key has e.g. the string value "C:/PixelLight/Bin/Runtime/x86/" (same
00166         *    as the PATH environment variable entry pointing to the PixelLight runtime directory).
00167         *
00168         *    On Linux, the "PL_RUNTIME" environment variable is used. If this variable does not exist,
00169         *    "/usr/local/share/pixellight/Runtime" will be used, if it exists.
00170         *
00171         *  @see
00172         *    - 'Registry' class documentation
00173         */
00174         static PLCORE_API String GetRegistryDirectory();
00175 
00176         /**
00177         *  @brief
00178         *    Try to find the system PixelLight runtime data directory by reading the registry
00179         *
00180         *  @return
00181         *    Path to the system PixelLight runtime data directory (e.g. "file://C:/PixelLight/Runtime/Data" on Windows), or ""
00182         *
00183         *  @see
00184         *    - "GetRegistryDirectory()"
00185         */
00186         static PLCORE_API String GetRegistryDataDirectory();
00187 
00188         /**
00189         *  @brief
00190         *    Try to find the PixelLight runtime directory used by the running process
00191         *
00192         *  @return
00193         *    Path to the PixelLight runtime directory used by the running process (e.g. "file://C:/MyApplication/x86" or "file://C:/PixelLight/Runtime/x86" etc. on Windows), or ""
00194         *
00195         *  @remarks
00196         *    As soon as an application executable is started and therefore has become a running process, it's bound to a
00197         *    certain PixelLight runtime. Usually, an OS will first search for required shared libraries within the same
00198         *    directory the application executable is in. If the PLCore shared library was found within the application
00199         *    executable directory, this means that a local PixelLight runtime is used. Of course, there can be a local
00200         *    and system PixelLight runtime at the same time (although this is not recommended), but this still means, that
00201         *    in the described situation, the local PLCore shared library is used and therefore the local PixelLight runtime.
00202         *    The "GetDirectory()"-method returns the PixelLight runtime used by the running process. This means that internally
00203         *    "GetLocalDirectory()" is called at first and if this method returns an empty string, a "GetSystemDirectory()"
00204         *    call follows in exactly this order.
00205         */
00206         static PLCORE_API String GetDirectory();
00207 
00208         /**
00209         *  @brief
00210         *    Try to find the PixelLight runtime data directory used by the running process
00211         *
00212         *  @return
00213         *    Path to the PixelLight runtime data directory used by the running process (e.g. "file://C:/MyApplication/Data" or "file://C:/PixelLight/Runtime/Data" etc. on Windows), or ""
00214         *
00215         *  @see
00216         *    - GetDirectory()
00217         */
00218         static PLCORE_API String GetDataDirectory();
00219 
00220         /**
00221         *  @brief
00222         *    Returns the name of the PLCore shared library
00223         *
00224         *  @return
00225         *    The name of the PLCore shared library (e.g. "libPLCore.so" or "PLCoreD.dll")
00226         */
00227         static PLCORE_API String GetPLCoreSharedLibraryName();
00228 
00229         /**
00230         *  @brief
00231         *    Returns the absolute path to the directory the PLCore shared library is in
00232         *
00233         *  @return
00234         *    The absolute path to the directory the PLCore shared library is in (e.g. "file://C:/PixelLight/Runtime/x86" on Windows), empty string on error
00235         */
00236         static PLCORE_API String GetPLCoreSharedLibraryDirectory();
00237 
00238 
00239         //[-------------------------------------------------------]
00240         //[ Active actions                                        ]
00241         //[-------------------------------------------------------]
00242         /**
00243         *  @brief
00244         *    Sets the given PixelLight runtime directory
00245         *
00246         *  @param[in]  sDirectory
00247         *    Path to the PixelLight runtime directory (e.g. "C:\PixelLight\Runtime\x86" on Windows), or ""
00248         *  @param[out] pszErrorMessage
00249         *    If this parameter is no null pointer and there was an error, this string will receive a human readable error description,
00250         *    if there was no error this string is not touched
00251         *
00252         *  @return
00253         *    Returns 'true' if all went fine, else 'false'
00254         *
00255         *  @see
00256         *    - "GetDirectory()"
00257         */
00258         static PLCORE_API bool SetDirectory(const String &sDirectory, String *pszErrorMessage = nullptr);
00259 
00260         /**
00261         *  @brief
00262         *    Scan system PixelLight runtime directory for compatible plugins and load them in
00263         *
00264         *  @param[in] sDirectory
00265         *    Directory to use (for example the result of "GetDirectory()", "GetLocalDirectory()" or "GetSystemDirectory()"), if empty string the result of "GetDirectory()" will be used
00266         *  @param[in] bDelayedPluginLoading
00267         *    'true' if it's allowed to perform delayed shared library loading to speed up the program start, else 'false'
00268         *
00269         *  @remarks
00270         *    The implementation does the following tasks:
00271         *    - Scan for plugins in PixelLight runtime directory non-recursively
00272         *
00273         *  @see
00274         *    - Runtime::GetDirectory()
00275         *    - ClassManager::ScanPlugins()
00276         */
00277         static PLCORE_API void ScanDirectoryPlugins(const String &sDirectory = "", bool bDelayedPluginLoading = true);
00278 
00279         /**
00280         *  @brief
00281         *    Scan system PixelLight runtime directory for compatible data and register it
00282         *
00283         *  @param[in] sDirectory
00284         *    Directory to use (for example the result of "GetDataDirectory()", "GetLocalDataDirectory()" or "GetSystemDataDirectory()"), if empty string the result of "GetDataDirectory()" will be used
00285         *
00286         *  @remarks
00287         *    The implementation does the following tasks:
00288         *    - Add PixelLight runtime directory "Data/" as a base directory to the loadable manager
00289         *    - Scan for data in PixelLight runtime directory "Data/"
00290         *
00291         *  @see
00292         *    - LoadableManager::AddBaseDir()
00293         *    - LoadableManager::ScanPackages()
00294         */
00295         static PLCORE_API void ScanDirectoryData(const String &sDirectory = "");
00296 
00297         /**
00298         *  @brief
00299         *    Scan PixelLight runtime directory for compatible plugins and load them in as well as scan for compatible data and register it
00300         *
00301         *  @param[in] bUrgentMessageAllowed
00302         *    Is this method allowed to show an urgent message to the user in case of a failure?
00303         *
00304         *  @return
00305         *    'true' if all went fine, else 'false'
00306         *
00307         *  @remarks
00308         *    In case you don't care about technical details and just want the stuff runnable, then just call this method
00309         *    and be happy. The PixelLight runtime to use is detected automatically, all available compatible plugins are
00310         *    registered as well as compatible data.
00311         *
00312         *  @see
00313         *    - ScanDirectoryPlugins()
00314         *    - ScanDirectoryData()
00315         */
00316         static PLCORE_API bool ScanDirectoryPluginsAndData(bool bUrgentMessageAllowed = true);
00317 
00318 
00319     //[-------------------------------------------------------]
00320     //[ Private static functions                              ]
00321     //[-------------------------------------------------------]
00322     private:
00323         /**
00324         *  @brief
00325         *    Try to find the PixelLight runtime directory by using the PLCore shared library
00326         *
00327         *  @param[in] nType
00328         *    Runtime installation type, must be "LocalInstallation" or "SystemInstallation"
00329         *
00330         *  @return
00331         *    Path to the PixelLight runtime directory (e.g. "C:\MyApplication\x86" on Windows), or ""
00332         */
00333         static PLCORE_API String GetDirectory(EType nType);
00334 
00335 
00336 };
00337 
00338 
00339 //[-------------------------------------------------------]
00340 //[ Namespace                                             ]
00341 //[-------------------------------------------------------]
00342 } // PLCore
00343 
00344 
00345 //[-------------------------------------------------------]
00346 //[ Implementation                                        ]
00347 //[-------------------------------------------------------]
00348 #include "PLCore/Runtime.inl"
00349 
00350 
00351 #endif // __PLCORE_RUNTIME_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:59
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported