Add more excludes
[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 <stdio.h>
18 #include <string.h>
19 #include <dlog.h>
20 #include "CAudioIODef.h"
21
22
23 using namespace std;
24 using namespace tizen_media_audio;
25
26
27 /**
28  * class CAudioError
29  */
30 CAudioError::EError CAudioError::__mLastError = CAudioError::EError::ERROR_NONE;
31 char CAudioError::__mLastErrorMsg[CAudioError::MSG_LENGTH];
32
33 //LCOV_EXCL_START
34 CAudioError::CAudioError(EError err) :
35     __mError(err) {
36     __mLastError = __mError;
37 }
38
39 CAudioError::CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum) :
40     __mError(err) {
41     __mLastError = __mError;
42
43     const char* findFileName = strrchr(fileName, '/');
44     if (findFileName)
45         findFileName++;
46     const char* errStr = __convertErrorToString(__mError);
47
48     snprintf(__mErrorMsg, CAudioError::MSG_LENGTH, "["
49             COLOR_RED    "THROW" COLOR_END ":%s|"
50             COLOR_YELLOW "ERR"    COLOR_END ":%s|"
51             COLOR_YELLOW "FUNC"   COLOR_END ":%s(%d)]", findFileName, errStr, parentFunc, lineNum);
52
53     snprintf(__mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", __mErrorMsg);
54 }
55 //LCOV_EXCL_STOP
56
57 CAudioError::CAudioError(EError err, const char* msg, const char* fileName, const char* parentFunc, int lineNum) :
58     __mError(err) {
59     __mLastError = __mError;
60
61     const char* findFileName = strrchr(fileName, '/');
62     if (findFileName)
63         findFileName++;
64     const char* errStr = __convertErrorToString(__mError);
65
66     snprintf(__mErrorMsg, CAudioError::MSG_LENGTH, "["
67             COLOR_RED    "THROW" COLOR_END ":%s|"
68             COLOR_YELLOW "ERR"    COLOR_END ":%s|"
69             COLOR_YELLOW "FUNC"   COLOR_END ":%s(%d)]"
70             COLOR_YELLOW "MSG"    COLOR_END ":"
71             COLOR_CYAN   "%s"     COLOR_END, findFileName, errStr, parentFunc, lineNum, msg);
72
73     snprintf(__mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", __mErrorMsg);
74 }
75
76 //LCOV_EXCL_START
77 CAudioError::CAudioError(const CAudioError& err) {
78     __mError = err.__mError;
79     memcpy(__mErrorMsg, err.__mErrorMsg, MSG_LENGTH);
80 }
81 //LCOV_EXCL_STOP
82
83 CAudioError::~CAudioError() {
84 }
85
86 const char* CAudioError::__convertErrorToString(EError err) {
87     switch (err) {
88     default:
89     case EError::ERROR_NONE:                return COLOR_GREEN "ERROR_NONE"               COLOR_END;
90     case EError::ERROR_INVALID_ARGUMENT:    return COLOR_RED   "ERROR_INVALID_ARGUMENT"   COLOR_END;
91 //LCOV_EXCL_START
92     case EError::ERROR_INVALID_HANDLE:      return COLOR_RED   "ERROR_INVALID_HANDLE"     COLOR_END;
93     case EError::ERROR_INVALID_SAMPLERATE:  return COLOR_RED   "ERROR_INVALID_SAMPLERATE" COLOR_END;
94     case EError::ERROR_INVALID_CHANNEL:     return COLOR_RED   "ERROR_INVALID_CHANNEL"    COLOR_END;
95     case EError::ERROR_INVALID_FORMAT:      return COLOR_RED   "ERROR_INVALID_FORMAT"     COLOR_END;
96     case EError::ERROR_INVALID_POINTER:     return COLOR_RED   "ERROR_INVALID_POINTER"    COLOR_END;
97 //LCOV_EXCL_STOP
98     case EError::ERROR_INVALID_OPERATION:   return COLOR_RED   "ERROR_INVALID_OPERATION"  COLOR_END;
99     case EError::ERROR_INVALID_STATE:       return COLOR_RED   "ERROR_INVALID_STATE"      COLOR_END;
100     case EError::ERROR_NOT_INITIALIZED:     return COLOR_RED   "ERROR_NOT_INITIALIZED"    COLOR_END;
101     case EError::ERROR_NOT_SUPPORTED:       return COLOR_RED   "ERROR_NOT_SUPPORTED"      COLOR_END;
102     case EError::ERROR_NOT_SUPPORTED_TYPE:  return COLOR_RED   "ERROR_NOT_SUPPORTED_TYPE" COLOR_END;
103 //LCOV_EXCL_START
104     case EError::ERROR_PERMISSION_DENIED:   return COLOR_RED   "ERROR_PERMISSION_DENIED"  COLOR_END;
105     case EError::ERROR_DEVICE_POLICY_RESTRICTION:   return COLOR_RED   "ERROR_DEVICE_POLICY_RESTRICTION"  COLOR_END;
106     case EError::ERROR_DEVICE_NOT_OPENED:   return COLOR_RED   "ERROR_DEVICE_NOT_OPENED"  COLOR_END;
107     case EError::ERROR_DEVICE_NOT_CLOSED:   return COLOR_RED   "ERROR_DEVICE_NOT_CLOSED"  COLOR_END;
108     case EError::ERROR_OUT_OF_MEMORY:       return COLOR_RED   "ERROR_OUT_OF_MEMORY"      COLOR_END;
109     case EError::ERROR_INTERNAL_OPERATION:  return COLOR_RED   "ERROR_INTERNAL_OPERATION" COLOR_END;
110     case EError::ERROR_FAILED_OPERATION:    return COLOR_RED   "ERROR_FAILED_OPERATION"   COLOR_END;
111     case EError::ERROR_POLICY_BLOCKED:      return COLOR_RED   "ERROR_POLICY_BLOCKED"     COLOR_END;
112     case EError::ERROR_POLICY_INTERRUPTED:  return COLOR_RED   "ERROR_POLICY_INTERRUPTED" COLOR_END;
113     case EError::ERROR_POLICY_DUPLICATED:   return COLOR_RED   "ERROR_POLICY_DUPLICATED"  COLOR_END;
114 //LCOV_EXCL_STOP
115     }
116 }
117
118 //LCOV_EXCL_START
119 CAudioError::EError CAudioError::getLastError() {
120     return __mLastError;
121 }
122
123 const char* CAudioError::getLastErrorMsg() {
124     return __mLastErrorMsg;
125 }
126 //LCOV_EXCL_STOP
127
128 CAudioError::EError CAudioError::getError() {
129     return __mError;
130 }
131
132 const char* CAudioError::getErrorMsg() {
133     return __mErrorMsg;
134 }
135
136 //LCOV_EXCL_START
137 CAudioError& CAudioError::operator = (const EError err) {
138     __mError = err;
139     __mLastError = __mError;
140     return *this;
141 }
142
143 CAudioError& CAudioError::operator = (const CAudioError& err) {
144     __mError = err.__mError;
145     __mLastError = __mError;
146     memcpy(__mErrorMsg, err.__mErrorMsg, MSG_LENGTH);
147     memcpy(__mLastErrorMsg, __mErrorMsg, MSG_LENGTH);
148     return *this;
149 }
150
151 bool CAudioError::operator != (const EError err) {
152     return (__mError != err);
153 }
154
155 bool CAudioError::operator == (const EError err) {
156     return (__mError == err);
157 }
158 //LCOV_EXCL_STOP
159
160 //bool operator == (const CAudioError& src, const CAudioError::EError& err) {
161 //    //return (src.__mLastError == err);
162 //    return true;
163 //}