b15134a1df033a11587b8bb610006833b7000821
[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 missingType,
35                 bool missingInterface,
36                 bool missingClientWrapper,
37                 bool invalidPort,
38                 bool invalidIp)
39         : m_whatMessage(),
40           m_missingUri(missingUri),
41           m_missingType(missingType),
42           m_missingInterface(missingInterface),
43           m_missingClientWrapper(missingClientWrapper),
44           m_invalidPort(invalidPort),
45           m_invalidIp(invalidIp)
46         {
47             if(isUriMissing())
48             {
49                 m_whatMessage += OC::InitException::MISSING_URI;
50             }
51
52             if(isTypeMissing())
53             {
54                 m_whatMessage += OC::InitException::MISSING_TYPE;
55             }
56
57             if(isInterfaceMissing())
58             {
59                 m_whatMessage += OC::InitException::MISSING_INTERFACE;
60             }
61
62             if(isClientWrapperMissing())
63             {
64                 m_whatMessage += OC::InitException::MISSING_CLIENT_WRAPPER;
65             }
66
67             if(isInvalidPort())
68             {
69                 m_whatMessage += OC::InitException::INVALID_PORT;
70             }
71
72             if(isInvalidIp())
73             {
74                 m_whatMessage += OC::InitException::INVALID_IP;
75             }
76         }
77
78         virtual ~ResourceInitException() throw() {}
79
80         bool isInvalidPort() const
81         {
82             return m_invalidPort;
83         }
84
85         bool isInvalidIp() const
86         {
87             return m_invalidIp;
88         }
89
90         bool isClientWrapperMissing() const
91         {
92             return m_missingClientWrapper;
93         }
94
95         bool isUriMissing() const
96         {
97             return m_missingUri;
98         }
99
100         bool isTypeMissing() const
101         {
102             return m_missingType;
103         }
104
105         bool isInterfaceMissing() const
106         {
107             return m_missingInterface;
108         }
109
110         virtual const char* what() const BOOST_NOEXCEPT
111         {
112             return m_whatMessage.c_str();
113         }
114
115     private:
116         std::string m_whatMessage;
117         bool m_missingUri;
118         bool m_missingType;
119         bool m_missingInterface;
120         bool m_missingClientWrapper;
121         bool m_invalidPort;
122         bool m_invalidIp;
123     };
124 }
125
126 #endif