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

Side by Side Diff: mojo/edk/system/ports/event.h

Issue 1585493002: [mojo] Ports EDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2016 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_EDK_SYSTEM_PORTS_EVENT_H_
6 #define MOJO_EDK_SYSTEM_PORTS_EVENT_H_
7
8 #include <stdint.h>
9
10 #include "mojo/edk/system/ports/message.h"
11 #include "mojo/edk/system/ports/name.h"
12 #include "mojo/public/c/system/macros.h"
13
14 namespace mojo {
15 namespace edk {
16 namespace ports {
17
18 // TODO: Add static assertions of alignment.
19
20 struct MOJO_ALIGNAS(8) PortDescriptor {
21 NodeName peer_node_name;
22 PortName peer_port_name;
23 NodeName referring_node_name;
24 PortName referring_port_name;
25 uint64_t next_sequence_num_to_send;
26 uint64_t next_sequence_num_to_receive;
27 uint64_t last_sequence_num_to_receive;
28 bool peer_closed;
29 };
30
31 enum struct EventType : uint32_t {
32 kUser,
33 kPortAccepted,
34 kObserveProxy,
35 kObserveProxyAck,
36 kObserveClosure,
37 };
38
39 struct EventHeader {
40 EventType type;
41 uint32_t padding;
42 PortName port_name;
43 };
44
45 struct UserEventData {
46 uint64_t sequence_num;
47 uint32_t num_ports;
48 uint32_t padding;
49 };
50
51 struct ObserveProxyEventData {
52 NodeName proxy_node_name;
53 PortName proxy_port_name;
54 NodeName proxy_to_node_name;
55 PortName proxy_to_port_name;
56 };
57
58 struct ObserveProxyAckEventData {
59 uint64_t last_sequence_num;
60 };
61
62 struct ObserveClosureEventData {
63 uint64_t last_sequence_num;
64 };
65
66 inline const EventHeader* GetEventHeader(const Message& message) {
67 return static_cast<const EventHeader*>(message.header_bytes());
68 }
69
70 inline EventHeader* GetMutableEventHeader(Message* message) {
71 return static_cast<EventHeader*>(message->mutable_header_bytes());
72 }
73
74 template <typename EventData>
75 inline const EventData* GetEventData(const Message& message) {
76 return reinterpret_cast<const EventData*>(
77 reinterpret_cast<const char*>(GetEventHeader(message) + 1));
78 }
79
80 template <typename EventData>
81 inline EventData* GetMutableEventData(Message* message) {
82 return reinterpret_cast<EventData*>(
83 reinterpret_cast<char*>(GetMutableEventHeader(message) + 1));
84 }
85
86 inline const PortDescriptor* GetPortDescriptors(const UserEventData* event) {
87 return reinterpret_cast<const PortDescriptor*>(
88 reinterpret_cast<const char*>(event + 1));
89 }
90
91 inline PortDescriptor* GetMutablePortDescriptors(UserEventData* event) {
92 return reinterpret_cast<PortDescriptor*>(reinterpret_cast<char*>(event + 1));
93 }
94
95 } // namespace ports
96 } // namespace edk
97 } // namespace mojo
98
99 #endif // MOJO_EDK_SYSTEM_PORTS_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698