Advertisement
Guest User

Code

a guest
Apr 26th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 KB | None | 0 0
  1. // Copyright Epic Games, Inc. All Rights Reserved.
  2.  
  3. #pragma once
  4.  
  5. #include "CoreMinimal.h"
  6. #include "Modules/ModuleInterface.h"
  7.  
  8. class IOnlineSubsystem;
  9.  
  10. typedef TSharedPtr<class IOnlineSubsystem, ESPMode::ThreadSafe> IOnlineSubsystemPtr;
  11.  
  12.  
  13. /**
  14. * Online subsystem module class
  15. * Wraps the loading of an online subsystem by name and allows new services to register themselves for use
  16. */
  17. class FOnlineSubsystemModule : public IModuleInterface
  18. {
  19. private:
  20.  
  21. /** Name of the default online service requested
  22. * Specified in DefaultEngine.ini
  23. * [OnlineSubsystem]
  24. * DefaultPlatformService
  25. */
  26. FName DefaultPlatformService;
  27.  
  28. /**
  29. * Name of the online service associated with the native platform
  30. * Specified in Base<Platform>Engine.ini
  31. * [OnlineSubsystem]
  32. * NativePlatformService
  33. */
  34. FName NativePlatformService;
  35.  
  36. /**
  37. * Name of the online service associated with User Defined strings
  38. * Specified in Base<Platform>Engine.ini
  39. * [OnlineSubsystem]
  40. * ConfigDefinedPlatformServices
  41. */
  42. TMap<FString, FName> ConfigDefinedSubsystems;
  43.  
  44. /** Existing instances of any online subsystems created <PlatformName:InstanceName> */
  45. TMap<FName, class IOnlineFactory*> OnlineFactories;
  46.  
  47. /** Mapping of all currently loaded platform service subsystems to their name */
  48. TMap<FName, IOnlineSubsystemPtr> OnlineSubsystems;
  49.  
  50. /** Have we warned already for a given online subsystem creation failure */
  51. TMap<FName, bool> OnlineSubsystemFailureNotes;
  52.  
  53. /** Config driven override of module name for online subsystem */
  54. TMap<FString, FName> ModuleRedirects;
  55.  
  56. /**
  57. * Transform an online subsystem identifier into its Subsystem and Instance constituents
  58. *
  59. * accepts the following forms:
  60. * <subsystem name>:<instance name> -> subsystem name / instance name
  61. * :<instance name> -> default subsystem / instance name
  62. * <subsystem name>: -> subsystem name / default instance
  63. * <subsystem name> -> subsystem name / default instance
  64. * <nothing> -> default subsystem / default instance
  65. *
  66. * @param FullName full name of the subsystem and instance that is being referenced
  67. * @param SubsystemName parsed out value or default subsystem name
  68. * @param InstanceName parsed out value or default instance name
  69. *
  70. * @return Properly formatted key name for accessing the online subsystem in the TMap
  71. */
  72. FName ParseOnlineSubsystemName(const FName& FullName, FName& SubsystemName, FName& InstanceName) const;
  73.  
  74. /**
  75. * Read any config defined subsystems from the configuration file
  76. */
  77. void ProcessConfigDefinedSubsystems();
  78.  
  79. /**
  80. * Read any config defined subsystem module overrides from the configuration file
  81. */
  82. void ProcessConfigDefinedModuleRedirects();
  83.  
  84. /**
  85. * Attempt to load the default subsystem specified in the configuration file
  86. */
  87. bool TryLoadSubsystemAndSetDefault(FName ModuleName);
  88.  
  89. /**
  90. * Attempt to load the default subsystem specified in the configuration file
  91. */
  92. void LoadDefaultSubsystem();
  93.  
  94. /**
  95. * Called before ShutdownOnlineSubsystem, before other modules have been unloaded
  96. */
  97. virtual void PreUnloadOnlineSubsystem();
  98.  
  99. /**
  100. * Shuts down all registered online subsystem platforms and unloads their modules
  101. */
  102. virtual void ShutdownOnlineSubsystem();
  103.  
  104. public:
  105.  
  106. FOnlineSubsystemModule() :
  107. DefaultPlatformService(NAME_None)
  108. {}
  109. virtual ~FOnlineSubsystemModule() {}
  110.  
  111. /**
  112. * Main entry point for accessing an online subsystem by name
  113. * Will load the appropriate module if the subsystem isn't currently loaded
  114. * It's possible that the subsystem doesn't exist and therefore can return NULL
  115. *
  116. * @param InSubsystemName - name of subsystem as referenced by consumers
  117. *
  118. * @return Requested online subsystem, or NULL if that subsystem was unable to load or doesn't exist
  119. */
  120. virtual IOnlineSubsystem* GetOnlineSubsystem(const FName InSubsystemName = NAME_None);
  121.  
  122. /**
  123. * Get the online subsystem native to the current hardware
  124. *
  125. * @param bAutoLoad - load the module if not already loaded
  126. *
  127. * @return pointer to the appropriate online subsystem
  128. */
  129. virtual IOnlineSubsystem* GetNativeSubsystem(bool bAutoLoad);
  130.  
  131. /**
  132. * Get the online subsystem associated with the given config string
  133. *
  134. * @param ConfigString - Key to query for
  135. * @param bAutoLoad - load the module if not already loaded
  136. *
  137. * @return pointer to the appropriate online subsystem
  138. */
  139. virtual IOnlineSubsystem* GetSubsystemByConfig(const FString& ConfigString, bool bAutoLoad);
  140.  
  141. /**
  142. * Destroys an online subsystem created internally via access with GetOnlineSubsystem
  143. * Typically destruction of the subsystem is handled at application exit, but
  144. * there may be rare instances where the subsystem is destroyed by request
  145. *
  146. * @param InSubsystemName - name of subsystem as referenced by consumers
  147. */
  148. virtual void DestroyOnlineSubsystem(const FName InSubsystemName);
  149.  
  150. /**
  151. * Does an instance of subsystem with the given name exist
  152. *
  153. * @return true if the instance exists, false otherwise
  154. */
  155. ONLINESUBSYSTEM_API "bool DoesInstanceExist(const FName InSubsystemName) const;
  156.  
  157. /**
  158. * Determine if a subsystem is loaded by the OSS module
  159. *
  160. * @param SubsystemName - name of subsystem as referenced by consumers
  161. * @return true if module for the subsystem is loaded
  162. */
  163. virtual bool IsOnlineSubsystemLoaded(const FName InSubsystemName) const;
  164.  
  165. /**
  166. * Register a new online subsystem interface with the base level factory provider
  167. * @param FactoryName - name of subsystem as referenced by consumers
  168. * @param Factory - instantiation of the online subsystem interface, this will take ownership
  169. */
  170. virtual void RegisterPlatformService(const FName FactoryName, class IOnlineFactory* Factory);
  171.  
  172. /**
  173. * Unregister an existing online subsystem interface from the base level factory provider
  174. * @param FactoryName - name of subsystem as referenced by consumers
  175. */
  176. virtual void UnregisterPlatformService(const FName FactoryName);
  177.  
  178. /**
  179. * Enumerate all loaded online subsystems
  180. *
  181. * @param EnumCb functor to call for each online subsystem
  182. */
  183. typedef TFunction<void(IOnlineSubsystem*)> FEnumerateOnlineSubsystemCb;
  184. void ONLINESUBSYSTEM_API EnumerateOnlineSubsystems(FEnumerateOnlineSubsystemCb& EnumCb);
  185.  
  186. /**
  187. * Shutdown the current default subsystem (may be the fallback) and attempt to reload the one
  188. * specified in the configuration file
  189. *
  190. * **NOTE** This is intended for editor use only, attempting to use this at the wrong time can result
  191. * in unexpected crashes/behavior
  192. */
  193. void ONLINESUBSYSTEM_API ReloadDefaultSubsystem();
  194.  
  195. // IModuleInterface
  196.  
  197. /**
  198. * Called right after the module DLL has been loaded and the module object has been created
  199. * Overloaded to allow the default subsystem a chance to load
  200. */
  201. virtual void StartupModule() override;
  202.  
  203. /**
  204. * Called before the module has been unloaded
  205. * Overloaded to allow online subsystems to cancel any outstanding http requests
  206. */
  207. virtual void PreUnloadCallback() override;
  208.  
  209. /**
  210. * Called before the module is unloaded, right before the module object is destroyed.
  211. * Overloaded to shut down all loaded online subsystems
  212. */
  213. virtual void ShutdownModule() override;
  214.  
  215. /**
  216. * Override this to set whether your module is allowed to be unloaded on the fly
  217. *
  218. * @return Whether the module supports shutdown separate from the rest of the engine.
  219. */
  220. virtual bool SupportsDynamicReloading() override
  221. {
  222. return false;
  223. }
  224.  
  225. /**
  226. * Override this to set whether your module would like cleanup on application shutdown
  227. *
  228. * @return Whether the module supports shutdown on application exit
  229. */
  230. virtual bool SupportsAutomaticShutdown() override
  231. {
  232. return true;
  233. }
  234.  
  235. private:
  236. // Cached instance names for efficient lookup in ParseOnlineSubsystemName
  237. struct FInstanceNameEntry
  238. {
  239. FName SubsystemName;
  240. FName InstanceName;
  241. FName FullPath;
  242. };
  243. mutable TMap<FName, FInstanceNameEntry> InstanceNames;
  244. };
  245.  
  246. /** Public references to the online subsystem module pointer should use this */
  247. typedef TSharedPtr<FOnlineSubsystemModule, ESPMode::ThreadSafe> FOnlineSubsystemModulePtr;
  248.  
  249.  
  250.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement