Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e15bb2b1 authored by Corey Tabaka's avatar Corey Tabaka
Browse files

libpdx: Remove superfluous DispatchRemoteMethod overloads.

The introduction of RemoteMethodReturn<>() properly handles the
differences between most of these overloads. Remove the ones that
are now obsolete in favor of the generic version.

Bug: None
Test: make -j30
Change-Id: I23e63431e9f668c324b408707ce65e7d6aee69c8
parent a2d4886b
Loading
Loading
Loading
Loading
+0 −146
Original line number Diff line number Diff line
@@ -212,117 +212,6 @@ void DispatchRemoteMethod(Class& instance,
    RemoteMethodReturn<RemoteMethodType>(message, 0);
}

// Dispatches a method by deserializing arguments from the given Message, with
// compile-time interface check. Overload for int return types.
template <typename RemoteMethodType, typename Class, typename... Args,
          typename = EnableIfNotVoidMethod<RemoteMethodType>>
void DispatchRemoteMethod(Class& instance,
                          int (Class::*method)(Message&, Args...),
                          Message& message,
                          std::size_t max_capacity = InitialBufferCapacity) {
  using Signature = typename RemoteMethodType::template RewriteArgs<Args...>;
  rpc::ServicePayload<ReceiveBuffer> payload(message);
  payload.Resize(max_capacity);

  auto size = message.Read(payload.Data(), payload.Size());
  if (size < 0) {
    RemoteMethodError(message, -size);
    return;
  }

  payload.Resize(size);

  ErrorType error;
  auto decoder = MakeArgumentDecoder<Signature>(&payload);
  auto arguments = decoder.DecodeArguments(&error);
  if (error) {
    RemoteMethodError(message, EIO);
    return;
  }

  auto return_value =
      UnpackArguments<Class, Signature>(instance, method, message, arguments)
          .Invoke();
  // Return the value to the caller unless the message was moved.
  if (message)
    RemoteMethodReturn<RemoteMethodType>(message, return_value);
}

// Dispatches a method by deserializing arguments from the given Message, with
// compile-time interface check. Overload for FileHandle return types.
template <typename RemoteMethodType, FileHandleMode Mode, typename Class,
          typename... Args, typename = EnableIfNotVoidMethod<RemoteMethodType>>
void DispatchRemoteMethod(Class& instance,
                          FileHandle<Mode> (Class::*method)(Message&, Args...),
                          Message& message,
                          std::size_t max_capacity = InitialBufferCapacity) {
  using Signature =
      typename RemoteMethodType::template RewriteSignature<FileHandle<Mode>,
                                                           Args...>;
  rpc::ServicePayload<ReceiveBuffer> payload(message);
  payload.Resize(max_capacity);

  auto size = message.Read(payload.Data(), payload.Size());
  if (size < 0) {
    RemoteMethodError(message, -size);
    return;
  }

  payload.Resize(size);

  ErrorType error;
  auto decoder = MakeArgumentDecoder<Signature>(&payload);
  auto arguments = decoder.DecodeArguments(&error);
  if (error) {
    RemoteMethodError(message, EIO);
    return;
  }

  auto return_value =
      UnpackArguments<Class, Signature>(instance, method, message, arguments)
          .Invoke();
  // Return the value to the caller unless the message was moved.
  if (message)
    RemoteMethodReturn<RemoteMethodType>(message, return_value);
}

// Dispatches a method by deserializing arguments from the given Message, with
// compile-time interface check. Overload for ChannelHandle return types.
template <typename RemoteMethodType, ChannelHandleMode Mode, typename Class,
          typename... Args, typename = EnableIfNotVoidMethod<RemoteMethodType>>
void DispatchRemoteMethod(
    Class& instance, ChannelHandle<Mode> (Class::*method)(Message&, Args...),
    Message& message, std::size_t max_capacity = InitialBufferCapacity) {
  using Signature =
      typename RemoteMethodType::template RewriteSignature<ChannelHandle<Mode>,
                                                           Args...>;
  rpc::ServicePayload<ReceiveBuffer> payload(message);
  payload.Resize(max_capacity);

  auto size = message.Read(payload.Data(), payload.Size());
  if (size < 0) {
    RemoteMethodError(message, -size);
    return;
  }

  payload.Resize(size);

  ErrorType error;
  auto decoder = MakeArgumentDecoder<Signature>(&payload);
  auto arguments = decoder.DecodeArguments(&error);
  if (error) {
    RemoteMethodError(message, EIO);
    return;
  }

  auto return_value =
      UnpackArguments<Class, Signature>(instance, method, message, arguments)
          .Invoke();
  // Return the value to the caller unless the message was moved.
  if (message)
    RemoteMethodReturn<RemoteMethodType>(message, return_value);
}

// Dispatches a method by deserializing arguments from the given Message, with
// compile-time interface signature check. Overload for generic return types.
template <typename RemoteMethodType, typename Class, typename Return,
@@ -414,41 +303,6 @@ void DispatchRemoteMethod(Class& instance, void (Class::*method)(Message&),
    RemoteMethodReturn<RemoteMethodType>(message, 0);
}

// Overload for int return type.
template <typename RemoteMethodType, typename Class,
          typename = EnableIfVoidMethod<RemoteMethodType>>
void DispatchRemoteMethod(Class& instance, int (Class::*method)(Message&),
                          Message& message) {
  const int return_value = (instance.*method)(message);
  // Return the value to the caller unless the message was moved.
  if (message)
    RemoteMethodReturn<RemoteMethodType>(message, return_value);
}

// Overload for FileHandle return type.
template <typename RemoteMethodType, typename Class, FileHandleMode Mode,
          typename = EnableIfVoidMethod<RemoteMethodType>>
void DispatchRemoteMethod(Class& instance,
                          FileHandle<Mode> (Class::*method)(Message&),
                          Message& message) {
  FileHandle<Mode> return_value = (instance.*method)(message);
  // Return the value to the caller unless the message was moved.
  if (message)
    RemoteMethodReturn<RemoteMethodType>(message, return_value);
}

// Overload for ChannelHandle return types.
template <typename RemoteMethodType, typename Class, ChannelHandleMode Mode,
          typename = EnableIfVoidMethod<RemoteMethodType>>
void DispatchRemoteMethod(Class& instance,
                          ChannelHandle<Mode> (Class::*method)(Message&),
                          Message& message) {
  ChannelHandle<Mode> return_value = (instance.*method)(message);
  // Return the value to the caller unless the message was moved.
  if (message)
    RemoteMethodReturn<RemoteMethodType>(message, return_value);
}

// Overload for generic return type.
template <typename RemoteMethodType, typename Class, typename Return,
          typename = EnableIfVoidMethod<RemoteMethodType>>