AkErrorMessageTranslator.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Copyright (c) 2023 Audiokinetic Inc.
  10. *******************************************************************************/
  11. #include <AK/SoundEngine/Common/AkSoundEngine.h> // Sound engine
  12. #define AK_TRANSLATOR_MAX_NAME_SIZE 150
  13. #define AK_MAX_ERROR_LENGTH 1000
  14. // AkErrorMessageTranslator.h
  15. /// \file
  16. /// Contains the interface for a message translator
  17. #pragma once
  18. class AkErrorMessageTranslator
  19. {
  20. public:
  21. AkErrorMessageTranslator() :
  22. m_isReadyForTranslation{ false },
  23. m_fallBackTranslator{ nullptr }
  24. {}
  25. /// ErrorMessageTranslator class destructor.
  26. virtual ~AkErrorMessageTranslator() {};
  27. /**
  28. Terminate the translator
  29. */
  30. virtual void Term() = 0;
  31. /**
  32. Sets the fallBackTranslator to the given fallback translator.
  33. The class that created the previously affected fallBackTranslator has
  34. the responsibilty to delete it.
  35. */
  36. void SetFallBackTranslator(AkErrorMessageTranslator* in_fallBackTranslator) { m_fallBackTranslator = in_fallBackTranslator; }
  37. /**
  38. Resolve names associated to the wwise tag(s) in the error message if possible
  39. @param[in] in_pszError The error message to translate
  40. @param[out] out_translatedPszError The final result of the translation
  41. @param[in] in_maxPszErrorSize The maximum size of the translatedPszError and also the maximum size of the m_translationBuffer
  42. @param[in] in_args The variable arguments used in the tranlsation
  43. @param[in] in_uArgSize The total size of variable arguments, in bytes
  44. @return bool Whether or not the translation was successful
  45. */
  46. virtual bool Translate(const AkOSChar* in_pszError, AkOSChar* out_translatedPszError, AkInt32 in_maxPszErrorSize, char* in_args, AkUInt32 in_uArgSize);
  47. protected:
  48. struct TagInformation
  49. {
  50. const AkOSChar* m_pTag = nullptr;
  51. const AkOSChar* m_pStartBlock = nullptr;
  52. const char* m_args = nullptr;
  53. AkOSChar m_parsedInfo[AK_TRANSLATOR_MAX_NAME_SIZE] = { 0 };
  54. AkUInt32 m_argSize = 0;
  55. AkUInt16 m_len;
  56. bool m_infoIsParsed = false;
  57. };
  58. bool m_isReadyForTranslation;
  59. AkErrorMessageTranslator* m_fallBackTranslator;
  60. /**
  61. Copy the given string to the parsingInformation.
  62. @param[out] out_parsedInfo The modified translatedPszError
  63. @param[in] in_maxSize The maximum space in the parsedInfo buffer
  64. @param[in] in_stringSize The size of the string to print in the translatedPszError
  65. @param[in] in_string The string to print in the translatedPszError
  66. */
  67. void CharPrintResult(AkOSChar* out_parsedInfo, AkInt32 in_maxSize, AkInt32 in_stringSize, const char* in_string);
  68. /**
  69. A translator specific function to get some informations based on the given tag.
  70. If the information is found, modify the translatedPszError and position
  71. @param[in] in_pTagList The list of tag to parse
  72. @param[in] in_uCount The number of tags to parse.
  73. @param[out] out_uTranslated The number of tags already translated.
  74. @return bool Whether or not all the tag were parsed
  75. */
  76. virtual bool GetInfo(TagInformation *in_pTagList, AkUInt32 in_uCount, AkUInt32& out_uTranslated) = 0;
  77. private:
  78. /**
  79. Extract all the tags from the pszError
  80. @param[in] in_pszError The error message to extract the tag from
  81. @param[in] in_args The variable arguments used in the parsing
  82. @param[in] in_uArgSize The size of the arguments used in the parsing
  83. @param[out] out_tagList The list of TagInformation with a standard tag
  84. @param[out] out_uCount The number of tags in out_TagsList
  85. @param[out] out_uTranslated The number of tags already translated in out_TagsList.
  86. @return bool True if we need extra translation of the tags.
  87. */
  88. bool ExtractTags(const AkOSChar* in_pszError, char* in_args, AkUInt32 in_uArgSize, TagInformation* out_tagList, AkUInt32& out_uCount, AkUInt32& out_uTranslated);
  89. };