This commit is contained in:
J. Nick Koston 2025-07-11 15:35:26 -10:00
parent 2384b54ee3
commit b67a88027d
No known key found for this signature in database
2 changed files with 1 additions and 19 deletions

View File

@ -24,14 +24,6 @@ static const char *const TAG = "api";
// APIServer
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() {
global_api_server = this;
// Pre-allocate shared write buffer

View File

@ -27,11 +27,6 @@ struct SavedNoisePsk {
} PACKED; // NOLINT
#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 {
public:
APIServer();
@ -145,14 +140,9 @@ class APIServer : public Component, public Controller {
void get_home_assistant_state(std::string entity_id, optional<std::string> attribute,
std::function<void(std::string)> f);
const std::vector<HomeAssistantStateSubscription> &get_state_subs() const;
const std::vector<UserServiceDescriptor *> &get_user_services() const {
#ifdef USE_API_SERVICES
return this->user_services_;
#else
// Return reference to global empty instance (no guard needed)
return get_empty_user_services_instance();
const std::vector<UserServiceDescriptor *> &get_user_services() const { return this->user_services_; }
#endif
}
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
Trigger<std::string, std::string> *get_client_connected_trigger() const { return this->client_connected_trigger_; }