DetectorGraph  2.0
graphstatestore.hpp
Go to the documentation of this file.
1 // Copyright 2017 Nest Labs, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DETECTORGRAPH_INCLUDE_GRAPHSTATESTORE_HPP_
16 #define DETECTORGRAPH_INCLUDE_GRAPHSTATESTORE_HPP_
17 
18 #include <list>
19 #include <queue>
20 
21 #include "sharedptr.hpp"
22 #include "topicstate.hpp"
23 #include "graph.hpp"
24 #include "statesnapshot.hpp"
25 
26 namespace DetectorGraph
27 {
28 
29 /**
30  * @brief A StateSnapshot keeper for DetectorGraph TopicStates.
31  *
32  * This class is responsible for maintaining a look back queue of previous graph
33  * states (in the form of StateSnapshots) in a no-duplication and safe-sharing
34  * fashion.
35  */
37 {
38 public:
39  /**
40  * @brief Constructs an empty graph store.
41  */
43 
44  /**
45  * @brief Default Destructor.
46  *
47  * Note that this destructor doesn't explicitly delete any of the
48  * StateSnapshots in mStatesLookbackQueue since that's implicitly
49  * handled by the ptr::shared_ptrs.
50  */
52 
53  /**
54  * @brief Takes a new state snapshot and appends it to the look back queue.
55  *
56  * This method takes a graph output list and combines it with the previous
57  * StateSnapshot (if existent) to generate a new StateSnapshot.
58  */
59  void TakeNewSnapshot(const std::list< ptr::shared_ptr<const TopicState> >& arTopicStates);
60 
61  /**
62  * @brief Returns a safe shared pointer to the latest complete StateSnapshot
63  *
64  * Always returns a valid ptr::shared_ptr even though the StateSnapshot might be
65  * empty.
66  */
67  ptr::shared_ptr<const StateSnapshot> GetLastState() const;
68 
69  // TODO(DGRAPH-19): APIs for accessing earlier snapshots.
70 
71 private:
72  std::queue< ptr::shared_ptr<const StateSnapshot> > mStatesLookbackQueue;
73 };
74 
75 }
76 
77 #endif // DETECTORGRAPH_INCLUDE_GRAPHSTATESTORE_HPP_
ptr::shared_ptr< const StateSnapshot > GetLastState() const
Returns a safe shared pointer to the latest complete StateSnapshot.
A StateSnapshot keeper for DetectorGraph TopicStates.
~GraphStateStore()
Default Destructor.
GraphStateStore()
Constructs an empty graph store.
void TakeNewSnapshot(const std::list< ptr::shared_ptr< const TopicState > > &arTopicStates)
Takes a new state snapshot and appends it to the look back queue.