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

Side by Side Diff: mojo/public/cpp/bindings/lib/message_builder.h

Issue 1460463003: Move mojo::internal::MessageBuilder out of the |internal| namespace. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: formatting + style changes (from trung comments) Created 5 years, 1 month 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 | « no previous file | mojo/public/cpp/bindings/lib/message_builder.cc » ('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 2013 The Chromium Authors. All rights reserved. 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 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 // These are helper classes for allocating, aligning, and framing a
6 // |mojo::Message|. They are mainly used from within the generated C++ bindings.
7
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_ 8 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_ 9 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
7 10
8 #include <stdint.h> 11 #include <stdint.h>
9 12
10 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 13 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
11 #include "mojo/public/cpp/bindings/lib/message_internal.h" 14 #include "mojo/public/cpp/bindings/lib/message_internal.h"
12 #include "mojo/public/cpp/bindings/message.h" 15 #include "mojo/public/cpp/bindings/message.h"
13 16
14 namespace mojo { 17 namespace mojo {
18
15 class Message; 19 class Message;
16 20
17 namespace internal { 21 // MessageBuilder helps initialize and frame a |mojo::Message| that does not
18 22 // expect a response message, and therefore does not tag the message with a
23 // request id (which may save some bytes).
24 //
25 // The underlying |Message| is owned by MessageBuilder, but can be permanently
26 // moved by accessing |message()| and calling its |MoveTo()|.
19 class MessageBuilder { 27 class MessageBuilder {
20 public: 28 public:
29 // This frames and configures a |mojo::Message| with the given message name.
21 MessageBuilder(uint32_t name, size_t payload_size); 30 MessageBuilder(uint32_t name, size_t payload_size);
22 ~MessageBuilder(); 31 ~MessageBuilder();
23 32
24 Buffer* buffer() { return &buf_; }
25 Message* message() { return &message_; } 33 Message* message() { return &message_; }
26 34
35 // TODO(vardhan): |buffer()| is internal and only consumed by internal classes
36 // and unittests. Consider making it private + friend class its consumers?
37 internal::Buffer* buffer() { return &buf_; }
38
27 protected: 39 protected:
28 MessageBuilder(); 40 MessageBuilder();
29 void Initialize(size_t size); 41 void Initialize(size_t size);
30 42
31 Message message_; 43 Message message_;
32 FixedBuffer buf_; 44 internal::FixedBuffer buf_;
33 45
34 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder); 46 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
35 }; 47 };
36 48
49 namespace internal {
50
37 class MessageWithRequestIDBuilder : public MessageBuilder { 51 class MessageWithRequestIDBuilder : public MessageBuilder {
38 public: 52 public:
39 MessageWithRequestIDBuilder(uint32_t name, 53 MessageWithRequestIDBuilder(uint32_t name,
40 size_t payload_size, 54 size_t payload_size,
41 uint32_t flags, 55 uint32_t flags,
42 uint64_t request_id); 56 uint64_t request_id);
43 }; 57 };
44 58
45 class RequestMessageBuilder : public MessageWithRequestIDBuilder { 59 } // namespace internal
60
61 // Builds a |mojo::Message| that is a "request" message that expects a response
62 // message. You can give it a unique |request_id| (with which you can construct
63 // a response message) by calling |message()->set_request_id()|.
64 //
65 // Has the same interface as |mojo::MessageBuilder|.
66 class RequestMessageBuilder : public internal::MessageWithRequestIDBuilder {
46 public: 67 public:
47 RequestMessageBuilder(uint32_t name, size_t payload_size) 68 RequestMessageBuilder(uint32_t name, size_t payload_size)
48 : MessageWithRequestIDBuilder(name, 69 : MessageWithRequestIDBuilder(name,
49 payload_size, 70 payload_size,
50 kMessageExpectsResponse, 71 internal::kMessageExpectsResponse,
51 0) {} 72 0) {}
52 }; 73 };
53 74
54 class ResponseMessageBuilder : public MessageWithRequestIDBuilder { 75 // Builds a |mojo::Message| that is a "response" message which pertains to a
76 // |request_id|.
77 //
78 // Has the same interface as |mojo::MessageBuilder|.
79 class ResponseMessageBuilder : public internal::MessageWithRequestIDBuilder {
55 public: 80 public:
56 ResponseMessageBuilder(uint32_t name, 81 ResponseMessageBuilder(uint32_t name,
57 size_t payload_size, 82 size_t payload_size,
58 uint64_t request_id) 83 uint64_t request_id)
59 : MessageWithRequestIDBuilder(name, 84 : MessageWithRequestIDBuilder(name,
60 payload_size, 85 payload_size,
61 kMessageIsResponse, 86 internal::kMessageIsResponse,
62 request_id) {} 87 request_id) {}
63 }; 88 };
64 89
65 } // namespace internal
66 } // namespace mojo 90 } // namespace mojo
67 91
68 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_ 92 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/message_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698