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) : mError(err) {
37 CAudioError::CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum) : mError(err) {
40 const char* findFileName = strrchr(fileName, '/');
42 const char* errStr = _convertErrorToString(mError);
44 snprintf(mErrorMsg, CAudioError::MSG_LENGTH, "["
45 COLOR_RED "THROW" COLOR_END ":%s|"
46 COLOR_YELLOW "ERR" COLOR_END ":%s|"
47 COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]", findFileName, errStr, parentFunc, lineNum);
49 snprintf(mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", mErrorMsg);
52 CAudioError::CAudioError(EError err, const char* msg, const char* fileName, const char* parentFunc, int lineNum) : mError(err) {
55 const char* findFileName = strrchr(fileName, '/');
57 const char* errStr = _convertErrorToString(mError);
59 snprintf(mErrorMsg, CAudioError::MSG_LENGTH, "["
60 COLOR_RED "THROW" COLOR_END ":%s|"
61 COLOR_YELLOW "ERR" COLOR_END ":%s|"
62 COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]"
63 COLOR_YELLOW "MSG" COLOR_END ":"
64 COLOR_CYAN "%s" COLOR_END, findFileName, errStr, parentFunc, lineNum, msg);
66 snprintf(mLastErrorMsg, CAudioError::MSG_LENGTH, "LastError:%s", mErrorMsg);
69 //CAudioError::CAudioError(CAudioError& err) {
70 // mError = err.mError;
71 // strncpy(mErrorMsg, err.mErrorMsg, MSG_LENGTH);
74 CAudioError::~CAudioError() {
77 const char* CAudioError::_convertErrorToString(EError err) {
81 case ERROR_NONE: return COLOR_GREEN "ERROR_NONE" COLOR_END;
82 case ERROR_INVALID_ARGUMENT: return COLOR_RED "ERROR_INVALID_ARGUMENT" COLOR_END;
83 case ERROR_INVALID_HANDLE: return COLOR_RED "ERROR_INVALID_HANDLE" COLOR_END;
84 case ERROR_INVALID_SAMPLERATE: return COLOR_RED "ERROR_INVALID_SAMPLERATE" COLOR_END;
85 case ERROR_INVALID_CHANNEL: return COLOR_RED "ERROR_INVALID_CHANNEL" COLOR_END;
86 case ERROR_INVALID_FORMAT: return COLOR_RED "ERROR_INVALID_FORMAT" COLOR_END;
87 case ERROR_INVALID_POINTER: return COLOR_RED "ERROR_INVALID_POINTER" COLOR_END;
88 case ERROR_INVALID_OPERATION: return COLOR_RED "ERROR_INVALID_OPERATION" COLOR_END;
89 case ERROR_NOT_INITIALIZED: return COLOR_RED "ERROR_NOT_INITIALIZED" COLOR_END;
90 case ERROR_NOT_SUPPORTED: return COLOR_RED "ERROR_NOT_SUPPORTED" COLOR_END;
91 case ERROR_PERMISSION_DENIED: return COLOR_RED "ERROR_PERMISSION_DENIED" COLOR_END;
92 case ERROR_DEVICE_NOT_OPENED: return COLOR_RED "ERROR_DEVICE_NOT_OPENED" COLOR_END;
93 case ERROR_DEVICE_NOT_CLOSED: return COLOR_RED "ERROR_DEVICE_NOT_CLOSED" COLOR_END;
94 case ERROR_OUT_OF_MEMORY: return COLOR_RED "ERROR_OUT_OF_MEMORY" COLOR_END;
95 case ERROR_INTERNAL_OPERATION: return COLOR_RED "ERROR_INTERNAL_OPERATION" COLOR_END;
96 case ERROR_FAILED_OPERATION: return COLOR_RED "ERROR_FAILED_OPERATION" COLOR_END;
97 case ERROR_POLICY_BLOCKED: return COLOR_RED "ERROR_POLICY_BLOCKED" COLOR_END;
98 case ERROR_POLICY_INTERRUPTED: return COLOR_RED "ERROR_POLICY_INTERRUPTED" COLOR_END;
99 case ERROR_POLICY_DUPLICATED: return COLOR_RED "ERROR_POLICY_DUPLICATED" COLOR_END;
103 CAudioError::EError CAudioError::getLastError() {
107 const char* CAudioError::getLastErrorMsg() {
108 return mLastErrorMsg;
111 CAudioError::EError CAudioError::getError() {
115 const char* CAudioError::getErrorMsg() {
119 CAudioError& CAudioError::operator = (const EError err) {
125 CAudioError& CAudioError::operator = (const CAudioError& err) {
128 memcpy(mErrorMsg, err.mErrorMsg, MSG_LENGTH);
129 memcpy(mLastErrorMsg, mErrorMsg, MSG_LENGTH);
133 bool CAudioError::operator != (const EError err) {
134 return (mError != err);
137 bool CAudioError::operator == (const EError err) {
138 return (mError == err);
141 //bool operator == (const CAudioError& src, const CAudioError::EError& err) {
142 // //return (src.mLastError == err);