1 //
2 // Copyright (C) 2009 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_GRAPH_UTILS_H_
18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_GRAPH_UTILS_H_
19 
20 #include <vector>
21 
22 #include <base/macros.h>
23 
24 #include "update_engine/payload_generator/graph_types.h"
25 #include "update_engine/update_metadata.pb.h"
26 
27 // A few utility functions for graphs
28 
29 namespace chromeos_update_engine {
30 
31 namespace graph_utils {
32 
33 // Returns the number of blocks represented by all extents in the edge.
34 uint64_t EdgeWeight(const Graph& graph, const Edge& edge);
35 
36 // These add a read-before dependency from graph[src] -> graph[dst]. If the dep
37 // already exists, the block/s is/are added to the existing edge.
38 void AddReadBeforeDep(Vertex* src,
39                       Vertex::Index dst,
40                       uint64_t block);
41 void AddReadBeforeDepExtents(Vertex* src,
42                              Vertex::Index dst,
43                              const std::vector<Extent>& extents);
44 
45 void DropWriteBeforeDeps(Vertex::EdgeMap* edge_map);
46 
47 // For each node N in graph, drop all edges N->|index|.
48 void DropIncomingEdgesTo(Graph* graph, Vertex::Index index);
49 
50 void DumpGraph(const Graph& graph);
51 
52 }  // namespace graph_utils
53 
54 }  // namespace chromeos_update_engine
55 
56 #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_GRAPH_UTILS_H_
57