Use in-class initializer for class members
[platform/core/api/audio-io.git] / src / cpp / CAudioError.cpp
1 /*
2  * Copyright (c) 2015 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 #include <sstream>
18 #include <dlog.h>
19 #include "CAudioIODef.h"
20
21 using namespace std;
22 using namespace tizen_media_audio;
23
24 /**
25  * class CAudioError
26  */
27 CAudioError::CAudioError(EError err, const char* msg, const char* file, const char* func, int line) :
28     __mError(err),
29     __mFullMsg(msg) {
30     ostringstream stringStream;
31
32     stringStream << "[ " << __convertErrorToString(__mError)
33                  << " | "<< file << ": " << func << "(" << line << ") | " << msg << " ]";
34     __mFullMsg = runtime_error{stringStream.str()};
35 }
36
37 const char *CAudioError::what() const noexcept {
38     return __mFullMsg.what();
39 }
40
41 const char* CAudioError::getErrorMsg() const noexcept {
42     return what();
43 }
44
45 CAudioError::EError CAudioError::getError() const noexcept {
46     return __mError;
47 }
48
49 const char* CAudioError::__convertErrorToString(EError err) noexcept {
50     switch (err) {
51     default:
52     case EError::ERROR_NONE:                return COLOR_GREEN "ERROR_NONE"               COLOR_END;
53     case EError::ERROR_INVALID_ARGUMENT:    return COLOR_RED   "ERROR_INVALID_ARGUMENT"   COLOR_END;
54 //LCOV_EXCL_START
55     case EError::ERROR_INVALID_HANDLE:      return COLOR_RED   "ERROR_INVALID_HANDLE"     COLOR_END;
56     case EError::ERROR_INVALID_POINTER:     return COLOR_RED   "ERROR_INVALID_POINTER"    COLOR_END;
57 //LCOV_EXCL_STOP
58     case EError::ERROR_INVALID_OPERATION:   return COLOR_RED   "ERROR_INVALID_OPERATION"  COLOR_END;
59     case EError::ERROR_INVALID_STATE:       return COLOR_RED   "ERROR_INVALID_STATE"      COLOR_END;
60     case EError::ERROR_NOT_INITIALIZED:     return COLOR_RED   "ERROR_NOT_INITIALIZED"    COLOR_END;
61     case EError::ERROR_NOT_SUPPORTED:       return COLOR_RED   "ERROR_NOT_SUPPORTED"      COLOR_END;
62     case EError::ERROR_NOT_SUPPORTED_TYPE:  return COLOR_RED   "ERROR_NOT_SUPPORTED_TYPE" COLOR_END;
63 //LCOV_EXCL_START
64     case EError::ERROR_PERMISSION_DENIED:   return COLOR_RED   "ERROR_PERMISSION_DENIED"  COLOR_END;
65     case EError::ERROR_DEVICE_POLICY_RESTRICTION:   return COLOR_RED   "ERROR_DEVICE_POLICY_RESTRICTION"  COLOR_END;
66     case EError::ERROR_DEVICE_NOT_OPENED:   return COLOR_RED   "ERROR_DEVICE_NOT_OPENED"  COLOR_END;
67     case EError::ERROR_DEVICE_NOT_CLOSED:   return COLOR_RED   "ERROR_DEVICE_NOT_CLOSED"  COLOR_END;
68     case EError::ERROR_OUT_OF_MEMORY:       return COLOR_RED   "ERROR_OUT_OF_MEMORY"      COLOR_END;
69     case EError::ERROR_INTERNAL_OPERATION:  return COLOR_RED   "ERROR_INTERNAL_OPERATION" COLOR_END;
70     case EError::ERROR_FAILED_OPERATION:    return COLOR_RED   "ERROR_FAILED_OPERATION"   COLOR_END;
71     case EError::ERROR_POLICY_BLOCKED:      return COLOR_RED   "ERROR_POLICY_BLOCKED"     COLOR_END;
72     case EError::ERROR_POLICY_INTERRUPTED:  return COLOR_RED   "ERROR_POLICY_INTERRUPTED" COLOR_END;
73     case EError::ERROR_POLICY_DUPLICATED:   return COLOR_RED   "ERROR_POLICY_DUPLICATED"  COLOR_END;
74 //LCOV_EXCL_STOP
75     }
76 }