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 configuration The configuration to pass to libCEC
46 * @param strLib The name of and/or path to libCEC
47 * @return An instance of ICECAdapter or NULL on error.
49 CEC::ICECAdapter
*LibCecInitialise(CEC::libcec_configuration
*configuration
, const char *strLib
= NULL
)
53 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.x64.dll");
55 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.dll");
60 typedef void* (__cdecl
*_LibCecInitialise
)(CEC::libcec_configuration
*);
61 _LibCecInitialise LibCecInitialise
;
62 LibCecInitialise
= (_LibCecInitialise
) (GetProcAddress(g_libCEC
, "CECInitialise"));
63 if (!LibCecInitialise
)
65 cout
<< "cannot find CECInitialise" << endl
;
69 return static_cast< CEC::ICECAdapter
* > (LibCecInitialise(configuration
));
73 * @brief Destroy an instance of libCEC.
74 * @param device The instance to destroy.
76 void UnloadLibCec(CEC::ICECAdapter
*device
)
78 typedef void (__cdecl
*_DestroyLibCec
)(void * device
);
79 _DestroyLibCec DestroyLibCec
;
80 DestroyLibCec
= (_DestroyLibCec
) (GetProcAddress(g_libCEC
, "CECDestroy"));
82 DestroyLibCec(device
);
84 FreeLibrary(g_libCEC
);
89 * @brief Start the bootloader on the first device that was detected.
90 * @param strLib The name of and/or path to libCEC
91 * @return True when the command was sent, false otherwise.
93 bool LibCecBootloader(const char *strLib
= NULL
)
97 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.x64.dll");
99 g_libCEC
= LoadLibrary(strLib
? strLib
: "libcec.dll");
104 typedef bool (__cdecl
*_LibCecBootloader
)(void);
105 _LibCecBootloader LibCecBootloader
;
106 LibCecBootloader
= (_LibCecBootloader
) (GetProcAddress(g_libCEC
, "CECStartBootloader"));
107 if (!LibCecBootloader
)
110 bool bReturn
= LibCecBootloader();
111 FreeLibrary(g_libCEC
);
120 void *g_libCEC
= NULL
;
123 * @brief Create a new libCEC instance.
124 * @param configuration The configuration to pass to libCEC
125 * @param strLib The name of and/or path to libCEC
126 * @return An instance of ICECAdapter or NULL on error.
128 CEC::ICECAdapter
*LibCecInitialise(CEC::libcec_configuration
*configuration
, const char *strLib
= NULL
)
132 #if defined(__APPLE__)
133 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
135 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so." CEC_LIB_VERSION_MAJOR_STR
, RTLD_LAZY
);
139 cout
<< dlerror() << endl
;
144 typedef void* _LibCecInitialise(CEC::libcec_configuration
*);
145 _LibCecInitialise
* LibCecInitialise
= (_LibCecInitialise
*) dlsym(g_libCEC
, "CECInitialise");
146 if (!LibCecInitialise
)
148 cout
<< "cannot find CECInitialise" << endl
;
152 return (CEC::ICECAdapter
*) LibCecInitialise(configuration
);
156 * @brief Destroy an instance of libCEC.
157 * @param device The instance to destroy.
159 void UnloadLibCec(CEC::ICECAdapter
*device
)
161 typedef void* _DestroyLibCec(CEC::ICECAdapter
*);
162 _DestroyLibCec
*DestroyLibCec
= (_DestroyLibCec
*) dlsym(g_libCEC
, "CECDestroy");
164 DestroyLibCec(device
);
170 * @brief Start the bootloader on the first device that was detected.
171 * @param strLib The name of and/or path to libCEC
172 * @return True when the command was sent, false otherwise.
174 bool LibCecBootloader(const char *strLib
= NULL
)
178 #if defined(__APPLE__)
179 g_libCEC
= dlopen(strLib
? strLib
: "libcec.dylib", RTLD_LAZY
);
181 g_libCEC
= dlopen(strLib
? strLib
: "libcec.so." CEC_LIB_VERSION_MAJOR_STR
, RTLD_LAZY
);
185 cout
<< dlerror() << endl
;
190 typedef bool _LibCecBootloader(void);
191 _LibCecBootloader
* LibCecBootloader
= (_LibCecBootloader
*) dlsym(g_libCEC
, "CECStartBootloader");
192 if (!LibCecBootloader
)
194 cout
<< "cannot find CECStartBootloader" << endl
;
198 bool bReturn
= LibCecBootloader();
205 #endif /* CECLOADER_H_ */