Skip to content

Commit 452856e

Browse files
committed
Update to v0.5.11
1 parent b7e421f commit 452856e

File tree

869 files changed

+15572
-10934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

869 files changed

+15572
-10934
lines changed

ClientSource/Connection/BotBase.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,4 @@ namespace PokemonAutomation{
1515

1616

1717

18-
void BotBaseControllerContext::wait_for_all_requests() const{
19-
m_lifetime_sanitizer.check_usage();
20-
m_controller.wait_for_all_requests(this);
21-
}
22-
void BotBaseControllerContext::cancel_now(){
23-
m_lifetime_sanitizer.check_usage();
24-
CancellableScope::cancel(nullptr);
25-
m_controller.stop_all_commands();
26-
}
27-
void BotBaseControllerContext::cancel_lazy(){
28-
m_lifetime_sanitizer.check_usage();
29-
CancellableScope::cancel(nullptr);
30-
m_controller.next_command_interrupt();
31-
}
32-
33-
bool BotBaseControllerContext::cancel(std::exception_ptr exception) noexcept{
34-
m_lifetime_sanitizer.check_usage();
35-
if (CancellableScope::cancel(std::move(exception))){
36-
return true;
37-
}
38-
try{
39-
m_controller.stop_all_commands();
40-
}catch (...){}
41-
return false;
42-
}
43-
44-
bool BotBaseControllerContext::try_issue_request(const BotBaseRequest& request) const{
45-
m_lifetime_sanitizer.check_usage();
46-
return m_controller.try_issue_request(request, this);
47-
}
48-
void BotBaseControllerContext::issue_request(const BotBaseRequest& request) const{
49-
m_lifetime_sanitizer.check_usage();
50-
m_controller.issue_request(request, this);
51-
}
52-
53-
BotBaseMessage BotBaseControllerContext::issue_request_and_wait(const BotBaseRequest& request) const{
54-
m_lifetime_sanitizer.check_usage();
55-
return m_controller.issue_request_and_wait(request, this);
56-
}
57-
58-
59-
6018
}

ClientSource/Connection/BotBase.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#define PokemonAutomation_AbstractBotBase_H
99

1010
#include "Common/Cpp/CancellableScope.h"
11-
#include "Common/Cpp/LifetimeSanitizer.h"
1211

