Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BUFFET_STATES_STATE_CHANGE_QUEUE_INTERFACE_H_ |
| 6 | #define BUFFET_STATES_STATE_CHANGE_QUEUE_INTERFACE_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include <base/time/time.h> |
| 11 | #include <chromeos/variant_dictionary.h> |
| 12 | |
Anton Muhin | 0182945 | 2014-11-21 02:16:04 +0400 | [diff] [blame] | 13 | #include "commands/schema_utils.h" |
| 14 | |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 15 | namespace buffet { |
| 16 | |
| 17 | // A simple notification record event to track device state changes. |
| 18 | // The |timestamp| records the time of the state change. |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 19 | // |changed_properties| contains a property set with the new property values |
| 20 | // which were updated at the time the event was recorded. |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 21 | struct StateChange { |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 22 | StateChange(base::Time time, |
Anton Muhin | 0182945 | 2014-11-21 02:16:04 +0400 | [diff] [blame] | 23 | native_types::Object properties) |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 24 | : timestamp(time), changed_properties(std::move(properties)) {} |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 25 | base::Time timestamp; |
Anton Muhin | 0182945 | 2014-11-21 02:16:04 +0400 | [diff] [blame] | 26 | native_types::Object changed_properties; |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | // An abstract interface to StateChangeQueue to record and retrieve state |
| 30 | // change notification events. |
| 31 | class StateChangeQueueInterface { |
| 32 | public: |
| 33 | // Returns true if the state change notification queue is empty. |
| 34 | virtual bool IsEmpty() const = 0; |
| 35 | |
| 36 | // Called by StateManager when device state properties are updated. |
Alex Vakulenko | ff73cf2 | 2014-10-29 09:53:52 -0700 | [diff] [blame] | 37 | virtual bool NotifyPropertiesUpdated( |
| 38 | base::Time timestamp, |
Anton Muhin | 0182945 | 2014-11-21 02:16:04 +0400 | [diff] [blame] | 39 | native_types::Object changed_properties) = 0; |
Alex Vakulenko | 57123b2 | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 40 | |
| 41 | // Returns the recorded state changes since last time this method was called. |
| 42 | virtual std::vector<StateChange> GetAndClearRecordedStateChanges() = 0; |
| 43 | |
| 44 | protected: |
| 45 | // No one should attempt do destroy the queue through the interface. |
| 46 | ~StateChangeQueueInterface() {} |
| 47 | }; |
| 48 | |
| 49 | } // namespace buffet |
| 50 | |
| 51 | #endif // BUFFET_STATES_STATE_CHANGE_QUEUE_INTERFACE_H_ |