VOL-1050 Delay stats collection after connection
Move the state of connectivity and activation to its own file (state)
It handles starting/stopping statistics collection and provides a hook for future actions
Change-Id: If6a7b4015824716ff45781e39f29ca7f06933702
diff --git a/src/state.cc b/src/state.cc
new file mode 100644
index 0000000..54339e1
--- /dev/null
+++ b/src/state.cc
@@ -0,0 +1,50 @@
+#include "stats_collection.h"
+#include <mutex>
+
+namespace state {
+
+ bool connected_to_voltha = false;
+ bool activated = false;
+ std::mutex state_lock;
+
+ bool is_connected() {
+ return connected_to_voltha;
+ }
+
+ bool is_activated() {
+ return activated;
+ }
+
+ void connect() {
+ state_lock.lock();
+ connected_to_voltha = true;
+ if (activated) {
+ start_collecting_statistics();
+ }
+ state_lock.unlock();
+ }
+
+ void disconnect() {
+ state_lock.lock();
+ connected_to_voltha = false;
+ stop_collecting_statistics();
+ state_lock.unlock();
+ }
+
+ void activate() {
+ state_lock.lock();
+ activated = true;
+ if (connected_to_voltha) {
+ start_collecting_statistics();
+ }
+ state_lock.unlock();
+ }
+
+ void deactivate() {
+ state_lock.lock();
+ activated = false;
+ stop_collecting_statistics();
+ state_lock.unlock();
+ }
+
+}