1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a BSD-style license that can
4  *  be found in the License.html file in the root of the source tree.
5  */
6 
7 //---------------------------------------------------------------------------
8 #ifndef Export_Graph_gvc_IncludeH
9 #define Export_Graph_gvc_IncludeH
10 //---------------------------------------------------------------------------
11 
12 //***************************************************************************
13 // Needed gvc.h and cgraph.h definitions
14 //***************************************************************************
15 
16 typedef void GVC_t;
17 typedef void graph_t;
18 
19 
20 //***************************************************************************
21 // Dynamic load stuff
22 //***************************************************************************
23 
24 extern "C"
25 {
26 
27 #if defined (_WIN32) || defined (WIN32)
28     #ifndef _UNICODE
29         #define GVCDLL_NAME "gvc.dll"
30         #define CGRAPHDLL_NAME "cgraph.dll"
31     #else //_UNICODE
32         #define GVCDLL_NAME L"gvc.dll"
33         #define CGRAPHDLL_NAME L"cgraph.dll"
34     #endif
35 #elif defined(__APPLE__) && defined(__MACH__)
36     #define GVCDLL_NAME "libgvc.6.dylib"
37     #define CGRAPHDLL_NAME "libcgraph.6.dylib"
38 #else
39     #define GVCDLL_NAME "libgvc.so.6"
40     #define CGRAPHDLL_NAME "libcgraph.so.6"
41 #endif //!defined(_WIN32) || defined (WIN32)
42 
43 #ifdef MEDIAINFO_GLIBC
44     #include <gmodule.h>
45     static GModule* gvc_Module=NULL;
46     static GModule* cgraph_Module=NULL;
47 #elif defined (_WIN32) || defined (WIN32)
48     #undef __TEXT
49     #if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
50         namespace WindowsNamespace
51         {
52     #endif
53     #include "windows.h"
54     #if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
55         }
56         using namespace WindowsNamespace;
57     #endif
58     static HMODULE gvc_Module=NULL;
59     static HMODULE cgraph_Module=NULL;
60 #else
61     #include <dlfcn.h>
62     static void* gvc_Module=NULL;
63     static void* cgraph_Module=NULL;
64 #endif
65 
66 #ifdef MEDIAINFO_GLIBC
67     #define ASSIGN(_Module, _Name) \
68         if (!g_module_symbol(_Module, #_Name, (gpointer*)&_Name)) \
69             Error=true;
70     #define DLOPEN(_Module, _Name) \
71         _Module=g_module_open(_Name, G_MODULE_BIND_LAZY);
72     #define DLCLOSE(_Module) \
73         g_module_close(_Module);
74 #elif defined (_WIN32) || defined (WIN32)
75     #define ASSIGN(_Module, _Name) \
76         _Name=(_Module##_##_Name)GetProcAddress(_Module, #_Name); \
77         if (_Name==NULL) Error=true;
78     #ifdef WINDOWS_UWP
79         #define DLOPEN(_Module, _Name) \
80             _Module=LoadPackagedLibrary(_Name, 0);
81     #else
82         #define DLOPEN(_Module, _Name) \
83             _Module=LoadLibrary(_Name);
84     #endif //WINDOWS_UWP
85     #define DLCLOSE(_Module) \
86         FreeLibrary(_Module);
87 #else
88     #define ASSIGN(_Module, _Name) \
89         _Name=(_Module##_##_Name)dlsym(_Module, #_Name); \
90         if (_Name==NULL) Error=true;
91     #define DLOPEN(_Module, _Name) \
92         _Module=dlopen(_Name, RTLD_LAZY); \
93         if (!_Module) \
94             _Module=dlopen("./" _Name, RTLD_LAZY); \
95         if (!_Module) \
96             _Module=dlopen("/usr/local/lib/" _Name, RTLD_LAZY); \
97         if (!_Module) \
98             _Module=dlopen("/usr/local/lib64/" _Name, RTLD_LAZY); \
99         if (!_Module) \
100             _Module=dlopen("/usr/lib/" _Name, RTLD_LAZY); \
101         if (!_Module) \
102             _Module=dlopen("/usr/lib64/" _Name, RTLD_LAZY);
103     #define DLCLOSE(_Module) \
104         dlclose(_Module);
105 #endif //MEDIAINFO_GLIBC
106 
107 //---------------------------------------------------------------------------
108 // Interface
109 typedef GVC_t* (*gvc_Module_gvContext)(); static gvc_Module_gvContext gvContext=NULL;
110 typedef int (*gvc_Module_gvFreeContext)(GVC_t*); static gvc_Module_gvFreeContext gvFreeContext=NULL;
111 typedef int (*gvc_Module_gvLayout)(GVC_t*, graph_t*, const char*); static gvc_Module_gvLayout gvLayout=NULL;
112 typedef int (*gvc_Module_gvFreeLayout)(GVC_t*, graph_t*); static gvc_Module_gvFreeLayout gvFreeLayout=NULL;
113 typedef int (*gvc_Module_gvRenderData)(GVC_t*, graph_t*, const char*, char**, unsigned int*); static gvc_Module_gvRenderData gvRenderData=NULL;
114 typedef void (*gvc_Module_gvFreeRenderData)(char*); static gvc_Module_gvFreeRenderData gvFreeRenderData=NULL;
115 typedef void (*gvc_Module_gvFinalize)(GVC_t*); static gvc_Module_gvFinalize gvFinalize=NULL;
116 typedef graph_t* (*cgraph_Module_agmemread)(const char*); static cgraph_Module_agmemread agmemread=NULL;
117 typedef int (*cgraph_Module_agclose)(graph_t*); static cgraph_Module_agclose agclose=NULL;
118 
119 }
120 
121 #endif
122