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.

175 lines
6.3KB

  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 "JackMutex.h"
  21. #include "JackTransportEngine.h"
  22. #include "JackPlatformPlug.h"
  23. #include "JackRequest.h"
  24. #include "JackChannel.h"
  25. #include <map>
  26. namespace Jack
  27. {
  28. class JackClientInterface;
  29. struct JackEngineControl;
  30. class JackExternalClient;
  31. /*!
  32. \brief Engine description.
  33. */
  34. class SERVER_EXPORT JackEngine : public JackLockAble
  35. {
  36. friend class JackLockedEngine;
  37. private:
  38. JackGraphManager* fGraphManager;
  39. JackEngineControl* fEngineControl;
  40. char fSelfConnectMode;
  41. JackClientInterface* fClientTable[CLIENT_NUM];
  42. JackSynchro* fSynchroTable;
  43. JackServerNotifyChannel fChannel; /*! To communicate between the RT thread and server */
  44. JackProcessSync fSignal;
  45. jack_time_t fLastSwitchUsecs;
  46. JackMetadata fMetadata;
  47. int fSessionPendingReplies;
  48. detail::JackChannelTransactionInterface* fSessionTransaction;
  49. JackSessionNotifyResult* fSessionResult;
  50. std::map<int,std::string> fReservationMap;
  51. int ClientCloseAux(int refnum, bool wait);
  52. void CheckXRun(jack_time_t callback_usecs);
  53. int NotifyAddClient(JackClientInterface* new_client, const char* new_name, int refnum);
  54. void NotifyRemoveClient(const char* name, int refnum);
  55. void ProcessNext(jack_time_t callback_usecs);
  56. void ProcessCurrent(jack_time_t callback_usecs);
  57. bool ClientCheckName(const char* name);
  58. bool GenerateUniqueName(char* name);
  59. int AllocateRefnum();
  60. void ReleaseRefnum(int refnum);
  61. int ClientNotify(JackClientInterface* client, int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
  62. void NotifyClient(int refnum, int event, int sync, const char* message, int value1, int value2);
  63. void NotifyClients(int event, int sync, const char* message, int value1, int value2);
  64. void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
  65. void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff);
  66. void NotifyPortRename(jack_port_id_t src, const char* old_name);
  67. void NotifyActivate(int refnum);
  68. void EnsureUUID(jack_uuid_t uuid);
  69. bool CheckClient(int refnum)
  70. {
  71. return (refnum >= 0 && refnum < CLIENT_NUM && fClientTable[refnum] != NULL);
  72. }
  73. int CheckPortsConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
  74. public:
  75. JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode);
  76. ~JackEngine();
  77. int Open();
  78. int Close();
  79. // Client management
  80. int ClientCheck(const char* name, jack_uuid_t uuid, char* name_res, int protocol, int options, int* status);
  81. int ClientExternalOpen(const char* name, int pid, jack_uuid_t uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
  82. int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
  83. int ClientExternalClose(int refnum);
  84. int ClientInternalClose(int refnum, bool wait);
  85. int ClientActivate(int refnum, bool is_real_time);
  86. int ClientDeactivate(int refnum);
  87. void ClientKill(int refnum);
  88. int GetClientPID(const char* name);
  89. int GetClientRefNum(const char* name);
  90. // Internal client management
  91. int GetInternalClientName(int int_ref, char* name_res);
  92. int InternalClientHandle(const char* client_name, int* status, int* int_ref);
  93. int InternalClientUnload(int refnum, int* status);
  94. // Port management
  95. int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port);
  96. int PortUnRegister(int refnum, jack_port_id_t port);
  97. int PortConnect(int refnum, const char* src, const char* dst);
  98. int PortDisconnect(int refnum, const char* src, const char* dst);
  99. int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
  100. int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
  101. int PortRename(int refnum, jack_port_id_t port, const char* name);
  102. int PortSetDefaultMetadata(jack_port_id_t port, const char* pretty_name);
  103. int ComputeTotalLatencies();
  104. int PropertyChangeNotify(jack_uuid_t subject, const char* key,jack_property_change_t change);
  105. // Graph
  106. bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
  107. // Notifications
  108. void NotifyDriverXRun();
  109. void NotifyClientXRun(int refnum);
  110. void NotifyFailure(int code, const char* reason);
  111. void NotifyGraphReorder();
  112. void NotifyBufferSize(jack_nframes_t buffer_size);
  113. void NotifySampleRate(jack_nframes_t sample_rate);
  114. void NotifyFreewheel(bool onoff);
  115. void NotifyQuit();
  116. // Session management
  117. void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result);
  118. int SessionReply(int refnum);
  119. int GetUUIDForClientName(const char *client_name, char *uuid_res);
  120. int GetClientNameForUUID(const char *uuid, char *name_res);
  121. int ReserveClientName(const char *name, const char *uuid);
  122. int ClientHasSessionCallback(const char *name);
  123. };
  124. } // end of namespace
  125. #endif