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.

248 lines
7.2KB

  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. * client needs to be run in a terminal.
  56. */
  57. JackSessionNeedTerminal = 0x02
  58. };
  59. typedef enum JackSessionFlags jack_session_flags_t;
  60. struct _jack_session_event {
  61. /**
  62. * the actual type of this session event.
  63. */
  64. jack_session_event_type_t type;
  65. /**
  66. * session_directory with trailing separator
  67. * this is per client. so the client can do whatever it likes in here.
  68. */
  69. const char *session_dir;
  70. /**
  71. * client_uuid which must be specified to jack_client_open on session reload.
  72. * client can specify it in the returned commandline as an option, or just save it
  73. * with the state file.
  74. */
  75. const char *client_uuid;
  76. /**
  77. * the command_line is the reply of the client.
  78. * it specifies in a platform dependent way, how the client must be restarted upon session reload.
  79. *
  80. * it should contain ${SESSION_DIR} instead of the actual session dir.
  81. * this would basically make the session dir moveable.
  82. *
  83. * memory will be freed along with jack_session_event_free()
  84. * initially set to NULL by jack;
  85. */
  86. char *command_line;
  87. /**
  88. * flags to be set by the client. normally left 0.
  89. */
  90. jack_session_flags_t flags;
  91. /**
  92. * future flags. will be set to zero for now.
  93. */
  94. uint32_t future;
  95. };
  96. typedef struct _jack_session_event jack_session_event_t;
  97. /**
  98. * Prototype for the client supplied function that is called
  99. * whenever a session notification is sent via jack_session_notify().
  100. *
  101. * ownership of the memory of @a event is passed to the application.
  102. * it must be freed using jack_session_event_free when its not used anymore.
  103. *
  104. * the client is also required to call jack_session_reply for this event.
  105. * there is no timeout yet. and the only way to get back to a sane state
  106. * would be to kill this client.
  107. *
  108. * @param event the event_structure.
  109. * @param arg pointer to a client supplied structure
  110. */
  111. typedef void (*JackSessionCallback)(jack_session_event_t *event, void *arg);
  112. /**
  113. * Tell the JACK server to call @a session_callback when a session event
  114. * is to be delivered.
  115. *
  116. * setting more than one session_callback per process is probably a design
  117. * error. if you have a multiclient application its more sensible to create
  118. * a jack_client with only a session callback set.
  119. *
  120. * @return 0 on success, otherwise a non-zero error code
  121. */
  122. int jack_set_session_callback(jack_client_t *client,
  123. JackSessionCallback session_callback,
  124. void *arg) JACK_WEAK_EXPORT;
  125. /**
  126. * reply to a session_event
  127. *
  128. * this can either be called directly from the callback, or later from a different thread.
  129. * so its possible to just stick the event pointer into a pipe and execute the save code
  130. * from the gui thread.
  131. *
  132. * @return 0 on success, otherwise a non-zero error code
  133. */
  134. int jack_session_reply( jack_client_t *client, jack_session_event_t *event ) JACK_WEAK_EXPORT;
  135. /**
  136. * free memory used by a jack_session_event_t
  137. * this also frees the memory used by the command_line pointer.
  138. * if its non NULL.
  139. */
  140. void jack_session_event_free (jack_session_event_t *event) JACK_WEAK_EXPORT;
  141. /**
  142. * get the assigned uuid for client.
  143. * safe to call from callback and all other threads.
  144. * memory needs to be freed.
  145. */
  146. char *jack_client_get_uuid (jack_client_t *client) JACK_WEAK_EXPORT;
  147. /*@}*/
  148. /**
  149. * @defgroup JackSessionManagerAPI this API is intended for a sessionmanager.
  150. * this API could be server specific. if we dont reach consensus here,
  151. * we can just drop it.
  152. * i know its a bit clumsy.
  153. * but this api isnt required to be as stable as the client api.
  154. * @{
  155. */
  156. typedef struct {
  157. const char *uuid;
  158. const char *client_name;
  159. const char *command;
  160. jack_session_flags_t flags;
  161. } jack_session_command_t;
  162. /**
  163. * send a save or quit event, to all clients listening for session
  164. * callbacks. the returned strings of the clients are accumulated and
  165. * returned as an array of jack_session_command_t.
  166. * its terminated by ret[i].uuid == NULL
  167. * target == NULL means send to all interested clients. otherwise a clientname
  168. */
  169. jack_session_command_t *jack_session_notify (jack_client_t* client,
  170. const char *target,
  171. jack_session_event_type_t type,
  172. const char *path ) JACK_WEAK_EXPORT;
  173. /**
  174. * free the memory allocated by a session command.
  175. */
  176. void jack_session_commands_free (jack_session_command_t *cmds) JACK_WEAK_EXPORT;
  177. /**
  178. * get the sessionid for a client name.
  179. * the sessionmanager needs this to reassociate a client_name to the session_id.
  180. */
  181. char *jack_get_uuid_for_client_name( jack_client_t *client, const char *client_name ) JACK_WEAK_EXPORT;
  182. /**
  183. * get the client name for a session_id.
  184. * in order to snapshot the graph connections, the sessionmanager needs to map
  185. * session_ids to client names.
  186. */
  187. char *jack_get_client_name_by_uuid( jack_client_t *client, const char *client_uuid ) JACK_WEAK_EXPORT;
  188. /**
  189. * reserve a client name and associate it to a uuid.
  190. * when a client later call jack_client_open() and specifies the uuid,
  191. * jackd will assign the reserved name.
  192. * this allows a session manager to know in advance under which client name
  193. * its managed clients will appear.
  194. *
  195. * @return 0 on success, otherwise a non-zero error code
  196. */
  197. int
  198. jack_reserve_client_name( jack_client_t *client, const char *name, const char *uuid ) JACK_WEAK_EXPORT;
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif