Skip to content

Commit 0aae238

Browse files
committed
fixed: v4 compatiblity
only the main lib is fully compatible. LibCecSharp is initialised differently now
1 parent 26febbf commit 0aae238

File tree

11 files changed

+224
-87
lines changed

11 files changed

+224
-87
lines changed

include/cec.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,13 @@ namespace CEC
239239
*/
240240
virtual uint8_t VolumeDown(bool bSendRelease = true) = 0;
241241

242+
#if CEC_LIB_VERSION_MAJOR >= 5
242243
/*!
243244
* @brief Toggles the mute status of an audiosystem, if it's present
244245
* @return The new audio status.
245246
*/
246247
virtual uint8_t MuteAudio(void) = 0;
248+
#endif
247249

248250
/*!
249251
* @brief Send a keypress to a device on the CEC bus.
@@ -318,7 +320,19 @@ namespace CEC
318320
/*!
319321
* @return True if this CEC adapter can save the user configuration, false otherwise.
320322
*/
323+
#if CEC_LIB_VERSION_MAJOR >= 5
321324
virtual bool CanSaveConfiguration(void) = 0;
325+
#else
326+
virtual bool CanPersistConfiguration(void) = 0;
327+
328+
/*!
329+
* @deprecated Use SetConfiguration() instead
330+
* @brief Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported)
331+
* @brief configuration The configuration to store.
332+
* @return True when the configuration was persisted, false otherwise.
333+
*/
334+
virtual bool PersistConfiguration(libcec_configuration *configuration) = 0;
335+
#endif
322336

323337
/*!
324338
* @brief Tell libCEC to poll for active devices on the bus.
@@ -339,6 +353,7 @@ namespace CEC
339353
*/
340354
virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000) = 0;
341355

356+
#if CEC_LIB_VERSION_MAJOR >= 5
342357
/*!
343358
* @brief Set and enable the callback methods
344359
* @param callbacks The callbacks to set.
@@ -352,7 +367,7 @@ namespace CEC
352367
* @return True if disabled, false otherwise.
353368
*/
354369
virtual bool DisableCallbacks(void) = 0;
355-
370+
#else
356371
/*!
357372
* @deprecated
358373
* @brief Set and enable the callback methods.
@@ -361,6 +376,7 @@ namespace CEC
361376
* @return True when enabled, false otherwise.
362377
*/
363378
virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) = 0;
379+
#endif
364380

