~ps-jenkins/platform-api/latestsnapshot-recup

« back to all changes in this revision

Viewing changes to src/ubuntu/hybris/bridge.h

  • Committer: Tarmac
  • Author(s): Martin Pitt
  • Date: 2014-01-09 14:43:13 UTC
  • mfrom: (175.2.32 test-backend)
  • Revision ID: tarmac-20140109144313-csok7dl9bm5ys8aj
Add backend for simulated sensor data.

Approved by Ricardo Mendoza, PS Jenkins bot, Thomas Voß.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <assert.h>
23
23
#include <dlfcn.h>
24
24
#include <stddef.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
25
27
 
26
28
#define HIDDEN_SYMBOL __attribute__ ((visibility ("hidden")))
27
29
 
39
41
namespace internal
40
42
{
41
43
 
 
44
/* By default we load the backend from /system/lib/libubuntu_application_api.so
 
45
 * Programs can select a different backend with $UBUNTU_PLATFORM_API_BACKEND,
 
46
 * which either needs to be a full path or just the file name (then it will be
 
47
 * looked up in the usual library search path, see dlopen(3)).
 
48
 */
42
49
struct HIDDEN_SYMBOL ToApplication
43
50
{
44
51
    static const char* path()
45
52
    {
46
 
        return "/system/lib/libubuntu_application_api.so";
47
 
    }
48
 
};
49
 
 
50
 
struct HIDDEN_SYMBOL ToHardware
51
 
{
52
 
    static const char* path()
53
 
    {
54
 
        return "/system/lib/libubuntu_platform_hardware_api.so";
 
53
        static const char* cache = NULL;
 
54
 
 
55
        if (cache == NULL) {
 
56
            cache = secure_getenv("UBUNTU_PLATFORM_API_BACKEND");
 
57
            if (cache == NULL)
 
58
                cache = "/system/lib/libubuntu_application_api.so";
 
59
        }
 
60
 
 
61
        return cache;
55
62
    }
56
63
};
57
64
 
67
74
 
68
75
    void* resolve_symbol(const char* symbol) const
69
76
    {
70
 
        return android_dlsym(lib_handle, symbol);
 
77
        return dlsym_fn(lib_handle, symbol);
71
78
    }
72
79
 
73
80
  protected:
74
81
    Bridge() : lib_handle(android_dlopen(Scope::path(), RTLD_LAZY))
75
82
    {
 
83
        const char* path = Scope::path();
 
84
        /* use Android dl functions for Android libs in /system/, glibc dl
 
85
         * functions for others */
 
86
        if (strncmp(path, "/system/", 8) == 0) {
 
87
            lib_handle = android_dlopen(path, RTLD_LAZY);
 
88
            dlsym_fn = android_dlsym;
 
89
        } else {
 
90
            lib_handle = dlopen(path, RTLD_LAZY);
 
91
            dlsym_fn = dlsym;
 
92
        }
 
93
 
76
94
        assert(lib_handle && "Error loading ubuntu_application_api");
77
95
    }
78
96
 
82
100
    }
83
101
 
84
102
    void* lib_handle;
 
103
    void* (*dlsym_fn) (void*, const char*);
85
104
};
86
105
 
87
106
}