MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ServiceComponent.hpp
1 #ifndef SERVICECOMPONENT_HPP
2 #define SERVICECOMPONENT_HPP
3 
4 #include "Component.hpp"
5 
6 namespace Showcase
7 {
8 
11 
12  class SHOWCASE_API ServiceInstance : public ComponentInstance, public Valuable::Node
13  {
14  public:
15  ServiceInstance(ComponentPtr component);
16  virtual ~ServiceInstance();
17 
18  virtual void init() {}
19 
21  virtual void removeInstance() override;
22 
23  virtual void propertyReceived(const PropertyKey &key,
24  const PropertyValue &value) override;
25  };
26  typedef std::shared_ptr<ServiceInstance> ServiceInstancePtr;
27 
28  //------------------------------------------------------------------------
29 
32  class SHOWCASE_API ServiceComponent : public Component
33  {
34  public:
35  typedef std::function<ServiceInstancePtr(ComponentPtr)> CreateFunction;
36 
37  ServiceComponent(CreateFunction create);
38 
39  virtual void placeholderStatusChanged(const NodeId& id) override;
40 
41  protected:
42  virtual ComponentInstancePtr instanceImpl() override;
43  virtual void initPlaceholder(ComponentPlaceholderPtr placeholder) override;
44 
45  private:
46  CreateFunction m_createFunc;
47  };
48  typedef std::shared_ptr<ServiceComponent> ServiceComponentPtr;
49 
50 }
51 
52 #define SHOWCASE_SERVICE_COMPONENT(name, type) \
53 namespace {\
54 Showcase::FactoryRegistrant<Showcase::ServiceComponent> MW_PLUGIN_CONCAT(component, __LINE__) \
55 (name, [] { return std::make_shared<Showcase::ServiceComponent>(\
56  [] (Showcase::ComponentPtr comp){ return std::make_shared<type>(comp); } ); }); \
57 }
58 
59 #endif // SERVICECOMPONENT_HPP