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