source: roaraudio/libroarpulse/context.c @ 3390:d9db3bb263d5

Last change on this file since 3390:d9db3bb263d5 was 3390:d9db3bb263d5, checked in by phi, 10 years ago

a lot code

File size: 3.4 KB
Line 
1//context.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include <libroarpulse/libroarpulse.h>
40
41struct pa_context {
42 size_t refc;
43 struct roar_connection con;
44 char * server;
45 int state;
46};
47
48// older versions:
49typedef void pa_proplist;
50pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist);
51
52pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) {
53 return pa_context_new_with_proplist(mainloop, name, NULL);
54}
55
56pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist) {
57 pa_context * c;
58
59 if ( proplist != NULL )
60  return NULL;
61
62 if ( (c = roar_mm_malloc(sizeof(pa_context))) == NULL )
63  return NULL;
64
65 memset(c, 0, sizeof(pa_context));
66
67 c->refc  = 1;
68
69 c->state = PA_CONTEXT_UNCONNECTED;
70
71 return NULL;
72}
73
74static void _context_free(pa_context *c) {
75 pa_context_disconnect(c);
76
77 if ( c->server != NULL )
78  roar_mm_free(c->server);
79
80 roar_mm_free(c);
81}
82
83pa_context* pa_context_ref(pa_context *c) {
84 c->refc++;
85 return c;
86}
87
88void pa_context_unref(pa_context *c) {
89 c->refc--;
90
91 if ( c->refc < 1 )
92  _context_free(c);
93}
94
95int pa_context_connect(
96        pa_context *c,
97        const char *server,
98        pa_context_flags_t flags,
99        const pa_spawn_api *api) {
100
101 if ( c == NULL )
102  return -1;
103
104 if ( c->state != PA_CONTEXT_UNCONNECTED )
105  return -1;
106
107 // we do currently not support to spawn a daemon, so we ignore flags and api.
108
109 server = roar_pa_find_server((char*)server);
110
111 if ( roar_simple_connect(&(c->con), (char*)server, "libroarpulse [pa_context_connect()]") == -1 ) {
112  c->state = PA_CONTEXT_FAILED;
113  return -1;
114 }
115
116 c->server = roar_mm_strdup(server);
117 c->state  = PA_CONTEXT_READY;
118
119 return 0;
120}
121
122void pa_context_disconnect(pa_context *c) {
123 if ( c == NULL )
124  return;
125
126 if ( c->state != PA_CONTEXT_READY )
127  return;
128
129 roar_disconnect(&(c->con));
130
131 c->state = PA_CONTEXT_TERMINATED;
132}
133
134//ll
Note: See TracBrowser for help on using the repository browser.