Updated license header to reference Apache 2.0 License
[platform/upstream/iotivity.git] / include / OCResource.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file OCResource.h 
22
23 /// @brief      This file contains the declaration of classes and its members related to 
24 ///                     Resource.
25
26 #ifndef __OCRESOURCE_H
27 #define __OCRESOURCE_H
28
29 #include <memory>
30 #include <random>
31
32 #include <boost/property_tree/ptree.hpp>
33 #include <boost/property_tree/json_parser.hpp>
34
35 #include <OCApi.h>
36 #include <ResourceInitException.h>
37
38 namespace OC
39 {
40         /**
41         *       @brief  OCResource represents an OC resource. A resource could be a light controller, 
42         *                       temperature sensor, smoke detector, etc. A resource comes with a well-defined 
43         *                       contract or interface onto which you can perform different operations, such as 
44         *                       turning on the light, getting the current temperature or subscribing for event 
45         *                       notifications from the smoke detector. A resource can be composed of one or
46         *                       more resources. 
47         */
48         class OCResource
49         {
50         public:
51                 typedef std::shared_ptr<OCResource> Ptr;
52                 
53                 OCResource(std::string host, boost::property_tree::ptree& resourceNode);
54                 virtual ~OCResource(void);
55                 
56                 // Gets the device host URI
57                 std::string host() const {return m_host;}
58                 // Gets the device-relative URI for this resource
59                 std::string uri() const {return m_uri;}
60                 // bool whether it is possible to attach an observer to this resource
61                 bool isObservable() const {return m_isObservable;}
62                 // bool whether this is a collection type, and will have children that can be queried
63                 bool isCollection() const {return m_isCollection;}
64                 // a collection of the resource-type names
65                 const std::vector<std::string> resourceTypes() const {return m_resourceTypes;}
66                 // a collection of the interfaces supported by this resource
67                 const std::vector<std::string> interfaces() const { return m_interfaces;}
68                 // a collection of property objects that allow calling of properties on this Resource
69                 const std::vector<std::string> properties() const { return m_properties;}
70                 // a collection of the names of the children of this resource, assuming it supports a collection interface
71                 const std::vector<std::string> children() const {return m_children;}
72                 
73                 
74                 // a method which allows 
75         private:        
76                 std::string m_uri;
77                 std::string m_host;
78                 bool m_isObservable;
79                 bool m_isCollection;
80                 std::vector<std::string> m_resourceTypes;
81                 std::vector<std::string> m_interfaces;
82                 std::vector<std::string> m_properties; // TODO: give a better type once we have the ability to call one!
83                 std::vector<std::string> m_children;
84         };
85
86 } // namespace OC
87
88 #endif //__OCRESOURCE_H