libCEC 8.1.0
C / C++ API — control CEC-capable HDMI devices
Loading...
Searching...
No Matches
cecloader.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
7 *
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 *
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 *
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
27 *
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
32 */
33
34#if defined(_WIN32) || defined(_WIN64) || defined(_M_ARM64)
35#include <windows.h>
36#include <conio.h>
37
38HINSTANCE g_libCEC = NULL;
39
46CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL)
47{
48 if (!g_libCEC)
49 g_libCEC = LoadLibrary(strLib ? strLib : "cec.dll");
50 if (!g_libCEC)
51 return NULL;
52
53 typedef void* (__cdecl*_LibCecInitialise)(CEC::libcec_configuration *);
54 _LibCecInitialise LibCecInitialise;
55 LibCecInitialise = (_LibCecInitialise) (GetProcAddress(g_libCEC, "CECInitialise"));
57 {
58 std::cout << "cannot find CECInitialise" << std::endl;
59 return NULL;
60 }
61
62 return static_cast< CEC::ICECAdapter* > (LibCecInitialise(configuration));
63}
64
70{
71 typedef void (__cdecl*_DestroyLibCec)(void * device);
72 _DestroyLibCec DestroyLibCec;
73 DestroyLibCec = (_DestroyLibCec) (GetProcAddress(g_libCEC, "CECDestroy"));
74 if (DestroyLibCec)
75 DestroyLibCec(device);
76
77 FreeLibrary(g_libCEC);
78 g_libCEC = NULL;
79}
80
86bool LibCecBootloader(const char *strLib = NULL)
87{
88 if (!g_libCEC)
89 g_libCEC = LoadLibrary(strLib ? strLib : "cec.dll");
90 if (!g_libCEC)
91 return false;
92
93 typedef bool (__cdecl*_LibCecBootloader)(void);
94 _LibCecBootloader LibCecBootloader;
95 LibCecBootloader = (_LibCecBootloader) (GetProcAddress(g_libCEC, "CECStartBootloader"));
97 return false;
98
99 bool bReturn = LibCecBootloader();
100 FreeLibrary(g_libCEC);
101 g_libCEC = NULL;
102 return bReturn;
103}
104
105#else
106
107#include <dlfcn.h>
108
109void *g_libCEC = NULL;
110
117CEC::ICECAdapter *LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib = NULL)
118{
119 if (!g_libCEC)
120 {
121#if defined(__APPLE__)
122 g_libCEC = dlopen(strLib ? strLib : "libcec." CEC_LIB_VERSION_MAJOR_STR ".dylib", RTLD_LAZY);
123#else
124 g_libCEC = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, RTLD_LAZY);
125#endif
126 if (!g_libCEC)
127 {
128 std::cout << dlerror() << std::endl;
129 return NULL;
130 }
131 }
132
133 typedef void* _LibCecInitialise(CEC::libcec_configuration *);
134 _LibCecInitialise* LibCecInitialise = (_LibCecInitialise*) dlsym(g_libCEC, "CECInitialise");
135 if (!LibCecInitialise)
136 {
137 std::cout << "cannot find CECInitialise" << std::endl;
138 return NULL;
139 }
140
141 return (CEC::ICECAdapter*) LibCecInitialise(configuration);
142}
143
149{
150 typedef void* _DestroyLibCec(CEC::ICECAdapter *);
151 _DestroyLibCec *DestroyLibCec = (_DestroyLibCec*) dlsym(g_libCEC, "CECDestroy");
152 if (DestroyLibCec)
153 DestroyLibCec(device);
154
155 dlclose(g_libCEC);
156 g_libCEC = NULL;
157}
158
164bool LibCecBootloader(const char *strLib = NULL)
165{
166 if (!g_libCEC)
167 {
168#if defined(__APPLE__)
169 g_libCEC = dlopen(strLib ? strLib : "libcec.dylib", RTLD_LAZY);
170#else
171 g_libCEC = dlopen(strLib ? strLib : "libcec.so." CEC_LIB_VERSION_MAJOR_STR, RTLD_LAZY);
172#endif
173 if (!g_libCEC)
174 {
175 std::cout << dlerror() << std::endl;
176 return false;
177 }
178 }
179
180 typedef bool _LibCecBootloader(void);
181 _LibCecBootloader* LibCecBootloader = (_LibCecBootloader*) dlsym(g_libCEC, "CECStartBootloader");
182 if (!LibCecBootloader)
183 {
184 std::cout << "cannot find CECStartBootloader" << std::endl;
185 return false;
186 }
187
188 bool bReturn = LibCecBootloader();
189 dlclose(g_libCEC);
190 g_libCEC = NULL;
191 return bReturn;
192}
193
194#endif
CEC::ICECAdapter * LibCecInitialise(CEC::libcec_configuration *configuration, const char *strLib=NULL)
Create a new libCEC instance.
Definition cecloader.h:117
bool LibCecBootloader(const char *strLib=NULL)
Start the bootloader on the first device that was detected.
Definition cecloader.h:164
void UnloadLibCec(CEC::ICECAdapter *device)
Destroy an instance of libCEC.
Definition cecloader.h:148
void * g_libCEC
Definition cecloader.h:109
To create a new libCEC instance, call CECInitialise() and pass the configuration as argument.
Definition cec.h:54