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

Side by Side Diff: mojo/public/bindings/lib/message.cc

Issue 220243007: Mojo: Move mojo/public/bindings/lib to mojo/public/cpp/bindings/lib. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/lib/interface.cc ('k') | mojo/public/bindings/lib/message_builder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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 #include "mojo/public/cpp/bindings/message.h"
6
7 #include <assert.h>
8 #include <stdlib.h>
9
10 #include <algorithm>
11
12 namespace mojo {
13
14 Message::Message()
15 : data_num_bytes_(0),
16 data_(NULL) {
17 }
18
19 Message::~Message() {
20 free(data_);
21
22 for (std::vector<Handle>::iterator it = handles_.begin();
23 it != handles_.end(); ++it) {
24 if (it->is_valid())
25 CloseRaw(*it);
26 }
27 }
28
29 void Message::AllocUninitializedData(uint32_t num_bytes) {
30 assert(!data_);
31 data_num_bytes_ = num_bytes;
32 data_ = static_cast<internal::MessageData*>(malloc(num_bytes));
33 }
34
35 void Message::AdoptData(uint32_t num_bytes, internal::MessageData* data) {
36 assert(!data_);
37 data_num_bytes_ = num_bytes;
38 data_ = data;
39 }
40
41 void Message::Swap(Message* other) {
42 std::swap(data_num_bytes_, other->data_num_bytes_);
43 std::swap(data_, other->data_);
44 std::swap(handles_, other->handles_);
45 }
46
47 MojoResult ReadAndDispatchMessage(MessagePipeHandle handle,
48 MessageReceiver* receiver,
49 bool* receiver_result) {
50 MojoResult rv;
51
52 uint32_t num_bytes = 0, num_handles = 0;
53 rv = ReadMessageRaw(handle,
54 NULL,
55 &num_bytes,
56 NULL,
57 &num_handles,
58 MOJO_READ_MESSAGE_FLAG_NONE);
59 if (rv != MOJO_RESULT_RESOURCE_EXHAUSTED)
60 return rv;
61
62 Message message;
63 message.AllocUninitializedData(num_bytes);
64 message.mutable_handles()->resize(num_handles);
65
66 rv = ReadMessageRaw(handle,
67 message.mutable_data(),
68 &num_bytes,
69 message.mutable_handles()->empty()
70 ? NULL
71 : reinterpret_cast<MojoHandle*>(
72 &message.mutable_handles()->front()),
73 &num_handles,
74 MOJO_READ_MESSAGE_FLAG_NONE);
75 if (receiver && rv == MOJO_RESULT_OK) {
76 bool result = receiver->Accept(&message);
77 if (receiver_result)
78 *receiver_result = result;
79 }
80
81 return rv;
82 }
83
84 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/bindings/lib/interface.cc ('k') | mojo/public/bindings/lib/message_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698