jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.0KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __JackInternalClient__
  17. #define __JackInternalClient__
  18. #include "JackClient.h"
  19. #include "JackClientControl.h"
  20. namespace Jack
  21. {
  22. struct JackEngineControl;
  23. /*!
  24. \brief Internal clients in the server.
  25. */
  26. class JackInternalClient : public JackClient
  27. {
  28. private:
  29. JackClientControl fClientControl; /*! Client control */
  30. public:
  31. JackInternalClient(JackServer* server, JackSynchro* table);
  32. virtual ~JackInternalClient();
  33. int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
  34. JackGraphManager* GetGraphManager() const;
  35. JackEngineControl* GetEngineControl() const;
  36. JackClientControl* GetClientControl() const;
  37. static JackGraphManager* fGraphManager; /*! Shared memory Port manager */
  38. static JackEngineControl* fEngineControl; /*! Shared engine cotrol */
  39. };
  40. /*!
  41. \brief Loadable internal clients in the server.
  42. */
  43. #ifdef WIN32
  44. #include <windows.h>
  45. #define HANDLE HINSTANCE
  46. #define LoadJackModule(name) LoadLibrary((name));
  47. #define UnloadJackModule(handle) FreeLibrary((handle));
  48. #define GetJackProc(handle, name) GetProcAddress((handle), (name));
  49. static void BuildClientPath(char* path_to_so, int path_len, const char* so_name)
  50. {
  51. snprintf(path_to_so, path_len, ADDON_DIR "/%s.dll", so_name);
  52. }
  53. static void PrintLoadError(const char* so_name)
  54. {
  55. // Retrieve the system error message for the last-error code
  56. LPVOID lpMsgBuf;
  57. LPVOID lpDisplayBuf;
  58. DWORD dw = GetLastError();
  59. FormatMessage(
  60. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  61. FORMAT_MESSAGE_FROM_SYSTEM |
  62. FORMAT_MESSAGE_IGNORE_INSERTS,
  63. NULL,
  64. dw,
  65. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  66. (LPTSTR) &lpMsgBuf,
  67. 0, NULL );
  68. // Display the error message and exit the process
  69. lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
  70. (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)so_name) + 40) * sizeof(TCHAR));
  71. _snprintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR),
  72. TEXT("error loading %s err = %s"), so_name, lpMsgBuf);
  73. jack_error((LPCTSTR)lpDisplayBuf);
  74. LocalFree(lpMsgBuf);
  75. LocalFree(lpDisplayBuf);
  76. }
  77. #else
  78. #include <dlfcn.h>
  79. #define HANDLE void*
  80. #define LoadJackModule(name) dlopen((name), RTLD_NOW | RTLD_LOCAL);
  81. #define UnloadJackModule(handle) dlclose((handle));
  82. #define GetJackProc(handle, name) dlsym((handle), (name));
  83. #define PrintLoadError(so_name) jack_log("error loading %s err = %s", so_name, dlerror());
  84. static void BuildClientPath(char* path_to_so, int path_len, const char* so_name)
  85. {
  86. snprintf(path_to_so, path_len, ADDON_DIR "/%s.so", so_name);
  87. }
  88. #endif
  89. typedef int (*InitializeCallback)(jack_client_t*, const char*);
  90. typedef void (*FinishCallback)(void *);
  91. class JackLoadableInternalClient : public JackInternalClient
  92. {
  93. private:
  94. HANDLE fHandle;
  95. InitializeCallback fInitialize;
  96. FinishCallback fFinish;
  97. char fObjectData[JACK_LOAD_INIT_LIMIT];
  98. public:
  99. JackLoadableInternalClient(JackServer* server, JackSynchro* table, const char* so_name, const char* object_data);
  100. virtual ~JackLoadableInternalClient();
  101. int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status);
  102. };
  103. } // end of namespace
  104. #endif