• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include "mojo/public/cpp/bindings/lib/message_internal.h"
12 #include "mojo/public/cpp/bindings/message.h"
13 
14 namespace mojo {
15 class Message;
16 
17 namespace internal {
18 
19 class MessageBuilder {
20  public:
21   MessageBuilder(uint32_t name, size_t payload_size);
22   ~MessageBuilder();
23 
buffer()24   Buffer* buffer() { return message_.buffer(); }
message()25   Message* message() { return &message_; }
26 
27  protected:
28   MessageBuilder();
29   void InitializeMessage(size_t size);
30 
31   Message message_;
32 
33   DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
34 };
35 
36 class MessageWithRequestIDBuilder : public MessageBuilder {
37  public:
38   MessageWithRequestIDBuilder(uint32_t name,
39                               size_t payload_size,
40                               uint32_t flags,
41                               uint64_t request_id);
42 };
43 
44 class RequestMessageBuilder : public MessageWithRequestIDBuilder {
45  public:
RequestMessageBuilder(uint32_t name,size_t payload_size)46   RequestMessageBuilder(uint32_t name, size_t payload_size)
47       : MessageWithRequestIDBuilder(name,
48                                     payload_size,
49                                     Message::kFlagExpectsResponse,
50                                     0) {}
51 
RequestMessageBuilder(uint32_t name,size_t payload_size,uint32_t extra_flags)52   RequestMessageBuilder(uint32_t name,
53                         size_t payload_size,
54                         uint32_t extra_flags)
55       : MessageWithRequestIDBuilder(name,
56                                     payload_size,
57                                     Message::kFlagExpectsResponse | extra_flags,
58                                     0) {}
59 };
60 
61 class ResponseMessageBuilder : public MessageWithRequestIDBuilder {
62  public:
ResponseMessageBuilder(uint32_t name,size_t payload_size,uint64_t request_id)63   ResponseMessageBuilder(uint32_t name,
64                          size_t payload_size,
65                          uint64_t request_id)
66       : MessageWithRequestIDBuilder(name,
67                                     payload_size,
68                                     Message::kFlagIsResponse,
69                                     request_id) {}
70 
ResponseMessageBuilder(uint32_t name,size_t payload_size,uint64_t request_id,uint32_t extra_flags)71   ResponseMessageBuilder(uint32_t name,
72                          size_t payload_size,
73                          uint64_t request_id,
74                          uint32_t extra_flags)
75       : MessageWithRequestIDBuilder(name,
76                                     payload_size,
77                                     Message::kFlagIsResponse | extra_flags,
78                                     request_id) {}
79 };
80 
81 }  // namespace internal
82 }  // namespace mojo
83 
84 #endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_BUILDER_H_
85