365381
/*!
366382
* @brief Changes the active HDMI port.

include/cecc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ extern DECLSPEC void libcec_destroy(libcec_connection_t connection);
5353
extern DECLSPEC int libcec_open(libcec_connection_t connection, const char* strPort, uint32_t iTimeout);
5454
extern DECLSPEC void libcec_close(libcec_connection_t connection);
5555
extern DECLSPEC void libcec_clear_configuration(CEC_NAMESPACE libcec_configuration* configuration);
56+
#if CEC_LIB_VERSION_MAJOR >= 5
5657
extern DECLSPEC int libcec_set_callbacks(libcec_connection_t connection, CEC_NAMESPACE ICECCallbacks* callbacks, void* cbParam);
5758
extern DECLSPEC int libcec_disabled_callbacks(libcec_connection_t connection);
59+
#else
5860
extern DECLSPEC int libcec_enable_callbacks(libcec_connection_t connection, void* cbParam, CEC_NAMESPACE ICECCallbacks* callbacks);
61+
#endif
5962
extern DECLSPEC int8_t libcec_find_adapters(libcec_connection_t connection, CEC_NAMESPACE cec_adapter* deviceList, uint8_t iBufSize, const char* strDevicePath);
6063
extern DECLSPEC int libcec_ping_adapters(libcec_connection_t connection);
6164
extern DECLSPEC int libcec_start_bootloader(libcec_connection_t connection);
@@ -85,15 +88,22 @@ extern DECLSPEC int libcec_is_active_device_type(libcec_connection_t connection,
8588
extern DECLSPEC int libcec_set_hdmi_port(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address baseDevice, uint8_t iPort);
8689
extern DECLSPEC int libcec_volume_up(libcec_connection_t connection, int bSendRelease);
8790
extern DECLSPEC int libcec_volume_down(libcec_connection_t connection, int bSendRelease);
91+
#if CEC_LIB_VERSION_MAJOR >= 5
8892
extern DECLSPEC int libcec_mute_audio(libcec_connection_t connection, int bSendRelease);
93+
#endif
8994
extern DECLSPEC int libcec_send_keypress(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iDestination, CEC_NAMESPACE cec_user_control_code key, int bWait);
9095
extern DECLSPEC int libcec_send_key_release(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iDestination, int bWait);
9196
extern DECLSPEC int libcec_get_device_osd_name(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress, CEC_NAMESPACE cec_osd_name name);
9297
extern DECLSPEC int libcec_set_stream_path_logical(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress);
9398
extern DECLSPEC int libcec_set_stream_path_physical(libcec_connection_t connection, uint16_t iPhysicalAddress);
9499
extern DECLSPEC CEC_NAMESPACE cec_logical_addresses libcec_get_logical_addresses(libcec_connection_t connection);
95100
extern DECLSPEC int libcec_get_current_configuration(libcec_connection_t connection, CEC_NAMESPACE libcec_configuration* configuration);
101+
#if CEC_LIB_VERSION_MAJOR >= 5
96102
extern DECLSPEC int libcec_can_save_configuration(libcec_connection_t connection);
103+
#else
104+
extern DECLSPEC int libcec_can_persist_configuration(libcec_connection_t connection);
105+
extern DECLSPEC int libcec_persist_configuration(libcec_connection_t connection, CEC_NAMESPACE libcec_configuration* configuration);
106+
#endif
97107
extern DECLSPEC int libcec_set_configuration(libcec_connection_t connection, const CEC_NAMESPACE libcec_configuration* configuration);
98108
extern DECLSPEC void libcec_rescan_devices(libcec_connection_t connection);
99109
extern DECLSPEC int libcec_is_libcec_active_source(libcec_connection_t connection);

project/nsis/cec-tray.nsh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Section "libCEC Tray" SecTray
2+
SetShellVarContext current
3+
SectionIn 1
4+
5+
; Copy to the installation directory
6+
SetOutPath "$INSTDIR\x86\netfx"
7+
File "..\build\x86\cec-tray.exe"
8+
SetOutPath "$INSTDIR\x64\netfx"
9+
File /nonfatal "..\build\amd64\cec-tray.exe"
10+
11+
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
12+
SetOutPath "$INSTDIR"
13+
14+
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
15+
${If} ${RunningX64}
16+
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x64\netfx\cec-tray.exe" \
17+
"" "$INSTDIR\x64\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
18+
"" "Start libCEC Tray (x64)."
19+
${Else}
20+
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x86\netfx\cec-tray.exe" \
21+
"" "$INSTDIR\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
22+
"" "Start libCEC Tray."
23+
${EndIf}
24+
!insertmacro MUI_STARTMENU_WRITE_END
25+
SectionEnd

project/nsis/sections.nsh

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Section "libCEC for .Net Framework" SecDotNet
109109
SetOutPath "$INSTDIR\x86\netfx"
110110
File "..\build\x86\LibCecSharp.dll"
111111
File "..\build\x86\LibCecSharp.xml"
112-
File "..\build\x86\CecSharpTester.exe"
112+
File /nonfatal "..\build\x86\CecSharpTester.exe"
113113

114114
${If} ${RunningX64}
115115
; Moved to netfx subdir
@@ -139,11 +139,11 @@ Section "libCEC for .Net Core" SecDotNetCore
139139
File "..\build\x86\netcore\LibCecSharpCore.dll"
140140
File "..\build\x86\netcore\LibCecSharpCore.runtimeconfig.json"
141141
File "..\build\x86\netcore\LibCecSharpCore.xml"
142-
File "..\build\x86\netcore\CecSharpCoreTester.exe"
143-
File "..\build\x86\netcore\CecSharpCoreTester.deps.json"
144-
File "..\build\x86\netcore\CecSharpCoreTester.dll"
145-
File "..\build\x86\netcore\CecSharpCoreTester.runtimeconfig.json"
146-
File "..\build\x86\netcore\Ijwhost.dll"
142+
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.exe"
143+
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.deps.json"
144+
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.dll"
145+
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.runtimeconfig.json"
146+
File /nonfatal "..\build\x86\netcore\Ijwhost.dll"
147147

148148
${If} ${RunningX64}
149149
SetOutPath "$INSTDIR\x64\netcore"
@@ -159,31 +159,9 @@ Section "libCEC for .Net Core" SecDotNetCore
159159
${EndIf}
160160
SectionEnd
161161

162-
Section "libCEC Tray" SecTray
163-
SetShellVarContext current
164-
SectionIn 1
165-
166-
; Copy to the installation directory
167-
SetOutPath "$INSTDIR\x86\netfx"
168-
File "..\build\x86\cec-tray.exe"
169-
SetOutPath "$INSTDIR\x64\netfx"
170-
File /nonfatal "..\build\amd64\cec-tray.exe"
171-
172-
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
173-
SetOutPath "$INSTDIR"
174-
175-
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
176-
${If} ${RunningX64}
177-
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x64\netfx\cec-tray.exe" \
178-
"" "$INSTDIR\x64\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
179-
"" "Start libCEC Tray (x64)."
180-
${Else}
181-
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x86\netfx\cec-tray.exe" \
182-
"" "$INSTDIR\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
183-
"" "Start libCEC Tray."
184-
${EndIf}
185-
!insertmacro MUI_STARTMENU_WRITE_END
186-
SectionEnd
162+
!ifdef NSISDOTNETAPPS
163+
!include "nsis\cec-tray.nsh"
164+
!endif
187165

188166
Section "libCEC client (cec-client)" SecCecClient
189167
SetShellVarContext current
@@ -309,13 +287,15 @@ SectionEnd
309287

310288
; Required options
311289
Function .onSelChange
290+
!ifdef NSISDOTNETAPPS
312291
${If} ${SectionIsSelected} ${SecTray}
313292
!define /math MYSECTIONFLAGS ${SF_SELECTED} | ${SF_RO}
314293
!insertmacro SetSectionFlag ${SecDotNet} ${MYSECTIONFLAGS}
315294
!undef MYSECTIONFLAGS
316295
${Else}
317296
!insertmacro ClearSectionFlag ${SecDotNet} ${SF_RO}
318297
${EndIf}
298+
!endif
319299

320300
${If} ${SectionIsSelected} ${SecPythonCecClient}
321301
!define /math MYSECTIONFLAGS ${SF_SELECTED} | ${SF_RO}

src/dotnetlib/CecSharpTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ namespace CecSharp
11271127
On = 1
11281128
};
11291129

1130+
#if CEC_LIB_VERSION_MAJOR >= 5
11301131
/// <summary>
11311132
/// A setting that can be enabled, disabled or not changed
11321133
/// </summary>
@@ -1145,6 +1146,7 @@ namespace CecSharp
11451146
/// </summary>
11461147
NotSet = 2
11471148
};
1149+
#endif
11481150

11491151
/// <summary>
11501152
/// Type of adapter to which libCEC is connected

src/dotnetlib/LibCecSharp.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ namespace CecSharp
110110
/// <returns>True when a connection was opened, false otherwise.</returns>
111111
bool Open(String ^ strPort, int iTimeoutMs)
112112
{
113-
if (!m_libCec) {
113+
if (!m_libCec)
114114
return false;
115-
}
116115
marshal_context ^ context = gcnew marshal_context();
117116
const char* strPortC = context->marshal_as<const char*>(strPort);
118117
bool bReturn = m_libCec->Open(strPortC, iTimeoutMs);
@@ -125,22 +124,31 @@ namespace CecSharp
125124
/// </summary>
126125
void Close(void)
127126
{
128-
if (m_libCec) {
127+
if (!!m_libCec)
129128
m_libCec->Close();
130-
}
131129
}
132130

133131
void EnableCallbacks(void)
134132
{
135-
if (m_libCec) {
133+
if (!!m_libCec)
134+
{
135+
#if CEC_LIB_VERSION_MAJOR >= 5
136136
m_libCec->SetCallbacks(GetLibCecCallbacks(), m_callbacks->Get());
137+
#else
138+
m_libCec->EnableCallbacks(m_callbacks->Get(), GetLibCecCallbacks());
139+
#endif
137140
}
138141
}
139142

140143
void DisableCallbacks(void)
141144
{
142-
if (m_libCec) {
145+
if (!!m_libCec)
146+
{
147+
#if CEC_LIB_VERSION_MAJOR >= 5
143148
m_libCec->DisableCallbacks();
149+
#else
150+
m_libCec->EnableCallbacks(nullptr, nullptr);
151+
#endif
144152
}
145153
}
146154

@@ -606,11 +614,24 @@ namespace CecSharp
606614
/// Check whether the CEC adapter can save a configuration.
607615
/// </summary>
608616
/// <returns>True when this CEC adapter can save the user configuration, false otherwise.</returns>
617+
#if CEC_LIB_VERSION_MAJOR >= 5
609618
bool CanSaveConfiguration(void)
610619
{
611620
return !!m_libCec &&
612621
m_libCec->CanSaveConfiguration();
613622
}
623+
#else
624+
bool CanPersistConfiguration(void)
625+
{
626+
return !!m_libCec &&
627+
m_libCec->CanPersistConfiguration();
628+
}
629+
630+
bool PersistConfiguration(LibCECConfiguration ^configuration)
631+
{
632+
return SetConfiguration(configuration);
633+
}
634+
#endif
614635

615636
/// <summary>
616637
/// Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported)

src/libcec/LibCEC.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ bool CLibCEC::PingAdapter(void)
125125
return m_client ? m_client->PingAdapter() : false;
126126
}
127127

128+
#if CEC_LIB_VERSION_MAJOR >= 5
128129
bool CLibCEC::SetCallbacks(ICECCallbacks *callbacks, void *cbParam)
129130
{
130131
return !!m_client ? m_client->EnableCallbacks(cbParam, callbacks) : false;
@@ -139,6 +140,12 @@ bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
139140
{
140141
return SetCallbacks(callbacks, cbParam);
141142
}
143+
#else
144+
bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
145+
{
146+
return !!m_client ? m_client->EnableCallbacks(cbParam, callbacks) : false;
147+
}
148+
#endif
142149

143150
bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration)
144151
{
@@ -150,11 +157,22 @@ bool CLibCEC::SetConfiguration(const libcec_configuration *configuration)
150157
return m_client ? m_client->SetConfiguration(*configuration) : false;
151158
}
152159

160+
#if CEC_LIB_VERSION_MAJOR >= 5
153161
bool CLibCEC::CanSaveConfiguration(void)
162+
#else
163+
bool CLibCEC::CanPersistConfiguration(void)
164+
#endif
154165
{
155166
return m_client ? m_client->CanSaveConfiguration() : false;
156167
}
157168

169+
#if CEC_LIB_VERSION_MAJOR < 5
170+
bool CLibCEC::PersistConfiguration(libcec_configuration *configuration)
171+
{
172+
return SetConfiguration(configuration);
173+
}
174+
#endif
175+
158176
void CLibCEC::RescanActiveDevices(void)
159177
{
160178
if (m_client)
@@ -290,12 +308,14 @@ uint8_t CLibCEC::VolumeDown(bool bSendRelease /* = true */)
290308
return m_client ? m_client->SendVolumeDown(bSendRelease) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
291309
}
292310

