Added API for setting representation in RCS Client of Resource Encapsulation.
[platform/upstream/iotivity.git] / service / resource-encapsulation / include / RCSException.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 exception classes for resource-encapsulation
25  */
26 #ifndef RES_ENCAPSULATION_RCSEXCEPTION_H
27 #define RES_ENCAPSULATION_RCSEXCEPTION_H
28
29 #include <string>
30
31 #include <octypes.h>
32
33 #include "boost/config.hpp"
34
35 namespace OIC
36 {
37     namespace Service
38     {
39
40         /**
41          * The base exception class for resource encapsulation.
42          *
43          */
44         class RCSException: public std::exception
45         {
46         public:
47
48             /**
49              * Constructs an exception with an empty description.
50              *
51              * @see RCSException(const std::string &)
52              * @see RCSException(std::string &&)
53              */
54             RCSException();
55
56             /**
57              * Constructs an exception with a description.
58              * @overload
59              * @param what The description for the error.
60              * @see RCSException()
61              * @see RCSException(std::string &&)
62              */
63             explicit RCSException(const std::string &what);
64
65             /**
66              * @overload
67              *
68              * @param what The description for the error.
69              * @see RCSException()
70              * @see RCSException(const std::string &)
71              */
72             explicit RCSException(std::string &&what);
73
74             virtual ~RCSException() BOOST_NOEXCEPT;
75
76             /**
77              * Returns the exception description.
78              *
79              */
80             virtual const char *what() const BOOST_NOEXCEPT;
81
82         private:
83             /**
84              *  Exception description
85              */
86             const std::string m_what;
87         };
88
89         /**
90          * Thrown when OC layer returns an error.
91          *
92          */
93         class RCSPlatformException: public RCSException
94         {
95         public:
96             explicit RCSPlatformException(OCStackResult reason);
97
98             /**
99              * Returns the reason.
100              *
101              */
102             OCStackResult getReasonCode() const;
103
104             /**
105              * Returns the reason description.
106              *
107              */
108             std::string getReason() const;
109
110         private:
111             OCStackResult m_reason;
112         };
113
114         /**
115          * Thrown when a request is not acceptable.
116          *
117          */
118         class RCSBadRequestException: public RCSException
119         {
120         public:
121             explicit RCSBadRequestException(const std::string& what);
122             explicit RCSBadRequestException(std::string&& what);
123         };
124
125         /**
126          * Thrown when a parameter is not valid.
127          *
128          */
129         class RCSInvalidParameterException: public RCSException
130         {
131         public:
132             explicit RCSInvalidParameterException(const std::string& what);
133             explicit RCSInvalidParameterException(std::string&& what);
134         };
135
136         /**
137          * Thrown when getting value with wrong template parameter.
138          */
139         class RCSBadGetException: public RCSException
140         {
141         public:
142             explicit RCSBadGetException(const std::string& what);
143             explicit RCSBadGetException(std::string&& what);
144         };
145
146         /**
147          * Thrown when a key is invalid.
148          *
149          */
150         class RCSInvalidKeyException: public RCSException
151         {
152         public:
153             explicit RCSInvalidKeyException(const std::string& what);
154             explicit RCSInvalidKeyException(std::string&& what);
155         };
156
157     }
158 }
159
160 #endif // RES_ENCAPSULATION_RCSEXCEPTION_H