Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Oct 3, 2024
1 parent 98b58d1 commit bc3bc68
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
22 changes: 12 additions & 10 deletions applications/system-service/powerapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@ PowerAPI::~PowerAPI(){
}
}

void PowerAPI::setEnabled(bool enabled) {
if(enabled){
if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::RM1){
Oxide::UDev::singleton()->start();
}else{
timer->start();
}
}else if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::RM1){
Oxide::UDev::singleton()->stop();
void PowerAPI::setEnabled(bool enabled){
if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::RM1){
if(enabled){
Oxide::UDev::singleton()->start();
}else{
timer->stop();
Oxide::UDev::singleton()->stop();
}
return;
}
if(enabled){
timer->start();
}else{
timer->stop();
}
}

int PowerAPI::state(){
Expand Down
33 changes: 18 additions & 15 deletions shared/liboxide/udev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
namespace Oxide {

UDev* UDev::singleton(){
static UDev* instance;
if(instance == nullptr){
instance = new UDev();
instance->start();
}
static std::once_flag initFlag;
static UDev* instance = nullptr;
std::call_once(initFlag, [](){
instance = new UDev();
instance->start();
});
return instance;
}

Expand Down Expand Up @@ -103,10 +104,10 @@ namespace Oxide {
O_DEBUG("UDev::Adding" << subsystem << deviceType);
QStringList* list;
if(monitors.contains(subsystem)){
list = monitors[subsystem];
list = monitors[subsystem].data();
}else{
list = new QStringList();
monitors.insert(subsystem, list);
monitors.insert(subsystem, QSharedPointer<QStringList>(list));
}
if(!list->contains(deviceType)){
list->append(deviceType);
Expand Down Expand Up @@ -145,7 +146,8 @@ namespace Oxide {
device.action = getActionType(udevDevice);
device.path = path;
device.subsystem = subsystem;
device.deviceType = QString(udev_device_get_devtype(udevDevice));
auto devType = udev_device_get_devtype(udevDevice);
device.deviceType = QString(devType ? devType : "");
udev_device_unref(udevDevice);
deviceList.append(device);
}
Expand All @@ -168,7 +170,7 @@ namespace Oxide {
if(actionType == "REMOVE"){
return Remove;
}
if(actionType == "Change"){
if(actionType == "CHANGE"){
return Change;
}
if(actionType == "OFFLINE"){
Expand Down Expand Up @@ -228,18 +230,19 @@ namespace Oxide {
update = false;
udev_monitor_unref(mon);
timer->deleteLater();
QTimer::singleShot(0, [this]{
monitor();
});
QTimer::singleShot(0, this, &UDev::monitor);
return;
}
udev_device* dev = udev_monitor_receive_device(mon);
if(dev != nullptr){
Device device;
device.action = getActionType(dev);
device.path = QString(udev_device_get_devnode(dev));
device.subsystem = QString(udev_device_get_subsystem(dev));
device.deviceType = QString(udev_device_get_devtype(dev));
auto devNode = udev_device_get_devnode(dev);
device.path = QString(devNode ? devNode : "");
auto devSubsystem = udev_device_get_subsystem(dev);
device.subsystem = QString(devSubsystem ? devSubsystem : "");
auto devType = udev_device_get_devtype(dev);
device.deviceType = QString(devType ? devType : "");
udev_device_unref(dev);
O_DEBUG("UDev::Monitor UDev event" << device);
emit event(device);
Expand Down
6 changes: 2 additions & 4 deletions shared/liboxide/udev.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <QObject>
#include <QMutex>

using namespace std;

namespace Oxide {
class UDev : public QObject {
Q_OBJECT
Expand Down Expand Up @@ -53,7 +51,7 @@ namespace Oxide {
return "UNKNOWN";
}
}
string debugString() const {
std::string debugString() const {
return QString("<Device %1/%2 %3>").arg(subsystem, deviceType, actionString()).toStdString();
}
};
Expand All @@ -79,7 +77,7 @@ namespace Oxide {
bool running = false;
bool exitRequested = false;
bool update = false;
QMap<QString, QStringList*> monitors;
QMap<QString, QSharedPointer<QStringList>> monitors;
QThread _thread;
QMutex statelock;

Expand Down

0 comments on commit bc3bc68

Please sign in to comment.