1312
namespace PokemonAutomation{
1413

@@ -73,66 +72,6 @@ class BotBaseController{
7372

7473

7574

76-
class ControllerContext0 : public CancellableScope{
77-
public:
78-
virtual void wait_for_all_requests() const = 0;
79-
virtual void cancel_now() = 0;
80-
virtual void cancel_lazy() = 0;
81-
};
82-
83-
84-
// A wrapper for BotBase that allows for asynchronous cancelling.
85-
class BotBaseControllerContext final : public ControllerContext0{
86-
public:
87-
using ControllerType = BotBaseController;
88-
89-
public:
90-
BotBaseControllerContext(BotBaseController& botbase)
91-
: m_controller(botbase)
92-
{}
93-
BotBaseControllerContext(CancellableScope& parent, BotBaseController& botbase)
94-
: m_controller(botbase)
95-
{
96-
attach(parent);
97-
}
98-
virtual ~BotBaseControllerContext(){
99-
detach();
100-
}
101-
102-
103-
virtual void wait_for_all_requests() const override;
104-
105-
operator BotBaseController&() const{ return m_controller; }
106-
BotBaseController& controller() const{ return m_controller; }
107-
108-
// Stop all commands in this context now.
109-
virtual void cancel_now() override;
110-
111-
// Stop the commands in this context, but do it lazily.
112-
// Still will stop new commands from being issued to the device,
113-
// and will tell the device that the next command that is issued
114-
// should replace the command queue.
115-
// This cancel is used when you need continuity from an ongoing
116-
// sequence.
117-
virtual void cancel_lazy() override;
118-
119-
120-
virtual bool cancel(std::exception_ptr exception) noexcept override;
121-
122-
123-
public:
124-
bool try_issue_request(const BotBaseRequest& request) const;
125-
void issue_request(const BotBaseRequest& request) const;
126-
BotBaseMessage issue_request_and_wait(const BotBaseRequest& request) const;
127-
128-
129-
private:
130-
BotBaseController& m_controller;
131-
LifetimeSanitizer m_lifetime_sanitizer;
132-
};
133-
134-
135-
13675

13776

13877
}

ClientSource/Connection/PABotBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class PABotBase : public BotBaseController, private PABotBaseConnection{
155155
const BotBaseRequest& request, bool silent_remove
156156
);
157157

158+
public:
158159
virtual bool try_issue_request(
159160
const BotBaseRequest& request,
160161
const Cancellable* cancelled
@@ -168,6 +169,7 @@ class PABotBase : public BotBaseController, private PABotBaseConnection{
168169
const Cancellable* cancelled
169170
) override;
170171

172+
private:
171173
BotBaseMessage wait_for_request(uint64_t seqnum);
172174

173175
private:

ClientSource/Libraries/MessageConverter.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,6 @@ std::string message_to_string(const BotBaseMessage& message){
349349
}
350350

351351

352-
std::string program_name(uint8_t id){
353-
switch (id){
354-
case PABB_PID_UNSPECIFIED: return "Microcontroller Program";
355-
case PABB_PID_PABOTBASE_12KB: return "PABotBase-12KB";
356-
case PABB_PID_PABOTBASE_31KB: return "PABotBase-31KB";
357-
default: return "Unknown ID";
358-
}
359-
}
360-
361352

362353

363354

ClientSource/Libraries/MessageConverter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ void register_message_converter(uint8_t type, MessageConverter converter);
1616
std::string message_to_string(const BotBaseMessage& message);
1717

1818

19-
std::string program_name(uint8_t id);
20-
2119

2220
}
2321

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Reverse Lock Guard
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_ReverseLockGuard_H
8+
#define PokemonAutomation_ReverseLockGuard_H
9+
10+
#include "Common/Cpp/Exceptions.h"
11+
12+
namespace PokemonAutomation{
13+
14+
15+
template <class Mutex>
16+
class ReverseLockGuard{
17+
public:
18+
ReverseLockGuard(Mutex& lock)
19+
: m_lock(lock)
20+
{
21+
if (lock.try_lock()){
22+
throw InternalProgramError(
23+
nullptr, PA_CURRENT_FUNCTION,
24+
"Attempted to unlock an already unlocked lock."
25+
);
26+
}
27+
lock.unlock();
28+
}
29+
~ReverseLockGuard(){
30+
m_lock.lock();
31+
}
32+
33+
34+
private:
35+
Mutex& m_lock;
36+
};
37+
38+
39+
}
40+
#endif

Common/Cpp/Containers/AlignedVector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class AlignedVector{
1818
~AlignedVector();
1919
AlignedVector(AlignedVector&& x) noexcept;
2020
void operator=(AlignedVector&& x) noexcept;
21-
AlignedVector(const AlignedVector&);
22-
void operator=(const AlignedVector&);
21+
AlignedVector(const AlignedVector& x);
22+
void operator=(const AlignedVector& x);
2323

2424
public:
2525
AlignedVector();
2626
AlignedVector(size_t items);
2727

28+
void clear() noexcept;
29+
2830
public:
2931
size_t empty() const{ return m_size == 0; }
3032
size_t size() const{ return m_size; }
@@ -42,8 +44,6 @@ class AlignedVector{
4244
void emplace_back(Args&&... args);
4345
void pop_back();
4446

45-
void clear();
46-
4747
const Object* begin() const;
4848
Object* begin();
4949
const Object* end() const;

Common/Cpp/Containers/AlignedVector.tpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <new>
1212
#include <type_traits>
1313
#include <utility>
14+
#include <algorithm>
1415
#include "Common/Compiler.h"
1516
#include "AlignedMalloc.h"
1617
#include "AlignedVector.h"
@@ -59,7 +60,10 @@ AlignedVector<Object>::AlignedVector(const AlignedVector& x)
5960
break;
6061
}
6162
}
62-
m_ptr = (Object*)aligned_malloc(m_capacity * sizeof(Object), 64);
63+
m_ptr = (Object*)aligned_malloc(
64+
m_capacity * sizeof(Object),
65+
std::max<size_t>(alignof(Object), 64)
66+
);
6367
if (m_ptr == nullptr){
6468
throw std::bad_alloc();
6569
}
@@ -119,6 +123,17 @@ AlignedVector<Object>::AlignedVector(size_t items){
119123
}
120124
}
121125

126+
template <typename Object>
127+
void AlignedVector<Object>::clear() noexcept{
128+
if constexpr (std::is_trivially_constructible<Object>::value){
129+
m_size = 0;
130+
}else{
131+
while (m_size > 0){
132+
pop_back();
133+
}
134+
}
135+
}
136+
122137
template <typename Object>
123138
template <class... Args>
124139
void AlignedVector<Object>::emplace_back(Args&&... args){
@@ -132,16 +147,6 @@ template <typename Object>
132147
void AlignedVector<Object>::pop_back(){
133148
m_ptr[--m_size].~Object();
134149
}
135-
template <typename Object>
136-
void AlignedVector<Object>::clear(){
137-
if constexpr (std::is_trivially_constructible<Object>::value){
138-
m_size = 0;
139-
}else{
140-
while (m_size > 0){
141-
pop_back();
142-
}
143-
}
144-
}
145150

146151
template <typename Object>
147152
PA_NO_INLINE void AlignedVector<Object>::expand(){

0 commit comments

Comments
 (0)