replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / include / ResourceInitException.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 #ifndef OC_RESOURCE_INIT_EXCEPTION_H_
22 #define OC_RESOURCE_INIT_EXCEPTION_H_
23
24 #include <stdexcept>
25 #include "StringConstants.h"
26
27 namespace OC
28 {
29     class ResourceInitException : public std::exception
30     {
31     public:
32         ResourceInitException(
33                 bool missingUri,
34                 bool invalidUri,
35                 bool missingType,
36                 bool missingInterface,
37                 bool missingClientWrapper,
38                 bool invalidPort,
39                 bool invalidIp,
40                 bool invalidHost)
41         : m_missingUri(missingUri),
42           m_invalidUri(invalidUri),
43           m_missingType(missingType),
44           m_missingInterface(missingInterface),
45           m_missingClientWrapper(missingClientWrapper),
46           m_invalidPort(invalidPort),
47           m_invalidIp(invalidIp),
48           m_invalidHost(invalidHost)
49         {
50         }
51
52         bool isInvalidPort() const
53         {
54             return m_invalidPort;
55         }
56
57         bool isInvalidIp() const
58         {
59             return m_invalidIp;
60         }
61
62         bool isInvalidHost() const
63         {
64             return m_invalidHost;
65         }
66
67         bool isClientWrapperMissing() const
68         {
69             return m_missingClientWrapper;
70         }
71
72         bool isUriMissing() const
73         {
74             return m_missingUri;
75         }
76
77         bool isInvalidUri() const
78         {
79             return m_invalidUri;
80         }
81
82         bool isTypeMissing() const
83         {
84             return m_missingType;
85         }
86
87         bool isInterfaceMissing() const
88         {
89             return m_missingInterface;
90         }
91
92         virtual const char* what() const BOOST_NOEXCEPT
93         {
94             std::string ret;
95
96             if(isUriMissing())
97             {
98                 ret += OC::InitException::MISSING_URI;
99             }
100             else if(isInvalidUri())
101             {
102                 ret += OC::InitException::INVALID_URI;
103             }
104
105             if(isTypeMissing())
106             {
107                 ret += OC::InitException::MISSING_TYPE;
108             }
109
110             if(isInterfaceMissing())
111             {
112                 ret += OC::InitException::MISSING_INTERFACE;
113             }
114
115             if(isClientWrapperMissing())
116             {
117                 ret += OC::InitException::MISSING_CLIENT_WRAPPER;
118             }
119
120             if(isInvalidPort())
121             {
122                 ret += OC::InitException::INVALID_PORT;
123             }
124
125             if(isInvalidIp())
126             {
127                 ret += OC::InitException::INVALID_IP;
128             }
129
130             if(isInvalidHost())
131             {
132                 ret += OC::InitException::INVALID_HOST;
133             }
134
135             return ret.c_str();
136         }
137
138     private:
139
140         bool m_missingUri;
141         bool m_invalidUri;
142         bool m_missingType;
143         bool m_missingInterface;
144         bool m_missingClientWrapper;
145         bool m_invalidPort;
146         bool m_invalidIp;
147         bool m_invalidHost;
148     };
149 }
150
151 #endif