mirror of
https://github.com/esphome/esphome.git
synced 2026-03-23 20:19:57 +08:00
[api] Remove virtual destructor and rename read_message to read_message_
The virtual destructor was unnecessary since APIConnection is only stored as unique_ptr<APIConnection>, never via a base class pointer. Removing it eliminates the vtable entirely. Rename read_message to read_message_ per clang-tidy naming convention for protected methods.
This commit is contained in:
@@ -234,7 +234,7 @@ void APIConnection::loop() {
|
||||
this->last_traffic_ = now;
|
||||
}
|
||||
// read a packet
|
||||
this->read_message(buffer.data_len, buffer.type, buffer.data);
|
||||
this->read_message_(buffer.data_len, buffer.type, buffer.data);
|
||||
if (this->flags_.remove)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class APIConnection final : public APIServerConnectionBase {
|
||||
friend class APIServer;
|
||||
friend class ListEntitiesIterator;
|
||||
APIConnection(std::unique_ptr<socket::Socket> socket, APIServer *parent);
|
||||
virtual ~APIConnection();
|
||||
~APIConnection();
|
||||
|
||||
void start();
|
||||
void loop();
|
||||
@@ -57,7 +57,7 @@ class APIConnection final : public APIServerConnectionBase {
|
||||
protected:
|
||||
// Override read_message here (instead of in APIServerConnectionBase) so the
|
||||
// compiler can devirtualize and inline on_* handler calls within this class.
|
||||
void read_message(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data);
|
||||
void read_message_(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data);
|
||||
|
||||
// Auth helpers defined here (not in ProtoService) so the compiler can
|
||||
// devirtualize is_connection_setup()/on_no_setup_connection() calls
|
||||
|
||||
@@ -21,7 +21,7 @@ void APIServerConnectionBase::log_receive_message_(const LogString *name) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void APIConnection::read_message(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) {
|
||||
void APIConnection::read_message_(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) {
|
||||
// Check authentication/connection requirements
|
||||
switch (msg_type) {
|
||||
case HelloRequest::MESSAGE_TYPE: // No setup required
|
||||
|
||||
@@ -3055,7 +3055,7 @@ static const char *const TAG = "api.service";
|
||||
# can devirtualize and inline the on_* handler calls within the same class.
|
||||
# APIConnection declares the override in api_connection.h.
|
||||
|
||||
out = "void APIConnection::read_message(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) {\n"
|
||||
out = "void APIConnection::read_message_(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) {\n"
|
||||
|
||||
# Auth check block before dispatch switch
|
||||
out += " // Check authentication/connection requirements\n"
|
||||
|
||||
Reference in New Issue
Block a user