Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: mojo/edk/system/channel_endpoint_id.h

Issue 1346383004: EDK: Remove MOJO_SYSTEM_IMPL_EXPORT, system_impl_export.h, etc. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/channel_endpoint_client.h ('k') | mojo/edk/system/channel_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_ 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_
6 #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_ 6 #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <functional> 11 #include <functional>
12 #include <ostream> 12 #include <ostream>
13 13
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "mojo/edk/system/system_impl_export.h"
16 #include "mojo/public/cpp/system/macros.h" 15 #include "mojo/public/cpp/system/macros.h"
17 16
18 namespace mojo { 17 namespace mojo {
19 namespace system { 18 namespace system {
20 19
21 // ChannelEndpointId ----------------------------------------------------------- 20 // ChannelEndpointId -----------------------------------------------------------
22 21
23 class LocalChannelEndpointIdGenerator; 22 class LocalChannelEndpointIdGenerator;
24 FORWARD_DECLARE_TEST(LocalChannelEndpointIdGeneratorTest, WrapAround); 23 FORWARD_DECLARE_TEST(LocalChannelEndpointIdGeneratorTest, WrapAround);
25 FORWARD_DECLARE_TEST(RemoteChannelEndpointIdGeneratorTest, WrapAround); 24 FORWARD_DECLARE_TEST(RemoteChannelEndpointIdGeneratorTest, WrapAround);
26 25
27 // Represents an ID for an endpoint (i.e., one side of a message pipe) on a 26 // Represents an ID for an endpoint (i.e., one side of a message pipe) on a
28 // |Channel|. This class must be POD. 27 // |Channel|. This class must be POD.
29 // 28 //
30 // Note: The terminology "remote" for a |ChannelEndpointId| means a destination 29 // Note: The terminology "remote" for a |ChannelEndpointId| means a destination
31 // ID that was actually allocated by the sender, or similarly a source ID that 30 // ID that was actually allocated by the sender, or similarly a source ID that
32 // was allocated by the receiver. 31 // was allocated by the receiver.
33 // 32 //
34 // From the standpoint of the |Channel| with such a remote ID in its endpoint 33 // From the standpoint of the |Channel| with such a remote ID in its endpoint
35 // table, such an ID is a "remotely-allocated local ID". From the standpoint of 34 // table, such an ID is a "remotely-allocated local ID". From the standpoint of
36 // the |Channel| allocating such a remote ID (for its peer |Channel|), it's a 35 // the |Channel| allocating such a remote ID (for its peer |Channel|), it's a
37 // "locally-allocated remote ID". 36 // "locally-allocated remote ID".
38 class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointId { 37 class ChannelEndpointId {
39 public: 38 public:
40 ChannelEndpointId() : value_(0) {} 39 ChannelEndpointId() : value_(0) {}
41 ChannelEndpointId(const ChannelEndpointId& other) : value_(other.value_) {} 40 ChannelEndpointId(const ChannelEndpointId& other) : value_(other.value_) {}
42 41
43 // Returns the local ID to use for the first message pipe endpoint on a 42 // Returns the local ID to use for the first message pipe endpoint on a
44 // channel. 43 // channel.
45 static ChannelEndpointId GetBootstrap() { return ChannelEndpointId(1); } 44 static ChannelEndpointId GetBootstrap() { return ChannelEndpointId(1); }
46 45
47 bool operator==(const ChannelEndpointId& other) const { 46 bool operator==(const ChannelEndpointId& other) const {
48 return value_ == other.value_; 47 return value_ == other.value_;
(...skipping 25 matching lines...) Expand all
74 73
75 // Copying and assignment allowed. 74 // Copying and assignment allowed.
76 }; 75 };
77 // This wrapper should add no overhead. 76 // This wrapper should add no overhead.
78 // TODO(vtl): Rewrite |sizeof(uint32_t)| as |sizeof(ChannelEndpointId::value)| 77 // TODO(vtl): Rewrite |sizeof(uint32_t)| as |sizeof(ChannelEndpointId::value)|
79 // once we have sufficient C++11 support. 78 // once we have sufficient C++11 support.
80 static_assert(sizeof(ChannelEndpointId) == sizeof(uint32_t), 79 static_assert(sizeof(ChannelEndpointId) == sizeof(uint32_t),
81 "ChannelEndpointId has incorrect size"); 80 "ChannelEndpointId has incorrect size");
82 81
83 // So logging macros and |DCHECK_EQ()|, etc. work. 82 // So logging macros and |DCHECK_EQ()|, etc. work.
84 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<( 83 inline std::ostream& operator<<(std::ostream& out,
85 std::ostream& out, 84 const ChannelEndpointId& channel_endpoint_id) {
86 const ChannelEndpointId& channel_endpoint_id) {
87 return out << channel_endpoint_id.value(); 85 return out << channel_endpoint_id.value();
88 } 86 }
89 87
90 // LocalChannelEndpointIdGenerator --------------------------------------------- 88 // LocalChannelEndpointIdGenerator ---------------------------------------------
91 89
92 // A generator for "new" local |ChannelEndpointId|s. It does not track 90 // A generator for "new" local |ChannelEndpointId|s. It does not track
93 // used/existing IDs; that must be done separately. (This class is not 91 // used/existing IDs; that must be done separately. (This class is not
94 // thread-safe.) 92 // thread-safe.)
95 class MOJO_SYSTEM_IMPL_EXPORT LocalChannelEndpointIdGenerator { 93 class LocalChannelEndpointIdGenerator {
96 public: 94 public:
97 LocalChannelEndpointIdGenerator() 95 LocalChannelEndpointIdGenerator()
98 : next_(ChannelEndpointId::GetBootstrap()) {} 96 : next_(ChannelEndpointId::GetBootstrap()) {}
99 97
100 ChannelEndpointId GetNext(); 98 ChannelEndpointId GetNext();
101 99
102 private: 100 private:
103 FRIEND_TEST_ALL_PREFIXES(LocalChannelEndpointIdGeneratorTest, WrapAround); 101 FRIEND_TEST_ALL_PREFIXES(LocalChannelEndpointIdGeneratorTest, WrapAround);
104 102
105 ChannelEndpointId next_; 103 ChannelEndpointId next_;
106 104
107 MOJO_DISALLOW_COPY_AND_ASSIGN(LocalChannelEndpointIdGenerator); 105 MOJO_DISALLOW_COPY_AND_ASSIGN(LocalChannelEndpointIdGenerator);
108 }; 106 };
109 107
110 // RemoteChannelEndpointIdGenerator -------------------------------------------- 108 // RemoteChannelEndpointIdGenerator --------------------------------------------
111 109
112 // A generator for "new" remote |ChannelEndpointId|s, for |Channel|s to 110 // A generator for "new" remote |ChannelEndpointId|s, for |Channel|s to
113 // locally allocate remote IDs. (See the comment above |ChannelEndpointId| for 111 // locally allocate remote IDs. (See the comment above |ChannelEndpointId| for
114 // an explanatory note.) It does not track used/existing IDs; that must be done 112 // an explanatory note.) It does not track used/existing IDs; that must be done
115 // separately. (This class is not thread-safe.) 113 // separately. (This class is not thread-safe.)
116 class MOJO_SYSTEM_IMPL_EXPORT RemoteChannelEndpointIdGenerator { 114 class RemoteChannelEndpointIdGenerator {
117 public: 115 public:
118 RemoteChannelEndpointIdGenerator() : next_(ChannelEndpointId::kRemoteFlag) {} 116 RemoteChannelEndpointIdGenerator() : next_(ChannelEndpointId::kRemoteFlag) {}
119 117
120 ChannelEndpointId GetNext(); 118 ChannelEndpointId GetNext();
121 119
122 private: 120 private:
123 FRIEND_TEST_ALL_PREFIXES(RemoteChannelEndpointIdGeneratorTest, WrapAround); 121 FRIEND_TEST_ALL_PREFIXES(RemoteChannelEndpointIdGeneratorTest, WrapAround);
124 122
125 ChannelEndpointId next_; 123 ChannelEndpointId next_;
126 124
(...skipping 10 matching lines...) Expand all
137 template <> 135 template <>
138 struct hash<mojo::system::ChannelEndpointId> { 136 struct hash<mojo::system::ChannelEndpointId> {
139 size_t operator()(mojo::system::ChannelEndpointId channel_endpoint_id) const { 137 size_t operator()(mojo::system::ChannelEndpointId channel_endpoint_id) const {
140 return static_cast<size_t>(channel_endpoint_id.value()); 138 return static_cast<size_t>(channel_endpoint_id.value());
141 } 139 }
142 }; 140 };
143 141
144 } // namespace std 142 } // namespace std
145 143
146 #endif // MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_ 144 #endif // MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_ID_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/channel_endpoint_client.h ('k') | mojo/edk/system/channel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698