• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 namespace mojo {
12 namespace service {
13 
14 // Connection id is used to indicate no connection. That is, no
15 // ViewManagerServiceImpl ever gets this id.
16 const ConnectionSpecificId kInvalidConnectionId = 0;
17 
18 // TODO(sky): remove this, temporary while window manager API is in existing
19 // api.
20 const ConnectionSpecificId kWindowManagerConnection = 1;
21 
22 // Adds a bit of type safety to view ids.
23 struct ViewId {
ViewIdViewId24   ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id)
25       : connection_id(connection_id),
26         view_id(view_id) {}
ViewIdViewId27   ViewId() : connection_id(0), view_id(0) {}
28 
29   bool operator==(const ViewId& other) const {
30     return other.connection_id == connection_id &&
31         other.view_id == view_id;
32   }
33 
34   bool operator!=(const ViewId& other) const {
35     return !(*this == other);
36   }
37 
38   ConnectionSpecificId connection_id;
39   ConnectionSpecificId view_id;
40 };
41 
ViewIdFromTransportId(Id id)42 inline ViewId ViewIdFromTransportId(Id id) {
43   return ViewId(HiWord(id), LoWord(id));
44 }
45 
ViewIdToTransportId(const ViewId & id)46 inline Id ViewIdToTransportId(const ViewId& id) {
47   return (id.connection_id << 16) | id.view_id;
48 }
49 
RootViewId()50 inline ViewId RootViewId() {
51   return ViewId(kInvalidConnectionId, 1);
52 }
53 
54 // Returns a ViewId that is reserved to indicate no view. That is, no view will
55 // ever be created with this id.
InvalidViewId()56 inline ViewId InvalidViewId() {
57   return ViewId(kInvalidConnectionId, 0);
58 }
59 
60 }  // namespace service
61 }  // namespace mojo
62 
63 #endif  // MOJO_SERVICES_VIEW_MANAGER_IDS_H_
64