RIC:1060: Change in PTL
[ric-plt/sdl.git] / include / private / error.hpp
1 /*
2    Copyright (c) 2018-2019 Nokia.
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 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_ERROR_HPP_
23 #define SHAREDDATALAYER_ERROR_HPP_
24
25 #include <system_error>
26
27 /* Error codes defined here are for SDL internal usage only.
28  * Error codes meant to be used by SDL clients are defined in sdl/errorqueries.hpp.
29  *
30  * Error code handling in SDL goes following way:
31  *
32  * - Implementation sets so called implementation specific error codes (e.g AsyncRedisCommandDispatcherErrorCode
33  *   and AsyncRedisConnection::ErrorCode).
34  * - All implementation specific error codes have mapping to InternalErrors. This mapping is handled by overriding
35  *   std::error_category default_error_condition function in all implementation specific error code categories.
36  * - All InternalErrors are mapped to shareddatalayer::Errors which SDL client can conveniently use in
37  *   its error handling implemention. This mapping is handled by overriding std::error_category equivalent function in
38  *   SharedDataLayerErrorCategory.
39  * - Async API error codes have corresponding exceptions in sync API. When modifying other one (async API error codes or
40  *   sync API exceptions) check the need for similar modification to other one also.
41  *
42  * When adding a new implementation specific error code, do also needed updates to mappings described above.
43  * At least mapping from new implementation specific error code error code to InternalError is always needed.
44  */
45
46 namespace shareddatalayer
47 {
48     enum class InternalError
49     {
50         SUCCESS = 0,
51         SDL_NOT_READY,
52         SDL_NOT_CONNECTED_TO_BACKEND,
53         SDL_ERROR_CODE_LOGIC_ERROR,
54         SDL_RECEIVED_INVALID_PARAMETER,
55         BACKEND_CONNECTION_LOST,
56         BACKEND_NOT_READY,
57         BACKEND_REJECTED_REQUEST,
58         BACKEND_ERROR
59     };
60
61     std::error_condition make_error_condition(shareddatalayer::InternalError ec);
62
63     namespace redis
64     {
65         enum class AsyncRedisCommandDispatcherErrorCode
66         {
67             SUCCESS = 0,
68             UNKNOWN_ERROR,
69             CONNECTION_LOST,
70             PROTOCOL_ERROR,
71             OUT_OF_MEMORY,
72             DATASET_LOADING,
73             NOT_CONNECTED,
74             IO_ERROR,
75             WRITING_TO_SLAVE,
76             //Keep this always as last item. Used in unit tests to loop all enum values.
77             END_MARKER
78         };
79
80         std::error_code make_error_code(AsyncRedisCommandDispatcherErrorCode errorCode);
81         AsyncRedisCommandDispatcherErrorCode& operator++ (AsyncRedisCommandDispatcherErrorCode& ecEnum);
82     }
83 }
84
85 namespace std
86 {
87     template <>
88     struct is_error_condition_enum<shareddatalayer::InternalError> : public true_type { };
89
90     template <>
91     struct is_error_code_enum<shareddatalayer::redis::AsyncRedisCommandDispatcherErrorCode>: public true_type { };
92 }
93
94 #endif