refactor: prefix private data members with m_

Rename all trailing-underscore private data members to the m_ prefix
required by AGENTS.md, across the auth, crypto, gip, mt76, and usb
transport classes plus the app session classes. Pure rename; no
behavior change. Full build and test suite pass.

Co-Authored-By: qwen3.8-27b@q3_k_xl: renamed members to m_ prefix
This commit is contained in:
portersky
2026-08-29 14:36:28 +02:00
parent ae9c71d76e
commit dfe7e8b87d
12 changed files with 329 additions and 329 deletions
+93 -93
View File
@@ -144,28 +144,28 @@ auto transport::probe(frame_callback frames, disconnect_callback disconnected) -
void transport::stop_pump()
{
{
std::lock_guard<std::mutex> lock(state_->lock);
if (state_->stopping)
std::lock_guard<std::mutex> lock(m_state->lock);
if (m_state->stopping)
return;
state_->stopping = true;
m_state->stopping = true;
}
for (auto &slot : state_->slots)
for (auto &slot : m_state->slots)
(*slot.iface_ref)->AbortPipe(slot.iface_ref, slot.pipe_ref);
if (!state_->thread_started)
if (!m_state->thread_started)
return;
CFRunLoopRef runloop = nullptr;
{
std::unique_lock<std::mutex> lock(state_->lock);
state_->cv.wait(lock, [this] { return state_->loop_ready && state_->in_flight == 0; });
runloop = state_->runloop;
std::unique_lock<std::mutex> lock(m_state->lock);
m_state->cv.wait(lock, [this] { return m_state->loop_ready && m_state->in_flight == 0; });
runloop = m_state->runloop;
}
// The reader thread is joined below; no callback can run after this.
CFRunLoopStop(runloop);
state_->thread.join();
m_state->thread.join();
}
auto transport::re_enumerate() -> int
@@ -177,65 +177,65 @@ auto transport::re_enumerate() -> int
// references while the kernel tears them down.
stop_pump();
auto kr = (*state_->dev_ref)->USBDeviceReEnumerate(state_->dev_ref, kUSBAddExtraResetTimeMask);
auto kr = (*m_state->dev_ref)->USBDeviceReEnumerate(m_state->dev_ref, kUSBAddExtraResetTimeMask);
if (kr != kIOReturnSuccess) {
xone::log_msg(log_level::error, "usb: re-enumerate failed (%d)", kr);
return -EIO;
}
// The kernel terminated all of our clients; the USB references are dead.
state_->re_enumerated = true;
m_state->re_enumerated = true;
xone::log_msg(log_level::info, "usb: re-enumerate ok");
return 0;
}
transport::~transport()
{
if (!state_)
if (!m_state)
return;
stop_pump();
// Release the termination watch and async event sources.
if (state_->termination_iter)
IOObjectRelease(state_->termination_iter);
if (state_->notify_port)
IONotificationPortDestroy(state_->notify_port);
if (m_state->termination_iter)
IOObjectRelease(m_state->termination_iter);
if (m_state->notify_port)
IONotificationPortDestroy(m_state->notify_port);
if (state_->re_enumerated) {
if (m_state->re_enumerated) {
// The kernel already tore down the device and interfaces.
if (state_->service)
IOObjectRelease(state_->service);
if (m_state->service)
IOObjectRelease(m_state->service);
return;
}
for (auto *source : state_->sources)
for (auto *source : m_state->sources)
CFRelease(source);
// Close the interfaces and their endpoint pipes.
for (auto &conn : state_->ifaces) {
for (auto &conn : m_state->ifaces) {
(*conn.iface_ref)->USBInterfaceClose(conn.iface_ref);
(*conn.iface_ref)->Release(conn.iface_ref);
IODestroyPlugInInterface(conn.iodev);
}
// Close the device connection.
if (state_->dev_ref) {
if (state_->dev_opened)
(*state_->dev_ref)->USBDeviceClose(state_->dev_ref);
(*state_->dev_ref)->Release(state_->dev_ref);
if (m_state->dev_ref) {
if (m_state->dev_opened)
(*m_state->dev_ref)->USBDeviceClose(m_state->dev_ref);
(*m_state->dev_ref)->Release(m_state->dev_ref);
}
if (state_->dev_iodev)
IODestroyPlugInInterface(state_->dev_iodev);
if (m_state->dev_iodev)
IODestroyPlugInInterface(m_state->dev_iodev);
if (state_->service)
IOObjectRelease(state_->service);
if (m_state->service)
IOObjectRelease(m_state->service);
}
auto transport::open(frame_callback frames, disconnect_callback disconnected) -> bool
{
state_ = std::make_unique<state>();
state_->frames = std::move(frames);
state_->disconnected = std::move(disconnected);
m_state = std::make_unique<state>();
m_state->frames = std::move(frames);
m_state->disconnected = std::move(disconnected);
// Find the dongle service (class match, filter by VID/PID).
io_iterator_t iter = 0;
@@ -250,8 +250,8 @@ auto transport::open(frame_callback frames, disconnect_callback disconnected) ->
break;
auto vp = read_vid_pid(service);
if (vp && is_dongle(*vp)) {
state_->service = service;
state_->pid = vp->pid;
m_state->service = service;
m_state->pid = vp->pid;
found = true;
} else {
IOObjectRelease(service);
@@ -263,32 +263,32 @@ auto transport::open(frame_callback frames, disconnect_callback disconnected) ->
// Open the device connection.
SInt32 score = 0;
kr = IOCreatePlugInInterfaceForService(state_->service, kIOUSBDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &state_->dev_iodev, &score);
kr = IOCreatePlugInInterfaceForService(m_state->service, kIOUSBDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &m_state->dev_iodev, &score);
if (kr != kIOReturnSuccess) {
xone::log_msg(log_level::error, "usb: create device interface failed (%d)", kr);
return false;
}
void *slot = nullptr;
HRESULT hr = (*state_->dev_iodev)->QueryInterface(state_->dev_iodev,
HRESULT hr = (*m_state->dev_iodev)->QueryInterface(m_state->dev_iodev,
CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID500), &slot);
if (hr != S_OK || !slot) {
xone::log_msg(log_level::error, "usb: query device interface failed");
return false;
}
state_->dev_ref = static_cast<IOUSBDeviceInterface500 **>(slot);
m_state->dev_ref = static_cast<IOUSBDeviceInterface500 **>(slot);
kr = (*state_->dev_ref)->USBDeviceOpen(state_->dev_ref);
kr = (*m_state->dev_ref)->USBDeviceOpen(m_state->dev_ref);
if (kr != kIOReturnSuccess) {
xone::log_msg(log_level::error, "usb: open device failed (%d)", kr);
return false;
}
state_->dev_opened = true;
m_state->dev_opened = true;
// Reset the chip so it starts from the boot ROM (port of the
// usb_reset_device call in xone_dongle_probe).
kr = (*state_->dev_ref)->ResetDevice(state_->dev_ref);
kr = (*m_state->dev_ref)->ResetDevice(m_state->dev_ref);
if (kr != kIOReturnSuccess) {
xone::log_msg(log_level::error, "usb: reset device failed (%d)", kr);
return false;
@@ -296,7 +296,7 @@ auto transport::open(frame_callback frames, disconnect_callback disconnected) ->
// Open every interface and collect the endpoint pipes we need.
io_iterator_t children = 0;
kr = IORegistryEntryGetChildIterator(state_->service, kIOServicePlane, &children);
kr = IORegistryEntryGetChildIterator(m_state->service, kIOServicePlane, &children);
if (kr != kIOReturnSuccess)
return false;
@@ -309,57 +309,57 @@ auto transport::open(frame_callback frames, disconnect_callback disconnected) ->
}
IOObjectRelease(children);
if (!state_->in_cmd_pipe || !state_->in_wlan_pipe || !state_->out_pipe) {
if (!m_state->in_cmd_pipe || !m_state->in_wlan_pipe || !m_state->out_pipe) {
xone::log_msg(log_level::error, "usb: missing endpoint (cmd in=%d, wlan in=%d, out=%d)",
state_->in_cmd_pipe.has_value(), state_->in_wlan_pipe.has_value(),
state_->out_pipe.has_value());
m_state->in_cmd_pipe.has_value(), m_state->in_wlan_pipe.has_value(),
m_state->out_pipe.has_value());
return false;
}
// Async completion dispatch for the opened interfaces.
for (auto &conn : state_->ifaces) {
for (auto &conn : m_state->ifaces) {
CFRunLoopSourceRef source = nullptr;
if ((*conn.iface_ref)->CreateInterfaceAsyncEventSource(conn.iface_ref, &source)
== kIOReturnSuccess
&& source)
state_->sources.push_back(source);
m_state->sources.push_back(source);
}
// Watch for the dongle going away (unplug or chip reconnect). The
// matching dictionary is consumed by this call.
state_->notify_port = IONotificationPortCreate(0);
kr = IOServiceAddMatchingNotification(state_->notify_port, kIOTerminatedNotification,
m_state->notify_port = IONotificationPortCreate(0);
kr = IOServiceAddMatchingNotification(m_state->notify_port, kIOTerminatedNotification,
IOServiceMatching("IOUSBDevice"),
on_dongle_terminated, this,
&state_->termination_iter);
&m_state->termination_iter);
if (kr != kIOReturnSuccess) {
xone::log_msg(log_level::error, "usb: add termination notification failed (%d)", kr);
return false;
}
state_->thread = std::thread([this] { worker_loop(); });
state_->thread_started = true;
m_state->thread = std::thread([this] { worker_loop(); });
m_state->thread_started = true;
// Submit the initial async reads (EP 0x05 IN and EP 0x04 IN). Reserve so
// the slot addresses stay valid for the ReadPipeAsync refcons.
state_->slots.reserve(num_in_reads * 2);
m_state->slots.reserve(num_in_reads * 2);
auto submit_all = [this](std::optional<state::pipe_ref> const &pipe,
std::uint8_t ep, std::size_t buf_len) -> bool {
for (std::size_t i = 0; i < num_in_reads; i++) {
state_->slots.push_back(
m_state->slots.push_back(
{ this, ep, pipe->iface_ref, pipe->ref, std::vector<std::uint8_t>(buf_len) });
if (!submit_read(&state_->slots.back()))
if (!submit_read(&m_state->slots.back()))
return false;
}
return true;
};
if (!submit_all(state_->in_cmd_pipe, ep_in_cmd, len_cmd_pkt))
if (!submit_all(m_state->in_cmd_pipe, ep_in_cmd, len_cmd_pkt))
return false;
if (!submit_all(state_->in_wlan_pipe, ep_in_wlan, len_wlan_pkt))
if (!submit_all(m_state->in_wlan_pipe, ep_in_wlan, len_wlan_pkt))
return false;
xone::log_msg(log_level::info, "usb: dongle connected (pid=0x%04x)", state_->pid);
xone::log_msg(log_level::info, "usb: dongle connected (pid=0x%04x)", m_state->pid);
return true;
}
@@ -387,7 +387,7 @@ auto transport::open_interface(io_service_t child) -> bool
return false;
}
state_->ifaces.push_back(conn);
m_state->ifaces.push_back(conn);
// Scan the interface's pipes for the endpoints we need.
UInt8 num_pipes = 0;
@@ -403,12 +403,12 @@ auto transport::open_interface(io_service_t child) -> bool
continue;
std::uint8_t ep = static_cast<std::uint8_t>(number);
if (direction == kUSBIn && ep == ep_in_cmd && !state_->in_cmd_pipe.has_value())
state_->in_cmd_pipe = { conn.iface_ref, i };
else if (direction == kUSBIn && ep == ep_in_wlan && !state_->in_wlan_pipe.has_value())
state_->in_wlan_pipe = { conn.iface_ref, i };
else if (direction == kUSBOut && ep == ep_out && !state_->out_pipe.has_value())
state_->out_pipe = { conn.iface_ref, i };
if (direction == kUSBIn && ep == ep_in_cmd && !m_state->in_cmd_pipe.has_value())
m_state->in_cmd_pipe = { conn.iface_ref, i };
else if (direction == kUSBIn && ep == ep_in_wlan && !m_state->in_wlan_pipe.has_value())
m_state->in_wlan_pipe = { conn.iface_ref, i };
else if (direction == kUSBOut && ep == ep_out && !m_state->out_pipe.has_value())
m_state->out_pipe = { conn.iface_ref, i };
}
return true;
@@ -416,7 +416,7 @@ auto transport::open_interface(io_service_t child) -> bool
auto transport::pid() const -> std::uint16_t
{
return state_->pid;
return m_state->pid;
}
auto transport::send_vendor_request(vendor_request req, bool is_read, std::uint16_t w_value,
@@ -432,7 +432,7 @@ auto transport::send_vendor_request(vendor_request req, bool is_read, std::uint1
request.wLength = static_cast<UInt16>(len);
request.pData = data;
IOReturn ret = (*state_->dev_ref)->DeviceRequest(state_->dev_ref, &request);
IOReturn ret = (*m_state->dev_ref)->DeviceRequest(m_state->dev_ref, &request);
if (ret != kIOReturnSuccess || request.wLenDone != len) {
xone::log_msg(log_level::error, "usb: vendor request 0x%02x failed (%d)",
static_cast<int>(req), ret);
@@ -444,7 +444,7 @@ auto transport::send_vendor_request(vendor_request req, bool is_read, std::uint1
auto transport::bulk_write(void const *data, std::size_t len) -> int
{
auto &pipe = state_->out_pipe.value();
auto &pipe = m_state->out_pipe.value();
IOReturn ret = (*pipe.iface_ref)->WritePipe(pipe.iface_ref, pipe.ref,
const_cast<void *>(data), static_cast<UInt32>(len));
if (ret != kIOReturnSuccess) {
@@ -458,19 +458,19 @@ auto transport::bulk_write(void const *data, std::size_t len) -> int
auto transport::submit_read(read_slot *slot) -> bool
{
{
std::lock_guard<std::mutex> lock(state_->lock);
if (state_->stopping)
std::lock_guard<std::mutex> lock(m_state->lock);
if (m_state->stopping)
return false;
state_->in_flight++;
m_state->in_flight++;
}
IOReturn ret = (*slot->iface_ref)->ReadPipeAsync(slot->iface_ref, slot->pipe_ref,
slot->buf.data(), static_cast<UInt32>(slot->buf.size()),
on_read_completion, slot);
if (ret != kIOReturnSuccess) {
std::lock_guard<std::mutex> lock(state_->lock);
state_->in_flight--;
state_->cv.notify_all();
std::lock_guard<std::mutex> lock(m_state->lock);
m_state->in_flight--;
m_state->cv.notify_all();
return false;
}
@@ -480,16 +480,16 @@ auto transport::submit_read(read_slot *slot) -> bool
void transport::worker_loop()
{
CFRunLoopRef runloop = CFRunLoopGetCurrent();
for (auto *source : state_->sources)
for (auto *source : m_state->sources)
CFRunLoopAddSource(runloop, source, kCFRunLoopDefaultMode);
CFRunLoopAddSource(runloop, IONotificationPortGetRunLoopSource(state_->notify_port),
CFRunLoopAddSource(runloop, IONotificationPortGetRunLoopSource(m_state->notify_port),
kCFRunLoopDefaultMode);
{
std::lock_guard<std::mutex> lock(state_->lock);
state_->runloop = runloop;
state_->loop_ready = true;
state_->cv.notify_all();
std::lock_guard<std::mutex> lock(m_state->lock);
m_state->runloop = runloop;
m_state->loop_ready = true;
m_state->cv.notify_all();
}
CFRunLoopRun();
@@ -497,13 +497,13 @@ void transport::worker_loop()
void transport::handle_read(read_slot *slot, IOReturn result, std::size_t len)
{
if (result == kIOReturnSuccess && len > 0 && state_->frames)
state_->frames(slot->ep, slot->buf.data(), len);
if (result == kIOReturnSuccess && len > 0 && m_state->frames)
m_state->frames(slot->ep, slot->buf.data(), len);
std::lock_guard<std::mutex> lock(state_->lock);
if (state_->stopping) {
state_->in_flight--;
state_->cv.notify_all();
std::lock_guard<std::mutex> lock(m_state->lock);
if (m_state->stopping) {
m_state->in_flight--;
m_state->cv.notify_all();
return;
}
@@ -511,8 +511,8 @@ void transport::handle_read(read_slot *slot, IOReturn result, std::size_t len)
slot->buf.data(), static_cast<UInt32>(slot->buf.size()),
on_read_completion, slot);
if (ret != kIOReturnSuccess) {
state_->in_flight--;
state_->cv.notify_all();
m_state->in_flight--;
m_state->cv.notify_all();
}
}
@@ -520,11 +520,11 @@ void transport::handle_disconnected()
{
disconnect_callback callback;
{
std::lock_guard<std::mutex> lock(state_->lock);
if (state_->stopping || state_->disconnected_notified)
std::lock_guard<std::mutex> lock(m_state->lock);
if (m_state->stopping || m_state->disconnected_notified)
return;
state_->disconnected_notified = true;
callback = state_->disconnected;
m_state->disconnected_notified = true;
callback = m_state->disconnected;
}
xone::log_msg(log_level::info, "usb: dongle disconnected");
@@ -549,7 +549,7 @@ void transport::on_dongle_terminated(void *refcon, io_iterator_t iter)
if (!service)
break;
auto vp = read_vid_pid(service);
if (vp && vp->vid == vid && vp->pid == t->state_->pid)
if (vp && vp->vid == vid && vp->pid == t->m_state->pid)
ours = true;
IOObjectRelease(service);
}