4 #include <Radiant/Singleton.hpp>
8 #include <MultiWidgets/Widget.hpp>
12 #include "CachedGraph.hpp"
14 #include "GraphGenerators.hpp"
15 #include "ShowcaseTypes.hpp"
16 #include "Configuration.hpp"
17 #include "UserInterface.hpp"
18 #include "UIComponent.hpp"
19 #include "ServiceProvider.hpp"
20 #include "RemoteControl.hpp"
21 #include "Package.hpp"
23 #include <boost/expected/expected.hpp>
25 namespace WebBrowserCef
27 class BrowserSessionManager;
37 class ShowcaseLicense;
39 class ScheduleManager;
41 INTRUSIVE_PTR_FORWARD_DECL(, ErrorPageWidget);
70 UserInterfacePtr ui();
74 ServiceProviderPtr services();
78 RemoteControlPtr remoteControl();
83 std::shared_ptr<ScheduleManager> scheduleManager();
93 PackagePtr packageOfComponent(
const QString& componentName);
97 void addCSSFiles(
const std::vector<QString>& filePaths);
104 void addCSSFile(
const QString& filePath);
108 void removeCSSFiles(
const std::vector<QString>& filePaths);
112 void removeCSSFile(
const QString& filePath);
117 static void setAssetsPath(
const QString & path);
127 bool hasRunConfiguration()
const;
132 RunConfigurationPtr runConfiguration();
137 void reloadRunConfiguration(
bool showLoadingOverlay =
false);
142 void runConfigurationChanged(
int id);
145 void reloadSchedule();
148 void scheduleChanged(
int id);
153 void updateRemoteConnectionState(
bool hasConnection);
154 void updateRunConfigurationState(
bool hasRunConf);
159 FactoryKey<GraphGenerator>
160 registerFactory(
const QString& name, GraphGenFactoryPtr factory);
162 FactoryKey<PropertyGenerator>
163 registerFactory(
const QString& name, PropGenFactoryPtr factory);
165 FactoryKey<UIComponent>
166 registerFactory(
const QString &name, UIComponentFactoryPtr factory);
168 FactoryKey<ServiceComponent>
169 registerFactory(
const QString &name, ServiceComponentFactoryPtr factory);
172 bool unregisterFactory(FactoryKey<GraphGenerator> key);
173 bool unregisterFactory(FactoryKey<PropertyGenerator> key);
174 bool unregisterFactory(FactoryKey<UIComponent> key);
175 bool unregisterFactory(FactoryKey<ServiceComponent> key);
181 static std::weak_ptr<Showcase> weakInstance();
185 static const QString& version();
188 static QByteArray showcaseGitHash();
193 void registerWidgetInstance(Valuable::Node::Uuid widgetId, std::weak_ptr<WidgetInstance> instance);
196 void unregisterWidgetInstance(Valuable::Node::Uuid widgetId);
201 std::shared_ptr<WidgetInstance> widgetInstance(Valuable::Node::Uuid widgetId);
206 void showErrorScreen(
const QByteArray & css =
"",
const QString & error =
"");
209 void removeErrorScreen();
214 QString editorAddress(
bool hideDefaultPort =
true)
const;
219 static boost::expected<QString, QString> showcaseRoot();
230 static QString localDataDirectory();
235 static QString localCacheDirectory();
239 static QString logDirectory();
244 static void errorMessage(
const QString& msg);
250 QString remoteControlServer()
const;
254 std::shared_ptr<folly::Executor>
graphExecutor() {
return m_graphExecutor; }
263 bool verifyGraphExecutorCallingThread()
const;
272 void addThemeComponent(
const QString & component);
276 const QStringList & themeComponents()
const;
281 void setShowExit(
bool show);
284 void reloadServices();
287 void reloadAppSchedule();
288 void showExpiredLicenseWarning(
const ShowcaseLicense& license);
291 void clear(
bool removeError =
true);
295 bool checkRemoteControlConnection();
296 bool checkDatabaseConnection();
298 bool checkRunConfiguration();
300 void loadPackagesFrom(
const QStringList& paths);
301 void parsePackagesFrom(
const QString& path, std::vector<PackagePtr>& packages);
306 UserInterfacePtr m_ui;
307 ServiceProviderPtr m_services;
308 RemoteControlPtr m_remoteControl;
309 std::shared_ptr<ScheduleManager> m_scheduleManager;
310 std::shared_ptr<AppSchedule> m_appSchedule;
311 std::shared_ptr<WebBrowserCef::BrowserSessionManager> m_browserSessions;
312 std::shared_ptr<Luminous::PDFManager> m_pdfManager;
314 std::map<QString, PackagePtr> m_loadedPackages;
315 QStringList m_themeComponents;
317 std::shared_ptr<RunConfiguration> m_runConf;
318 std::shared_ptr<ScheduleConfig> m_schedule;
320 std::map<QString, size_t> m_loadedCSSFiles;
322 std::mutex m_widgetInstancesMutex;
323 std::map<Valuable::Node::Uuid, std::weak_ptr<WidgetInstance>> m_widgetInstances;
326 std::mutex m_stateMutex;
328 bool m_hasRemoteConnection;
334 ErrorPageWidgetPtr m_errorScreen;
336 std::shared_ptr<Radiant::BGThread> m_graphThreadPool;
337 std::shared_ptr<folly::Executor> m_graphExecutor;
339 std::shared_ptr<Radiant::BGThread> m_configThreadPool;
340 std::shared_ptr<folly::Executor> m_configExecutor;
342 template <
typename Factory>
friend class FactoryRegistrant;
344 typedef std::shared_ptr<Showcase> ShowcasePtr;
352 template <
typename T,
typename Predicate =
void>
355 template <
typename T>
356 struct APIClass<T, typename std::enable_if<std::is_base_of<GraphGenerator, T>::value>::type>
359 template <
typename T>
360 struct APIClass<T, typename std::enable_if<std::is_base_of<PropertyGenerator, T>::value>::type>
363 template <
typename T>
364 struct APIClass<T, typename std::enable_if<std::is_base_of<UIComponent, T>::value>::type>
365 {
typedef UIComponent type; };
367 template <
typename T>
368 struct APIClass<T, typename std::enable_if<std::is_base_of<ServiceComponent, T>::value>::type>
369 {
typedef ServiceComponent type; };
373 template <
typename ComponentType>
374 class FactoryRegistrant
377 typedef typename APIClass<ComponentType>::type Base;
378 typedef typename ShowcaseFactory<Base>::CreateFunc CreateFunc;
380 FactoryRegistrant(
const QString& name, CreateFunc f);
381 ~FactoryRegistrant();
384 FactoryKey<Base> m_key;
391 template <
typename ComponentType>
392 FactoryRegistrant<ComponentType>::FactoryRegistrant(
393 const QString &name, CreateFunc f)
398 ShowcaseFactoryPtr<Base> factory =
399 std::make_shared<ShowcaseFactory<Base>>(
typeid(ComponentType), f);
402 auto showcase = weak.lock();
405 auto package = showcase->packageOfComponent(name);
414 ComponentDefinitionPtr component = package->component(name);
416 component->initComponent();
418 const Schema& schema = component->schema();
419 factory->setSchema(schema);
421 m_key = showcase->registerFactory(name, factory);
424 template <
typename ComponentType>
425 FactoryRegistrant<ComponentType>::~FactoryRegistrant()
428 std::shared_ptr<Showcase> s = weak.lock();
431 s->unregisterFactory(m_key);
436 #define _MW_PLUGIN_CONCAT(x,y) x ## y
437 #define MW_PLUGIN_CONCAT(x,y) _MW_PLUGIN_CONCAT(x,y)
439 #define SHOWCASE_COMPONENT(name, type) \
441 Showcase::FactoryRegistrant<type> MW_PLUGIN_CONCAT(component, __LINE__) \
442 (name, std::make_shared<type> ); \