Compare commits

..

1 Commits

Author SHA1 Message Date
Lioncash
c715fc4c5e gc_adapter: Make DeviceConnected() a const member function
This doesn't modify instance state, so it can be made const.
2020-09-07 02:49:13 -04:00
6 changed files with 28 additions and 28 deletions

View File

@@ -29,7 +29,7 @@ namespace Service::Sockets {
* Worker abstraction to execute blocking calls on host without blocking the guest thread
*
* @tparam Service Service where the work is executed
* @tparam Types Types of work to execute
* @tparam ...Types Types of work to execute
*/
template <class Service, class... Types>
class BlockingWorker {
@@ -109,8 +109,9 @@ private:
while (keep_running) {
work_event.Wait();
const auto visit_fn = [service, &keep_running]<typename T>(T&& w) {
if constexpr (std::is_same_v<std::decay_t<T>, std::monostate>) {
const auto visit_fn = [service, &keep_running](auto&& w) {
using T = std::decay_t<decltype(w)>;
if constexpr (std::is_same_v<T, std::monostate>) {
keep_running = false;
} else {
w.Execute(service);

View File

@@ -491,7 +491,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
for (PollFD& pollfd : fds) {
ASSERT(pollfd.revents == 0);
if (pollfd.fd > static_cast<s32>(MAX_FD) || pollfd.fd < 0) {
if (pollfd.fd > MAX_FD || pollfd.fd < 0) {
LOG_ERROR(Service, "File descriptor handle={} is invalid", pollfd.fd);
pollfd.revents = 0;
return {0, Errno::SUCCESS};
@@ -764,7 +764,6 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>&
SockAddrIn guest_addr_in;
std::memcpy(&guest_addr_in, addr.data(), sizeof(guest_addr_in));
addr_in = Translate(guest_addr_in);
p_addr_in = &addr_in;
}
return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in));
@@ -796,7 +795,7 @@ s32 BSD::FindFreeFileDescriptorHandle() noexcept {
}
bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
if (fd > MAX_FD || fd < 0) {
LOG_ERROR(Service, "Invalid file descriptor handle={}", fd);
return false;
}
@@ -810,7 +809,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
bool BSD::IsBlockingSocket(s32 fd) const noexcept {
// Inform invalid sockets as non-blocking
// This way we avoid using a worker thread as it will fail without blocking host
if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
if (fd > MAX_FD || fd < 0) {
return false;
}
if (!file_descriptors[fd]) {

View File

@@ -131,21 +131,21 @@ u16 TranslatePollEventsToGuest(u16 flags) {
Network::SockAddrIn Translate(SockAddrIn value) {
ASSERT(value.len == 0 || value.len == sizeof(value));
return {
.family = Translate(static_cast<Domain>(value.family)),
.ip = value.ip,
.portno = static_cast<u16>(value.portno >> 8 | value.portno << 8),
};
Network::SockAddrIn result;
result.family = Translate(static_cast<Domain>(value.family));
result.ip = value.ip;
result.portno = value.portno >> 8 | value.portno << 8;
return result;
}
SockAddrIn Translate(Network::SockAddrIn value) {
return {
.len = sizeof(SockAddrIn),
.family = static_cast<u8>(Translate(value.family)),
.portno = static_cast<u16>(value.portno >> 8 | value.portno << 8),
.ip = value.ip,
.zeroes = {},
};
SockAddrIn result;
result.len = sizeof(result);
result.family = static_cast<u8>(Translate(value.family));
result.portno = value.portno >> 8 | value.portno << 8;
result.ip = value.ip;
result.zeroes = {};
return result;
}
Network::ShutdownHow Translate(ShutdownHow how) {

View File

@@ -283,7 +283,7 @@ void Adapter::Reset() {
}
}
bool Adapter::DeviceConnected(std::size_t port) {
bool Adapter::DeviceConnected(std::size_t port) const {
return adapter_controllers_status[port] != ControllerTypes::None;
}

View File

@@ -76,7 +76,7 @@ public:
void EndConfiguration();
/// Returns true if there is a device connected to port
bool DeviceConnected(std::size_t port);
bool DeviceConnected(std::size_t port) const;
std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;

View File

@@ -15,7 +15,7 @@ namespace InputCommon {
class GCButton final : public Input::ButtonDevice {
public:
explicit GCButton(int port_, int button_, GCAdapter::Adapter* adapter)
explicit GCButton(int port_, int button_, const GCAdapter::Adapter* adapter)
: port(port_), button(button_), gcadapter(adapter) {}
~GCButton() override;
@@ -30,13 +30,13 @@ public:
private:
const int port;
const int button;
GCAdapter::Adapter* gcadapter;
const GCAdapter::Adapter* gcadapter;
};
class GCAxisButton final : public Input::ButtonDevice {
public:
explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_,
GCAdapter::Adapter* adapter)
const GCAdapter::Adapter* adapter)
: port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_),
gcadapter(adapter),
origin_value(static_cast<float>(adapter->GetOriginValue(port_, axis_))) {}
@@ -60,7 +60,7 @@ private:
const int axis;
float threshold;
bool trigger_if_greater;
GCAdapter::Adapter* gcadapter;
const GCAdapter::Adapter* gcadapter;
const float origin_value;
};
@@ -149,8 +149,8 @@ void GCButtonFactory::EndConfiguration() {
class GCAnalog final : public Input::AnalogDevice {
public:
GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter,
float range_)
GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_,
const GCAdapter::Adapter* adapter, float range_)
: port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter),
origin_value_x(static_cast<float>(adapter->GetOriginValue(port_, axis_x_))),
origin_value_y(static_cast<float>(adapter->GetOriginValue(port_, axis_y_))),
@@ -212,7 +212,7 @@ private:
const int axis_x;
const int axis_y;
const float deadzone;
GCAdapter::Adapter* gcadapter;
const GCAdapter::Adapter* gcadapter;
const float origin_value_x;
const float origin_value_y;
const float range;