blob: 053278895560d99695f6f1c01431bdf1bcfceaf2 [file] [log] [blame]
Alex Vakulenko57123b22014-10-28 13:50:16 -07001// 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 Muhin01829452014-11-21 02:16:04 +040013#include "commands/schema_utils.h"
14
Alex Vakulenko57123b22014-10-28 13:50:16 -070015namespace buffet {
16
17// A simple notification record event to track device state changes.
18// The |timestamp| records the time of the state change.
Alex Vakulenkoff73cf22014-10-29 09:53:52 -070019// |changed_properties| contains a property set with the new property values
20// which were updated at the time the event was recorded.
Alex Vakulenko57123b22014-10-28 13:50:16 -070021struct StateChange {
Alex Vakulenkoff73cf22014-10-29 09:53:52 -070022 StateChange(base::Time time,
Anton Muhin01829452014-11-21 02:16:04 +040023 native_types::Object properties)
Alex Vakulenkoff73cf22014-10-29 09:53:52 -070024 : timestamp(time), changed_properties(std::move(properties)) {}
Alex Vakulenko57123b22014-10-28 13:50:16 -070025 base::Time timestamp;
Anton Muhin01829452014-11-21 02:16:04 +040026 native_types::Object changed_properties;
Alex Vakulenko57123b22014-10-28 13:50:16 -070027};
28
29// An abstract interface to StateChangeQueue to record and retrieve state
30// change notification events.
31class 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 Vakulenkoff73cf22014-10-29 09:53:52 -070037 virtual bool NotifyPropertiesUpdated(
38 base::Time timestamp,
Anton Muhin01829452014-11-21 02:16:04 +040039 native_types::Object changed_properties) = 0;
Alex Vakulenko57123b22014-10-28 13:50:16 -070040
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_