1 #ifndef __LIGHT_RESOURCE_HPP
2 #define __LIGHT_RESOURCE_HPP
14 #include "OCResource.h"
15 #include "OCPlatform.h"
17 /* An example of a server-side resource: */
18 namespace Intel { namespace OCDemo {
23 /// This class represents a single resource named 'lightResource'. This resource has
24 /// two simple properties named 'state' and 'power'
28 bool m_state; // off or on?
29 int m_power; // power level
30 OCRepresentation m_rep;
33 atomic<bool> m_observation; // are we under observation?
36 static atomic<bool> shutdown_flag;
37 static thread observe_thread;
40 OCResourceHandle m_resourceHandle;
53 if(observe_thread.joinable())
54 observe_thread.join();
58 inline std::string make_URI(const unsigned int resource_number)
60 std::string uri = std::string("/a/light") + "_" + std::to_string(resource_number);
66 // This function internally calls registerResource API.
67 void createResource(const unsigned int resource_number);
68 void unregisterResource();
69 OCResourceHandle getHandle() const { return m_resourceHandle; }
71 void setRepresentation(const OCRepresentation& rep);
72 OCRepresentation getRepresentation(void);
74 void addType(const std::string& type) const;
75 void addInterface(const std::string& interface) const;
78 OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request,
79 std::shared_ptr<OCResourceResponse> response);
82 void observe_function();
86 void dispatch_request(const std::string& request_type, std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
87 void handle_get_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
88 void handle_put_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
89 void handle_post_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
90 void handle_delete_request(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
91 void handle_observe_event(std::shared_ptr<OCResourceRequest> request, std::shared_ptr<OCResourceResponse> response);
94 }} // namespace Intel::OCDemo