Home | History | Annotate | Download | only in view_manager
      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 
     12 namespace mojo {
     13 namespace view_manager {
     14 namespace service {
     15 
     16 // Connection id reserved for the root.
     17 const ConnectionSpecificId kRootConnection = 0;
     18 
     19 // TODO(sky): remove this, temporary while window manager API is in existing
     20 // api.
     21 const ConnectionSpecificId kWindowManagerConnection = 1;
     22 
     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),
     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.
     44 struct 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.
     64 inline NodeId NodeIdFromTransportId(Id id) {
     65   return NodeId(HiWord(id), LoWord(id));
     66 }
     67 
     68 inline Id NodeIdToTransportId(const NodeId& id) {
     69   return (id.connection_id << 16) | id.node_id;
     70 }
     71 
     72 inline ViewId ViewIdFromTransportId(Id id) {
     73   return ViewId(HiWord(id), LoWord(id));
     74 }
     75 
     76 inline Id ViewIdToTransportId(const ViewId& id) {
     77   return (id.connection_id << 16) | id.view_id;
     78 }
     79 
     80 inline 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.
     86 inline 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