3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
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/
37 #if defined(_WIN32) || defined(_WIN64)
41 HINSTANCE g_libCEC
= NULL
;
44 * @brief Create a new libCEC instance.
45 * @param strDeviceName The name of the primary device to pass to other CEC devices.
46 * @param types The list of device types to register on the bus.
47 * @param strLib The name of and/or path to libCEC
48 * @return An instance of libCEC or NULL when it failed to load.
50 CEC::ICECAdapter
*LibCecInit(const char *strDeviceName
, CEC::cec_device_type_list types
, const char *strLib
= NULL
)
54 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.x64.dll");
56 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.dll");
61 typedef void* (__cdecl
*_LibCecInit
)(const char *, CEC::cec_device_type_list
);
62 _LibCecInit LibCecInit
;
63 LibCecInit
= (_LibCecInit
) (GetProcAddress(g_libCEC
, "CECInit"));
66 return static_cast< CEC::ICECAdapter
* > (LibCecInit(strDeviceName
, types
));
70 * @brief Create a new libCEC instance.
71 * @param configuration The configuration to pass to libCEC
72 * @param strLib The name of and/or path to libCEC
73 * @return An instance of ICECAdapter or NULL on error.
75 CEC::ICECAdapter
*LibCecInitialise(CEC::libcec_configuration
*configuration
, const char *strLib
= NULL
)
79 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.x64.dll");
81 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.dll");
86 typedef void* (__cdecl
*_LibCecInitialise
)(CEC::libcec_configuration
*);
87 _LibCecInitialise LibCecInitialise
;
88 LibCecInitialise
= (_LibCecInitialise
) (GetProcAddress(g_libCEC
, "CECInitialise"));
89 if (!LibCecInitialise
)
91 cout
<< "cannot find CECInitialise" << endl
;
95 return static_cast< CEC::ICECAdapter
* > (LibCecInitialise(configuration
));
99 * @brief Destroy an instance of libCEC.
100 * @param device The instance to destroy.
102 void UnloadLibCec(CEC::ICECAdapter
*device
)
104 typedef void (__cdecl
*_DestroyLibCec
)(void * device
);
105 _DestroyLibCec DestroyLibCec
;
106 DestroyLibCec
= (_DestroyLibCec
) (GetProcAddress(g_libCEC
, "CECDestroy"));
108 DestroyLibCec(device
);
110 FreeLibrary(g_libCEC
);
115 * @brief Start the bootloader on the first device that was detected.
116 * @param strLib The name of and/or path to libCEC
117 * @return True when the command was sent, false otherwise.
119 bool LibCecBootloader(const char *strLib
= NULL
)
123 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.x64.dll");
125 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.dll");
130 typedef bool (__cdecl
*_LibCecBootloader
)(void);
131 _LibCecBootloader LibCecBootloader
;
132 LibCecBootloader
= (_LibCecBootloader
) (GetProcAddress(g_libCEC
, "CECStartBootloader"));
133 if (!LibCecBootloader
)
136 bool bReturn
= LibCecBootloader();
137 FreeLibrary(g_libCEC
);
146 void *g_libCEC
= NULL
;
149 * @brief Create a new libCEC instance.
150 * @param strDeviceName The name of the primary device to pass to other CEC devices.
151 * @param types The list of device types to register on the bus.
152 * @param strLib The name of and/or path to libCEC
153 * @return An instance of libCEC or NULL when it failed to load.
155 CEC::ICECAdapter
*LibCecInit(const char *strDeviceName
, CEC::cec_device_type_list types
, const char *strLib
= NULL
)
159 #if defined(__APPLE__)
160 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
162 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so", RTLD_LAZY
);
166 #if defined(__APPLE__)
167 cout
<< "cannot find " << (strLib
? strLib
: "libcec.dylib") << dlerror() << endl
;
169 cout
<< "cannot find " << (strLib
? strLib
: "libcec.so") << dlerror() << endl
;
175 typedef void* _LibCecInit(const char *, CEC::cec_device_type_list
);
176 _LibCecInit
* LibCecInit
= (_LibCecInit
*) dlsym(g_libCEC
, "CECInit");
179 cout
<< "cannot find CECInit" << endl
;
183 return (CEC::ICECAdapter
*) LibCecInit(strDeviceName
, types
);
187 * @brief Create a new libCEC instance.
188 * @param configuration The configuration to pass to libCEC
189 * @param strLib The name of and/or path to libCEC
190 * @return An instance of ICECAdapter or NULL on error.
192 CEC::ICECAdapter
*LibCecInitialise(CEC::libcec_configuration
*configuration
, const char *strLib
= NULL
)
196 #if defined(__APPLE__)
197 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
199 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so", RTLD_LAZY
);
203 #if defined(__APPLE__)
204 cout
<< "cannot find " << (strLib
? strLib
: "libcec.dylib") << dlerror() << endl
;
206 cout
<< "cannot find " << (strLib
? strLib
: "libcec.so") << dlerror() << endl
;
212 typedef void* _LibCecInitialise(CEC::libcec_configuration
*);
213 _LibCecInitialise
* LibCecInitialise
= (_LibCecInitialise
*) dlsym(g_libCEC
, "CECInitialise");
214 if (!LibCecInitialise
)
216 cout
<< "cannot find CECInitialise" << endl
;
220 return (CEC::ICECAdapter
*) LibCecInitialise(configuration
);
224 * @brief Destroy an instance of libCEC.
225 * @param device The instance to destroy.
227 void UnloadLibCec(CEC::ICECAdapter
*device
)
229 typedef void* _DestroyLibCec(CEC::ICECAdapter
*);
230 _DestroyLibCec
*DestroyLibCec
= (_DestroyLibCec
*) dlsym(g_libCEC
, "CECDestroy");
232 DestroyLibCec(device
);
238 * @brief Start the bootloader on the first device that was detected.
239 * @param strLib The name of and/or path to libCEC
240 * @return True when the command was sent, false otherwise.
242 bool LibCecBootloader(const char *strLib
= NULL
)
246 #if defined(__APPLE__)
247 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
249 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so", RTLD_LAZY
);
253 #if defined(__APPLE__)
254 cout
<< "cannot find " << (strLib
? strLib
: "libcec.dylib") << dlerror() << endl
;
256 cout
<< "cannot find " << (strLib
? strLib
: "libcec.so") << dlerror() << endl
;
262 typedef bool _LibCecBootloader(void);
263 _LibCecBootloader
* LibCecBootloader
= (_LibCecBootloader
*) dlsym(g_libCEC
, "CECStartBootloader");
264 if (!LibCecBootloader
)
266 cout
<< "cannot find CECStartBootloader" << endl
;
270 bool bReturn
= LibCecBootloader();
277 #endif /* CECLOADER_H_ */