Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: mojo/services/view_manager/ids.h

Issue 250633003: Adds more to viewmanager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: override Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
26 uint16_t connection_id; 30 uint16_t connection_id;
27 uint16_t node_id; 31 uint16_t node_id;
28 }; 32 };
29 33
30 // Adds a bit of type safety to view ids. 34 // Adds a bit of type safety to view ids.
31 struct MOJO_VIEW_MANAGER_EXPORT ViewId { 35 struct MOJO_VIEW_MANAGER_EXPORT ViewId {
32 ViewId(uint16_t connection_id, uint16_t view_id) 36 ViewId(uint16_t connection_id, uint16_t view_id)
33 : connection_id(connection_id), 37 : connection_id(connection_id),
34 view_id(view_id) {} 38 view_id(view_id) {}
35 ViewId() : connection_id(0), view_id(0) {} 39 ViewId() : connection_id(0), view_id(0) {}
36 40
37 bool operator==(const ViewId& other) const { 41 bool operator==(const ViewId& other) const {
38 return other.connection_id == connection_id && 42 return other.connection_id == connection_id &&
39 other.view_id == view_id; 43 other.view_id == view_id;
40 } 44 }
41 45
46 bool operator!=(const ViewId& other) const {
47 return !(*this == other);
48 }
49
42 uint16_t connection_id; 50 uint16_t connection_id;
43 uint16_t view_id; 51 uint16_t view_id;
44 }; 52 };
45 53
46 // Functions for converting to/from structs and transport values. 54 // Functions for converting to/from structs and transport values.
47 inline uint16_t FirstIdFromTransportId(uint32_t id) { 55 inline uint16_t FirstIdFromTransportId(uint32_t id) {
48 return static_cast<uint16_t>((id >> 16) & 0xFFFF); 56 return static_cast<uint16_t>((id >> 16) & 0xFFFF);
49 } 57 }
50 58
51 inline uint16_t SecondIdFromTransportId(uint32_t id) { 59 inline uint16_t SecondIdFromTransportId(uint32_t id) {
52 return static_cast<uint16_t>(id & 0xFFFF); 60 return static_cast<uint16_t>(id & 0xFFFF);
53 } 61 }
54 62
55 inline NodeId NodeIdFromTransportId(uint32_t id) { 63 inline NodeId NodeIdFromTransportId(uint32_t id) {
56 return NodeId(FirstIdFromTransportId(id), SecondIdFromTransportId(id)); 64 return NodeId(FirstIdFromTransportId(id), SecondIdFromTransportId(id));
57 } 65 }
58 66
59 inline uint32_t NodeIdToTransportId(const NodeId& id) { 67 inline uint32_t NodeIdToTransportId(const NodeId& id) {
60 return (id.connection_id << 16) | id.node_id; 68 return (id.connection_id << 16) | id.node_id;
61 } 69 }
62 70
63 inline ViewId ViewIdFromTransportId(uint32_t id) { 71 inline ViewId ViewIdFromTransportId(uint32_t id) {
64 return ViewId(FirstIdFromTransportId(id), SecondIdFromTransportId(id)); 72 return ViewId(FirstIdFromTransportId(id), SecondIdFromTransportId(id));
65 } 73 }
66 74
75 inline uint32_t ViewIdToTransportId(const ViewId& id) {
76 return (id.connection_id << 16) | id.view_id;
77 }
78
67 } // namespace view_manager 79 } // namespace view_manager
68 } // namespace services 80 } // namespace services
69 } // namespace mojo 81 } // namespace mojo
70 82
71 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 83 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_
OLDNEW
« no previous file with comments | « mojo/services/public/interfaces/view_manager/view_manager.mojom ('k') | mojo/services/view_manager/node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698