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"
14 // Connection id is used to indicate no connection. That is, no
15 // ViewManagerServiceImpl ever gets this id.
16 const ConnectionSpecificId kInvalidConnectionId = 0;
18 // TODO(sky): remove this, temporary while window manager API is in existing
20 const ConnectionSpecificId kWindowManagerConnection = 1;
22 // Adds a bit of type safety to view ids.
24 ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id)
25 : connection_id(connection_id),
27 ViewId() : connection_id(0), view_id(0) {}
29 bool operator==(const ViewId& other) const {
30 return other.connection_id == connection_id &&
31 other.view_id == view_id;
34 bool operator!=(const ViewId& other) const {
35 return !(*this == other);
38 ConnectionSpecificId connection_id;
39 ConnectionSpecificId view_id;
42 inline ViewId ViewIdFromTransportId(Id id) {
43 return ViewId(HiWord(id), LoWord(id));
46 inline Id ViewIdToTransportId(const ViewId& id) {
47 return (id.connection_id << 16) | id.view_id;
50 inline ViewId RootViewId() {
51 return ViewId(kInvalidConnectionId, 1);
54 // Returns a ViewId that is reserved to indicate no view. That is, no view will
55 // ever be created with this id.
56 inline ViewId InvalidViewId() {
57 return ViewId(kInvalidConnectionId, 0);
60 } // namespace service
63 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_