Free Electron
IFEOps.h
1 #pragma once
2 
3 #include "CoreMinimal.h"
4 #include "Modules/ModuleInterface.h"
5 #include "Modules/ModuleManager.h"
6 
7 #if defined(_WIN32) || defined(_WIN64)
8 #pragma warning(push)
9 #pragma warning(disable:4002)
10 #pragma warning(disable:4003)
11 #endif
12 
13 #include "unreal/unrealModule.pmh"
14 
15 #if defined(_WIN32) || defined(_WIN64)
16 #pragma warning(pop)
17 #endif
18 
19 inline void UnrealLogString(fe::String a_string)
20 {
21  UE_LOG(LogTemp,Display,TEXT("%s"),*FString(a_string.c_str()));
22 }
23 
24 inline void UnrealPrintFunction(const char* a_ascii)
25 {
26  UnrealLogString(fe::String(a_ascii).chop("\n"));
27 }
28 
29 class FE_DL_PUBLIC UnrealLog: public fe::Log
30 {
31  public:
32  UnrealLog(void) {}
33 virtual ~UnrealLog(void) {}
34 
35  using Log::log;
36 
37 virtual void log(const std::string &a_message)
38  {
39  const fe::String text=fe::String(
40  a_message.c_str()).chop("\n");
41  const fe::String trim=text.prechop("\n");
42  if(trim!=text)
43  {
44  UnrealLogString("");
45  }
46  UnrealLogString(m_preface+trim);
47  }
48 
49  void setPreface(fe::String a_preface)
50  { m_preface=a_preface; }
51 
52  protected:
53  fe::String m_preface;
54 };
55 
56 /**
57  The public interface to this module.
58  In most cases, this interface is only public to sibling modules
59  within this plugin.
60  */
61 class IFEOps : public IModuleInterface
62 {
63 
64 public:
65 
66  /**
67  Singleton-like access to this module's interface.
68  This is just for convenience!
69  Beware of calling this during the shutdown phase, though.
70  Your module might have been unloaded already.
71 
72  @return Returns singleton instance,
73  loading the module on demand if needed
74  */
75  static inline IFEOps& Get()
76  {
77  return FModuleManager::LoadModuleChecked< IFEOps >("FEOps");
78  }
79 
80  /**
81  Checks to see if this module is loaded and ready.
82  It is only valid to call Get() if IsAvailable() returns true.
83 
84  @return True if the module is loaded and ready to use
85  */
86  static inline bool IsAvailable()
87  {
88  return FModuleManager::Get().IsModuleLoaded("FEOps");
89  }
90 };
91 
92 inline fe::sp<fe::SingleMaster> UnrealGetSingleMaster(void)
93 {
94  fe::Logger* oldLogger=gs_feLogger;
95 
96  fe::sp<fe::SingleMaster> spSingleMaster=fe::SingleMaster::create();
97  FEASSERT(spSingleMaster.isValid());
98 
99  if(!oldLogger)
100  {
101  //* NOTE initializations run only once
102 
103 #if FE_OS==FE_WIN32 || FE_OS==FE_WIN64
104  UnrealLogString("ResetFeLogger");
105 
106  //* for feLogDirect, including Exceptions
107  fe::setPrintFunction(&UnrealPrintFunction);
108 
109  //* NOTE all common log mechanisms are useless on Windows Unreal
110  feLogger()->clearAll();
111 
112  UnrealLog* pUnrealLogFe=new UnrealLog();
113  pUnrealLogFe->setPreface("fe ");
114  feLogger()->setLog("unreal_fe", pUnrealLogFe);
115  feLogger()->bind(".*", "unreal_fe");
116 
117  UnrealLog* pUnrealLogLua=new UnrealLog();
118  pUnrealLogLua->setPreface("lua ");
119  feLogger()->setLog("unreal_lua", pUnrealLogLua);
120  feLogger()->bind("lua_script", "unreal_lua");
121  feLogger()->antibind("lua_script", "unreal_fe");
122 
123  //* just to show that we can
124  UnrealLog* pUnrealLogUnreal=new UnrealLog();
125  pUnrealLogUnreal->setPreface("fe+ ");
126  feLogger()->setLog("unreal", pUnrealLogUnreal);
127  feLogger()->bind("unreal_plugins", "unreal");
128  feLogger()->antibind("unreal_plugins", "unreal_fe");
129 #endif
130 
131 #if FE_COMPILER==FE_GNU && !defined(__clang__)
132 #pragma GCC diagnostic push
133 #pragma GCC diagnostic ignored "-Wconditionally-supported"
134 #endif
135  const fe::String loadPath=fe::System::getLoadPath(
136  (void*)IFEOps::IsAvailable,TRUE).pathname();
137 #if FE_COMPILER==FE_GNU && !defined(__clang__)
138 #pragma GCC diagnostic pop
139 #endif
140 
141  fe::DL_Loader::addPath(loadPath);
142 
143  feLog("(IFEOps) ::UnrealGetSingleMaster loadPath \"%s\"\n",
144  loadPath.c_str());
145 
146  fe::sp<fe::Registry> spRegistry=spSingleMaster->master()->registry();
147 
148 // spRegistry->master()->catalog()->catalog<String>("path:media")=
149 // "/home/symhost/sym/proj/fe/main/media";
150 
151  spRegistry->manage("fexOperatorDL");
152  spRegistry->manage("fexVegetationDL");
153 
154 // spRegistry->manage("fexIronWorksDL");
155 // spRegistry->manage("fexGrassDL");
156  }
157 
158  return spSingleMaster;
159 }
C++ portion of logging interface implementation.
Definition: debug.h:292
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
static String FE_CDECL getLoadPath(void *a_symbol, BWORD a_prune)
Get the full path to the symbol&#39;s library.
Definition: System.cc:214
String prechop(const String &prefix) const
Return the substring after the prefix.
Definition: String.cc:118
static Result addPath(String a_absPath)
Add a path search for managed dynamic libraries.
Definition: DL_Loader.cc:116
Automatically reference-counted string container.
Definition: String.h:128
The public interface to this module.
Definition: IFEOps.h:61
String pathname(void) const
Return the substring preceding the last &#39;/&#39;.
Definition: String.cc:77
static IFEOps & Get()
Singleton-like access to this module&#39;s interface.
Definition: IFEOps.h:75
static bool IsAvailable()
Checks to see if this module is loaded and ready.
Definition: IFEOps.h:86
Base class for logging system Log objects.
Definition: debug.h:24