Imported Upstream version 1.1.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         *            HeaderOptions instance creation fails if above condition is not satisfied.
45         */
46         const uint16_t MIN_HEADER_OPTIONID = 2048;
47         const uint16_t MAX_HEADER_OPTIONID = 3000;
48
49         class OCHeaderOption
50         {
51         private:
52             uint16_t m_optionID;
53             std::string m_optionData;
54
55         public:
56             /**
57             * OCHeaderOption constructor
58             */
59             OCHeaderOption(uint16_t optionID, std::string optionData):
60                 m_optionID(optionID),
61                 m_optionData(optionData)
62             {
63                 if(!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID))
64                 {
65                     throw OCException(OC::Exception::OPTION_ID_RANGE_INVALID);
66                 }
67             }
68
69             virtual ~OCHeaderOption(){}
70
71             OCHeaderOption(const OCHeaderOption&) = default;
72
73             OCHeaderOption(OCHeaderOption&&) = default;
74
75             OCHeaderOption& operator=(const OCHeaderOption&) = default;
76
77             OCHeaderOption& operator=(OCHeaderOption&&) = default;
78
79             /**
80             * API to get Option ID
81             * @return unsigned integer option ID
82             */
83             uint16_t getOptionID() const
84             {
85                 return m_optionID;
86             }
87
88             /*
89             * API to get Option data
90             * @return std::string of option data
91             */
92             std::string getOptionData() const
93             {
94                 return m_optionData;
95             }
96         };
97     } // namespace HeaderOption
98 } // namespace OC
99
100 #endif // OC_HEADEROPTION_H_