FileIOErrorHandler.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/IO/FileIOEventBus.h>
  10. #include <AzCore/std/string/string.h>
  11. namespace AtomSampleViewer
  12. {
  13. //! Use this to report AZ::IO errors and include the OS error code in the message.
  14. //! The general pattern is to call:
  15. //! FileIOErrorHandler::BusConnect()
  16. //! if(!someAzIoOperation())
  17. //! FileIOErrorHandler::ReportLatestIOError(myMessage)
  18. //! FileIOErrorHandler::BusDisconnect()
  19. class FileIOErrorHandler
  20. : public AZ::IO::FileIOEventBus::Handler
  21. {
  22. using Base = AZ::IO::FileIOEventBus::Handler;
  23. public:
  24. void BusConnect(); //!< Also resets m_ioErrorCode
  25. void ReportLatestIOError(AZStd::string message);
  26. void BusDisconnect(); //!< Also resets m_ioErrorCode
  27. private:
  28. // AZ::IO::FileIOEventBus::Handler overrides...
  29. void OnError(const AZ::IO::SystemFile* file, const char* fileName, int errorCode) override;
  30. static constexpr int ErrorCodeNotSet = -1;
  31. int m_ioErrorCode = ErrorCodeNotSet;
  32. };
  33. } // namespace AtomSampleViewer