31517c5de50ccc960a428f9248e748b1a2bd590b
[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 /// @file OCHeaderOption.h
22
23 /// @brief  This file contains the declaration of classes and its members related to
24 ///         OCHeaderOption.
25
26 #ifndef __OCHEADEROPTION_H
27 #define __OCHEADEROPTION_H
28
29 #include <OCException.h>
30 #include <StringConstants.h>
31 namespace OC
32 {
33     namespace HeaderOption
34     {
35         /**
36         *     @brief OCHeaderOption class allows to create instances which comprises optionID
37         *            and optionData as members. These are used in setting Header options.
38         *            After creating instances of OCHeaderOptions, use setHeaderOptions API
39         *            (in OCResource.h) to set header Options.
40         *            NOTE: HeaderOptionID  is an unsigned integer value which MUST be within
41         *            range of 2048 to 3000 inclusive of lower and upper bound.
42         *            HeaderOptions instance creation fails if above condition is not satisfied.
43         */
44         const uint16_t MIN_HEADER_OPTIONID = 2048;
45         const uint16_t MAX_HEADER_OPTIONID = 3000;
46
47         class OCHeaderOption
48         {
49         private:
50             uint16_t m_optionID;
51             std::string m_optionData;
52
53         public:
54             /**
55             * OCHeaderOption constructor
56             */
57             OCHeaderOption(uint16_t optionID, std::string optionData):
58                 m_optionID(optionID),
59                 m_optionData(optionData)
60             {
61                 if(!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID))
62                 {
63                     throw OCException(OC::Exception::OPTION_ID_RANGE_INVALID);
64                 }
65             }
66
67             /**
68             * API to get Option ID
69             * @return unsigned integer option ID
70             */
71             uint16_t getOptionID() const
72             {
73                 return m_optionID;
74             }
75
76             /*
77             * API to get Option data
78             * @return std::string of option data
79             */
80             std::string getOptionData() const
81             {
82                 return m_optionData;
83             }
84         };
85     } // namespace HeaderOption
86 } // namespace OC
87
88 #endif //__OCHEADEROPTION_H