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.

184 lines
7.2KB

  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __JackEngine__
  16. #define __JackEngine__
  17. #include "JackConstants.h"
  18. #include "JackGraphManager.h"
  19. #include "JackSynchro.h"
  20. #include "JackTransportEngine.h"
  21. namespace Jack
  22. {
  23. class JackClientInterface;
  24. struct JackEngineControl;
  25. class JackServerNotifyChannelInterface;
  26. class JackExternalClient;
  27. class JackSyncInterface;
  28. class JackEngineInterface
  29. {
  30. public:
  31. JackEngineInterface()
  32. {}
  33. JackEngineInterface(JackGraphManager* manager, JackSynchro** table, JackEngineControl* controler)
  34. {}
  35. virtual ~JackEngineInterface()
  36. {}
  37. virtual int Open() = 0;
  38. virtual int Close() = 0;
  39. // Client management
  40. virtual int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status) = 0;
  41. virtual int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) = 0;
  42. virtual int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait) = 0;
  43. virtual int ClientExternalClose(int refnum) = 0;
  44. virtual int ClientInternalClose(int refnum, bool wait) = 0;
  45. virtual int ClientActivate(int refnum, bool state) = 0;
  46. virtual int ClientDeactivate(int refnum) = 0;
  47. virtual int GetClientPID(const char* name) = 0;
  48. // Internal client management
  49. virtual int GetInternalClientName(int int_ref, char* name_res) = 0;
  50. virtual int InternalClientHandle(const char* client_name, int* status, int* int_ref) = 0;
  51. virtual int InternalClientUnload(int refnum, int* status) = 0;
  52. // Port management
  53. virtual int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, unsigned int* port) = 0;
  54. virtual int PortUnRegister(int refnum, jack_port_id_t port) = 0;
  55. virtual int PortConnect(int refnum, const char* src, const char* dst) = 0;
  56. virtual int PortDisconnect(int refnum, const char* src, const char* dst) = 0;
  57. virtual int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst) = 0;
  58. virtual int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst) = 0;
  59. // Graph
  60. virtual bool Process(jack_time_t callback_usecs) = 0;
  61. // Notifications
  62. virtual void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs) = 0;
  63. virtual void NotifyXRun(int refnum) = 0;
  64. virtual void NotifyGraphReorder() = 0;
  65. virtual void NotifyBufferSize(jack_nframes_t nframes) = 0;
  66. virtual void NotifyFreewheel(bool onoff) = 0;
  67. virtual void NotifyPortRegistation(jack_port_id_t port_index, bool onoff) = 0;
  68. virtual void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff) = 0;
  69. virtual void NotifyActivate(int refnum) = 0;
  70. };
  71. /*!
  72. \brief Engine description.
  73. */
  74. class JackEngine : public JackEngineInterface
  75. {
  76. private:
  77. JackGraphManager* fGraphManager;
  78. JackEngineControl* fEngineControl;
  79. JackClientInterface* fClientTable[CLIENT_NUM];
  80. JackSynchro** fSynchroTable;
  81. JackServerNotifyChannelInterface* fChannel; /*! To communicate between the RT thread and server */
  82. JackSyncInterface* fSignal;
  83. jack_time_t fLastSwitchUsecs;
  84. int ClientCloseAux(int refnum, JackClientInterface* client, bool wait);
  85. void CheckXRun(jack_time_t callback_usecs);
  86. int NotifyAddClient(JackClientInterface* new_client, const char* name, int refnum);
  87. void NotifyRemoveClient(const char* name, int refnum);
  88. void ProcessNext(jack_time_t callback_usecs);
  89. void ProcessCurrent(jack_time_t callback_usecs);
  90. bool ClientCheckName(const char* name);
  91. bool GenerateUniqueName(char* name);
  92. int AllocateRefnum();
  93. void ReleaseRefnum(int ref);
  94. void NotifyClient(int refnum, int event, int sync, int value1, int value2);
  95. void NotifyClients(int event, int sync, int value1, int value2);
  96. public:
  97. JackEngine()
  98. {}
  99. JackEngine(JackGraphManager* manager, JackSynchro** table, JackEngineControl* controler);
  100. virtual ~JackEngine();
  101. virtual int Open();
  102. virtual int Close();
  103. // Client management
  104. virtual int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status);
  105. virtual int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
  106. virtual int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
  107. virtual int ClientExternalClose(int refnum);
  108. virtual int ClientInternalClose(int refnum, bool wait);
  109. virtual int ClientActivate(int refnum, bool state);
  110. virtual int ClientDeactivate(int refnum);
  111. virtual int GetClientPID(const char* name);
  112. // Internal client management
  113. virtual int GetInternalClientName(int int_ref, char* name_res);
  114. virtual int InternalClientHandle(const char* client_name, int* status, int* int_ref);
  115. virtual int InternalClientUnload(int refnum, int* status);
  116. // Port management
  117. virtual int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, unsigned int* port);
  118. virtual int PortUnRegister(int refnum, jack_port_id_t port);
  119. virtual int PortConnect(int refnum, const char* src, const char* dst);
  120. virtual int PortDisconnect(int refnum, const char* src, const char* dst);
  121. virtual int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
  122. virtual int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
  123. // Graph
  124. virtual bool Process(jack_time_t callback_usecs);
  125. // Notifications
  126. virtual void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs);
  127. virtual void NotifyXRun(int refnum);
  128. virtual void NotifyGraphReorder();
  129. virtual void NotifyBufferSize(jack_nframes_t nframes);
  130. virtual void NotifyFreewheel(bool onoff);
  131. virtual void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
  132. virtual void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff);
  133. virtual void NotifyActivate(int refnum);
  134. };
  135. } // end of namespace
  136. #endif