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.

286 lines
8.6KB

  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/types.h>
  23. #include <jack/weakmacros.h>
  24. /**
  25. * @defgroup SessionClientFunctions Session API for clients.
  26. * @{
  27. */
  28. /**
  29. * Session event type.
  30. *
  31. * if a client cant save templates, i might just do a normal save.
  32. *
  33. * There is no "quit without saving" event because a client might refuse to
  34. * quit when it has unsaved data, but other clients may have already quit.
  35. * This results in too much confusion, so it is unsupported.
  36. */
  37. enum JackSessionEventType {
  38. /**
  39. * Save the session completely.
  40. *
  41. * The client may save references to data outside the provided directory,
  42. * but it must do so by creating a link inside the provided directory and
  43. * referring to that in any save files. The client must not refer to data
  44. * files outside the provided directory directly in save files, because
  45. * this makes it impossible for the session manager to create a session
  46. * archive for distribution or archival.
  47. */
  48. JackSessionSave = 1,
  49. /**
  50. * Save the session completly, then quit.
  51. *
  52. * The rules for saving are exactly the same as for JackSessionSave.
  53. */
  54. JackSessionSaveAndQuit = 2,
  55. /**
  56. * Save a session template.
  57. *
  58. * A session template is a "skeleton" of the session, but without any data.
  59. * Clients must save a session that, when restored, will create the same
  60. * ports as a full save would have. However, the actual data contained in
  61. * the session may not be saved (e.g. a DAW would create the necessary
  62. * tracks, but not save the actual recorded data).
  63. */
  64. JackSessionSaveTemplate = 3
  65. };
  66. typedef enum JackSessionEventType jack_session_event_type_t;
  67. /**
  68. * @ref jack_session_flags_t bits
  69. */
  70. enum JackSessionFlags {
  71. /**
  72. * An error occured while saving.
  73. */
  74. JackSessionSaveError = 0x01,
  75. /**
  76. * Client needs to be run in a terminal.
  77. */
  78. JackSessionNeedTerminal = 0x02
  79. };
  80. /**
  81. * Session flags.
  82. */
  83. typedef enum JackSessionFlags jack_session_flags_t;
  84. struct _jack_session_event {
  85. /**
  86. * The type of this session event.
  87. */
  88. jack_session_event_type_t type;
  89. /**
  90. * Session directory path, with trailing separator.
  91. *
  92. * This directory is exclusive to the client; when saving the client may
  93. * create any files it likes in this directory.
  94. */
  95. const char *session_dir;
  96. /**
  97. * Client UUID which must be passed to jack_client_open on session load.
  98. *
  99. * The client can specify this in the returned command line, or save it
  100. * in a state file within the session directory.
  101. */
  102. const char *client_uuid;
  103. /**
  104. * Reply (set by client): the command line needed to restore the client.
  105. *
  106. * This is a platform dependent command line. It must contain
  107. * ${SESSION_DIR} instead of the actual session directory path. More
  108. * generally, just as in session files, clients should not include any
  109. * paths outside the session directory here as this makes
  110. * archival/distribution impossible.
  111. *
  112. * This field is set to NULL by Jack when the event is delivered to the
  113. * client. The client must set to allocated memory that is safe to
  114. * free(). This memory will be freed by jack_session_event_free.
  115. */
  116. char *command_line;
  117. /**
  118. * Reply (set by client): Session flags.
  119. */
  120. jack_session_flags_t flags;
  121. /**
  122. * Future flags. Set to zero for now.
  123. */
  124. uint32_t future;
  125. };
  126. typedef struct _jack_session_event jack_session_event_t;
  127. /**
  128. * Prototype for the client supplied function that is called
  129. * whenever a session notification is sent via jack_session_notify().
  130. *
  131. * Ownership of the memory of @a event is passed to the application.
  132. * It must be freed using jack_session_event_free when its not used anymore.
  133. *
  134. * The client must promptly call jack_session_reply for this event.
  135. *
  136. * @param event The event structure.
  137. * @param arg Pointer to a client supplied structure.
  138. */
  139. typedef void (*JackSessionCallback)(jack_session_event_t *event,
  140. void *arg);
  141. /**
  142. * Tell the JACK server to call @a session_callback when a session event
  143. * is to be delivered.
  144. *
  145. * setting more than one session_callback per process is probably a design
  146. * error. if you have a multiclient application its more sensible to create
  147. * a jack_client with only a session callback set.
  148. *
  149. * @return 0 on success, otherwise a non-zero error code
  150. */
  151. int jack_set_session_callback (jack_client_t *client,
  152. JackSessionCallback session_callback,
  153. void *arg) JACK_WEAK_EXPORT;
  154. /**
  155. * Reply to a session event.
  156. *
  157. * This can either be called directly from the callback, or later from a
  158. * different thread. For example, it is possible to push the event through a
  159. * queue and execute the save code from the GUI thread.
  160. *
  161. * @return 0 on success, otherwise a non-zero error code
  162. */
  163. int jack_session_reply (jack_client_t *client,
  164. jack_session_event_t *event) JACK_WEAK_EXPORT;
  165. /**
  166. * free memory used by a jack_session_event_t
  167. * this also frees the memory used by the command_line pointer.
  168. * if its non NULL.
  169. */
  170. void jack_session_event_free (jack_session_event_t *event) JACK_WEAK_EXPORT;
  171. /**
  172. * get the assigned uuid for client.
  173. * safe to call from callback and all other threads.
  174. * memory needs to be freed.
  175. */
  176. char *jack_client_get_uuid (jack_client_t *client) JACK_WEAK_EXPORT;
  177. /**
  178. * @}
  179. */
  180. /**
  181. * @defgroup JackSessionManagerAPI API for a session manager.
  182. *
  183. * @{
  184. */
  185. typedef struct {
  186. const char *uuid;
  187. const char *client_name;
  188. const char *command;
  189. jack_session_flags_t flags;
  190. } jack_session_command_t;
  191. /**
  192. * Send an event to all clients listening for session callbacks.
  193. *
  194. * The returned strings of the clients are accumulated and returned as an array
  195. * of jack_session_command_t. its terminated by ret[i].uuid == NULL target ==
  196. * NULL means send to all interested clients. otherwise a clientname
  197. */
  198. jack_session_command_t *jack_session_notify (
  199. jack_client_t* client,
  200. const char *target,
  201. jack_session_event_type_t type,
  202. const char *path) JACK_WEAK_EXPORT;
  203. /**
  204. * Free the memory allocated by a session command.
  205. */
  206. void jack_session_commands_free (jack_session_command_t *cmds) JACK_WEAK_EXPORT;
  207. /**
  208. * Get the session ID for a client name.
  209. * The session manager needs this to reassociate a client name to the session_id.
  210. */
  211. char *jack_get_uuid_for_client_name (jack_client_t *client,
  212. const char *client_name) JACK_WEAK_EXPORT;
  213. /**
  214. * Get the client name for a session_id.
  215. *
  216. * In order to snapshot the graph connections, the session manager needs to map
  217. * session_ids to client names.
  218. */
  219. char *jack_get_client_name_by_uuid (jack_client_t *client,
  220. const char *client_uuid ) JACK_WEAK_EXPORT;
  221. /**
  222. * Reserve a client name and associate it with a UUID.
  223. *
  224. * When a client later calls jack_client_open() and specifies the UUID, jackd
  225. * will assign the reserved name. This allows a session manager to know in
  226. * advance under which client name its managed clients will appear.
  227. *
  228. * @return 0 on success, otherwise a non-zero error code
  229. */
  230. int
  231. jack_reserve_client_name (jack_client_t *client,
  232. const char *name,
  233. const char *uuid) JACK_WEAK_EXPORT;
  234. /**
  235. * Find out whether a client has set up a session callback.
  236. *
  237. * @return 0 when the client has no session callback, 1 when it has one.
  238. * -1 on error.
  239. */
  240. int
  241. jack_client_has_session_callback (jack_client_t *client, const char *client_name) JACK_WEAK_EXPORT;
  242. #ifdef __cplusplus
  243. }
  244. #endif
  245. #endif