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::ERROR_NONE;
31 char CAudioError::mLastErrorMsg[CAudioError::MSG_LENGTH];
33 CAudioError::CAudioError(EError err) :
38 CAudioError::CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum) :
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) :
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 ERROR_NONE: return COLOR_GREEN "ERROR_NONE" COLOR_END;
84 case ERROR_INVALID_ARGUMENT: return COLOR_RED "ERROR_INVALID_ARGUMENT" COLOR_END;
85 case ERROR_INVALID_HANDLE: return COLOR_RED "ERROR_INVALID_HANDLE" COLOR_END;
86 case ERROR_INVALID_SAMPLERATE: return COLOR_RED "ERROR_INVALID_SAMPLERATE" COLOR_END;
87 case ERROR_INVALID_CHANNEL: return COLOR_RED "ERROR_INVALID_CHANNEL" COLOR_END;
88 case ERROR_INVALID_FORMAT: return COLOR_RED "ERROR_INVALID_FORMAT" COLOR_END;
89 case ERROR_INVALID_POINTER: return COLOR_RED "ERROR_INVALID_POINTER" COLOR_END;
90 case ERROR_INVALID_OPERATION: return COLOR_RED "ERROR_INVALID_OPERATION" COLOR_END;
91 case ERROR_NOT_INITIALIZED: return COLOR_RED "ERROR_NOT_INITIALIZED" COLOR_END;
92 case ERROR_NOT_SUPPORTED: return COLOR_RED "ERROR_NOT_SUPPORTED" COLOR_END;
93 case ERROR_NOT_SUPPORTED_TYPE: return COLOR_RED "ERROR_NOT_SUPPORTED_TYPE" COLOR_END;
94 case ERROR_PERMISSION_DENIED: return COLOR_RED "ERROR_PERMISSION_DENIED" COLOR_END;
95 case ERROR_DEVICE_NOT_OPENED: return COLOR_RED "ERROR_DEVICE_NOT_OPENED" COLOR_END;
96 case ERROR_DEVICE_NOT_CLOSED: return COLOR_RED "ERROR_DEVICE_NOT_CLOSED" COLOR_END;
97 case ERROR_OUT_OF_MEMORY: return COLOR_RED "ERROR_OUT_OF_MEMORY" COLOR_END;
98 case ERROR_INTERNAL_OPERATION: return COLOR_RED "ERROR_INTERNAL_OPERATION" COLOR_END;
99 case ERROR_FAILED_OPERATION: return COLOR_RED "ERROR_FAILED_OPERATION" COLOR_END;
100 case ERROR_POLICY_BLOCKED: return COLOR_RED "ERROR_POLICY_BLOCKED" COLOR_END;
101 case ERROR_POLICY_INTERRUPTED: return COLOR_RED "ERROR_POLICY_INTERRUPTED" COLOR_END;
102 case 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) {
128 CAudioError& CAudioError::operator = (const CAudioError& err) {
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);