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.

230 lines
7.0KB

  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 types.
  30. *
  31. * if a client cant save templates, i might just do a normal save.
  32. *
  33. * the rationale, why there is no quit without save, is that a client
  34. * might refuse to quit when it has unsaved data.
  35. * however some other clients might have already quit.
  36. * this results in too much confusion, so we just dont support that.
  37. * the session manager can check, if the saved state is different from a previous
  38. * save, and just remove the saved stuff.
  39. *
  40. * (an inquiry function, whether a quit is ok, followed by a quit event
  41. * would have a race)
  42. */
  43. enum JackSessionEventType {
  44. JackSessionSave = 1,
  45. JackSessionSaveAndQuit = 2,
  46. JackSessionSaveTemplate = 3
  47. };
  48. typedef enum JackSessionEventType jack_session_event_type_t;
  49. enum JackSessionFlags {
  50. /**
  51. * an error occured while saving.
  52. */
  53. JackSessionSaveError = 0x01,
  54. /**
  55. * this reply indicates that a client is part of a multiclient application.
  56. * the command reply is left empty. but the session manager should still
  57. * consider this client part of a session. it will come up due to invocation of another
  58. * client.
  59. */
  60. JackSessionChildClient = 0x02
  61. };
  62. typedef enum JackSessionFlags jack_session_flags_t;
  63. struct _jack_session_event {
  64. /**
  65. * the actual type of this session event.
  66. */
  67. jack_session_event_type_t type;
  68. /**
  69. * session_directory with trailing separator
  70. * this is per client. so the client can do whatever it likes in here.
  71. */
  72. const char *session_dir;
  73. /**
  74. * client_uuid which must be specified to jack_client_open on session reload.
  75. * client can specify it in the returned commandline as an option, or just save it
  76. * with the state file.
  77. */
  78. const char *client_uuid;
  79. /**
  80. * the command_line is the reply of the client.
  81. * it specifies in a platform dependent way, how the client must be restarted upon session reload.
  82. *
  83. * probably it should contain ${SESSION_DIR} instead of the actual session dir.
  84. * this would basically make the session dir moveable.
  85. *
  86. * ownership of the memory is handed to jack.
  87. * initially set to NULL by jack;
  88. */
  89. char *command_line;
  90. /**
  91. * flags to be set by the client. normally left 0.
  92. */
  93. jack_session_flags_t flags;
  94. };
  95. typedef struct _jack_session_event jack_session_event_t;
  96. /**
  97. * Prototype for the client supplied function that is called
  98. * whenever a session notification is sent via jack_session_notify().
  99. *
  100. * The session_id must be passed to jack_client_open on session reload (this can be
  101. * done by specifying it somehow on the returned command line).
  102. *
  103. * @param event the event_structure.
  104. * @param arg pointer to a client supplied structure
  105. */
  106. typedef void (*JackSessionCallback)(jack_session_event_t *event, void *arg);
  107. /**
  108. * Tell the JACK server to call @a save_callback the session handler wants
  109. * to save.
  110. *
  111. * @return 0 on success, otherwise a non-zero error code
  112. */
  113. int jack_set_session_callback(jack_client_t *client,
  114. JackSessionCallback session_callback,
  115. void *arg) JACK_WEAK_EXPORT;
  116. /**
  117. * reply to a session_event
  118. *
  119. * this can either be called directly from the callback, or later from a different thread.
  120. * so its possible to just stick the event pointer into a pipe and execute the save code
  121. * from the gui thread.
  122. *
  123. * @return 0 on success, otherwise a non-zero error code
  124. */
  125. int jack_session_reply( jack_client_t *client, jack_session_event_t *event ) JACK_WEAK_EXPORT;
  126. /**
  127. * free memory used by a jack_session_event_t
  128. * this also frees the memory used by the command_line pointer.
  129. * if its non NULL.
  130. */
  131. void jack_session_event_free (jack_session_event_t *event);
  132. /*@}*/
  133. /**
  134. * @defgroup JackSessionManagerAPI this API is intended for a sessionmanager.
  135. * this API could be server specific. if we dont reach consensus here,
  136. * we can just drop it.
  137. * i know its a bit clumsy.
  138. * but this api isnt required to be as stable as the client api.
  139. * @{
  140. */
  141. typedef struct {
  142. const char *uuid;
  143. const char *client_name;
  144. const char *command;
  145. jack_session_flags_t flags;
  146. } jack_session_command_t;
  147. /**
  148. * send a save or quit event, to all clients listening for session
  149. * callbacks. the returned strings of the clients are accumulated and
  150. * returned as an array of jack_session_command_t.
  151. * its terminated by ret[i].uuid == NULL
  152. * target == NULL means send to all interested clients. otherwise a clientname
  153. */
  154. jack_session_command_t *jack_session_notify (jack_client_t* client,
  155. const char *target,
  156. jack_session_event_type_t type,
  157. const char *path ) JACK_WEAK_EXPORT;
  158. /**
  159. * free the memory allocated by a session command.
  160. */
  161. void jack_session_commands_free (jack_session_command_t *cmds) JACK_WEAK_EXPORT;
  162. /**
  163. * get the sessionid for a client name.
  164. * the sessionmanager needs this to reassociate a client_name to the session_id.
  165. */
  166. char *jack_get_uuid_for_client_name( jack_client_t *client, const char *client_name ) JACK_WEAK_EXPORT;
  167. /**
  168. * get the client name for a session_id.
  169. * in order to snapshot the graph connections, the sessionmanager needs to map
  170. * session_ids to client names.
  171. */
  172. char *jack_get_client_name_by_uuid( jack_client_t *client, const char *client_uuid ) JACK_WEAK_EXPORT;
  173. /**
  174. * reserve a client name and associate it to a uuid.
  175. * when a client later call jack_client_open() and specifies the uuid,
  176. * jackd will assign the reserved name.
  177. * this allows a session manager to know in advance under which client name
  178. * its managed clients will appear.
  179. *
  180. * @return 0 on success, otherwise a non-zero error code
  181. */
  182. int
  183. jack_reserve_client_name( jack_client_t *client, const char *name, const char *uuid ) JACK_WEAK_EXPORT;
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif