2
* Copyright (C) 2013 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voss <thomas.voss@canonical.com>
17
* Ricardo Mendoza <ricardo.mendoza@canonical.com>
20
#ifndef UBUNTU_APPLICATION_API_HYBRIS_BRIDGE_H_
21
#define UBUNTU_APPLICATION_API_HYBRIS_BRIDGE_H_
35
static const char* path_to_library();
36
static Bridge& instance();
38
void* resolve_symbol(const char* symbol) const;
46
// Sweet and beautiful music.
47
#define DLSYM(fptr, sym) if (*(fptr) == NULL) { *((void**)fptr) = (void *) ubuntu::hybris::Bridge::instance().resolve_symbol(sym); }
49
#define IMPLEMENT_FUNCTION0(return_type, symbol) \
50
return_type symbol() \
52
static return_type (*f)() = NULL; \
56
#define IMPLEMENT_VOID_FUNCTION0(symbol) \
59
static void (*f)() = NULL; \
63
#define IMPLEMENT_FUNCTION1(return_type, symbol, arg1) \
64
return_type symbol(arg1 _1) \
66
static return_type (*f)(arg1) = NULL; \
70
#define IMPLEMENT_SF_FUNCTION1(return_type, symbol, arg1) \
71
return_type symbol(arg1 _1) \
73
static return_type (*f)(arg1) __attribute__((pcs("aapcs"))) = NULL; \
78
#define IMPLEMENT_VOID_FUNCTION1(symbol, arg1) \
79
void symbol(arg1 _1) \
81
static void (*f)(arg1) = NULL; \
85
#define IMPLEMENT_FUNCTION2(return_type, symbol, arg1, arg2) \
86
return_type symbol(arg1 _1, arg2 _2) \
88
static return_type (*f)(arg1, arg2) = NULL; \
92
#define IMPLEMENT_VOID_FUNCTION2(symbol, arg1, arg2) \
93
void symbol(arg1 _1, arg2 _2) \
95
static void (*f)(arg1, arg2) = NULL; \
99
#define IMPLEMENT_FUNCTION3(return_type, symbol, arg1, arg2, arg3) \
100
return_type symbol(arg1 _1, arg2 _2, arg3 _3) \
102
static return_type (*f)(arg1, arg2, arg3) = NULL; \
103
DLSYM(&f, #symbol); \
104
return f(_1, _2, _3); }
106
#define IMPLEMENT_VOID_FUNCTION3(symbol, arg1, arg2, arg3) \
107
void symbol(arg1 _1, arg2 _2, arg3 _3) \
109
static void (*f)(arg1, arg2, arg3) = NULL; \
110
DLSYM(&f, #symbol); \
113
#define IMPLEMENT_VOID_FUNCTION4(symbol, arg1, arg2, arg3, arg4) \
114
void symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4) \
116
static void (*f)(arg1, arg2, arg3, arg4) = NULL; \
117
DLSYM(&f, #symbol); \
120
#define IMPLEMENT_FUNCTION4(return_type, symbol, arg1, arg2, arg3, arg4) \
121
return_type symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4) \
123
static return_type (*f)(arg1, arg2, arg3, arg4) = NULL; \
124
DLSYM(&f, #symbol); \
125
return f(_1, _2, _3, _4); }
127
#define IMPLEMENT_FUNCTION6(return_type, symbol, arg1, arg2, arg3, arg4, arg5, arg6) \
128
return_type symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4, arg5 _5, arg6 _6) \
130
static return_type (*f)(arg1, arg2, arg3, arg4, arg5, arg6) = NULL; \
131
DLSYM(&f, #symbol); \
132
return f(_1, _2, _3, _4, _5, _6); }
134
#define IMPLEMENT_VOID_FUNCTION7(symbol, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
135
void symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4, arg5 _5, arg6 _6, arg7 _7) \
137
static void (*f)(arg1, arg2, arg3, arg4, arg5, arg6, arg7) = NULL; \
138
DLSYM(&f, #symbol); \
139
f(_1, _2, _3, _4, _5, _6, _7); }
141
#define IMPLEMENT_VOID_FUNCTION8(symbol, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
142
void symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4, arg5 _5, arg6 _6, arg7 _7, arg8 _8) \
144
static void (*f)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) = NULL; \
145
DLSYM(&f, #symbol); \
146
f(_1, _2, _3, _4, _5, _6, _7, _8); }
148
#endif // UBUNTU_APPLICATION_API_HYBRIS_BRIDGE_H_