libspeechd_loader.cc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // This is generated file. Do not modify directly.
  2. // Path to the code generator:
  3. // tools/generate_library_loader/generate_library_loader.py .
  4. #include "library_loaders/libspeechd.h"
  5. #include <dlfcn.h>
  6. // Put these sanity checks here so that they fire at most once
  7. // (to avoid cluttering the build output).
  8. #if !defined( \
  9. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN) && \
  10. !defined( \
  11. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  12. #error neither LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN nor LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED defined
  13. #endif
  14. #if defined( \
  15. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN) && \
  16. defined( \
  17. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  18. #error both LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN and LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED defined
  19. #endif
  20. LibSpeechdLoader::LibSpeechdLoader() : loaded_(false) {}
  21. LibSpeechdLoader::~LibSpeechdLoader() {
  22. CleanUp(loaded_);
  23. }
  24. bool LibSpeechdLoader::Load(const std::string& library_name) {
  25. if (loaded_)
  26. return false;
  27. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  28. library_ = dlopen(library_name.c_str(), RTLD_LAZY);
  29. if (!library_)
  30. return false;
  31. #endif
  32. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  33. spd_open =
  34. reinterpret_cast<decltype(this->spd_open)>(dlsym(library_, "spd_open"));
  35. #endif
  36. #if defined( \
  37. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  38. spd_open = &::spd_open;
  39. #endif
  40. if (!spd_open) {
  41. CleanUp(true);
  42. return false;
  43. }
  44. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  45. spd_say =
  46. reinterpret_cast<decltype(this->spd_say)>(dlsym(library_, "spd_say"));
  47. #endif
  48. #if defined( \
  49. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  50. spd_say = &::spd_say;
  51. #endif
  52. if (!spd_say) {
  53. CleanUp(true);
  54. return false;
  55. }
  56. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  57. spd_stop =
  58. reinterpret_cast<decltype(this->spd_stop)>(dlsym(library_, "spd_stop"));
  59. #endif
  60. #if defined( \
  61. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  62. spd_stop = &::spd_stop;
  63. #endif
  64. if (!spd_stop) {
  65. CleanUp(true);
  66. return false;
  67. }
  68. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  69. spd_close =
  70. reinterpret_cast<decltype(this->spd_close)>(dlsym(library_, "spd_close"));
  71. #endif
  72. #if defined( \
  73. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  74. spd_close = &::spd_close;
  75. #endif
  76. if (!spd_close) {
  77. CleanUp(true);
  78. return false;
  79. }
  80. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  81. spd_pause =
  82. reinterpret_cast<decltype(this->spd_pause)>(dlsym(library_, "spd_pause"));
  83. #endif
  84. #if defined( \
  85. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  86. spd_pause = &::spd_pause;
  87. #endif
  88. if (!spd_pause) {
  89. CleanUp(true);
  90. return false;
  91. }
  92. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  93. spd_resume = reinterpret_cast<decltype(this->spd_resume)>(
  94. dlsym(library_, "spd_resume"));
  95. #endif
  96. #if defined( \
  97. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  98. spd_resume = &::spd_resume;
  99. #endif
  100. if (!spd_resume) {
  101. CleanUp(true);
  102. return false;
  103. }
  104. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  105. spd_set_notification_on =
  106. reinterpret_cast<decltype(this->spd_set_notification_on)>(
  107. dlsym(library_, "spd_set_notification_on"));
  108. #endif
  109. #if defined( \
  110. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  111. spd_set_notification_on = &::spd_set_notification_on;
  112. #endif
  113. if (!spd_set_notification_on) {
  114. CleanUp(true);
  115. return false;
  116. }
  117. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  118. spd_set_voice_rate = reinterpret_cast<decltype(this->spd_set_voice_rate)>(
  119. dlsym(library_, "spd_set_voice_rate"));
  120. #endif
  121. #if defined( \
  122. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  123. spd_set_voice_rate = &::spd_set_voice_rate;
  124. #endif
  125. if (!spd_set_voice_rate) {
  126. CleanUp(true);
  127. return false;
  128. }
  129. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  130. spd_set_voice_pitch = reinterpret_cast<decltype(this->spd_set_voice_pitch)>(
  131. dlsym(library_, "spd_set_voice_pitch"));
  132. #endif
  133. #if defined( \
  134. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  135. spd_set_voice_pitch = &::spd_set_voice_pitch;
  136. #endif
  137. if (!spd_set_voice_pitch) {
  138. CleanUp(true);
  139. return false;
  140. }
  141. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  142. spd_list_synthesis_voices =
  143. reinterpret_cast<decltype(this->spd_list_synthesis_voices)>(
  144. dlsym(library_, "spd_list_synthesis_voices"));
  145. #endif
  146. #if defined( \
  147. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  148. spd_list_synthesis_voices = &::spd_list_synthesis_voices;
  149. #endif
  150. if (!spd_list_synthesis_voices) {
  151. CleanUp(true);
  152. return false;
  153. }
  154. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  155. spd_set_synthesis_voice =
  156. reinterpret_cast<decltype(this->spd_set_synthesis_voice)>(
  157. dlsym(library_, "spd_set_synthesis_voice"));
  158. #endif
  159. #if defined( \
  160. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  161. spd_set_synthesis_voice = &::spd_set_synthesis_voice;
  162. #endif
  163. if (!spd_set_synthesis_voice) {
  164. CleanUp(true);
  165. return false;
  166. }
  167. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  168. spd_list_modules = reinterpret_cast<decltype(this->spd_list_modules)>(
  169. dlsym(library_, "spd_list_modules"));
  170. #endif
  171. #if defined( \
  172. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  173. spd_list_modules = &::spd_list_modules;
  174. #endif
  175. if (!spd_list_modules) {
  176. CleanUp(true);
  177. return false;
  178. }
  179. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  180. spd_set_output_module =
  181. reinterpret_cast<decltype(this->spd_set_output_module)>(
  182. dlsym(library_, "spd_set_output_module"));
  183. #endif
  184. #if defined( \
  185. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  186. spd_set_output_module = &::spd_set_output_module;
  187. #endif
  188. if (!spd_set_output_module) {
  189. CleanUp(true);
  190. return false;
  191. }
  192. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  193. spd_set_language = reinterpret_cast<decltype(this->spd_set_language)>(
  194. dlsym(library_, "spd_set_language"));
  195. #endif
  196. #if defined( \
  197. LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DT_NEEDED)
  198. spd_set_language = &::spd_set_language;
  199. #endif
  200. if (!spd_set_language) {
  201. CleanUp(true);
  202. return false;
  203. }
  204. loaded_ = true;
  205. return true;
  206. }
  207. void LibSpeechdLoader::CleanUp(bool unload) {
  208. #if defined(LIBRARY_LOADER_OUT_RELEASE_GEN_LIBRARY_LOADERS_LIBSPEECHD_H_DLOPEN)
  209. if (unload) {
  210. dlclose(library_);
  211. library_ = NULL;
  212. }
  213. #endif
  214. loaded_ = false;
  215. spd_open = NULL;
  216. spd_say = NULL;
  217. spd_stop = NULL;
  218. spd_close = NULL;
  219. spd_pause = NULL;
  220. spd_resume = NULL;
  221. spd_set_notification_on = NULL;
  222. spd_set_voice_rate = NULL;
  223. spd_set_voice_pitch = NULL;
  224. spd_list_synthesis_voices = NULL;
  225. spd_set_synthesis_voice = NULL;
  226. spd_list_modules = NULL;
  227. spd_set_output_module = NULL;
  228. spd_set_language = NULL;
  229. }