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 view ids.
24 struct MOJO_VIEW_MANAGER_EXPORT ViewId
{
25 ViewId(ConnectionSpecificId connection_id
, ConnectionSpecificId view_id
)
26 : connection_id(connection_id
),
28 ViewId() : connection_id(0), view_id(0) {}
30 bool operator==(const ViewId
& other
) const {
31 return other
.connection_id
== connection_id
&&
32 other
.view_id
== view_id
;
35 bool operator!=(const ViewId
& other
) const {
36 return !(*this == other
);
39 ConnectionSpecificId connection_id
;
40 ConnectionSpecificId view_id
;
43 inline ViewId
ViewIdFromTransportId(Id id
) {
44 return ViewId(HiWord(id
), LoWord(id
));
47 inline Id
ViewIdToTransportId(const ViewId
& id
) {
48 return (id
.connection_id
<< 16) | id
.view_id
;
51 inline ViewId
RootViewId() {
52 return ViewId(kInvalidConnectionId
, 1);
55 // Returns a ViewId that is reserved to indicate no view. That is, no view will
56 // ever be created with this id.
57 inline ViewId
InvalidViewId() {
58 return ViewId(kInvalidConnectionId
, 0);
61 } // namespace service
64 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_