[api] Move auth check helpers from ProtoService to APIConnection

check_connection_setup_() and check_authenticated_() call virtual
methods (is_connection_setup, on_no_setup_connection). When defined
in ProtoService, the compiler cannot devirtualize these calls.
Moving them to APIConnection (final) enables devirtualization.
This commit is contained in:
J. Nick Koston
2026-03-20 21:10:41 -10:00
parent 9583a6a921
commit e9d25645cb
2 changed files with 12 additions and 11 deletions
+12
View File
@@ -59,6 +59,18 @@ class APIConnection final : public APIServerConnectionBase {
// 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) override;
// Auth helpers defined here (not in ProtoService) so the compiler can
// devirtualize is_connection_setup()/on_no_setup_connection() calls
// within this final class.
inline bool check_connection_setup_() {
if (!this->is_connection_setup()) {
this->on_no_setup_connection();
return false;
}
return true;
}
inline bool check_authenticated_() { return this->check_connection_setup_(); }
public:
bool send_list_info_done() {
return this->schedule_message_(nullptr, ListEntitiesDoneResponse::MESSAGE_TYPE,
-11
View File
@@ -706,17 +706,6 @@ class ProtoService {
virtual void on_no_setup_connection() = 0;
virtual bool send_buffer(ProtoWriteBuffer buffer, uint8_t message_type) = 0;
virtual void read_message(uint32_t msg_size, uint32_t msg_type, const uint8_t *msg_data) = 0;
// Authentication helper methods
inline bool check_connection_setup_() {
if (!this->is_connection_setup()) {
this->on_no_setup_connection();
return false;
}
return true;
}
inline bool check_authenticated_() { return this->check_connection_setup_(); }
};
} // namespace esphome::api