Merge "Patch 1 : Adding Arduino WiFi support. This requires updated Arduino WiFi...
[platform/upstream/iotivity.git] / include / OCApi.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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 #ifndef __INTEL_OCAPI_H_2014_07_10
22  #define __INTEL_OCAPI_H_2014_07_10
23
24 #include <string>
25 #include <sstream>
26 #include <vector>
27 #include <map>
28
29 #include "ocstack.h"
30
31 namespace OC {
32
33
34 class OCResource;
35
36 } // namespace OC
37
38 namespace OC { namespace OCReflect {
39
40 struct entity;
41
42 }} // namespace OC::OCReflect
43
44 namespace OC {
45
46  enum class OCPlatformStatus {
47     PlatformUp,
48     PlatformDown
49  };
50
51  enum class OCAdvertisementStatus{
52     None
53  };
54
55  typedef std::string URI;
56
57  enum class ServiceType
58  {
59      InProc,
60      OutOfProc
61  };
62
63  enum class ModeType
64  {
65      Server,
66      Client,
67      Both
68  };
69
70  enum class QualityOfService : uint8_t
71  {
72     Confirmable     = OC_CONFIRMABLE,
73     NonConfirmable  = OC_NON_CONFIRMABLE
74  };
75
76  struct PlatformConfig
77  {
78     ServiceType                serviceType;   // This will indicate whether it is InProc or OutOfProc
79     ModeType                   mode;          // This will indicate whether we want to do server, client or both
80     std::string                ipAddress;     // This is the ipAddress of the server to connect to
81     uint16_t                   port;          // Port of the server
82
83     QualityOfService           QoS;
84
85     public:
86     PlatformConfig(const ServiceType serviceType_,
87                    const ModeType mode_,
88                    const std::string& ipAddress_,
89                    const uint16_t port_,
90                    const QualityOfService QoS_)
91      : serviceType(serviceType_),
92        mode(mode_),
93        ipAddress(ipAddress_),
94        port(port_),
95        QoS(QoS_)
96     {}
97  };
98
99  enum class RequestHandlerFlag
100  {
101     InitFlag,
102     RequestFlag,
103     ObserverFlag
104  };
105
106  enum class ObserveType
107  {
108      Observe,
109      ObserveAll
110  };
111
112  // TODO: To find the complete JSon data structure and modify map value type
113  // Typedef for attribute values and attribute map. 
114  typedef std::vector<std::string> AttributeValues;
115  typedef std::map<std::string, AttributeValues> AttributeMap; 
116
117  // Typedef for query parameter map
118  typedef std::map<std::string, std::string> QueryParamsMap;
119
120  // const strings for different interfaces
121
122  // Default interface
123  const std::string DEFAULT_INTERFACE = "oc.mi.def";
124
125  // Used in discovering (GET) links to other resources of a collection.
126  const std::string LINK_INTERFACE = "oc.mi.ll";
127
128  // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
129  const std::string BATCH_INTERFACE = "oc.mi.b";
130
131  // Helper function to escape character in a string.
132  std::string escapeString(const std::string& value);
133
134  class OCRepresentation
135     {
136
137     private:
138
139         std::string m_uri;
140         AttributeMap m_attributeMap;
141         std::vector<std::string> m_resourceTypes;
142         std::vector<std::string> m_resourceInterfaces;
143         bool m_observable; // TODO : do we need this here???
144         int errorCode;
145
146         std::vector<OCRepresentation> m_children;
147
148     public:
149
150         OCRepresentation() {}
151
152         std::string getUri(void) const
153         {
154             return m_uri;
155         }
156
157         void setUri(std::string uri)
158         {
159             m_uri = uri;
160         }
161
162         std::vector<OCRepresentation> getChildren(void) const
163         {
164             return m_children;
165         }
166
167         void setChildren(std::vector<OCRepresentation> children)
168         {
169             m_children = children;
170         }
171
172         OCResource* getResource() const
173         {
174             // TODO Needs to be implemented
175             OCResource* res = NULL;
176
177             return res;
178         }
179
180         AttributeMap getAttributeMap() const 
181         {
182             return m_attributeMap;
183         }
184
185         void setAttributeMap(AttributeMap map)
186         {
187             m_attributeMap = map;
188         }
189
190         std::vector<std::string> getResourceTypes() const
191         {
192             return m_resourceTypes;
193         }
194
195         void setResourceTypes(std::vector<std::string> resourceTypes)
196         {
197             m_resourceTypes = resourceTypes;
198         }
199
200         std::vector<std::string> getResourceInterfaces(void) const
201         {
202             return m_resourceInterfaces;
203         }
204
205         void setResourceInterfaces(std::vector<std::string> resourceInterfaces)
206         {
207             m_resourceInterfaces = resourceInterfaces;
208         }
209     };
210 } // namespace OC
211
212 #endif