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/core/dispatcher.h"
6
7 #include "base/logging.h"
8 #include "mojo/core/configuration.h"
9 #include "mojo/core/data_pipe_consumer_dispatcher.h"
10 #include "mojo/core/data_pipe_producer_dispatcher.h"
11 #include "mojo/core/message_pipe_dispatcher.h"
12 #include "mojo/core/platform_handle_dispatcher.h"
13 #include "mojo/core/ports/event.h"
14 #include "mojo/core/shared_buffer_dispatcher.h"
15
16 namespace mojo {
17 namespace core {
18
DispatcherInTransit()19 Dispatcher::DispatcherInTransit::DispatcherInTransit() {}
20
21 Dispatcher::DispatcherInTransit::DispatcherInTransit(
22 const DispatcherInTransit& other) = default;
23
~DispatcherInTransit()24 Dispatcher::DispatcherInTransit::~DispatcherInTransit() {}
25
WatchDispatcher(scoped_refptr<Dispatcher> dispatcher,MojoHandleSignals signals,MojoTriggerCondition condition,uintptr_t context)26 MojoResult Dispatcher::WatchDispatcher(scoped_refptr<Dispatcher> dispatcher,
27 MojoHandleSignals signals,
28 MojoTriggerCondition condition,
29 uintptr_t context) {
30 return MOJO_RESULT_INVALID_ARGUMENT;
31 }
32
CancelWatch(uintptr_t context)33 MojoResult Dispatcher::CancelWatch(uintptr_t context) {
34 return MOJO_RESULT_INVALID_ARGUMENT;
35 }
36
Arm(uint32_t * num_blocking_events,MojoTrapEvent * blocking_events)37 MojoResult Dispatcher::Arm(uint32_t* num_blocking_events,
38 MojoTrapEvent* blocking_events) {
39 return MOJO_RESULT_INVALID_ARGUMENT;
40 }
41
WriteMessage(std::unique_ptr<ports::UserMessageEvent> message)42 MojoResult Dispatcher::WriteMessage(
43 std::unique_ptr<ports::UserMessageEvent> message) {
44 return MOJO_RESULT_INVALID_ARGUMENT;
45 }
46
ReadMessage(std::unique_ptr<ports::UserMessageEvent> * message)47 MojoResult Dispatcher::ReadMessage(
48 std::unique_ptr<ports::UserMessageEvent>* message) {
49 return MOJO_RESULT_INVALID_ARGUMENT;
50 }
51
DuplicateBufferHandle(const MojoDuplicateBufferHandleOptions * options,scoped_refptr<Dispatcher> * new_dispatcher)52 MojoResult Dispatcher::DuplicateBufferHandle(
53 const MojoDuplicateBufferHandleOptions* options,
54 scoped_refptr<Dispatcher>* new_dispatcher) {
55 return MOJO_RESULT_INVALID_ARGUMENT;
56 }
57
MapBuffer(uint64_t offset,uint64_t num_bytes,std::unique_ptr<PlatformSharedMemoryMapping> * mapping)58 MojoResult Dispatcher::MapBuffer(
59 uint64_t offset,
60 uint64_t num_bytes,
61 std::unique_ptr<PlatformSharedMemoryMapping>* mapping) {
62 return MOJO_RESULT_INVALID_ARGUMENT;
63 }
64
GetBufferInfo(MojoSharedBufferInfo * info)65 MojoResult Dispatcher::GetBufferInfo(MojoSharedBufferInfo* info) {
66 return MOJO_RESULT_INVALID_ARGUMENT;
67 }
68
ReadData(const MojoReadDataOptions & options,void * elements,uint32_t * num_bytes)69 MojoResult Dispatcher::ReadData(const MojoReadDataOptions& options,
70 void* elements,
71 uint32_t* num_bytes) {
72 return MOJO_RESULT_INVALID_ARGUMENT;
73 }
74
BeginReadData(const void ** buffer,uint32_t * buffer_num_bytes)75 MojoResult Dispatcher::BeginReadData(const void** buffer,
76 uint32_t* buffer_num_bytes) {
77 return MOJO_RESULT_INVALID_ARGUMENT;
78 }
79
EndReadData(uint32_t num_bytes_read)80 MojoResult Dispatcher::EndReadData(uint32_t num_bytes_read) {
81 return MOJO_RESULT_INVALID_ARGUMENT;
82 }
83
WriteData(const void * elements,uint32_t * num_bytes,const MojoWriteDataOptions & options)84 MojoResult Dispatcher::WriteData(const void* elements,
85 uint32_t* num_bytes,
86 const MojoWriteDataOptions& options) {
87 return MOJO_RESULT_INVALID_ARGUMENT;
88 }
89
BeginWriteData(void ** buffer,uint32_t * buffer_num_bytes)90 MojoResult Dispatcher::BeginWriteData(void** buffer,
91 uint32_t* buffer_num_bytes) {
92 return MOJO_RESULT_INVALID_ARGUMENT;
93 }
94
EndWriteData(uint32_t num_bytes_written)95 MojoResult Dispatcher::EndWriteData(uint32_t num_bytes_written) {
96 return MOJO_RESULT_INVALID_ARGUMENT;
97 }
98
AttachMessagePipe(base::StringPiece name,ports::PortRef remote_peer_port)99 MojoResult Dispatcher::AttachMessagePipe(base::StringPiece name,
100 ports::PortRef remote_peer_port) {
101 return MOJO_RESULT_INVALID_ARGUMENT;
102 }
103
ExtractMessagePipe(base::StringPiece name,MojoHandle * message_pipe_handle)104 MojoResult Dispatcher::ExtractMessagePipe(base::StringPiece name,
105 MojoHandle* message_pipe_handle) {
106 return MOJO_RESULT_INVALID_ARGUMENT;
107 }
108
SetQuota(MojoQuotaType type,uint64_t limit)109 MojoResult Dispatcher::SetQuota(MojoQuotaType type, uint64_t limit) {
110 return MOJO_RESULT_INVALID_ARGUMENT;
111 }
112
QueryQuota(MojoQuotaType type,uint64_t * limit,uint64_t * usage)113 MojoResult Dispatcher::QueryQuota(MojoQuotaType type,
114 uint64_t* limit,
115 uint64_t* usage) {
116 return MOJO_RESULT_INVALID_ARGUMENT;
117 }
118
GetHandleSignalsState() const119 HandleSignalsState Dispatcher::GetHandleSignalsState() const {
120 return HandleSignalsState();
121 }
122
AddWatcherRef(const scoped_refptr<WatcherDispatcher> & watcher,uintptr_t context)123 MojoResult Dispatcher::AddWatcherRef(
124 const scoped_refptr<WatcherDispatcher>& watcher,
125 uintptr_t context) {
126 return MOJO_RESULT_INVALID_ARGUMENT;
127 }
128
RemoveWatcherRef(WatcherDispatcher * watcher,uintptr_t context)129 MojoResult Dispatcher::RemoveWatcherRef(WatcherDispatcher* watcher,
130 uintptr_t context) {
131 return MOJO_RESULT_INVALID_ARGUMENT;
132 }
133
StartSerialize(uint32_t * num_bytes,uint32_t * num_ports,uint32_t * num_platform_handles)134 void Dispatcher::StartSerialize(uint32_t* num_bytes,
135 uint32_t* num_ports,
136 uint32_t* num_platform_handles) {
137 *num_bytes = 0;
138 *num_ports = 0;
139 *num_platform_handles = 0;
140 }
141
EndSerialize(void * destination,ports::PortName * ports,PlatformHandle * handles)142 bool Dispatcher::EndSerialize(void* destination,
143 ports::PortName* ports,
144 PlatformHandle* handles) {
145 LOG(ERROR) << "Attempting to serialize a non-transferrable dispatcher.";
146 return true;
147 }
148
BeginTransit()149 bool Dispatcher::BeginTransit() {
150 return true;
151 }
152
CompleteTransitAndClose()153 void Dispatcher::CompleteTransitAndClose() {}
154
CancelTransit()155 void Dispatcher::CancelTransit() {}
156
157 // static
Deserialize(Type type,const void * bytes,size_t num_bytes,const ports::PortName * ports,size_t num_ports,PlatformHandle * platform_handles,size_t num_platform_handles)158 scoped_refptr<Dispatcher> Dispatcher::Deserialize(
159 Type type,
160 const void* bytes,
161 size_t num_bytes,
162 const ports::PortName* ports,
163 size_t num_ports,
164 PlatformHandle* platform_handles,
165 size_t num_platform_handles) {
166 switch (type) {
167 case Type::MESSAGE_PIPE:
168 return MessagePipeDispatcher::Deserialize(bytes, num_bytes, ports,
169 num_ports, platform_handles,
170 num_platform_handles);
171 case Type::SHARED_BUFFER:
172 return SharedBufferDispatcher::Deserialize(bytes, num_bytes, ports,
173 num_ports, platform_handles,
174 num_platform_handles);
175 case Type::DATA_PIPE_CONSUMER:
176 return DataPipeConsumerDispatcher::Deserialize(
177 bytes, num_bytes, ports, num_ports, platform_handles,
178 num_platform_handles);
179 case Type::DATA_PIPE_PRODUCER:
180 return DataPipeProducerDispatcher::Deserialize(
181 bytes, num_bytes, ports, num_ports, platform_handles,
182 num_platform_handles);
183 case Type::PLATFORM_HANDLE:
184 return PlatformHandleDispatcher::Deserialize(bytes, num_bytes, ports,
185 num_ports, platform_handles,
186 num_platform_handles);
187 default:
188 LOG(ERROR) << "Deserializing invalid dispatcher type.";
189 return nullptr;
190 }
191 }
192
Dispatcher()193 Dispatcher::Dispatcher() {}
194
~Dispatcher()195 Dispatcher::~Dispatcher() {}
196
197 } // namespace core
198 } // namespace mojo
199