Merge branch 'plugin-interface' into master
[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 namespace OIC
34 {
35     namespace Service
36     {
37
38         /**
39          * The base exception class for resource encapsulation.
40          *
41          */
42         class RCSException: public std::exception
43         {
44         public:
45
46             /**
47              * Constructs an exception with an empty description.
48              */
49             RCSException();
50
51             /**
52              * Constructs an exception with a description.
53              *
54              * @param what The description for the error.
55              */
56             explicit RCSException(const std::string &what);
57
58             /**
59              * @overload
60              */
61             explicit RCSException(std::string &&what);
62
63             virtual ~RCSException() noexcept;
64
65             /**
66              * Returns the exception description.
67              *
68              */
69             virtual const char *what() const noexcept;
70
71         private:
72             /**
73              *  Exception description
74              */
75             const std::string m_what;
76         };
77
78         /**
79          * Thrown when OC layer returns an error.
80          *
81          */
82         class RCSPlatformException: public RCSException
83         {
84         public:
85             explicit RCSPlatformException(OCStackResult reason);
86
87             /**
88              * Returns the reason.
89              *
90              */
91             OCStackResult getReasonCode() const;
92
93             /**
94              * Returns the reason description.
95              *
96              */
97             std::string getReason() const;
98
99         private:
100             OCStackResult m_reason;
101         };
102
103         /**
104          * Thrown when a request is not acceptable.
105          *
106          */
107         class RCSBadRequestException: public RCSException
108         {
109         public:
110             explicit RCSBadRequestException(const std::string& what);
111             explicit RCSBadRequestException(std::string&& what);
112         };
113
114         /**
115          * Thrown when a parameter is not valid.
116          *
117          */
118         class RCSInvalidParameterException: public RCSException
119         {
120         public:
121             explicit RCSInvalidParameterException(const std::string& what);
122             explicit RCSInvalidParameterException(std::string&& what);
123         };
124
125         /**
126          * Thrown when getting value with wrong template parameter.
127          */
128         class RCSBadGetException: public RCSException
129         {
130         public:
131             explicit RCSBadGetException(const std::string& what);
132             explicit RCSBadGetException(std::string&& what);
133         };
134
135         /**
136          * Thrown when a key is invalid.
137          *
138          */
139         class RCSInvalidKeyException: public RCSException
140         {
141         public:
142             explicit RCSInvalidKeyException(const std::string& what);
143             explicit RCSInvalidKeyException(std::string&& what);
144         };
145
146     }
147 }
148
149 #endif // RES_ENCAPSULATION_RCSEXCEPTION_H