Chromium Code Reviews

Side by Side Diff: mojo/edk/system/transport_data.cc

Issue 1957553003: EDK: Plumb Handle/HandleVector yet one more layer down: MessageInTransit. (Closed) Base URL: https://github.com/domokit/mojo.git@work787_edk_handle_13.6
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « mojo/edk/system/transport_data.h ('k') | no next file » | 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 #include "mojo/edk/system/transport_data.h" 5 #include "mojo/edk/system/transport_data.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "mojo/edk/system/channel.h" 12 #include "mojo/edk/system/channel.h"
13 #include "mojo/edk/system/configuration.h" 13 #include "mojo/edk/system/configuration.h"
14 #include "mojo/edk/system/message_in_transit.h" 14 #include "mojo/edk/system/message_in_transit.h"
15 15
16 using mojo::platform::AlignedAlloc; 16 using mojo::platform::AlignedAlloc;
17 using mojo::platform::ScopedPlatformHandle; 17 using mojo::platform::ScopedPlatformHandle;
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace system { 20 namespace system {
21 21
22 namespace {
23
24 // TODO(vtl): Temporary, until |TransportData| really supports handles.
25 std::unique_ptr<DispatcherVector> DispatcherVectorFromHandleVector(
26 std::unique_ptr<HandleVector> handles) {
27 DCHECK(handles);
28
29 std::unique_ptr<DispatcherVector> dispatchers(new DispatcherVector());
30 dispatchers->reserve(handles->size());
31 for (size_t i = 0; i < handles->size(); i++)
32 dispatchers->push_back(std::move(handles->at(i).dispatcher));
33 return dispatchers;
34 }
35
36 } // namespace
37
22 // The maximum amount of space needed per platform handle. 38 // The maximum amount of space needed per platform handle.
23 // (|{Channel,RawChannel}::GetSerializedPlatformHandleSize()| should always 39 // (|{Channel,RawChannel}::GetSerializedPlatformHandleSize()| should always
24 // return a value which is at most this. This is only used to calculate 40 // return a value which is at most this. This is only used to calculate
25 // |TransportData::kMaxBufferSize|. This value should be a multiple of the 41 // |TransportData::kMaxBufferSize|. This value should be a multiple of the
26 // alignment in order to simplify calculations, even though the actual amount of 42 // alignment in order to simplify calculations, even though the actual amount of
27 // space needed need not be a multiple of the alignment. 43 // space needed need not be a multiple of the alignment.
28 const size_t kMaxSizePerPlatformHandle = 8; 44 const size_t kMaxSizePerPlatformHandle = 8;
29 static_assert(kMaxSizePerPlatformHandle % MessageInTransit::kMessageAlignment == 45 static_assert(kMaxSizePerPlatformHandle % MessageInTransit::kMessageAlignment ==
30 0, 46 0,
31 "kMaxSizePerPlatformHandle not a multiple of alignment"); 47 "kMaxSizePerPlatformHandle not a multiple of alignment");
(...skipping 24 matching lines...)
56 MessageInTransit::kMessageAlignment == 72 MessageInTransit::kMessageAlignment ==
57 0, 73 0,
58 "kMaxSerializedDispatcherSize not a multiple of alignment"); 74 "kMaxSerializedDispatcherSize not a multiple of alignment");
59 static_assert(sizeof(HandleTableEntry) % 75 static_assert(sizeof(HandleTableEntry) %
60 MessageInTransit::kMessageAlignment == 76 MessageInTransit::kMessageAlignment ==
61 0, 77 0,
62 "sizeof(MessageInTransit::HandleTableEntry) not a multiple of " 78 "sizeof(MessageInTransit::HandleTableEntry) not a multiple of "
63 "alignment"); 79 "alignment");
64 }; 80 };
65 81
82 // TODO(vtl): Make this the real one.
83 TransportData::TransportData(std::unique_ptr<HandleVector> handles,
84 Channel* channel)
85 : TransportData(DispatcherVectorFromHandleVector(std::move(handles)),
86 channel) {}
87
66 TransportData::TransportData(std::unique_ptr<DispatcherVector> dispatchers, 88 TransportData::TransportData(std::unique_ptr<DispatcherVector> dispatchers,
67 Channel* channel) 89 Channel* channel)
68 : buffer_size_() { 90 : buffer_size_() {
69 DCHECK(dispatchers); 91 DCHECK(dispatchers);
70 DCHECK(channel); 92 DCHECK(channel);
71 93
72 const size_t num_handles = dispatchers->size(); 94 const size_t num_handles = dispatchers->size();
73 DCHECK_GT(num_handles, 0u); 95 DCHECK_GT(num_handles, 0u);
74 96
75 // The offset to the start of the (Mojo) handle table. 97 // The offset to the start of the (Mojo) handle table.
(...skipping 261 matching lines...)
337 const void* source = static_cast<const char*>(buffer) + offset; 359 const void* source = static_cast<const char*>(buffer) + offset;
338 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( 360 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize(
339 channel, handle_table[i].type, source, size, platform_handles.get()); 361 channel, handle_table[i].type, source, size, platform_handles.get());
340 } 362 }
341 363
342 return dispatchers; 364 return dispatchers;
343 } 365 }
344 366
345 } // namespace system 367 } // namespace system
346 } // namespace mojo 368 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/transport_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine