a2d65d1043e1a080dab93c3b338a22d726abd84a
[platform/core/security/cynara.git] / src / common / exceptions / InvalidProtocolException.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        InvalidProtocolException.h
18  * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
19  * @version     1.0
20  * @brief       Implementation of InvalidProtocolException
21  */
22
23 #ifndef SRC_COMMON_EXCEPTIONS_INVALIDPROTOCOLEXCEPTION_H_
24 #define SRC_COMMON_EXCEPTIONS_INVALIDPROTOCOLEXCEPTION_H_
25
26 #include <exception>
27 #include <sstream>
28
29 #include "Exception.h"
30
31 namespace Cynara {
32
33 class InvalidProtocolException : public Exception {
34 public:
35     enum ExceptionType {
36         InvalidSignature,
37         WrongOpCode,
38         Other
39     };
40
41 private:
42     std::string m_whatMessage;
43     ExceptionType m_exceptionType;
44
45 public:
46     InvalidProtocolException(ExceptionType exceptionType) :
47         m_exceptionType(exceptionType) {
48         switch(m_exceptionType) {
49             case InvalidSignature:
50                 m_whatMessage = "No valid signature found";
51                 break;
52             case WrongOpCode:
53                 m_whatMessage = "Wrong request code";
54                 break;
55             case Other:
56                 m_whatMessage = "Unknown problem";
57                 break;
58         }
59
60     }
61
62     virtual ~InvalidProtocolException() = default;
63
64     virtual const std::string message(void) const {
65         return m_whatMessage;
66     }
67
68     ExceptionType exceptionTyp(void) const {
69         return m_exceptionType;
70     }
71 };
72
73 } // namespace Cynara
74
75 #endif /* SRC_COMMON_EXCEPTIONS_INVALIDPROTOCOLEXCEPTION_H_ */