~rsalveti/+junk/platform-api-mir

« back to all changes in this revision

Viewing changes to src/hybris/hybris_bridge.h

  • Committer: Ricardo Mendoza
  • Date: 2013-06-14 21:33:34 UTC
  • mfrom: (61.3.66 mir)
  • Revision ID: ricardo.mendoza@canonical.com-20130614213334-mzcv4cmf3j47rihc
Enable Mir in packaging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical Ltd
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Thomas Voss <thomas.voss@canonical.com>
 
17
 *              Ricardo Mendoza <ricardo.mendoza@canonical.com>
 
18
 */
 
19
 
 
20
#ifndef UBUNTU_APPLICATION_API_HYBRIS_BRIDGE_H_
 
21
#define UBUNTU_APPLICATION_API_HYBRIS_BRIDGE_H_
 
22
 
 
23
#include <stddef.h>
 
24
 
 
25
namespace ubuntu
 
26
{
 
27
namespace hybris
 
28
{
 
29
 
 
30
struct Bridge
 
31
{
 
32
    Bridge();
 
33
    ~Bridge();
 
34
 
 
35
    static const char* path_to_library();
 
36
    static Bridge& instance();
 
37
    
 
38
    void* resolve_symbol(const char* symbol) const;
 
39
 
 
40
    void* lib_handle;
 
41
};
 
42
 
 
43
}
 
44
}
 
45
 
 
46
// Sweet and beautiful music.
 
47
#define DLSYM(fptr, sym) if (*(fptr) == NULL) { *((void**)fptr) = (void *) ubuntu::hybris::Bridge::instance().resolve_symbol(sym); }
 
48
    
 
49
#define IMPLEMENT_FUNCTION0(return_type, symbol)  \
 
50
    return_type symbol()                          \
 
51
    {                                             \
 
52
        static return_type (*f)() = NULL;         \
 
53
        DLSYM(&f, #symbol);                       \
 
54
        return f();}
 
55
 
 
56
#define IMPLEMENT_VOID_FUNCTION0(symbol)          \
 
57
    void symbol()                                 \
 
58
    {                                             \
 
59
        static void (*f)() = NULL;                \
 
60
        DLSYM(&f, #symbol);                       \
 
61
        f();}
 
62
    
 
63
#define IMPLEMENT_FUNCTION1(return_type, symbol, arg1) \
 
64
    return_type symbol(arg1 _1)                        \
 
65
    {                                                  \
 
66
        static return_type (*f)(arg1) = NULL;          \
 
67
        DLSYM(&f, #symbol);                     \
 
68
        return f(_1); }
 
69
 
 
70
#define IMPLEMENT_SF_FUNCTION1(return_type, symbol, arg1) \
 
71
    return_type symbol(arg1 _1)                        \
 
72
    {                                                  \
 
73
        static return_type (*f)(arg1) __attribute__((pcs("aapcs"))) = NULL; \
 
74
        DLSYM(&f, #symbol);                     \
 
75
        return f(_1); }
 
76
 
 
77
 
 
78
#define IMPLEMENT_VOID_FUNCTION1(symbol, arg1)               \
 
79
    void symbol(arg1 _1)                                     \
 
80
    {                                                        \
 
81
        static void (*f)(arg1) = NULL;                       \
 
82
        DLSYM(&f, #symbol);                           \
 
83
        f(_1); }
 
84
 
 
85
#define IMPLEMENT_FUNCTION2(return_type, symbol, arg1, arg2)    \
 
86
    return_type symbol(arg1 _1, arg2 _2)                        \
 
87
    {                                                           \
 
88
        static return_type (*f)(arg1, arg2) = NULL;             \
 
89
        DLSYM(&f, #symbol);                              \
 
90
        return f(_1, _2); }
 
91
 
 
92
#define IMPLEMENT_VOID_FUNCTION2(symbol, arg1, arg2)            \
 
93
    void symbol(arg1 _1, arg2 _2)                               \
 
94
    {                                                           \
 
95
        static void (*f)(arg1, arg2) = NULL;                    \
 
96
        DLSYM(&f, #symbol);                              \
 
97
        f(_1, _2); }
 
98
 
 
99
#define IMPLEMENT_FUNCTION3(return_type, symbol, arg1, arg2, arg3)    \
 
100
    return_type symbol(arg1 _1, arg2 _2, arg3 _3)                     \
 
101
    {                                                                 \
 
102
        static return_type (*f)(arg1, arg2, arg3) = NULL;             \
 
103
        DLSYM(&f, #symbol);                                           \
 
104
        return f(_1, _2, _3); } 
 
105
 
 
106
#define IMPLEMENT_VOID_FUNCTION3(symbol, arg1, arg2, arg3)      \
 
107
    void symbol(arg1 _1, arg2 _2, arg3 _3)                      \
 
108
    {                                                           \
 
109
        static void (*f)(arg1, arg2, arg3) = NULL;              \
 
110
        DLSYM(&f, #symbol);                                     \
 
111
        f(_1, _2, _3); }
 
112
 
 
113
#define IMPLEMENT_VOID_FUNCTION4(symbol, arg1, arg2, arg3, arg4) \
 
114
    void symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4)              \
 
115
    {                                                            \
 
116
        static void (*f)(arg1, arg2, arg3, arg4) = NULL;         \
 
117
        DLSYM(&f, #symbol);                                      \
 
118
        f(_1, _2, _3, _4); }
 
119
 
 
120
#define IMPLEMENT_FUNCTION4(return_type, symbol, arg1, arg2, arg3, arg4) \
 
121
    return_type symbol(arg1 _1, arg2 _2, arg3 _3, arg4 _4)               \
 
122
    {                                                                    \
 
123
        static return_type (*f)(arg1, arg2, arg3, arg4) = NULL;          \
 
124
        DLSYM(&f, #symbol);                                              \
 
125
        return f(_1, _2, _3, _4); }
 
126
 
 
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)         \
 
129
    {                                                                                \
 
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); }
 
133
 
 
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) \
 
136
    {                                                                   \
 
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); }
 
140
 
 
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) \
 
143
    {                                                                   \
 
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); }
 
147
 
 
148
#endif // UBUNTU_APPLICATION_API_HYBRIS_BRIDGE_H_