TraceAvCaster.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*\
  2. |*| Copyright 2015-2016 bill-auger <https://github.com/bill-auger/av-caster/issues>
  3. |*|
  4. |*| This file is part of the AvCaster program.
  5. |*|
  6. |*| AvCaster is free software: you can redistribute it and/or modify
  7. |*| it under the terms of the GNU General Public License version 3
  8. |*| as published by the Free Software Foundation.
  9. |*|
  10. |*| AvCaster is distributed in the hope that it will be useful,
  11. |*| but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. |*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. |*| GNU General Public License for more details.
  14. |*|
  15. |*| You should have received a copy of the GNU General Public License
  16. |*| along with AvCaster. If not, see <http://www.gnu.org/licenses/>.
  17. \*/
  18. #ifndef _TRACEAVCASTER_H_
  19. #define _TRACEAVCASTER_H_
  20. #ifdef DEBUG_TRACE
  21. # include "Trace.h"
  22. /* feature switches */
  23. StringArray DisableFeatures()
  24. {
  25. StringArray disabled_features = StringArray() ;
  26. # ifdef DISABLE_MEDIA
  27. disabled_features.add(APP::CLI_DISABLE_MEDIA_TOKEN) ;
  28. # endif // DISABLE_MEDIA
  29. # ifdef SCREEN_ONLY
  30. disabled_features.add(APP::CLI_SCREEN_ONLY_TOKEN) ;
  31. # endif // SCREEN_ONLY
  32. # ifdef CAMERA_ONLY
  33. disabled_features.add(APP::CLI_CAMERA_ONLY_TOKEN) ;
  34. # endif // CAMERA_ONLY
  35. # ifdef TEXT_ONLY
  36. # if ! TEXT_BIN_NYI
  37. disabled_features.add(APP::CLI_TEXT_ONLY_TOKEN) ;
  38. # endif // TEXT_BIN_NYI
  39. # endif // TEXT_ONLY
  40. # ifdef IMAGE_ONLY
  41. # if ! IMAGE_BIN_NYI
  42. disabled_features.add(APP::CLI_IMAGE_ONLY_TOKEN) ;
  43. # endif // IMAGE_BIN_NYI
  44. # endif // IMAGE_ONLY
  45. # if DISABLE_PREVIEW
  46. disabled_features.add(APP::CLI_DISABLE_PREVIEW_TOKEN) ;
  47. # endif // DISABLE_PREVIEW
  48. # if DISABLE_AUDIO
  49. disabled_features.add(APP::CLI_DISABLE_AUDIO_TOKEN) ;
  50. # endif // DISABLE_AUDIO
  51. # ifdef DISABLE_CHAT
  52. disabled_features.add(APP::CLI_DISABLE_CHAT_TOKEN) ;
  53. # endif // DISABLE_CHAT
  54. return disabled_features ;
  55. }
  56. # define DEBUG_DISABLE_FEATURES \
  57. String dbg = "disabling feature per #define constant '" ; \
  58. cli_params.removeEmptyStrings() ; \
  59. cli_params.addArray(DisableFeatures()) ; cli_params.removeDuplicates(false) ; \
  60. /*cli_params.mergeArray(DisabledFeatures()) ; // TODO: JUCE 4 feature */ \
  61. for (int switch_n = 0 ; switch_n < cli_params.size() ; ++switch_n) \
  62. Trace::TraceState(dbg + cli_params[switch_n] + "'") ; \
  63. if (TEXT_BIN_NYI ) { Trace::TraceState(dbg + "TEXT_BIN_NYI'" ) ; \
  64. DisabledFeatures.set(CONFIG::TEXT_ID , var::null) ; } \
  65. if (IMAGE_BIN_NYI) { Trace::TraceState(dbg + "IMAGE_BIN_NYI'") ; \
  66. DisabledFeatures.set(CONFIG::IMAGE_ID , var::null) ; }
  67. void SeedIrcNetworks()
  68. {
  69. # if SEED_IRC_NETWORKS
  70. AvCaster::SetValue(CONFIG::NETWORK_ID , var(String("irc.debian.org"))) ;
  71. AvCaster::SetValue(CONFIG::PORT_ID , var(6667 )) ;
  72. AvCaster::SetValue(CONFIG::NICK_ID , var(String("[mr-cooldude]" ))) ;
  73. AvCaster::SetValue(CONFIG::CHANNEL_ID , var(String("#av-caster" ))) ;
  74. // AvCaster::SetValue(CONFIG::NETWORK_ID , var(String("localhost" ))) ;
  75. // AvCaster::SetValue(CONFIG::NICK_ID , var(String("bill-auger" ))) ;
  76. // AvCaster::SetValue(CONFIG::CHANNEL_ID , var(String("#mychat" ))) ;
  77. AvCaster::StorePreset(AvCaster::GetPresetName()) ;
  78. # endif // SEED_IRC_NETWORKS
  79. }
  80. # define DEBUG_SEED_IRC_NETWORKS SeedIrcNetworks() ;
  81. /* state */
  82. # define DEBUG_TRACE_INIT_PHASE_1 Trace::TraceState("validating environment") ;
  83. # define DEBUG_TRACE_INIT_PHASE_2 Trace::TraceState("instantiating model") ;
  84. # define DEBUG_TRACE_INIT_PHASE_3 Trace::TraceState("processing CLI params") ;
  85. # define DEBUG_TRACE_INIT_PHASE_4 Trace::TraceState("instantiating GUI") ;
  86. # define DEBUG_TRACE_INIT_PHASE_5 \
  87. Trace::TraceState((IsMediaEnabled) ? "instantiating media" : "media disabled") ;
  88. # define DEBUG_TRACE_INIT_PHASE_6 \
  89. Trace::TraceState((IsChatEnabled) ? "instantiating chat" : "chat disabled") ;
  90. # define DEBUG_TRACE_INIT_PHASE_7 Trace::TraceState("finalizing initialization") ;
  91. # define DEBUG_TRACE_INIT_PHASE_8 Trace::TraceState("AvCaster ready") ;
  92. # define DEBUG_TRACE_HANDLE_CLI_PARAMS String token ; \
  93. if (cli_params.contains(APP::CLI_HELP_TOKEN )) token = APP::CLI_HELP_TOKEN ; \
  94. else if (cli_params.contains(APP::CLI_PRESETS_TOKEN)) token = APP::CLI_PRESETS_TOKEN ; \
  95. else if (cli_params.contains(APP::CLI_VERSION_TOKEN)) token = APP::CLI_VERSION_TOKEN ; \
  96. if (token.isNotEmpty()) Trace::TraceConfig("found terminating cli token " + token) ;
  97. # define DEBUG_TRACE_PROCESS_CLI_PARAMS StringArray handled_tokens , unhandled_tokens ; \
  98. for (String* token = cli_params.begin() ; token != cli_params.end() ; ++token) \
  99. if (*token == APP::CLI_PRESET_TOKEN || \
  100. *token == APP::CLI_DISABLE_MEDIA_TOKEN || \
  101. *token == APP::CLI_SCREEN_ONLY_TOKEN || \
  102. *token == APP::CLI_CAMERA_ONLY_TOKEN || \
  103. *token == APP::CLI_TEXT_ONLY_TOKEN || \
  104. *token == APP::CLI_IMAGE_ONLY_TOKEN || \
  105. *token == APP::CLI_DISABLE_PREVIEW_TOKEN || \
  106. *token == APP::CLI_DISABLE_AUDIO_TOKEN || \
  107. *token == APP::CLI_DISABLE_CHAT_TOKEN ) \
  108. handled_tokens.add(*token) ; \
  109. else unhandled_tokens.add(*token) ; \
  110. if (handled_tokens .size()) Trace::TraceConfig("found pre-init cli tokens [ " + \
  111. handled_tokens .joinIntoString(",") + "]") ; \
  112. if (unhandled_tokens.size()) Trace::TraceConfig("found unknown cli tokens [ " + \
  113. unhandled_tokens.joinIntoString(",") + "]") ; \
  114. Trace::TraceConfigVb("dumping cli_params => [" + cli_params .joinIntoString(",") + "]") ;
  115. # define DEBUG_TRACE_VALIDATE_ENVIRONMENT \
  116. bool is_err = false ; String dbg = "" ; \
  117. if (!is_sufficient_gst_version) { is_err = true ; dbg += " insufficient libgstreamer version" ; } \
  118. if (!is_sufficient_irc_version) { is_err = true ; dbg += " insufficient libircclient version" ; } \
  119. if (!is_valid_home_dir ) { is_err = true ; dbg += " invlaid HOME_DIR" ; } \
  120. if (!is_valid_appdata_dir ) { is_err = true ; dbg += " invlaid APPDATA_DIR" ; } \
  121. if (!is_valid_pictures_dir ) { is_err = true ; dbg += " invlaid PICTURES_DIR" ; } \
  122. if (!is_valid_videos_dir ) { is_err = true ; dbg += " invlaid VIDEOS_DIR" ; } \
  123. if (is_err) Trace::TraceError(dbg) ; else Trace::TraceState("environment is sane") ;
  124. # define DEBUG_TRACE_REFRESH_GUI \
  125. String gui = (!IsInitialized ) ? "Background" : \
  126. (is_config_pending) ? "Config" : \
  127. (is_preview_on ) ? "Preview" : "Chat" ; \
  128. Trace::TraceState("showing " + gui + " GUI") ;
  129. # define DEBUG_TRACE_SHUTDOWN_PHASE_1 Trace::TraceState("shutting down network") ;
  130. # define DEBUG_TRACE_SHUTDOWN_PHASE_2 Trace::TraceState("shutting down media") ;
  131. # define DEBUG_TRACE_SHUTDOWN_PHASE_3 Trace::TraceState("shutting down storage") ;
  132. /* config */
  133. # define DEBUG_TRACE_HANDLE_CONFIG_CHANGE \
  134. String handled = ((!should_reconfigure_media) ? "not " : "") ; \
  135. bool was_preset_combo_changed = a_key == CONFIG::PRESET_ID ; \
  136. bool was_config_button_pressed = a_key == CONFIG::IS_PENDING_ID ; \
  137. bool is_swapping_presets = was_preset_combo_changed && !is_config_pending ; \
  138. bool is_entering_config_mode = was_config_button_pressed && is_config_pending ; \
  139. bool is_exiting_config_mode = was_config_button_pressed && !is_config_pending ; \
  140. bool should_logout_chat = is_preset_control && is_config_pending ; \
  141. String chat_state = (should_login_chat) ? "into" : "out of" ; \
  142. String pad = "\n " ; \
  143. Trace::TraceConfigVb(handled + "handling config value change '" + STRING(a_key) + "'" + \
  144. pad + "is_media_toggle = " + String(is_media_toggle ) + \
  145. pad + "is_preset_control = " + String(is_preset_control ) + \
  146. pad + "is_stream_active = " + String(is_stream_active ) + \
  147. pad + "is_config_pending = " + String(is_config_pending ) + \
  148. pad + "should_stop_stream = " + String(should_stop_stream ) + \
  149. pad + "should_reconfigure_media = " + String(should_reconfigure_media) + \
  150. pad + "should_reconfigure_chat = " + String(should_reconfigure_chat ) + \
  151. pad + "is_swapping_presets = " + String(is_swapping_presets ) + \
  152. pad + "is_entering_config_mode = " + String(is_entering_config_mode ) + \
  153. pad + "is_exiting_config_mode = " + String(is_exiting_config_mode ) + \
  154. pad + "should_logout_chat = " + String(should_logout_chat ) + \
  155. pad + "should_login_chat = " + String(should_login_chat ) ) ; \
  156. if (is_swapping_presets ) Trace::TraceConfig("swapping presets" ) ; \
  157. if (is_entering_config_mode) Trace::TraceConfig("entering config mode") ; \
  158. if (is_exiting_config_mode ) Trace::TraceConfig("exitng config mode" ) ; \
  159. if (should_reconfigure_chat) Trace::TraceConfig("logging " + chat_state + " chat" + \
  160. ((!IsChatEnabled) ? " (disabled)" : "")) ;
  161. /* helpers */
  162. # define DEBUG_TRACE_DISPLAY_ALERT \
  163. if (message_type == GUI::ALERT_TYPE_WARNING) Trace::TraceWarning(message_text) ; \
  164. else if (message_type == GUI::ALERT_TYPE_ERROR ) Trace::TraceError (message_text) ;
  165. #else // DEBUG_TRACE
  166. # define DEBUG_DISABLE_FEATURES ;
  167. # define DEBUG_SEED_IRC_NETWORKS ;
  168. # define DEBUG_TRACE_INIT_PHASE_1 ;
  169. # define DEBUG_TRACE_INIT_PHASE_2 ;
  170. # define DEBUG_TRACE_INIT_PHASE_3 ;
  171. # define DEBUG_TRACE_INIT_PHASE_4 ;
  172. # define DEBUG_TRACE_INIT_PHASE_5 ;
  173. # define DEBUG_TRACE_INIT_PHASE_6 ;
  174. # define DEBUG_TRACE_INIT_PHASE_7 ;
  175. # define DEBUG_TRACE_INIT_PHASE_8 ;
  176. # define DEBUG_TRACE_HANDLE_CLI_PARAMS ;
  177. # define DEBUG_TRACE_PROCESS_CLI_PARAMS ;
  178. # define DEBUG_TRACE_VALIDATE_ENVIRONMENT ;
  179. # define DEBUG_TRACE_REFRESH_GUI ;
  180. # define DEBUG_TRACE_SHUTDOWN_PHASE_1 ;
  181. # define DEBUG_TRACE_SHUTDOWN_PHASE_2 ;
  182. # define DEBUG_TRACE_SHUTDOWN_PHASE_3 ;
  183. # define DEBUG_TRACE_HANDLE_CONFIG_CHANGE ;
  184. # define DEBUG_TRACE_DISPLAY_ALERT ;
  185. #endif // DEBUG_TRACE
  186. #endif // _TRACEAVCASTER_H_