Skip to content

Commit 56879d5

Browse files
committed
Use LCDBuffer read-only when doing interrupt transfers.
1 parent 473d940 commit 56879d5

File tree

8 files changed

+26
-17
lines changed

8 files changed

+26
-17
lines changed

src/bin/daemon/LCDScreenPluginsManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const bool LCDScreenPluginsManager::findOneLCDScreenPlugin(const uint64_t LCDPlu
166166
return ret;
167167
}
168168

169-
PixelsData & LCDScreenPluginsManager::getNextLCDScreenBuffer(
169+
const PixelsData & LCDScreenPluginsManager::getNextLCDScreenBuffer(
170170
const std::string & LCDKey,
171171
const uint64_t LCDPluginsMask1
172172
) {

src/bin/daemon/LCDScreenPluginsManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class LCDScreenPluginsManager
4848

4949
const bool findOneLCDScreenPlugin(const uint64_t LCDPluginsMask1) const;
5050

51-
PixelsData & getNextLCDScreenBuffer(
51+
const PixelsData & getNextLCDScreenBuffer(
5252
const std::string & LCDKey,
5353
const uint64_t LCDPluginsMask1
5454
);

src/bin/daemon/hidapi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This file is part of GLogiK project.
44
* GLogiK, daemon to handle special features on gaming keyboards
5-
* Copyright (C) 2016-2020 Fabrice Delliaux <[email protected]>
5+
* Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -183,7 +183,7 @@ int hidapi::performKeysInterruptTransfer(
183183

184184
int hidapi::performLCDScreenInterruptTransfer(
185185
USBDevice & device,
186-
unsigned char* buffer,
186+
const unsigned char * buffer,
187187
int bufferLength,
188188
unsigned int timeout)
189189
{

src/bin/daemon/hidapi.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This file is part of GLogiK project.
44
* GLogiK, daemon to handle special features on gaming keyboards
5-
* Copyright (C) 2016-2020 Fabrice Delliaux <[email protected]>
5+
* Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -55,7 +55,7 @@ class hidapi
5555

5656
int performLCDScreenInterruptTransfer(
5757
USBDevice & device,
58-
unsigned char* buffer,
58+
const unsigned char * buffer,
5959
int bufferLength,
6060
unsigned int timeout
6161
);

src/bin/daemon/keyboardDriver.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,13 @@ void KeyboardDriver::LCDScreenLoop(const std::string & devID) {
555555
LCDPluginsMask1 = device._LCDPluginsMask1;
556556
}
557557

558-
PixelsData & LCDBuffer = device.getLCDPluginsManager()->getNextLCDScreenBuffer(LCDKey, LCDPluginsMask1);
558+
const PixelsData & LCDBuffer = device.getLCDPluginsManager()->getNextLCDScreenBuffer(LCDKey, LCDPluginsMask1);
559559
int ret = this->performLCDScreenInterruptTransfer(
560560
device,
561561
LCDBuffer.data(),
562562
LCDBuffer.size(),
563-
1000);
563+
1000
564+
);
564565

565566
auto interval = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t1);
566567
auto one = std::chrono::milliseconds( device.getLCDPluginsManager()->getPluginTiming() );
@@ -588,8 +589,13 @@ void KeyboardDriver::LCDScreenLoop(const std::string & devID) {
588589
const uint64_t endscreen = toEnumType(LCDScreenPlugin::GK_LCD_ENDSCREEN);
589590
/* make sure endscreen plugin is loaded before using it */
590591
if( device.getLCDPluginsManager()->findOneLCDScreenPlugin( endscreen ) ) {
591-
PixelsData & LCDBuffer = device.getLCDPluginsManager()->getNextLCDScreenBuffer("", endscreen);
592-
int ret = this->performLCDScreenInterruptTransfer(device, LCDBuffer.data(), LCDBuffer.size(), 1000);
592+
const PixelsData & LCDBuffer = device.getLCDPluginsManager()->getNextLCDScreenBuffer("", endscreen);
593+
int ret = this->performLCDScreenInterruptTransfer(
594+
device,
595+
LCDBuffer.data(),
596+
LCDBuffer.size(),
597+
1000
598+
);
593599
if(ret != 0) {
594600
GKSysLog(LOG_ERR, ERROR, "endscreen LCD refresh failure");
595601
}

src/bin/daemon/keyboardDriver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class KeyboardDriver
165165
) = 0;
166166
virtual int performLCDScreenInterruptTransfer(
167167
USBDevice & device,
168-
unsigned char* buffer,
168+
const unsigned char * buffer,
169169
int bufferLength,
170170
unsigned int timeout
171171
) = 0;
@@ -241,7 +241,7 @@ class USBKeyboardDriver
241241

242242
int performLCDScreenInterruptTransfer(
243243
USBDevice & device,
244-
unsigned char* buffer,
244+
const unsigned char * buffer,
245245
int bufferLength,
246246
unsigned int timeout
247247
) override {

src/bin/daemon/libUSB.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This file is part of GLogiK project.
44
* GLogiK, daemon to handle special features on gaming keyboards
5-
* Copyright (C) 2016-2020 Fabrice Delliaux <[email protected]>
5+
* Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -227,7 +227,7 @@ int LibUSB::performKeysInterruptTransfer(
227227

228228
int LibUSB::performLCDScreenInterruptTransfer(
229229
USBDevice & device,
230-
unsigned char* buffer,
230+
const unsigned char * buffer,
231231
int bufferLength,
232232
unsigned int timeout)
233233
{
@@ -239,10 +239,13 @@ int LibUSB::performLCDScreenInterruptTransfer(
239239
int ret = 0;
240240
{
241241
std::lock_guard<std::mutex> lock(device._libUSBMutex);
242+
/* here we assume that buffer will be used read-only by
243+
* interrupt_transfer since _LCDEndpoint direction is OUT
244+
* (host-to-device) */
242245
ret = libusb_interrupt_transfer(
243246
device._pUSBDeviceHandle,
244247
device._LCDEndpoint,
245-
buffer,
248+
const_cast<unsigned char *>(buffer),
246249
bufferLength,
247250
&(device._lastLCDInterruptTransferLength),
248251
timeout

src/bin/daemon/libUSB.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* This file is part of GLogiK project.
44
* GLogiK, daemon to handle special features on gaming keyboards
5-
* Copyright (C) 2016-2020 Fabrice Delliaux <[email protected]>
5+
* Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -55,7 +55,7 @@ class LibUSB
5555

5656
int performLCDScreenInterruptTransfer(
5757
USBDevice & device,
58-
unsigned char* buffer,
58+
const unsigned char * buffer,
5959
int bufferLength,
6060
unsigned int timeout
6161
);

0 commit comments

Comments
 (0)