From d98db011dfa36089f6fd5cf7374155afcd46e0a6 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 8 Apr 2015 15:34:06 +0200 Subject: [PATCH] Do not start control socket if not requested + do not report stats if not requested --- src/control_socket.cpp | 16 +++++++++++++++- src/control_socket.h | 2 +- src/main.cpp | 10 ++++++---- src/stats.h | 11 ++++++++--- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/control_socket.cpp b/src/control_socket.cpp index 71727efb0..24a6e1a60 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -269,6 +269,10 @@ int control_init(int port, int connection_type, struct control_state **state, st void control_start(struct control_state *s) { + if (s == NULL) { + return; + } + fd_t sock; sock = create_internal_port(&s->local_port); @@ -724,14 +728,21 @@ void control_done(struct control_state *s) delete s; } -void control_add_stats(struct control_state *s, struct stats_reportable *stats, int32_t port_id) +bool control_add_stats(struct control_state *s, struct stats_reportable *stats, int32_t port_id) { + if (!s) { + return false; + } std::unique_lock lk(s->stats_lock); s->stats.emplace(port_id, stats); + return true; } void control_remove_stats(struct control_state *s, struct stats_reportable *stats) { + if (!s) { + return; + } std::unique_lock lk(s->stats_lock); for (auto it = s->stats.begin(); it != s->stats.end(); ++it) { if (it->second == stats) { @@ -743,6 +754,9 @@ void control_remove_stats(struct control_state *s, struct stats_reportable *stat void control_replace_port_mapping(struct control_state *s, std::map &&m) { + if (!s) { + return; + } std::unique_lock lk(s->stats_lock); s->stats_id_port_mapping = move(m); } diff --git a/src/control_socket.h b/src/control_socket.h index 701943164..74658aedf 100644 --- a/src/control_socket.h +++ b/src/control_socket.h @@ -62,7 +62,7 @@ struct stats_reportable; int control_init(int port, int connection_type, struct control_state **state, struct module *root_module); void control_start(struct control_state *state); void control_done(struct control_state *s); -void control_add_stats(struct control_state *state, struct stats_reportable *stats, int32_t port_id = -1); +bool control_add_stats(struct control_state *state, struct stats_reportable *stats, int32_t port_id = -1); void control_remove_stats(struct control_state *state, struct stats_reportable *stats); void control_replace_port_mapping(struct control_state *state, std::map &&); diff --git a/src/main.cpp b/src/main.cpp index d3927a122..b626ca1b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -414,7 +414,7 @@ int main(int argc, char *argv[]) char *export_opts = NULL; char *sage_opts = NULL; - int control_port = CONTROL_DEFAULT_PORT; + int control_port = -1; int connection_type = 0; struct control_state *control = NULL; @@ -868,9 +868,11 @@ int main(int argc, char *argv[]) } #endif - if(control_init(control_port, connection_type, &control, &root_mod) != 0) { - fprintf(stderr, "Error: Unable to initialize remote control!\n"); - return EXIT_FAIL_CONTROL_SOCK; + if (control_port != -1) { + if (control_init(control_port, connection_type, &control, &root_mod) != 0) { + fprintf(stderr, "Error: Unable to initialize remote control!\n"); + return EXIT_FAIL_CONTROL_SOCK; + } } if(!audio_host) { diff --git a/src/stats.h b/src/stats.h index 6120e241a..544a320a3 100644 --- a/src/stats.h +++ b/src/stats.h @@ -21,11 +21,13 @@ struct stats : public stats_reportable { * are reported. */ stats(struct module *mod, std::string name) - : m_name(name), m_val() { + : m_name(name), m_val(), m_disabled(false) { m_control = (struct control_state *) get_module(get_root_module(mod), "control"); uint32_t id; bool ret = get_port_id(mod, &id); - control_add_stats(m_control, this, ret ? id : -1); + if (!control_add_stats(m_control, this, ret ? id : -1)) { + m_disabled = true; + } } ~stats() { @@ -33,7 +35,9 @@ struct stats : public stats_reportable { } void update(T val) { - m_val = val; + if (!m_disabled) { + m_val = val; + } } std::string get_stat() { @@ -47,6 +51,7 @@ struct stats : public stats_reportable { struct control_state *m_control; std::string m_name; std::atomic m_val; + bool m_disabled; }; #endif // stat_h_