MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ServiceProvider.hpp
1 #ifndef SERVICEPROVIDER_HPP
2 #define SERVICEPROVIDER_HPP
3 
4 #include "Export.hpp"
5 #include "Graph.hpp"
6 #include "UserInterface.hpp"
7 #include "ServiceComponent.hpp"
8 #include "services/EmailServiceAPI.hpp"
9 #include "services/CodiceServiceAPI.hpp"
10 #include "services/codice-service/CodiceCache.hpp"
11 #include "services/DataGatheringServiceAPI.hpp"
12 
13 namespace Showcase
14 {
15 
16  typedef ShowcaseFactoryPtr<ServiceComponent> ServiceComponentFactoryPtr;
17 
18  class SystemConfiguration;
19  typedef std::shared_ptr<SystemConfiguration> SystemConfigurationPtr;
20 
22  class SHOWCASE_API ServiceProvider
23  {
24  public:
26 
27  void init(GraphPtr graph, const GraphNode& node);
28 
29  bool hasComponent(const QString& name) const;
30  ServiceComponentPtr createComponent(const QString& name);
31 
32  FactoryKey<ServiceComponent>
33  registerFactory(const QString &name, ServiceComponentFactoryPtr factory);
34 
35  bool unregisterFactory(FactoryKey<ServiceComponent> key);
36 
37  void clear();
38 
39  // Actual API for developers
40 
41 
45  std::shared_ptr<EmailServiceAPI> emailService(const QString& name = QString());
46 
49  std::shared_ptr<CodiceServiceAPI> codiceService();
50 
53  std::shared_ptr<CodiceServiceCache> codiceServiceCache();
54 
57  std::shared_ptr<DataGathering::DataGatheringServiceAPI> dataGatheringService();
58 
62  ServiceInstancePtr
63  service(const QString& componentName, const QString& name = QString()) const;
64 
65  protected:
66  void addServiceInstance(const QString& component, const QString& name,
67  ServiceInstancePtr instance);
68  void removeServiceInstance(const QString& component, const QString& name);
69 
70  private:
71  FactoryMap<ServiceComponent> m_componentFactories;
72 
74  typedef std::map<QString, ServiceInstancePtr> ServiceMap;
76  std::map<QString, ServiceMap> m_services;
77 
78  SystemConfigurationPtr m_systemConfig;
79 
80  // CodiceService is a special case since it is built-in to Showcase and
81  // always available. It doesn't use normal service component architecture.
82  std::shared_ptr<CodiceServiceAPI> m_codiceService;
83 
84  // CodiceServiceCache acts as a cache for CodiceService.
85  std::shared_ptr<CodiceServiceCache> m_codiceServiceCache;
86 
87  friend class SystemConfiguration;
88  };
89  typedef std::shared_ptr<ServiceProvider> ServiceProviderPtr;
90 
91 }
92 
93 #endif // SERVICEPROVIDER_HPP