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

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: More comments for MessageBuilder + a unittest. 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
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 {
15 class Message; 18 class Message;
16 19
17 namespace internal { 20 // MessageBuilder helps initialize and frame a |mojo::Message| which does not
viettrungluu 2015/11/18 23:55:59 nit: "which" -> "that"
18 21 // expect a response message, and therefore does not tag the message with a
22 // request id (which may save some bytes).
23 //
24 // The underlying |Message| is owned by MessageBuilder, but can be permanently
25 // moved by calling accessing |message()| and calling its |MoveTo()|.
19 class MessageBuilder { 26 class MessageBuilder {
20 public: 27 public:
28 // This frames and configures a |mojo::Message| with the given message name.
21 MessageBuilder(uint32_t name, size_t payload_size); 29 MessageBuilder(uint32_t name, size_t payload_size);
22 ~MessageBuilder(); 30 ~MessageBuilder();
23 31
24 Buffer* buffer() { return &buf_; }
25 Message* message() { return &message_; } 32 Message* message() { return &message_; }
26 33
34 // TODO(vardhan): |buffer()| is internal and only consumed by internal classes
35 // and unittests. Consider making it private + friend class its consumers?
36 internal::Buffer* buffer() { return &buf_; }
37
27 protected: 38 protected:
28 MessageBuilder(); 39 MessageBuilder();
29 void Initialize(size_t size); 40 void Initialize(size_t size);
30 41
31 Message message_; 42 Message message_;
32 FixedBuffer buf_; 43 internal::FixedBuffer buf_;
33 44
34 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder); 45 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
35 }; 46 };
36 47
48 namespace internal {
viettrungluu 2015/11/18 23:55:59 nit: Generally, there should be a blank line foll
37 class MessageWithRequestIDBuilder : public MessageBuilder { 49 class MessageWithRequestIDBuilder : public MessageBuilder {
38 public: 50 public:
39 MessageWithRequestIDBuilder(uint32_t name, 51 MessageWithRequestIDBuilder(uint32_t name,
40 size_t payload_size, 52 size_t payload_size,
41 uint32_t flags, 53 uint32_t flags,
42 uint64_t request_id); 54 uint64_t request_id);
43 }; 55 };
56 } // namespace internal
44 57
45 class RequestMessageBuilder : public MessageWithRequestIDBuilder { 58 // Builds a |mojo::Message| that is a "request" message, which expects a
viettrungluu 2015/11/18 23:55:59 nit: ", which" -> " that" (no comma)
59 // response message. You can give it a unique |request_id| (with which you can
60 // construct a response message) by calling |message()->set_request_id()|.
61 //
62 // Has the same interface as |mojo::MessageBuilder|.
63 class RequestMessageBuilder : public internal::MessageWithRequestIDBuilder {
46 public: 64 public:
47 RequestMessageBuilder(uint32_t name, size_t payload_size) 65 RequestMessageBuilder(uint32_t name, size_t payload_size)
48 : MessageWithRequestIDBuilder(name, 66 : MessageWithRequestIDBuilder(name,
49 payload_size, 67 payload_size,
50 kMessageExpectsResponse, 68 internal::kMessageExpectsResponse,
51 0) {} 69 0) {}
52 }; 70 };
53 71
54 class ResponseMessageBuilder : public MessageWithRequestIDBuilder { 72 // Builds a |mojo::Message| that is a "response" message which pertains to a
73 // |request_id|.
74 //
75 // Has the same interface as |mojo::MessageBuilder|.
76 class ResponseMessageBuilder : public internal::MessageWithRequestIDBuilder {
55 public: 77 public:
56 ResponseMessageBuilder(uint32_t name, 78 ResponseMessageBuilder(uint32_t name,
57 size_t payload_size, 79 size_t payload_size,
58 uint64_t request_id) 80 uint64_t request_id)
59 : MessageWithRequestIDBuilder(name, 81 : MessageWithRequestIDBuilder(name,
60 payload_size, 82 payload_size,
61 kMessageIsResponse, 83 internal::kMessageIsResponse,
62 request_id) {} 84 request_id) {}
63 }; 85 };
64 86
65 } // namespace internal
66 } // namespace mojo 87 } // namespace mojo
67 88
68 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_ 89 #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') | mojo/public/cpp/bindings/lib/message_builder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698