]> code.delx.au - pulseaudio/blob - polyp/polyplib-context.h
implement proper refcounting in polyplib
[pulseaudio] / polyp / polyplib-context.h
1 #ifndef foopolyplibcontexthfoo
2 #define foopolyplibcontexthfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
9 polypaudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
13
14 polypaudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include "sample.h"
26 #include "polyplib-def.h"
27 #include "mainloop-api.h"
28 #include "cdecl.h"
29 #include "polyplib-operation.h"
30
31 /** \file
32 * Connection contexts */
33
34 PA_C_DECL_BEGIN
35
36 /** The state of a connection context */
37 enum pa_context_state {
38 PA_CONTEXT_UNCONNECTED, /**< The context hasn't been connected yet */
39 PA_CONTEXT_CONNECTING, /**< A connection is being established */
40 PA_CONTEXT_AUTHORIZING, /**< The client is authorizing itself to the daemon */
41 PA_CONTEXT_SETTING_NAME, /**< The client is passing its application name to the daemon */
42 PA_CONTEXT_READY, /**< The connection is established, the context is ready to execute operations */
43 PA_CONTEXT_FAILED, /**< The connection failed or was disconnected */
44 PA_CONTEXT_TERMINATED /**< The connect was terminated cleanly */
45 };
46
47 /** \struct pa_context
48 * A connection context to a daemon */
49 struct pa_context;
50
51 /** Instantiate a new connection context with an abstract mainloop API
52 * and an application name */
53 struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
54
55 /** Decrease the reference counter of the context by one */
56 void pa_context_unref(struct pa_context *c);
57
58 /** Increase the reference counter of the context by one */
59 struct pa_context* pa_context_ref(struct pa_context *c);
60
61 /** Set a callback function that is called whenever the context status changes */
62 void pa_context_set_state_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
63
64 /** Return the error number of the last failed operation */
65 int pa_context_errno(struct pa_context *c);
66
67 /** Return non-zero if some data is pending to be written to the connection */
68 int pa_context_is_pending(struct pa_context *c);
69
70 /** Return the current context status */
71 enum pa_context_state pa_context_get_state(struct pa_context *c);
72
73 /** Connect the context to the specified server. If server is NULL,
74 connect to the default server. This routine may but will not always
75 return synchronously on error. Use pa_context_set_state_callback() to
76 be notified when the connection is established */
77 int pa_context_connect(struct pa_context *c, const char *server);
78
79 /** Terminate the context connection immediately */
80 void pa_context_disconnect(struct pa_context *c);
81
82 /** Drain the context. If there is nothing to drain, the function returns NULL */
83 struct pa_operation* pa_context_drain(struct pa_context *c, void (*cb) (struct pa_context*c, void *userdata), void *userdata);
84
85 /** Tell the daemon to exit. No operation object is returned as the
86 * connection is terminated when the daemon quits, thus this operation
87 * would never complete. */
88 void pa_context_exit_daemon(struct pa_context *c);
89
90 PA_C_DECL_END
91
92 #endif