thing_manager.h 811 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef THING_MANAGER_H
  2. #define THING_MANAGER_H
  3. #include "thing.h"
  4. #include <cJSON.h>
  5. #include <vector>
  6. #include <memory>
  7. #include <functional>
  8. #include <map>
  9. namespace iot {
  10. class ThingManager {
  11. public:
  12. static ThingManager& GetInstance() {
  13. static ThingManager instance;
  14. return instance;
  15. }
  16. ThingManager(const ThingManager&) = delete;
  17. ThingManager& operator=(const ThingManager&) = delete;
  18. void AddThing(Thing* thing);
  19. std::string GetDescriptorsJson();
  20. bool GetStatesJson(std::string& json, bool delta = false);
  21. void Invoke(const cJSON* command);
  22. private:
  23. ThingManager() = default;
  24. ~ThingManager() = default;
  25. std::vector<Thing*> things_;
  26. std::map<std::string, std::string> last_states_;
  27. };
  28. } // namespace iot
  29. #endif // THING_MANAGER_H