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