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(const 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
)(const 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
);
118 void *g_libCEC
= NULL
;
121 * @brief Create a new libCEC instance.
122 * @param strDeviceName The name of the primary device to pass to other CEC devices.
123 * @param types The list of device types to register on the bus.
124 * @param strLib The name of and/or path to libCEC
125 * @return An instance of libCEC or NULL when it failed to load.
127 CEC::ICECAdapter
*LibCecInit(const char *strDeviceName
, CEC::cec_device_type_list types
, const char *strLib
= NULL
)
131 #if defined(__APPLE__)
132 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
134 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so", RTLD_LAZY
);
138 #if defined(__APPLE__)
139 cout
<< "cannot find " << (strLib
? strLib
: "libcec.dylib") << dlerror() << endl
;
141 cout
<< "cannot find " << (strLib
? strLib
: "libcec.so") << dlerror() << endl
;
147 typedef void* _LibCecInit(const char *, CEC::cec_device_type_list
);
148 _LibCecInit
* LibCecInit
= (_LibCecInit
*) dlsym(g_libCEC
, "CECInit");
151 cout
<< "cannot find CECInit" << endl
;
155 return (CEC::ICECAdapter
*) LibCecInit(strDeviceName
, types
);
159 * @brief Create a new libCEC instance.
160 * @param configuration The configuration to pass to libCEC
161 * @return An instance of ICECAdapter or NULL on error.
163 CEC::ICECAdapter
*LibCecInitialise(const CEC::CecAdapterConfiguration
&configuration
)
167 #if defined(__APPLE__)
168 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
170 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so", RTLD_LAZY
);
174 #if defined(__APPLE__)
175 cout
<< "cannot find " << (strLib
? strLib
: "libcec.dylib") << dlerror() << endl
;
177 cout
<< "cannot find " << (strLib
? strLib
: "libcec.so") << dlerror() << endl
;
183 typedef void* _LibCecInitialise(const CEC::CecAdapterConfiguration
&);
184 _LibCecInitialise
* LibCecInitialise
= (_LibCecInitialise
*) dlsym(g_libCEC
, "CECInitialise");
185 if (!LibCecInitialise
)
187 cout
<< "cannot find CECInitialise" << endl
;
191 return (CEC::ICECAdapter
*) LibCecInitialise(configuration
);
195 * @brief Destroy an instance of libCEC.
196 * @param device The instance to destroy.
198 void UnloadLibCec(CEC::ICECAdapter
*device
)
200 typedef void* _DestroyLibCec(CEC::ICECAdapter
*);
201 _DestroyLibCec
*DestroyLibCec
= (_DestroyLibCec
*) dlsym(g_libCEC
, "CECDestroy");
203 DestroyLibCec(device
);
210 #endif /* CECLOADER_H_ */