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