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.

162 lines
5.8KB

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