Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / resource / include / OCHeaderOption.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 /**
22  * @file
23  *
24  * This file contains the declaration of classes and its members related to
25  * OCHeaderOption.
26  */
27
28 #ifndef OC_HEADEROPTION_H_
29 #define OC_HEADEROPTION_H_
30
31 #include <OCException.h>
32 #include <StringConstants.h>
33 namespace OC
34 {
35     namespace HeaderOption
36     {
37         /**
38         *     @brief OCHeaderOption class allows to create instances which comprises optionID
39         *            and optionData as members. These are used in setting Header options.
40         *            After creating instances of OCHeaderOptions, use setHeaderOptions API
41         *            (in OCResource.h) to set header Options.
42         *            NOTE: HeaderOptionID  is an unsigned integer value which MUST be within
43         *            range of 2048 to 3000 inclusive of lower and upper bound
44         *            except for If-Match with empty(num : 1), If-None-Match(num : 5),
45         *            Location-Path(num : 8), Location-Query(num : 20) option.
46         *            HeaderOptions instance creation fails if above condition is not satisfied.
47         */
48         const uint16_t MIN_HEADER_OPTIONID = 2048;
49         const uint16_t MAX_HEADER_OPTIONID = 3000;
50         const uint16_t IF_MATCH_OPTION_ID = 1;
51         const uint16_t IF_NONE_MATCH_OPTION_ID = 5;
52         const uint16_t LOCATION_PATH_OPTION_ID = 8;
53         const uint16_t LOCATION_QUERY_OPTION_ID = 20;
54
55         class OCHeaderOption
56         {
57         private:
58             uint16_t m_optionID;
59             std::string m_optionData;
60
61         public:
62             /**
63             * OCHeaderOption constructor
64             */
65             OCHeaderOption(uint16_t optionID, std::string optionData):
66                 m_optionID(optionID),
67                 m_optionData(optionData)
68             {
69                 if (!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID)
70                         && optionID != IF_MATCH_OPTION_ID
71                         && optionID != IF_NONE_MATCH_OPTION_ID
72                         && optionID != LOCATION_PATH_OPTION_ID
73                         && optionID != LOCATION_QUERY_OPTION_ID)
74                 {
75                     throw OCException(OC::Exception::OPTION_ID_RANGE_INVALID);
76                 }
77             }
78
79             virtual ~OCHeaderOption(){}
80
81             OCHeaderOption(const OCHeaderOption&) = default;
82
83 #if defined(_MSC_VER) && (_MSC_VER < 1900)
84             OCHeaderOption(OCHeaderOption&& o)
85             {
86                 std::memmove(this, &o, sizeof(o));
87             }
88 #else
89             OCHeaderOption(OCHeaderOption&&) = default;
90 #endif
91
92             OCHeaderOption& operator=(const OCHeaderOption&) = default;
93
94 #if defined(_MSC_VER) && (_MSC_VER < 1900)
95             OCHeaderOption& operator=(OCHeaderOption&& o)
96             {
97                 std::memmove(this, &o, sizeof(o));
98             }
99 #else
100             OCHeaderOption& operator=(OCHeaderOption&&) = default;
101 #endif
102
103             /**
104             * API to get Option ID
105             * @return unsigned integer option ID
106             */
107             uint16_t getOptionID() const
108             {
109                 return m_optionID;
110             }
111
112             /*
113             * API to get Option data
114             * @return std::string of option data
115             */
116             std::string getOptionData() const
117             {
118                 return m_optionData;
119             }
120         };
121     } // namespace HeaderOption
122 } // namespace OC
123
124 #endif // OC_HEADEROPTION_H_