Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__ |
| 7 | |
| 8 | #include <map> |
| 9 | #include <set> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 10 | #include <string> |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | #include "base/basictypes.h" |
| 14 | #include "update_engine/update_metadata.pb.h" |
| 15 | |
| 16 | // A few classes that help in generating delta images use these types |
| 17 | // for the graph work. |
| 18 | |
| 19 | namespace chromeos_update_engine { |
| 20 | |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame] | 21 | bool operator==(const Extent& a, const Extent& b); |
| 22 | |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 23 | struct EdgeProperties { |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame] | 24 | // Read-before extents. I.e., blocks in |extents| must be read by the |
| 25 | // node pointed to before the pointing node runs (presumably b/c it |
| 26 | // overwrites these blocks). |
| 27 | std::vector<Extent> extents; |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 28 | |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame] | 29 | // Write before extents. I.e., blocks in |write_extents| must be written |
| 30 | // by the node pointed to before the pointing node runs (presumably |
| 31 | // b/c it reads the data written by the other node). |
| 32 | std::vector<Extent> write_extents; |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 33 | |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame] | 34 | bool operator==(const EdgeProperties& that) const { |
| 35 | return extents == that.extents && write_extents == that.write_extents; |
| 36 | } |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct Vertex { |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 40 | Vertex() : |
| 41 | valid(true), |
| 42 | index(-1), |
| 43 | lowlink(-1), |
| 44 | chunk_offset(0), |
| 45 | chunk_size(-1) {} |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame] | 46 | bool valid; |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 47 | |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 48 | typedef std::map<std::vector<Vertex>::size_type, EdgeProperties> EdgeMap; |
| 49 | EdgeMap out_edges; |
| 50 | |
| 51 | // We sometimes wish to consider a subgraph of a graph. A subgraph would have |
| 52 | // a subset of the vertices from the graph and a subset of the edges. |
| 53 | // When considering this vertex within a subgraph, subgraph_edges stores |
| 54 | // the out-edges. |
| 55 | typedef std::set<std::vector<Vertex>::size_type> SubgraphEdgeMap; |
| 56 | SubgraphEdgeMap subgraph_edges; |
| 57 | |
| 58 | // For Tarjan's algorithm: |
| 59 | std::vector<Vertex>::size_type index; |
| 60 | std::vector<Vertex>::size_type lowlink; |
| 61 | |
| 62 | // Other Vertex properties: |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 63 | DeltaArchiveManifest_InstallOperation op; |
| 64 | std::string file_name; |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 65 | off_t chunk_offset; |
| 66 | off_t chunk_size; |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 67 | |
| 68 | typedef std::vector<Vertex>::size_type Index; |
| 69 | static const Vertex::Index kInvalidIndex = -1; |
| 70 | }; |
| 71 | |
| 72 | typedef std::vector<Vertex> Graph; |
| 73 | |
| 74 | typedef std::pair<Vertex::Index, Vertex::Index> Edge; |
| 75 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 76 | const uint64_t kSparseHole = kuint64max; |
Andrew de los Reyes | 1bc16ab | 2010-10-06 15:07:21 -0700 | [diff] [blame] | 77 | const uint64_t kTempBlockStart = 1ULL << 60; |
| 78 | COMPILE_ASSERT(kTempBlockStart != 0, kTempBlockStart_invalid); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 79 | |
Andrew de los Reyes | 0ce161b | 2010-02-22 15:27:01 -0800 | [diff] [blame] | 80 | } // namespace chromeos_update_engine |
| 81 | |
| 82 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_GRAPH_TYPES_H__ |