ids.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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. 4 5#ifndef MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 6#define MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 7 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" 11 12namespace mojo { 13namespace view_manager { 14namespace service { 15 16// Connection id reserved for the root. 17const ConnectionSpecificId kRootConnection = 0; 18 19// TODO(sky): remove this, temporary while window manager API is in existing 20// api. 21const ConnectionSpecificId kWindowManagerConnection = 1; 22 23// Adds a bit of type safety to node ids. 24struct MOJO_VIEW_MANAGER_EXPORT NodeId { 25 NodeId(ConnectionSpecificId connection_id, ConnectionSpecificId node_id) 26 : connection_id(connection_id), 27 node_id(node_id) {} 28 NodeId() : connection_id(0), node_id(0) {} 29 30 bool operator==(const NodeId& other) const { 31 return other.connection_id == connection_id && 32 other.node_id == node_id; 33 } 34 35 bool operator!=(const NodeId& other) const { 36 return !(*this == other); 37 } 38 39 ConnectionSpecificId connection_id; 40 ConnectionSpecificId node_id; 41}; 42 43// Adds a bit of type safety to view ids. 44struct MOJO_VIEW_MANAGER_EXPORT ViewId { 45 ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id) 46 : connection_id(connection_id), 47 view_id(view_id) {} 48 ViewId() : connection_id(0), view_id(0) {} 49 50 bool operator==(const ViewId& other) const { 51 return other.connection_id == connection_id && 52 other.view_id == view_id; 53 } 54 55 bool operator!=(const ViewId& other) const { 56 return !(*this == other); 57 } 58 59 ConnectionSpecificId connection_id; 60 ConnectionSpecificId view_id; 61}; 62 63// Functions for converting to/from structs and transport values. 64inline NodeId NodeIdFromTransportId(Id id) { 65 return NodeId(HiWord(id), LoWord(id)); 66} 67 68inline Id NodeIdToTransportId(const NodeId& id) { 69 return (id.connection_id << 16) | id.node_id; 70} 71 72inline ViewId ViewIdFromTransportId(Id id) { 73 return ViewId(HiWord(id), LoWord(id)); 74} 75 76inline Id ViewIdToTransportId(const ViewId& id) { 77 return (id.connection_id << 16) | id.view_id; 78} 79 80inline NodeId RootNodeId() { 81 return NodeId(kRootConnection, 1); 82} 83 84// Returns a NodeId that is reserved to indicate no node. That is, no node will 85// ever be created with this id. 86inline NodeId InvalidNodeId() { 87 return NodeId(kRootConnection, 0); 88} 89 90} // namespace service 91} // namespace view_manager 92} // namespace mojo 93 94#endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 95