Merge "Enabling Multiple Interfaces in CStack." into connectivity-abstraction
[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
62 // TODO-CA Remove this (for some reason optionID is coming to be zero)
63 #ifndef CA_INT
64                 if(!(optionID >= MIN_HEADER_OPTIONID && optionID <= MAX_HEADER_OPTIONID))
65                 {
66                     throw OCException(OC::Exception::OPTION_ID_RANGE_INVALID);
67                 }
68 #endif
69             }
70
71             /**
72             * API to get Option ID
73             * @return unsigned integer option ID
74             */
75             uint16_t getOptionID() const
76             {
77                 return m_optionID;
78             }
79
80             /*
81             * API to get Option data
82             * @return std::string of option data
83             */
84             std::string getOptionData() const
85             {
86                 return m_optionData;
87             }
88         };
89     } // namespace HeaderOption
90 } // namespace OC
91
92 #endif //__OCHEADEROPTION_H