cannam@124: #include "portaudiocpp/Exception.hxx" cannam@124: cannam@124: namespace portaudio cannam@124: { cannam@124: // ----------------------------------------------------------------------------------- cannam@124: // PaException: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: cannam@124: ////// cannam@124: /// Wraps a PortAudio error into a PortAudioCpp PaException. cannam@124: ////// cannam@124: PaException::PaException(PaError error) : error_(error) cannam@124: { cannam@124: } cannam@124: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: cannam@124: ////// cannam@124: /// Alias for paErrorText(), to have std::exception compliance. cannam@124: ////// cannam@124: const char *PaException::what() const throw() cannam@124: { cannam@124: return paErrorText(); cannam@124: } cannam@124: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: cannam@124: ////// cannam@124: /// Returns the PortAudio error code (PaError). cannam@124: ////// cannam@124: PaError PaException::paError() const cannam@124: { cannam@124: return error_; cannam@124: } cannam@124: cannam@124: ////// cannam@124: /// Returns the error as a (zero-terminated) text string. cannam@124: ////// cannam@124: const char *PaException::paErrorText() const cannam@124: { cannam@124: return Pa_GetErrorText(error_); cannam@124: } cannam@124: cannam@124: ////// cannam@124: /// Returns true is the error is a HostApi error. cannam@124: ////// cannam@124: bool PaException::isHostApiError() const cannam@124: { cannam@124: return (error_ == paUnanticipatedHostError); cannam@124: } cannam@124: cannam@124: ////// cannam@124: /// Returns the last HostApi error (which is the current one if cannam@124: /// isHostApiError() returns true) as an error code. cannam@124: ////// cannam@124: long PaException::lastHostApiError() const cannam@124: { cannam@124: return Pa_GetLastHostErrorInfo()->errorCode; cannam@124: } cannam@124: cannam@124: ////// cannam@124: /// Returns the last HostApi error (which is the current one if cannam@124: /// isHostApiError() returns true) as a (zero-terminated) text cannam@124: /// string, if it's available. cannam@124: ////// cannam@124: const char *PaException::lastHostApiErrorText() const cannam@124: { cannam@124: return Pa_GetLastHostErrorInfo()->errorText; cannam@124: } cannam@124: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: cannam@124: bool PaException::operator==(const PaException &rhs) const cannam@124: { cannam@124: return (error_ == rhs.error_); cannam@124: } cannam@124: cannam@124: bool PaException::operator!=(const PaException &rhs) const cannam@124: { cannam@124: return !(*this == rhs); cannam@124: } cannam@124: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: // PaCppException: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: cannam@124: PaCppException::PaCppException(ExceptionSpecifier specifier) : specifier_(specifier) cannam@124: { cannam@124: } cannam@124: cannam@124: const char *PaCppException::what() const throw() cannam@124: { cannam@124: switch (specifier_) cannam@124: { cannam@124: case UNABLE_TO_ADAPT_DEVICE: cannam@124: { cannam@124: return "Unable to adapt the given device to the specified host api specific device extension"; cannam@124: } cannam@124: } cannam@124: cannam@124: return "Unknown exception"; cannam@124: } cannam@124: cannam@124: PaCppException::ExceptionSpecifier PaCppException::specifier() const cannam@124: { cannam@124: return specifier_; cannam@124: } cannam@124: cannam@124: bool PaCppException::operator==(const PaCppException &rhs) const cannam@124: { cannam@124: return (specifier_ == rhs.specifier_); cannam@124: } cannam@124: cannam@124: bool PaCppException::operator!=(const PaCppException &rhs) const cannam@124: { cannam@124: return !(*this == rhs); cannam@124: } cannam@124: cannam@124: // ----------------------------------------------------------------------------------- cannam@124: cannam@124: } // namespace portaudio cannam@124: cannam@124: