mirror of
https://github.com/esphome/esphome.git
synced 2025-08-03 08:57:47 +00:00
guard
This commit is contained in:
parent
2384b54ee3
commit
b67a88027d
@ -24,14 +24,6 @@ static const char *const TAG = "api";
|
|||||||
// APIServer
|
// APIServer
|
||||||
APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
||||||
#ifndef USE_API_SERVICES
|
|
||||||
// Global empty vector to avoid guard variables (saves 8 bytes)
|
|
||||||
// This is initialized at program startup before any threads
|
|
||||||
static const std::vector<UserServiceDescriptor *> empty_user_services{};
|
|
||||||
|
|
||||||
const std::vector<UserServiceDescriptor *> &get_empty_user_services_instance() { return empty_user_services; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
APIServer::APIServer() {
|
APIServer::APIServer() {
|
||||||
global_api_server = this;
|
global_api_server = this;
|
||||||
// Pre-allocate shared write buffer
|
// Pre-allocate shared write buffer
|
||||||
|
@ -27,11 +27,6 @@ struct SavedNoisePsk {
|
|||||||
} PACKED; // NOLINT
|
} PACKED; // NOLINT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef USE_API_SERVICES
|
|
||||||
// Forward declaration of helper function
|
|
||||||
const std::vector<UserServiceDescriptor *> &get_empty_user_services_instance();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class APIServer : public Component, public Controller {
|
class APIServer : public Component, public Controller {
|
||||||
public:
|
public:
|
||||||
APIServer();
|
APIServer();
|
||||||
@ -145,14 +140,9 @@ class APIServer : public Component, public Controller {
|
|||||||
void get_home_assistant_state(std::string entity_id, optional<std::string> attribute,
|
void get_home_assistant_state(std::string entity_id, optional<std::string> attribute,
|
||||||
std::function<void(std::string)> f);
|
std::function<void(std::string)> f);
|
||||||
const std::vector<HomeAssistantStateSubscription> &get_state_subs() const;
|
const std::vector<HomeAssistantStateSubscription> &get_state_subs() const;
|
||||||
const std::vector<UserServiceDescriptor *> &get_user_services() const {
|
|
||||||
#ifdef USE_API_SERVICES
|
#ifdef USE_API_SERVICES
|
||||||
return this->user_services_;
|
const std::vector<UserServiceDescriptor *> &get_user_services() const { return this->user_services_; }
|
||||||
#else
|
|
||||||
// Return reference to global empty instance (no guard needed)
|
|
||||||
return get_empty_user_services_instance();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
||||||
Trigger<std::string, std::string> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
Trigger<std::string, std::string> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user