• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /* this file is used to test that we can use libesd with lazy dynamic linking */
17 
18 #include <esd.h>
19 #include <dlfcn.h>
20 #include <stdio.h>
21 
22 #define  D(...)  fprintf(stderr,__VA_ARGS__)
23 #define  STRINGIFY(x)  _STRINGIFY(x)
24 #define _STRINGIFY(x)  #x
25 
26 #define  PULSEAUDIO_SYMBOLS \
27     PULSEAUDIO_SYMBOLS(pa_simple*,pa_simple_new,(const char* server,const char* name, pa_stream_direction_t dir, const char* dev, const char* stream_name, const pa_sample_spec* ss, const pa_channel_map* map, const pa_buffer_attr *attr, int *error)) \
28     PULSEAUDIO_SYMBOLS(void,pa+simple_free,(pa_simple* s))\
29     PULSEAUDIO_SYMBOLS(int,pa_simple_write,(pa_simple* s, const void* data, size_t bytes, int* error))\
30     PULSEAUDIO_SYMBOLS(int,pa_simple_read,(pa_simple* s,void* data, size_t bytes, int* error))\
31     PULSEAUDIO_SYMBOLS(const char*,pa_strerror,(int error))
32 
33 /* define pointers to library functions we're going to use */
34 #define  PULSEAUDIO_FUNCTION(ret,name,sig)   \
35     static ret  (*func_ ## name)sig;
36 
37 PULSEAUDIO_SYMBOLS
38 
39 #undef  PULSEAUDIO_FUNCTION
40 static void*    pa_lib;
41 
main(void)42 int main( void )
43 {
44     int  fd;
45 
46     pa_lib = dlopen( "libpulse-simple.so", RTLD_NOW );
47     if (pa_lib == NULL)
48         pa_lib = dlopen( "libpulse-simple.so.0", RTLD_NOW );
49 
50     if (pa_lib == NULL) {
51         D("could not find libpulse on this system");
52         return 1;
53     }
54 
55 #undef  PULSEAUDIO_FUNCTION
56 #define PULSEAUDIO_FUNCTION(ret,name,sig)                                               \
57     do {                                                                         \
58         (func_ ##name) = dlsym( pa_lib, STRINGIFY(name) );                      \
59         if ((func_##name) == NULL) {                                             \
60             D("could not find %s in libpulse\n", STRINGIFY(name));   \
61             return 1;                                               \
62         }                                                                        \
63     } while (0);
64 
65     PULSEAUDIO_SYMBOLS
66 
67     return 0;
68 }
69