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