OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_VIEW_MANAGER_IDS_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_IDS_H_ |
6 #define MOJO_SERVICES_VIEW_MANAGER_IDS_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_IDS_H_ |
7 | 7 |
8 #include "mojo/services/view_manager/view_manager_export.h" | 8 #include "mojo/services/view_manager/view_manager_export.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 namespace services { | 11 namespace services { |
12 namespace view_manager { | 12 namespace view_manager { |
13 | 13 |
14 // Adds a bit of type safety to node ids. | 14 // Adds a bit of type safety to node ids. |
15 struct MOJO_VIEW_MANAGER_EXPORT NodeId { | 15 struct MOJO_VIEW_MANAGER_EXPORT NodeId { |
16 NodeId(uint16_t connection_id, uint16_t node_id) | 16 NodeId(uint16_t connection_id, uint16_t node_id) |
17 : connection_id(connection_id), | 17 : connection_id(connection_id), |
18 node_id(node_id) {} | 18 node_id(node_id) {} |
19 NodeId() : connection_id(0), node_id(0) {} | 19 NodeId() : connection_id(0), node_id(0) {} |
20 | 20 |
21 bool operator==(const NodeId& other) const { | 21 bool operator==(const NodeId& other) const { |
22 return other.connection_id == connection_id && | 22 return other.connection_id == connection_id && |
23 other.node_id == node_id; | 23 other.node_id == node_id; |
24 } | 24 } |
25 | 25 |
26 bool operator!=(const NodeId& other) const { | |
27 return !(*this == other); | |
28 } | |
29 | |
30 uint16_t connection_id; | 26 uint16_t connection_id; |
31 uint16_t node_id; | 27 uint16_t node_id; |
32 }; | 28 }; |
33 | 29 |
34 // Adds a bit of type safety to view ids. | 30 // Adds a bit of type safety to view ids. |
35 struct MOJO_VIEW_MANAGER_EXPORT ViewId { | 31 struct MOJO_VIEW_MANAGER_EXPORT ViewId { |
36 ViewId(uint16_t connection_id, uint16_t view_id) | 32 ViewId(uint16_t connection_id, uint16_t view_id) |
37 : connection_id(connection_id), | 33 : connection_id(connection_id), |
38 view_id(view_id) {} | 34 view_id(view_id) {} |
39 ViewId() : connection_id(0), view_id(0) {} | 35 ViewId() : connection_id(0), view_id(0) {} |
40 | 36 |
41 bool operator==(const ViewId& other) const { | 37 bool operator==(const ViewId& other) const { |
42 return other.connection_id == connection_id && | 38 return other.connection_id == connection_id && |
43 other.view_id == view_id; | 39 other.view_id == view_id; |
44 } | 40 } |
45 | 41 |
46 bool operator!=(const ViewId& other) const { | |
47 return !(*this == other); | |
48 } | |
49 | |
50 uint16_t connection_id; | 42 uint16_t connection_id; |
51 uint16_t view_id; | 43 uint16_t view_id; |
52 }; | 44 }; |
53 | 45 |
54 // Functions for converting to/from structs and transport values. | 46 // Functions for converting to/from structs and transport values. |
55 inline uint16_t FirstIdFromTransportId(uint32_t id) { | 47 inline uint16_t FirstIdFromTransportId(uint32_t id) { |
56 return static_cast<uint16_t>((id >> 16) & 0xFFFF); | 48 return static_cast<uint16_t>((id >> 16) & 0xFFFF); |
57 } | 49 } |
58 | 50 |
59 inline uint16_t SecondIdFromTransportId(uint32_t id) { | 51 inline uint16_t SecondIdFromTransportId(uint32_t id) { |
60 return static_cast<uint16_t>(id & 0xFFFF); | 52 return static_cast<uint16_t>(id & 0xFFFF); |
61 } | 53 } |
62 | 54 |
63 inline NodeId NodeIdFromTransportId(uint32_t id) { | 55 inline NodeId NodeIdFromTransportId(uint32_t id) { |
64 return NodeId(FirstIdFromTransportId(id), SecondIdFromTransportId(id)); | 56 return NodeId(FirstIdFromTransportId(id), SecondIdFromTransportId(id)); |
65 } | 57 } |
66 | 58 |
67 inline uint32_t NodeIdToTransportId(const NodeId& id) { | 59 inline uint32_t NodeIdToTransportId(const NodeId& id) { |
68 return (id.connection_id << 16) | id.node_id; | 60 return (id.connection_id << 16) | id.node_id; |
69 } | 61 } |
70 | 62 |
71 inline ViewId ViewIdFromTransportId(uint32_t id) { | 63 inline ViewId ViewIdFromTransportId(uint32_t id) { |
72 return ViewId(FirstIdFromTransportId(id), SecondIdFromTransportId(id)); | 64 return ViewId(FirstIdFromTransportId(id), SecondIdFromTransportId(id)); |
73 } | 65 } |
74 | 66 |
75 inline uint32_t ViewIdToTransportId(const ViewId& id) { | |
76 return (id.connection_id << 16) | id.view_id; | |
77 } | |
78 | |
79 } // namespace view_manager | 67 } // namespace view_manager |
80 } // namespace services | 68 } // namespace services |
81 } // namespace mojo | 69 } // namespace mojo |
82 | 70 |
83 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_ | 71 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_ |
OLD | NEW |