jack1 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.

220 lines
6.5KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004 Jack O'Quin
  4. Copyright (C) 2010 Torben Hohn
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. #ifndef __jack_session_h__
  18. #define __jack_session_h__
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include <jack/weakmacros.h>
  23. /**
  24. * @defgroup SessionClientFunctions Session API for clients.
  25. * @{
  26. */
  27. /**
  28. * session event types.
  29. *
  30. * if a client cant save templates, i might just do a normal save.
  31. *
  32. * the rationale, why there is no quit without save, is that a client
  33. * might refuse to quit when it has unsaved data.
  34. * however some other clients might have already quit.
  35. * this results in too much confusion, so we just dont support that.
  36. * the session manager can check, if the saved state is different from a previous
  37. * save, and just remove the saved stuff.
  38. *
  39. * (an inquiry function, whether a quit is ok, followed by a quit event
  40. * would have a race)
  41. */
  42. enum JackSessionEventType {
  43. JackSessionSave = 1,
  44. JackSessionSaveAndQuit = 2,
  45. JackSessionSaveTemplate = 3
  46. };
  47. typedef enum JackSessionEventType jack_session_event_type_t;
  48. enum JackSessionFlags {
  49. /**
  50. * an error occured while saving.
  51. */
  52. JackSessionSaveError = 0x01,
  53. /**
  54. * this reply indicates that a client is part of a multiclient application.
  55. * the command reply is left empty. but the session manager should still
  56. * consider this client part of a session. it will come up due to invocation of another
  57. * client.
  58. */
  59. JackSessionChildClient = 0x02
  60. };
  61. typedef enum JackSessionFlags jack_session_flags_t;
  62. struct _jack_session_event {
  63. /**
  64. * the actual type of this session event.
  65. */
  66. jack_session_event_type_t type;
  67. /**
  68. * session_directory with trailing separator
  69. * this is per client. so the client can do whatever it likes in here.
  70. */
  71. const char *session_dir;
  72. /**
  73. * client_uuid which must be specified to jack_client_open on session reload.
  74. * client can specify it in the returned commandline as an option, or just save it
  75. * with the state file.
  76. */
  77. const char *client_uuid;
  78. /**
  79. * the command_line is the reply of the client.
  80. * it specifies in a platform dependent way, how the client must be restarted upon session reload.
  81. *
  82. * probably it should contain ${SESSION_DIR} instead of the actual session dir.
  83. * this would basically make the session dir moveable.
  84. *
  85. * ownership of the memory is handed to jack.
  86. * initially set to NULL by jack;
  87. */
  88. char *command_line;
  89. /**
  90. * flags to be set by the client. normally left 0.
  91. */
  92. jack_session_flags_t flags;
  93. };
  94. typedef struct _jack_session_event jack_session_event_t;
  95. /**
  96. * Prototype for the client supplied function that is called
  97. * whenever a session notification is sent via jack_session_notify().
  98. *
  99. * The session_id must be passed to jack_client_open on session reload (this can be
  100. * done by specifying it somehow on the returned command line).
  101. *
  102. * @param event the event_structure.
  103. * @param arg pointer to a client supplied structure
  104. */
  105. typedef void (*JackSessionCallback)(jack_session_event_t *event, void *arg);
  106. /**
  107. * Tell the JACK server to call @a save_callback the session handler wants
  108. * to save.
  109. *
  110. * @return 0 on success, otherwise a non-zero error code
  111. */
  112. int jack_set_session_callback(jack_client_t *client,
  113. JackSessionCallback session_callback,
  114. void *arg) JACK_WEAK_EXPORT;
  115. /**
  116. * reply to a session_event
  117. *
  118. * this can either be called directly from the callback, or later from a different thread.
  119. * so its possible to just stick the event pointer into a pipe and execute the save code
  120. * from the gui thread.
  121. *
  122. * @return 0 on success, otherwise a non-zero error code
  123. */
  124. int jack_session_reply( jack_client_t *client, jack_session_event_t *event ) JACK_WEAK_EXPORT;
  125. /*@}*/
  126. /**
  127. * @defgroup JackSessionManagerAPI this API is intended for a sessionmanager.
  128. * this API could be server specific. if we dont reach consensus here,
  129. * we can just drop it.
  130. * i know its a bit clumsy.
  131. * but this api isnt required to be as stable as the client api.
  132. * @{
  133. */
  134. typedef struct {
  135. const char *uuid;
  136. const char *client_name;
  137. const char *command;
  138. } jack_session_command_t;
  139. /**
  140. * send a save or quit event, to all clients listening for session
  141. * callbacks. the returned strings of the clients are accumulated and
  142. * returned as an array of jack_session_command_t.
  143. * its terminated by ret[i].uuid == NULL
  144. * target == NULL means send to all interested clients. otherwise a clientname
  145. */
  146. jack_session_command_t *jack_session_notify (jack_client_t* client,
  147. const char *target,
  148. jack_session_event_type_t type,
  149. const char *path ) JACK_WEAK_EXPORT;
  150. /**
  151. * free the memory allocated by a session command.
  152. */
  153. void jack_session_commands_free (jack_session_command_t *cmds) JACK_WEAK_EXPORT;
  154. /**
  155. * get the sessionid for a client name.
  156. * the sessionmanager needs this to reassociate a client_name to the session_id.
  157. */
  158. char *jack_get_uuid_for_client_name( jack_client_t *client, const char *client_name ) JACK_WEAK_EXPORT;
  159. /**
  160. * get the client name for a session_id.
  161. * in order to snapshot the graph connections, the sessionmanager needs to map
  162. * session_ids to client names.
  163. */
  164. char *jack_get_client_name_by_uuid( jack_client_t *client, const char *client_uuid ) JACK_WEAK_EXPORT;
  165. /**
  166. * reserve a client name and associate it to a uuid.
  167. * when a client later call jack_client_open() and specifies the uuid,
  168. * jackd will assign the reserved name.
  169. * this allows a session manager to know in advance under which client name
  170. * its managed clients will appear.
  171. *
  172. * @return 0 on success, otherwise a non-zero error code
  173. */
  174. int
  175. jack_reserve_client_name( jack_client_t *client, const char *name, const char *uuid ) JACK_WEAK_EXPORT;
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif