2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "CAudioIODef.h"
24 using namespace tizen_media_audio;
30 CAudioError::EError CAudioError::__mLastError = CAudioError::EError::ERROR_NONE;
31 char CAudioError::__mLastErrorMsg[CAudioError::MSG_LENGTH];
33 CAudioError::CAudioError(EError err) :
35 __mLastError = __mError;
38 CAudioError::CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum) :
40 __mLastError = __mError;
42 const char* findFileName = strrchr(fileName, '/');
44 const char* errStr = __convertErrorToString(__mError);
46 snprintf(__mErrorMsg, CAudioError::MSG_LENGTH, "["
47 COLOR_RED "THROW" COLOR_END ":%s|"
48 COLOR_YELLOW "ERR" COLOR_END ":%s|"
49 COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]", findFileName, errStr, parentFunc, lineNum);
51 snprintf(__mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", __mErrorMsg);
54 CAudioError::CAudioError(EError err, const char* msg, const char* fileName, const char* parentFunc, int lineNum) :
56 __mLastError = __mError;
58 const char* findFileName = strrchr(fileName, '/');
60 const char* errStr = __convertErrorToString(__mError);
62 snprintf(__mErrorMsg, CAudioError::MSG_LENGTH, "["
63 COLOR_RED "THROW" COLOR_END ":%s|"
64 COLOR_YELLOW "ERR" COLOR_END ":%s|"
65 COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]"
66 COLOR_YELLOW "MSG" COLOR_END ":"
67 COLOR_CYAN "%s" COLOR_END, findFileName, errStr, parentFunc, lineNum, msg);
69 snprintf(__mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", __mErrorMsg);
72 //CAudioError::CAudioError(CAudioError& err) {
73 // __mError = err.__mError;
74 // strncpy(__mErrorMsg, err.__mErrorMsg, MSG_LENGTH);
77 CAudioError::~CAudioError() {
80 const char* CAudioError::__convertErrorToString(EError err) {
83 case EError::ERROR_NONE: return COLOR_GREEN "ERROR_NONE" COLOR_END;
84 case EError::ERROR_INVALID_ARGUMENT: return COLOR_RED "ERROR_INVALID_ARGUMENT" COLOR_END;
85 case EError::ERROR_INVALID_HANDLE: return COLOR_RED "ERROR_INVALID_HANDLE" COLOR_END;
86 case EError::ERROR_INVALID_SAMPLERATE: return COLOR_RED "ERROR_INVALID_SAMPLERATE" COLOR_END;
87 case EError::ERROR_INVALID_CHANNEL: return COLOR_RED "ERROR_INVALID_CHANNEL" COLOR_END;
88 case EError::ERROR_INVALID_FORMAT: return COLOR_RED "ERROR_INVALID_FORMAT" COLOR_END;
89 case EError::ERROR_INVALID_POINTER: return COLOR_RED "ERROR_INVALID_POINTER" COLOR_END;
90 case EError::ERROR_INVALID_OPERATION: return COLOR_RED "ERROR_INVALID_OPERATION" COLOR_END;
91 case EError::ERROR_NOT_INITIALIZED: return COLOR_RED "ERROR_NOT_INITIALIZED" COLOR_END;
92 case EError::ERROR_NOT_SUPPORTED: return COLOR_RED "ERROR_NOT_SUPPORTED" COLOR_END;
93 case EError::ERROR_NOT_SUPPORTED_TYPE: return COLOR_RED "ERROR_NOT_SUPPORTED_TYPE" COLOR_END;
94 case EError::ERROR_PERMISSION_DENIED: return COLOR_RED "ERROR_PERMISSION_DENIED" COLOR_END;
95 case EError::ERROR_DEVICE_NOT_OPENED: return COLOR_RED "ERROR_DEVICE_NOT_OPENED" COLOR_END;
96 case EError::ERROR_DEVICE_NOT_CLOSED: return COLOR_RED "ERROR_DEVICE_NOT_CLOSED" COLOR_END;
97 case EError::ERROR_OUT_OF_MEMORY: return COLOR_RED "ERROR_OUT_OF_MEMORY" COLOR_END;
98 case EError::ERROR_INTERNAL_OPERATION: return COLOR_RED "ERROR_INTERNAL_OPERATION" COLOR_END;
99 case EError::ERROR_FAILED_OPERATION: return COLOR_RED "ERROR_FAILED_OPERATION" COLOR_END;
100 case EError::ERROR_POLICY_BLOCKED: return COLOR_RED "ERROR_POLICY_BLOCKED" COLOR_END;
101 case EError::ERROR_POLICY_INTERRUPTED: return COLOR_RED "ERROR_POLICY_INTERRUPTED" COLOR_END;
102 case EError::ERROR_POLICY_DUPLICATED: return COLOR_RED "ERROR_POLICY_DUPLICATED" COLOR_END;
106 CAudioError::EError CAudioError::getLastError() {
110 const char* CAudioError::getLastErrorMsg() {
111 return __mLastErrorMsg;
114 CAudioError::EError CAudioError::getError() {
118 const char* CAudioError::getErrorMsg() {
122 CAudioError& CAudioError::operator = (const EError err) {
124 __mLastError = __mError;
128 CAudioError& CAudioError::operator = (const CAudioError& err) {
129 __mError = err.__mError;
130 __mLastError = __mError;
131 memcpy(__mErrorMsg, err.__mErrorMsg, MSG_LENGTH);
132 memcpy(__mLastErrorMsg, __mErrorMsg, MSG_LENGTH);
136 bool CAudioError::operator != (const EError err) {
137 return (__mError != err);
140 bool CAudioError::operator == (const EError err) {
141 return (__mError == err);
144 //bool operator == (const CAudioError& src, const CAudioError::EError& err) {
145 // //return (src.__mLastError == err);