Skip to content

Commit

Permalink
Disable move and copy on classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 15, 2024
1 parent c81d86c commit 8aafec9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
4 changes: 4 additions & 0 deletions include/CaptivePortalInstance.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Common.h"
#include "WebSocketDeFragger.h"

#include <DNSServer.h>
Expand All @@ -14,6 +15,9 @@

namespace OpenShock {
class CaptivePortalInstance {
DISABLE_COPY(CaptivePortalInstance);
DISABLE_MOVE(CaptivePortalInstance);

public:
CaptivePortalInstance();
~CaptivePortalInstance();
Expand Down
4 changes: 4 additions & 0 deletions include/GatewayClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Common.h"
#include "GatewayClientState.h"

#include <WebSocketsClient.h>
Expand All @@ -11,6 +12,9 @@

namespace OpenShock {
class GatewayClient {
DISABLE_COPY(GatewayClient);
DISABLE_MOVE(GatewayClient);

public:
GatewayClient(const std::string& authToken);
~GatewayClient();
Expand Down
1 change: 1 addition & 0 deletions include/PinPatternManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace OpenShock {
class PinPatternManager {
DISABLE_COPY(PinPatternManager);
DISABLE_MOVE(PinPatternManager);

public:
struct State {
Expand Down
1 change: 1 addition & 0 deletions include/RGBPatternManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace OpenShock {
class RGBPatternManager {
DISABLE_COPY(RGBPatternManager);
DISABLE_MOVE(RGBPatternManager);

public:
RGBPatternManager() = delete;
Expand Down
44 changes: 25 additions & 19 deletions include/ReadWriteMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace OpenShock {
class ReadWriteMutex {
DISABLE_COPY(ReadWriteMutex);
DISABLE_MOVE(ReadWriteMutex);

public:
ReadWriteMutex();
~ReadWriteMutex();
Expand All @@ -17,6 +18,7 @@ namespace OpenShock {

bool lockWrite(TickType_t xTicksToWait);
void unlockWrite();

private:
SemaphoreHandle_t m_mutex;
SemaphoreHandle_t m_readSem;
Expand All @@ -26,8 +28,11 @@ namespace OpenShock {
class ScopedReadLock {
DISABLE_COPY(ScopedReadLock);
DISABLE_MOVE(ScopedReadLock);

public:
ScopedReadLock(ReadWriteMutex* mutex, TickType_t xTicksToWait = portMAX_DELAY) : m_mutex(mutex) {
ScopedReadLock(ReadWriteMutex* mutex, TickType_t xTicksToWait = portMAX_DELAY)
: m_mutex(mutex)
{
bool result = false;
if (m_mutex != nullptr) {
result = m_mutex->lockRead(xTicksToWait);
Expand All @@ -38,17 +43,17 @@ namespace OpenShock {
}
}

~ScopedReadLock() {
~ScopedReadLock()
{
if (m_mutex != nullptr) {
m_mutex->unlockRead();
}
}

bool isLocked() const {
return m_mutex != nullptr;
}
bool isLocked() const { return m_mutex != nullptr; }

bool unlock() {
bool unlock()
{
if (m_mutex != nullptr) {
m_mutex->unlockRead();
m_mutex = nullptr;
Expand All @@ -58,18 +63,20 @@ namespace OpenShock {
return false;
}

ReadWriteMutex* getMutex() const {
return m_mutex;
}
ReadWriteMutex* getMutex() const { return m_mutex; }

private:
ReadWriteMutex* m_mutex;
};

class ScopedWriteLock {
DISABLE_COPY(ScopedWriteLock);
DISABLE_MOVE(ScopedWriteLock);

public:
ScopedWriteLock(ReadWriteMutex* mutex, TickType_t xTicksToWait = portMAX_DELAY) : m_mutex(mutex) {
ScopedWriteLock(ReadWriteMutex* mutex, TickType_t xTicksToWait = portMAX_DELAY)
: m_mutex(mutex)
{
bool result = false;
if (m_mutex != nullptr) {
result = m_mutex->lockWrite(xTicksToWait);
Expand All @@ -80,17 +87,17 @@ namespace OpenShock {
}
}

~ScopedWriteLock() {
~ScopedWriteLock()
{
if (m_mutex != nullptr) {
m_mutex->unlockWrite();
}
}

bool isLocked() const {
return m_mutex != nullptr;
}
bool isLocked() const { return m_mutex != nullptr; }

bool unlock() {
bool unlock()
{
if (m_mutex != nullptr) {
m_mutex->unlockWrite();
m_mutex = nullptr;
Expand All @@ -100,10 +107,9 @@ namespace OpenShock {
return false;
}

ReadWriteMutex* getMutex() const {
return m_mutex;
}
ReadWriteMutex* getMutex() const { return m_mutex; }

private:
ReadWriteMutex* m_mutex;
};
} // namespace OpenShock
} // namespace OpenShock
8 changes: 5 additions & 3 deletions include/WebSocketDeFragger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

#include <WebSockets.h>

#include <map>
#include <cstdint>
#include <functional>
#include <map>

namespace OpenShock {
class WebSocketDeFragger {
DISABLE_COPY(WebSocketDeFragger);
public:
DISABLE_MOVE(WebSocketDeFragger);

public:
typedef std::function<void(uint8_t socketId, WebSocketMessageType type, const uint8_t* data, uint32_t length)> EventCallback;

WebSocketDeFragger(EventCallback callback);
Expand All @@ -23,6 +24,7 @@ namespace OpenShock {
void onEvent(const EventCallback& callback);
void clear(uint8_t socketId);
void clear();

private:
void start(uint8_t socketId, WebSocketMessageType type, const uint8_t* data, uint32_t length);
void append(uint8_t socketId, const uint8_t* data, uint32_t length);
Expand All @@ -38,4 +40,4 @@ namespace OpenShock {
std::map<uint8_t, Message> m_messages;
EventCallback m_callback;
};
}
} // namespace OpenShock
4 changes: 4 additions & 0 deletions include/radio/RFTransmitter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Common.h"
#include "ShockerCommandType.h"
#include "ShockerModelType.h"

Expand All @@ -13,6 +14,9 @@

namespace OpenShock {
class RFTransmitter {
DISABLE_COPY(RFTransmitter);
DISABLE_MOVE(RFTransmitter);

public:
RFTransmitter(gpio_num_t gpioPin);
~RFTransmitter();
Expand Down

0 comments on commit 8aafec9

Please sign in to comment.