311+
#if CEC_LIB_VERSION_MAJOR >= 5
293312
uint8_t CLibCEC::MuteAudio(void)
294313
{
295314
return !!m_client ?
296315
m_client->SendMuteAudio() :
297316
(uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
298317
}
318+
#endif
299319

300320
bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
301321
{

src/libcec/LibCEC.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ namespace CEC
6363

6464
bool Open(const char *strPort, uint32_t iTimeout = CEC_DEFAULT_CONNECT_TIMEOUT);
6565
void Close(void);
66+
#if CEC_LIB_VERSION_MAJOR >= 5
6667
bool SetCallbacks(ICECCallbacks *callbacks, void *cbParam);
6768
bool DisableCallbacks(void);
69+
#endif
6870
bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
6971
int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL);
7072
int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL, bool bQuickScan = false);
@@ -96,7 +98,9 @@ namespace CEC
9698
bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort = CEC_DEFAULT_HDMI_PORT);
9799
uint8_t VolumeUp(bool bSendRelease = true);
98100
uint8_t VolumeDown(bool bSendRelease = true);
101+
#if CEC_LIB_VERSION_MAJOR >= 5
99102
uint8_t MuteAudio(void);
103+
#endif
100104
bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
101105
bool SendKeyRelease(cec_logical_address iDestination, bool bWait = true);
102106
std::string GetDeviceOSDName(cec_logical_address iAddress);
@@ -107,7 +111,12 @@ namespace CEC
107111
cec_logical_addresses GetLogicalAddresses(void);
108112
bool GetCurrentConfiguration(libcec_configuration *configuration);
109113
bool SetConfiguration(const libcec_configuration *configuration);
114+
#if CEC_LIB_VERSION_MAJOR >= 5
110115
bool CanSaveConfiguration(void);
116+
#else
117+
bool CanPersistConfiguration(void);
118+
bool PersistConfiguration(libcec_configuration *configuration);
119+
#endif
111120
void RescanActiveDevices(void);
112121
bool IsLibCECActiveSource(void);
113122

0 commit comments

Comments
 (0)