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
3 // found in the LICENSE file.
5 #ifndef MOJO_SERVICES_VIEW_MANAGER_IDS_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_IDS_H_
8 #include "mojo/services/public/cpp/view_manager/types.h"
9 #include "mojo/services/public/cpp/view_manager/util.h"
10 #include "mojo/services/view_manager/view_manager_export.h"
15 // Connection id is used to indicate no connection. That is, no
16 // ViewManagerServiceImpl ever gets this id.
17 const ConnectionSpecificId kInvalidConnectionId
= 0;
19 // TODO(sky): remove this, temporary while window manager API is in existing
21 const ConnectionSpecificId kWindowManagerConnection
= 1;
23 // Adds a bit of type safety to node ids.
24 struct MOJO_VIEW_MANAGER_EXPORT NodeId
{
25 NodeId(ConnectionSpecificId connection_id
, ConnectionSpecificId node_id
)
26 : connection_id(connection_id
),
28 NodeId() : connection_id(0), node_id(0) {}
30 bool operator==(const NodeId
& other
) const {
31 return other
.connection_id
== connection_id
&&
32 other
.node_id
== node_id
;
35 bool operator!=(const NodeId
& other
) const {
36 return !(*this == other
);
39 ConnectionSpecificId connection_id
;
40 ConnectionSpecificId node_id
;
43 // Adds a bit of type safety to view ids.
44 struct MOJO_VIEW_MANAGER_EXPORT ViewId
{
45 ViewId(ConnectionSpecificId connection_id
, ConnectionSpecificId view_id
)
46 : connection_id(connection_id
),
48 ViewId() : connection_id(0), view_id(0) {}
50 bool operator==(const ViewId
& other
) const {
51 return other
.connection_id
== connection_id
&&
52 other
.view_id
== view_id
;
55 bool operator!=(const ViewId
& other
) const {
56 return !(*this == other
);
59 ConnectionSpecificId connection_id
;
60 ConnectionSpecificId view_id
;
63 // Functions for converting to/from structs and transport values.
64 inline NodeId
NodeIdFromTransportId(Id id
) {
65 return NodeId(HiWord(id
), LoWord(id
));
68 inline Id
NodeIdToTransportId(const NodeId
& id
) {
69 return (id
.connection_id
<< 16) | id
.node_id
;
72 inline ViewId
ViewIdFromTransportId(Id id
) {
73 return ViewId(HiWord(id
), LoWord(id
));
76 inline Id
ViewIdToTransportId(const ViewId
& id
) {
77 return (id
.connection_id
<< 16) | id
.view_id
;
80 inline NodeId
RootNodeId() {
81 return NodeId(kInvalidConnectionId
, 1);
84 // Returns a NodeId that is reserved to indicate no node. That is, no node will
85 // ever be created with this id.
86 inline NodeId
InvalidNodeId() {
87 return NodeId(kInvalidConnectionId
, 0);
90 } // namespace service
93 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_