Nicolas Palpacuer | 3cad49d | 2018-07-02 14:03:24 -0400 | [diff] [blame] | 1 | #include "stats_collection.h" |
| 2 | #include <mutex> |
| 3 | |
| 4 | namespace state { |
| 5 | |
| 6 | bool connected_to_voltha = false; |
| 7 | bool activated = false; |
| 8 | std::mutex state_lock; |
| 9 | |
| 10 | bool is_connected() { |
| 11 | return connected_to_voltha; |
| 12 | } |
| 13 | |
| 14 | bool is_activated() { |
| 15 | return activated; |
| 16 | } |
| 17 | |
| 18 | void connect() { |
| 19 | state_lock.lock(); |
| 20 | connected_to_voltha = true; |
| 21 | if (activated) { |
| 22 | start_collecting_statistics(); |
| 23 | } |
| 24 | state_lock.unlock(); |
| 25 | } |
| 26 | |
| 27 | void disconnect() { |
| 28 | state_lock.lock(); |
| 29 | connected_to_voltha = false; |
| 30 | stop_collecting_statistics(); |
| 31 | state_lock.unlock(); |
| 32 | } |
| 33 | |
| 34 | void activate() { |
| 35 | state_lock.lock(); |
| 36 | activated = true; |
| 37 | if (connected_to_voltha) { |
| 38 | start_collecting_statistics(); |
| 39 | } |
| 40 | state_lock.unlock(); |
| 41 | } |
| 42 | |
| 43 | void deactivate() { |
| 44 | state_lock.lock(); |
| 45 | activated = false; |
| 46 | stop_collecting_statistics(); |
| 47 | state_lock.unlock(); |
| 48 | } |
| 49 | |
| 50 | } |