From 1451d425ee207a9ca88a04e5dfef1e7d9c2e3340 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 23 Aug 2019 14:34:55 +0900 Subject: [PATCH] Revise CAudioError to derive std::exception catch error by const reference Change-Id: Ied91d1ea47de3e899466a6a23b787729ad13db81 --- include/CAudioError.h | 52 ++++++------- include/CAudioIODef.h | 17 +---- src/cpp/CAudioError.cpp | 114 +++++------------------------ src/cpp/CAudioIO.cpp | 8 +- src/cpp/CAudioInput.cpp | 8 +- src/cpp/CAudioOutput.cpp | 8 +- src/cpp/CPulseAudioClient.cpp | 10 +-- src/cpp/cpp_audio_io.cpp | 165 +++++++++++++++++++++--------------------- 8 files changed, 143 insertions(+), 239 deletions(-) diff --git a/include/CAudioError.h b/include/CAudioError.h index 0c0bc8a..b508fe8 100644 --- a/include/CAudioError.h +++ b/include/CAudioError.h @@ -20,14 +20,15 @@ #ifdef __cplusplus +#include +#include +#include namespace tizen_media_audio { - - /** * Audio Error */ - class CAudioError { +class CAudioError : public std::exception { public: /* Enums Definition */ enum class EError : unsigned int { @@ -65,34 +66,23 @@ namespace tizen_media_audio { /* Constructor & Destructor */ explicit CAudioError(EError err); - CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum); - CAudioError(EError err, const char* msg, const char* fileName, const char* parentFunc, int lineNum); - CAudioError(const CAudioError& err); - virtual ~CAudioError() = default; - - /* Static Methods */ - static EError getLastError(); - static const char* getLastErrorMsg(); - - /* Setter & Getter */ - EError getError(); - const char* getErrorMsg(); - - /* Overrided Operation */ - CAudioError& operator = (const EError err); - CAudioError& operator = (const CAudioError& err); - bool operator != (const EError err); - bool operator == (const EError err); - //friend bool operator == (const CAudioError& src, const EError& err); - - private: - const char* __convertErrorToString(EError err); - - /* Members */ - static EError __mLastError; - static char __mLastErrorMsg[MSG_LENGTH]; - EError __mError; - char __mErrorMsg[MSG_LENGTH]{}; + CAudioError(EError err, const char* msg, const char* file, const char* func, int line); + ~CAudioError() = default; + + const char *what() const noexcept override { + return __mFullMsg.c_str(); + } + + const char* getErrorMsg() const noexcept; + const EError getError() const noexcept; + +private: + static const char* __convertErrorToString(EError err) noexcept; + + EError __mError; + std::string __mMsg; + std::string __mFullMsg; + }; diff --git a/include/CAudioIODef.h b/include/CAudioIODef.h index b7ce786..d400d43 100644 --- a/include/CAudioIODef.h +++ b/include/CAudioIODef.h @@ -76,24 +76,12 @@ #define COLOR_END #endif - -#define RET_ERROR(_x_) do {return CAudioError((_x_), __FILE__, __func__, __LINE__);} while(0) -#define RET_ERROR_MSG(_x_, _msg_) do {return CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__);} while(0) - -#define RET_ERROR_MSG_FORMAT(_x_, _format_, ...) do { \ - char _msg_[CAudioError::MSG_LENGTH] = {0, }; \ - snprintf(_msg_, CAudioError::MSG_LENGTH, _format_, ##__VA_ARGS__); \ - return CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__); \ -} while (0) - - -#define THROW_ERROR(_x_) do {throw CAudioError((_x_), __FILE__, __func__, __LINE__);} while (0) -#define THROW_ERROR_MSG(_x_, _msg_) do {throw CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__);} while (0) +#define THROW_ERROR_MSG(_x_, _msg_) do {throw CAudioError((_x_), (_msg_), __BASE_FILE__, __func__, __LINE__);} while (0) #define THROW_ERROR_MSG_FORMAT(_x_, _format_, ...) do { \ char _msg_[CAudioError::MSG_LENGTH] = {0, }; \ snprintf(_msg_, CAudioError::MSG_LENGTH, _format_, ##__VA_ARGS__); \ - throw CAudioError((_x_), (_msg_), __FILE__, __func__, __LINE__); \ + throw CAudioError((_x_), (_msg_), __BASE_FILE__, __func__, __LINE__); \ } while (0) #define VALID_POINTER_START(_x_) { \ @@ -103,7 +91,6 @@ #define SAFE_DELETE(_x_) do {if ((_x_)) {delete (_x_); (_x_) = NULL;}} while (0) #define SAFE_FINALIZE(_x_) do {if ((_x_)) {(_x_)->finalize();}} while (0) -#define SAFE_REMOVE(_x_) do {if ((_x_)) {(_x_)->finalize(); delete (_x_); (_x_) = NULL;}} while (0) #define DEFAULT_PERIOD_SIZE 50 diff --git a/src/cpp/CAudioError.cpp b/src/cpp/CAudioError.cpp index 7612b49..cfd3422 100644 --- a/src/cpp/CAudioError.cpp +++ b/src/cpp/CAudioError.cpp @@ -19,68 +19,41 @@ #include #include "CAudioIODef.h" - using namespace std; using namespace tizen_media_audio; - /** * class CAudioError */ -CAudioError::EError CAudioError::__mLastError = CAudioError::EError::ERROR_NONE; -char CAudioError::__mLastErrorMsg[MSG_LENGTH]; - -//LCOV_EXCL_START -CAudioError::CAudioError(EError err) : - __mError(err) { - __mLastError = __mError; +CAudioError::CAudioError(EError err, const char* msg, const char* file, const char* func, int line) : + __mError(err), + __mMsg(msg) { + char __mErrorMsg[MSG_LENGTH] = { 0, }; + snprintf(__mErrorMsg, MSG_LENGTH, "[%s|%s|%s(%d)|" + COLOR_CYAN "%s" COLOR_END "]", + __convertErrorToString(__mError), file, func, line, msg); + + __mFullMsg = __mErrorMsg; } -CAudioError::CAudioError(EError err, const char* fileName, const char* parentFunc, int lineNum) : - __mError(err) { - __mLastError = __mError; - - const char* findFileName = strrchr(fileName, '/'); - if (findFileName) - findFileName++; - const char* errStr = __convertErrorToString(__mError); - - snprintf(__mErrorMsg, MSG_LENGTH, "[" - COLOR_RED "THROW" COLOR_END ":%s|" - COLOR_YELLOW "ERR" COLOR_END ":%s|" - COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]", findFileName, errStr, parentFunc, lineNum); +CAudioError::CAudioError(EError err) : + __mError(err), + __mMsg(nullptr) { + char __mErrorMsg[MSG_LENGTH] = { 0, }; + snprintf(__mErrorMsg, MSG_LENGTH, "[%s]", __convertErrorToString(__mError)); - snprintf(__mLastErrorMsg, MSG_LENGTH, "LastError:%s", __mErrorMsg); + __mFullMsg = __mErrorMsg; } -//LCOV_EXCL_STOP - -CAudioError::CAudioError(EError err, const char* msg, const char* fileName, const char* parentFunc, int lineNum) : - __mError(err) { - __mLastError = __mError; - const char* findFileName = strrchr(fileName, '/'); - if (findFileName) - findFileName++; - const char* errStr = __convertErrorToString(__mError); - - snprintf(__mErrorMsg, MSG_LENGTH, "[" - COLOR_RED "THROW" COLOR_END ":%s|" - COLOR_YELLOW "ERR" COLOR_END ":%s|" - COLOR_YELLOW "FUNC" COLOR_END ":%s(%d)]" - COLOR_YELLOW "MSG" COLOR_END ":" - COLOR_CYAN "%s" COLOR_END, findFileName, errStr, parentFunc, lineNum, msg); - - snprintf(__mLastErrorMsg, MSG_LENGTH, "LastError:%s", __mErrorMsg); +const char* CAudioError::getErrorMsg() const noexcept { + return __mFullMsg.c_str(); } -//LCOV_EXCL_START -CAudioError::CAudioError(const CAudioError& err) { - __mError = err.__mError; - memcpy(__mErrorMsg, err.__mErrorMsg, MSG_LENGTH); +const CAudioError::EError CAudioError::getError() const noexcept { + return __mError; } -//LCOV_EXCL_STOP -const char* CAudioError::__convertErrorToString(EError err) { +const char* CAudioError::__convertErrorToString(EError err) noexcept { switch (err) { default: case EError::ERROR_NONE: return COLOR_GREEN "ERROR_NONE" COLOR_END; @@ -108,50 +81,3 @@ const char* CAudioError::__convertErrorToString(EError err) { //LCOV_EXCL_STOP } } - -//LCOV_EXCL_START -CAudioError::EError CAudioError::getLastError() { - return __mLastError; -} - -const char* CAudioError::getLastErrorMsg() { - return __mLastErrorMsg; -} -//LCOV_EXCL_STOP - -CAudioError::EError CAudioError::getError() { - return __mError; -} - -const char* CAudioError::getErrorMsg() { - return __mErrorMsg; -} - -//LCOV_EXCL_START -CAudioError& CAudioError::operator = (const EError err) { - __mError = err; - __mLastError = __mError; - return *this; -} - -CAudioError& CAudioError::operator = (const CAudioError& err) { - __mError = err.__mError; - __mLastError = __mError; - memcpy(__mErrorMsg, err.__mErrorMsg, MSG_LENGTH); - memcpy(__mLastErrorMsg, __mErrorMsg, MSG_LENGTH); - return *this; -} - -bool CAudioError::operator != (const EError err) { - return (__mError != err); -} - -bool CAudioError::operator == (const EError err) { - return (__mError == err); -} -//LCOV_EXCL_STOP - -//bool operator == (const CAudioError& src, const CAudioError::EError& err) { -// //return (src.__mLastError == err); -// return true; -//} diff --git a/src/cpp/CAudioIO.cpp b/src/cpp/CAudioIO.cpp index fbeaf82..a1786c2 100644 --- a/src/cpp/CAudioIO.cpp +++ b/src/cpp/CAudioIO.cpp @@ -235,7 +235,7 @@ void CAudioIO::pause() { AUDIO_IO_LOGD("pause"); mpPulseAudioClient->cork(true); internalUnlock(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { internalUnlock(); throw; } @@ -250,7 +250,7 @@ void CAudioIO::resume() { AUDIO_IO_LOGD("resume"); mpPulseAudioClient->cork(false); internalUnlock(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { internalUnlock(); throw; } @@ -268,7 +268,7 @@ void CAudioIO::drain() { mpPulseAudioClient->drain(); internalUnlock(); } - } catch (CAudioError& e) { + } catch (const CAudioError& e) { if (!mpPulseAudioClient->isInThread()) internalUnlock(); throw; @@ -287,7 +287,7 @@ void CAudioIO::flush() { mpPulseAudioClient->flush(); internalUnlock(); } - } catch (CAudioError& e) { + } catch (const CAudioError& e) { if (!mpPulseAudioClient->isInThread()) internalUnlock(); throw; diff --git a/src/cpp/CAudioInput.cpp b/src/cpp/CAudioInput.cpp index 7c4863c..d930137 100644 --- a/src/cpp/CAudioInput.cpp +++ b/src/cpp/CAudioInput.cpp @@ -82,7 +82,7 @@ void CAudioInput::initialize() { try { CAudioIO::initialize(); __setInit(true); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { finalize(); throw; } @@ -138,7 +138,7 @@ void CAudioInput::prepare() { internalUnlock(); CAudioIO::prepare(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { SAFE_FINALIZE(mpPulseAudioClient); SAFE_DELETE(mpPulseAudioClient); internalUnlock(); @@ -170,7 +170,7 @@ void CAudioInput::unprepare() { SAFE_FINALIZE(mpPulseAudioClient); SAFE_DELETE(mpPulseAudioClient); internalUnlock(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { internalUnlock(); throw; } @@ -270,7 +270,7 @@ size_t CAudioInput::read(void* buffer, size_t length) { internalUnlock(); sched_yield(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { internalUnlock(); throw; } diff --git a/src/cpp/CAudioOutput.cpp b/src/cpp/CAudioOutput.cpp index f122752..8308d4f 100644 --- a/src/cpp/CAudioOutput.cpp +++ b/src/cpp/CAudioOutput.cpp @@ -77,7 +77,7 @@ void CAudioOutput::initialize() { try { CAudioIO::initialize(); __setInit(true); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { finalize(); throw; } @@ -143,7 +143,7 @@ void CAudioOutput::prepare() { internalUnlock(); CAudioIO::prepare(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { SAFE_FINALIZE(mpPulseAudioClient); SAFE_DELETE(mpPulseAudioClient); internalUnlock(); @@ -175,7 +175,7 @@ void CAudioOutput::unprepare() { SAFE_FINALIZE(mpPulseAudioClient); SAFE_DELETE(mpPulseAudioClient); internalUnlock(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { internalUnlock(); throw; } @@ -312,7 +312,7 @@ size_t CAudioOutput::write(const void* buffer, size_t length) { internalUnlock(); sched_yield(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { __mIsUsedSyncWrite = false; internalUnlock(); throw; diff --git a/src/cpp/CPulseAudioClient.cpp b/src/cpp/CPulseAudioClient.cpp index 219ac1e..3b24ece 100644 --- a/src/cpp/CPulseAudioClient.cpp +++ b/src/cpp/CPulseAudioClient.cpp @@ -431,7 +431,7 @@ void CPulseAudioClient::initialize() { pa_threaded_mainloop_unlock(__mpMainloop); // __mIsInit = true; // Moved to __streamStateChangeCb() - } catch (CAudioError& e) { + } catch (const CAudioError& e) { finalize(); throw; } @@ -572,7 +572,7 @@ int CPulseAudioClient::read(void* buffer, size_t length) { pa_threaded_mainloop_unlock(__mpMainloop); __mIsUsedSyncRead = false; - } catch (CAudioError& e) { + } catch (const CAudioError& e) { pa_threaded_mainloop_unlock(__mpMainloop); __mIsUsedSyncRead = false; throw; @@ -894,7 +894,7 @@ size_t CPulseAudioClient::getBufferSize() { ret = attr->fragsize; AUDIO_IO_LOGD("RECORD buffer size[%zu]", ret); } - } catch (CAudioError& e) { + } catch (const CAudioError& e) { if (!isInThread()) pa_threaded_mainloop_unlock(__mpMainloop); throw; @@ -938,7 +938,7 @@ pa_usec_t CPulseAudioClient::getLatency() { /* Wait until latency data is available again */ pa_threaded_mainloop_wait(__mpMainloop); } - } catch (CAudioError& e) { + } catch (const CAudioError& e) { pa_threaded_mainloop_unlock(__mpMainloop); throw; } @@ -983,7 +983,7 @@ pa_usec_t CPulseAudioClient::getFinalLatency() { if (!isInThread()) pa_threaded_mainloop_unlock(__mpMainloop); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { if (!isInThread()) pa_threaded_mainloop_unlock(__mpMainloop); throw; diff --git a/src/cpp/cpp_audio_io.cpp b/src/cpp/cpp_audio_io.cpp index 77c8f4f..4d4e2b3 100644 --- a/src/cpp/cpp_audio_io.cpp +++ b/src/cpp/cpp_audio_io.cpp @@ -22,6 +22,7 @@ #include "CAudioIODef.h" #include +#include #define FEATURE_MICROPHONE "http://tizen.org/feature/microphone" @@ -96,8 +97,8 @@ typedef struct audio_io_s { /** * Internal functions */ -static audio_io_error_e __convert_CAudioError(CAudioError& error) { - switch (error.getError()) { +static audio_io_error_e __convert_audio_io_error(CAudioError::EError error) { + switch (error) { case CAudioError::EError::ERROR_NONE: return AUDIO_IO_ERROR_NONE; case CAudioError::EError::ERROR_INVALID_ARGUMENT: @@ -350,15 +351,15 @@ int cpp_audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_t AUDIO_IO_LOGD("[%p] created", handle); *input = handle; - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); __handle_safe_free(handle, (void *)input, false); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } catch (const std::bad_alloc&) { - CAudioError e(CAudioError::EError::ERROR_OUT_OF_MEMORY); +//LCOV_EXCL_START AUDIO_IO_LOGE("Failed to allocate handle"); __handle_safe_free(handle, (void *)input, false); - return __convert_CAudioError(e); + return __convert_audio_io_error(CAudioError::EError::ERROR_OUT_OF_MEMORY); //LCOV_EXCL_STOP } @@ -381,9 +382,9 @@ int cpp_audio_in_destroy(audio_in_h input) { SAFE_FINALIZE(handle->audioIoHandle); SAFE_DELETE(handle->audioIoHandle); SAFE_DELETE(handle); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("destroyed"); @@ -402,9 +403,9 @@ int cpp_audio_in_set_sound_stream_info(audio_in_h input, sound_stream_info_h str AUDIO_IO_LOGD("[%p], stream_info:[%p]", handle, stream_info); handle->audioIoHandle->setStreamInfo(stream_info); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -423,9 +424,9 @@ int cpp_audio_in_prepare(audio_in_h input) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->prepare(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] prepared", handle); @@ -444,9 +445,9 @@ int cpp_audio_in_unprepare(audio_in_h input) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->unprepare(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] unprepared", handle); @@ -465,9 +466,9 @@ int cpp_audio_in_pause(audio_in_h input) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->pause(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] paused", handle); @@ -486,9 +487,9 @@ int cpp_audio_in_resume(audio_in_h input) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->resume(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] resumed", handle); @@ -507,9 +508,9 @@ int cpp_audio_in_flush(audio_in_h input) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->flush(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] flushed", handle); @@ -536,9 +537,9 @@ int cpp_audio_in_read(audio_in_h input, void *buffer, unsigned int length) { #ifdef _AUDIO_IO_DEBUG_TIMING_ AUDIO_IO_LOGD("readn:%zu", readn); #endif - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return ret; @@ -557,9 +558,9 @@ int cpp_audio_in_get_buffer_size(audio_in_h input, int *size) { THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL"); *size = inputHandle->getBufferSize(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -574,9 +575,9 @@ int cpp_audio_in_get_sample_rate(audio_in_h input, int *sample_rate) { assert(handle->audioIoHandle); *sample_rate = handle->audioIoHandle->getAudioInfo().getSampleRate(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -591,9 +592,9 @@ int cpp_audio_in_get_channel(audio_in_h input, audio_channel_e *channel) { assert(handle->audioIoHandle); *channel = __convert_audio_info_channel_to_channel(handle->audioIoHandle->getAudioInfo().getChannel()); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -608,9 +609,9 @@ int cpp_audio_in_get_sample_type(audio_in_h input, audio_sample_type_e *type) { assert(handle->audioIoHandle); *type = __convert_audio_info_sample_type_to_sample_type(handle->audioIoHandle->getAudioInfo().getSampleType()); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -655,9 +656,9 @@ int cpp_audio_in_set_stream_cb(audio_in_h input, audio_in_stream_cb callback, vo cb.set(__stream_cb_internal, static_cast(handle)); handle->audioIoHandle->setStreamCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -680,9 +681,9 @@ int cpp_audio_in_unset_stream_cb(audio_in_h input) { cb.unset(); handle->audioIoHandle->setStreamCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -704,9 +705,9 @@ int cpp_audio_in_peek(audio_in_h input, const void **buffer, unsigned int *lengt THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL"); inputHandle->peek(buffer, &_length); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } *length = (unsigned int)_length; @@ -726,9 +727,9 @@ int cpp_audio_in_drop(audio_in_h input) { THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL"); inputHandle->drop(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -750,9 +751,9 @@ int cpp_audio_in_set_state_changed_cb(audio_in_h input, audio_in_state_changed_c cb.set(__state_changed_cb_internal, static_cast(handle)); handle->audioIoHandle->setStateChangedCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -776,9 +777,9 @@ int cpp_audio_in_unset_state_changed_cb(audio_in_h input) { cb.unset(); handle->audioIoHandle->setStateChangedCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -808,15 +809,15 @@ int cpp_audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sam AUDIO_IO_LOGD("[%p] created", handle); *output = handle; - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); __handle_safe_free(handle, (void *)output, true); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } catch (const std::bad_alloc&) { - CAudioError e(CAudioError::EError::ERROR_OUT_OF_MEMORY); +//LCOV_EXCL_START AUDIO_IO_LOGE("Failed to allocate handle"); __handle_safe_free(handle, (void *)output, true); - return __convert_CAudioError(e); + return __convert_audio_io_error(CAudioError::EError::ERROR_OUT_OF_MEMORY); //LCOV_EXCL_STOP } @@ -839,9 +840,9 @@ int cpp_audio_out_destroy(audio_out_h output) { SAFE_FINALIZE(handle->audioIoHandle); SAFE_DELETE(handle->audioIoHandle); SAFE_DELETE(handle); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] destroyed", handle); @@ -860,9 +861,9 @@ int cpp_audio_out_set_sound_stream_info(audio_out_h output, sound_stream_info_h AUDIO_IO_LOGD("[%p], stream_info:[%p]", handle, stream_info); handle->audioIoHandle->setStreamInfo(stream_info); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -881,9 +882,9 @@ int cpp_audio_out_prepare(audio_out_h output) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->prepare(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] prepared", handle); @@ -902,9 +903,9 @@ int cpp_audio_out_unprepare(audio_out_h output) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->unprepare(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] unprepared", handle); @@ -923,9 +924,9 @@ int cpp_audio_out_pause(audio_out_h output) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->pause(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] paused", handle); @@ -944,9 +945,9 @@ int cpp_audio_out_resume(audio_out_h output) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->resume(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] resumed", handle); @@ -965,9 +966,9 @@ int cpp_audio_out_drain(audio_out_h output) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->drain(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] drained", handle); @@ -986,9 +987,9 @@ int cpp_audio_out_flush(audio_out_h output) { AUDIO_IO_LOGD("[%p]", handle); handle->audioIoHandle->flush(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] flushed", handle); @@ -1015,9 +1016,9 @@ int cpp_audio_out_write(audio_out_h output, void *buffer, unsigned int length) { #ifdef _AUDIO_IO_DEBUG_TIMING_ AUDIO_IO_LOGD("written:%zu", written); #endif - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return ret; @@ -1036,9 +1037,9 @@ int cpp_audio_out_get_buffer_size(audio_out_h output, int *size) { THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_HANDLE, "Handle is NULL"); *size = outputHandle->getBufferSize(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -1053,9 +1054,9 @@ int cpp_audio_out_get_sample_rate(audio_out_h output, int *sample_rate) { assert(handle->audioIoHandle); *sample_rate = handle->audioIoHandle->getAudioInfo().getSampleRate(); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -1070,9 +1071,9 @@ int cpp_audio_out_get_channel(audio_out_h output, audio_channel_e *channel) { assert(handle->audioIoHandle); *channel = __convert_audio_info_channel_to_channel(handle->audioIoHandle->getAudioInfo().getChannel()); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -1087,9 +1088,9 @@ int cpp_audio_out_get_sample_type(audio_out_h output, audio_sample_type_e *type) assert(handle->audioIoHandle); *type = __convert_audio_info_sample_type_to_sample_type(handle->audioIoHandle->getAudioInfo().getSampleType()); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -1105,9 +1106,9 @@ int cpp_audio_out_get_sound_type(audio_out_h output, sound_type_e *type) { assert(handle->audioIoHandle); *type = __convert_audio_info_audio_type_to_sound_type(handle->audioIoHandle->getAudioInfo().getAudioType()); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } return AUDIO_IO_ERROR_NONE; @@ -1129,9 +1130,9 @@ int cpp_audio_out_set_stream_cb(audio_out_h output, audio_out_stream_cb callback cb.set(__stream_cb_internal, static_cast(handle)); handle->audioIoHandle->setStreamCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -1155,9 +1156,9 @@ int cpp_audio_out_unset_stream_cb(audio_out_h output) { cb.unset(); handle->audioIoHandle->setStreamCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -1181,9 +1182,9 @@ int cpp_audio_out_set_state_changed_cb(audio_out_h output, audio_in_state_change cb.set(__state_changed_cb_internal, static_cast(handle)); handle->audioIoHandle->setStateChangedCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); @@ -1207,9 +1208,9 @@ int cpp_audio_out_unset_state_changed_cb(audio_out_h output) { cb.unset(); handle->audioIoHandle->setStateChangedCallback(cb); - } catch (CAudioError& e) { + } catch (const CAudioError& e) { AUDIO_IO_LOGE("%s", e.getErrorMsg()); - return __convert_CAudioError(e); + return __convert_audio_io_error(e.getError()); } AUDIO_IO_LOGD("[%p] done", handle); -- 2.7.4