~ubuntu-branches/ubuntu/saucy/jack-audio-connection-kit/saucy

« back to all changes in this revision

Viewing changes to libjack/intclient.c

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-12-06 11:05:15 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081206110515-xa9v9pajr9jqvfvg
Tags: 0.115.6-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - Redirect stderr in bash completion (Debian #504488).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-file-style: "bsd"; -*- */
 
2
/*
 
3
 *  Copyright (C) 2004 Jack O'Quin
 
4
 *  
 
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
 *  
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU Lesser General Public License for more details.
 
14
 *  
 
15
 *  You should have received a copy of the GNU Lesser General Public License
 
16
 *  along with this program; if not, write to the Free Software 
 
17
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
 
 
23
#include <errno.h>
 
24
#include <stdarg.h>
 
25
#include <stdio.h>
 
26
#include <string.h>
 
27
 
 
28
#include <jack/internal.h>
 
29
#include <jack/intclient.h>
 
30
#include <jack/varargs.h>
 
31
 
 
32
#include "local.h"
 
33
 
 
34
static jack_intclient_t
 
35
jack_intclient_request(RequestType type, jack_client_t *client,
 
36
                  const char* client_name, jack_options_t options,
 
37
                  jack_status_t *status, jack_varargs_t *va)
 
38
{
 
39
        jack_request_t req;
 
40
 
 
41
        memset (&req, 0, sizeof (req));
 
42
 
 
43
        if (strlen (client_name) >= sizeof (req.x.intclient.name)) {
 
44
                jack_error ("\"%s\" is too long for a JACK client name.\n"
 
45
                            "Please use %lu characters or less.",
 
46
                            client_name, sizeof (req.x.intclient.name));
 
47
                return 0;
 
48
        }
 
49
 
 
50
        if (va->load_name
 
51
            && (strlen (va->load_name) > sizeof (req.x.intclient.path) - 1)) {
 
52
                jack_error ("\"%s\" is too long for a shared object name.\n"
 
53
                             "Please use %lu characters or less.",
 
54
                            va->load_name, sizeof (req.x.intclient.path) - 1);
 
55
                *status |= (JackFailure|JackInvalidOption);
 
56
                return 0;
 
57
        }
 
58
 
 
59
        if (va->load_init
 
60
            && (strlen (va->load_init) > sizeof (req.x.intclient.init) - 1)) {
 
61
                jack_error ("\"%s\" is too long for internal client init "
 
62
                            "string.\nPlease use %lu characters or less.",
 
63
                            va->load_init, sizeof (req.x.intclient.init) - 1);
 
64
                *status |= (JackFailure|JackInvalidOption);
 
65
                return 0;
 
66
        }
 
67
 
 
68
        req.type = type;
 
69
        req.x.intclient.options = options;
 
70
        strncpy (req.x.intclient.name, client_name,
 
71
                 sizeof (req.x.intclient.name));
 
72
        if (va->load_name)
 
73
                strncpy (req.x.intclient.path, va->load_name,
 
74
                         sizeof (req.x.intclient.path));
 
75
        if (va->load_init)
 
76
                strncpy (req.x.intclient.init, va->load_init,
 
77
                         sizeof (req.x.intclient.init));
 
78
 
 
79
        jack_client_deliver_request (client, &req);
 
80
 
 
81
        *status |= req.status;
 
82
 
 
83
        if (*status & JackFailure)
 
84
                return 0;
 
85
 
 
86
        return req.x.intclient.id;
 
87
}
 
88
 
 
89
char *
 
90
jack_get_internal_client_name (jack_client_t *client,
 
91
                               jack_intclient_t intclient)
 
92
{
 
93
        jack_request_t req;
 
94
        char *name;
 
95
 
 
96
        memset (&req, 0, sizeof (req));
 
97
        req.type = IntClientName;
 
98
        req.x.intclient.options = JackNullOption;
 
99
        req.x.intclient.id = intclient;
 
100
 
 
101
        jack_client_deliver_request (client, &req);
 
102
 
 
103
        if (req.status & JackFailure)
 
104
                return NULL;
 
105
 
 
106
        /* allocate storage for returning the name */
 
107
        name = malloc (strlen (req.x.intclient.name));
 
108
        strcpy (name, req.x.intclient.name);
 
109
 
 
110
        return name;
 
111
}
 
112
 
 
113
jack_intclient_t
 
114
jack_internal_client_handle (jack_client_t *client,
 
115
                             const char *client_name,
 
116
                             jack_status_t *status)
 
117
{
 
118
        jack_request_t req;
 
119
        jack_status_t my_status;
 
120
 
 
121
        if (status == NULL)             /* no status from caller? */
 
122
                status = &my_status;    /* use local status word */
 
123
        *status = 0;
 
124
 
 
125
        memset (&req, 0, sizeof (req));
 
126
        req.type = IntClientHandle;
 
127
        req.x.intclient.options = JackNullOption;
 
128
        strncpy (req.x.intclient.name, client_name,
 
129
                 sizeof (req.x.intclient.name));
 
130
 
 
131
        *status = jack_client_deliver_request (client, &req);
 
132
 
 
133
        return req.x.intclient.id;
 
134
}
 
135
 
 
136
jack_intclient_t
 
137
jack_internal_client_load_aux (jack_client_t *client,
 
138
                  const char *client_name,
 
139
                  jack_options_t options,
 
140
                  jack_status_t *status, va_list ap)
 
141
{
 
142
        jack_varargs_t va;
 
143
        jack_status_t my_status;
 
144
 
 
145
        if (status == NULL)             /* no status from caller? */
 
146
                status = &my_status;    /* use local status word */
 
147
        *status = 0;
 
148
 
 
149
        /* validate parameters */
 
150
        if ((options & ~JackLoadOptions)) {
 
151
                *status |= (JackFailure|JackInvalidOption);
 
152
                return 0;
 
153
        }
 
154
 
 
155
        /* parse variable arguments */
 
156
        jack_varargs_parse (options, ap, &va);
 
157
 
 
158
        return jack_intclient_request (IntClientLoad, client, client_name,
 
159
                                       options, status, &va);
 
160
}
 
161
 
 
162
jack_intclient_t
 
163
jack_internal_client_load (jack_client_t *client,
 
164
                           const char *client_name,
 
165
                           jack_options_t options,
 
166
                           jack_status_t *status, ...)
 
167
{
 
168
    va_list ap;
 
169
    va_start(ap, status);
 
170
    jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
 
171
    va_end(ap);
 
172
    return res;
 
173
}
 
174
 
 
175
jack_status_t
 
176
jack_internal_client_unload (jack_client_t *client,
 
177
                             jack_intclient_t intclient)
 
178
{
 
179
        jack_request_t req;
 
180
        jack_status_t status;
 
181
 
 
182
        if (intclient) {
 
183
 
 
184
                memset (&req, 0, sizeof (req));
 
185
                req.type = IntClientUnload;
 
186
                req.x.intclient.options = JackNullOption;
 
187
                req.x.intclient.id = intclient;
 
188
                jack_client_deliver_request (client, &req);
 
189
                status = req.status;
 
190
 
 
191
        } else {                        /* intclient is null */
 
192
                status = (JackNoSuchClient|JackFailure);
 
193
        }
 
194
 
 
195
        return status;
 
196
}