source: roaraudio/libroar/enumdev.c @ 4352:6c46e5e41e82

Last change on this file since 4352:6c46e5e41e82 was 4352:6c46e5e41e82, checked in by phi, 14 years ago

wrote everything needed to get a list of exactly the default entry

File size: 3.3 KB
Line 
1//enumdev.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38// TODO: we should put all the data in one big alloced block.
39
40struct locmed {
41 int supflags;
42 ssize_t (*func)(int flags, int dir, int socktype, char ** servers, size_t maxlen);
43};
44
45static struct locmed _libroar_locmod[] = {
46};
47
48struct roar_server * roar_enum_servers(int flags, int dir, int socktype) {
49 struct roar_server * ret = NULL;
50 struct roar_server * c;
51 char * servers[64];
52 size_t have = 1;
53 size_t i;
54 ssize_t r;
55 int testflags = flags;
56
57 if ( testflags & ROAR_ENUM_FLAG_DESC )
58  testflags -= ROAR_ENUM_FLAG_DESC;
59 if ( testflags & ROAR_ENUM_FLAG_LOCATION )
60  testflags -= ROAR_ENUM_FLAG_LOCATION;
61
62 for (i = 0; i < sizeof(_libroar_locmod)/sizeof(*_libroar_locmod); i++) {
63  if ( (_libroar_locmod[i].supflags & testflags) == testflags ) {
64   r = _libroar_locmod[i].func(flags, dir, socktype, &(servers[have-1]), (sizeof(servers)/sizeof(*servers)) - have);
65   if ( r > 0 )
66    have += r;
67  }
68 }
69
70 ret = roar_mm_malloc(have*sizeof(struct roar_server));
71
72 if (ret == NULL)
73  return NULL;
74
75 have--;
76
77 for (i = 0; i < have; i++) {
78  c = &(ret[i]);
79  c->server = servers[i];
80  c->description = NULL;
81  c->location = NULL;
82 }
83
84 ret[have].server = NULL;
85 ret[have].description = roar_mm_strdup("Default server");
86 ret[have].location = NULL;
87
88 return ret;
89}
90
91int roar_enum_servers_free(struct roar_server * servs) {
92 struct roar_server * c;
93 int i;
94
95 if ( servs == NULL )
96  return -1;
97
98 for (i = 0; (c = &(servs[i]))->server != NULL; i++) {
99  roar_mm_free((void*)c->server);
100  if ( c->description != NULL )
101   roar_mm_free((void*)c->description);
102  if ( c->location != NULL )
103   roar_mm_free((void*)c->location);
104 }
105
106 if ( c->description != NULL )
107  roar_mm_free((void*)c->description);
108 if ( c->location != NULL )
109  roar_mm_free((void*)c->location);
110
111 roar_mm_free(servs);
112
113 return 0;
114}
115
116ssize_t roar_enum_servers_num(struct roar_server * servs) {
117 size_t ret;
118
119 if ( servs == NULL )
120  return -1;
121
122 for (ret = 0; servs[ret].server != NULL; ret++);
123
124 return ret;
125}
126
127//ll
Note: See TracBrowser for help on using the repository browser.