[FIX] build for new projects with PRIVATE_CAPI_APPFW
[platform/core/system/swap-probe.git] / helper / common_probe_init.cpp
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Vitaliy Cherepanov <v.cherepanov@samsung.com>
9  *
10  * This library is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU Lesser General Public License as published by the
12  * Free Software Foundation; either version 2.1 of the License, or (at your option)
13  * any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
16  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation, Inc., 51
22  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  * Contributors:
25  * - S-Core Co., Ltd
26  *
27  */
28
29 #include <unistd.h>
30 #include "common_probe_init.h"
31
32
33
34 //#define EGL_TEST
35
36 void dummy()
37 {
38         return;
39 }
40
41 void probe_terminate_with_err(const char *msg, const char *func_name,
42                               ORIGINAL_LIBRARY id)
43 {
44         char error_msg[1024];
45
46         sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_string[id]);
47         perror(error_msg);
48         PRINTERR(error_msg);
49         //wait for flush
50         sleep(1);
51         exit(0);
52
53 }
54
55 ////////////////////////////////////////////////////////////////////////////
56 //egl init probe function
57 //  params:
58 //    func_name    - original function name for dlsym search
59 //    func_pointer - original function pointer (return)
60 //
61 //  info
62 //    search original function by name
63 //    function have no return becouse on error it terminates main application
64 #ifdef EGL_TEST
65 void init_probe_egl(__attribute__ ((unused))const char *func_name, void **func_pointer,
66                     __attribute__ ((unused))ORIGINAL_LIBRARY id)
67 {
68         PRINTMSG(func_name);
69         *func_pointer = (void *)dummy;
70 }
71 #else
72 void init_probe_egl(const char *func_name, void **func_pointer,
73                     ORIGINAL_LIBRARY id)
74 {
75         void *faddr = 0;
76
77         (gProbeBlockCount++);
78         if (lib_handle[id] == ((void *)0)) {
79                 lib_handle[id] = dlopen(lib_string[id],
80                                         RTLD_LAZY | RTLD_GLOBAL);
81
82                 if (lib_handle[id] == ((void *)0))
83                         probe_terminate_with_err("dlopen failed", func_name, id);
84         };
85         faddr = dlsym(lib_handle[id], func_name);
86         if (faddr == __null || dlerror() != __null)
87                 probe_terminate_with_err("dlsym failed", func_name, id);
88         memcpy(func_pointer, &faddr, sizeof(faddr));
89         (gProbeBlockCount--);
90 }
91 #endif