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

Commit 93e3900a authored by Alex Vakulenko's avatar Alex Vakulenko Committed by Android (Google) Code Review
Browse files

Merge "pdx: Rework error reporting when transfering file and channel handles" into oc-dev

parents ac81f70b f0a7bd03
Loading
Loading
Loading
Loading
+19 −22
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
#include <log/log.h>

#include <pdx/trace.h>
#include "errno_guard.h"

namespace android {
namespace pdx {
@@ -84,7 +83,6 @@ int Client::error() const { return error_; }

Status<void> Client::SendImpulse(int opcode) {
  PDX_TRACE_NAME("Client::SendImpulse");
  ErrnoGuard errno_guard;

  auto status = CheckReconnect();
  if (!status)
@@ -98,7 +96,6 @@ Status<void> Client::SendImpulse(int opcode) {
Status<void> Client::SendImpulse(int opcode, const void* buffer,
                                 size_t length) {
  PDX_TRACE_NAME("Client::SendImpulse");
  ErrnoGuard errno_guard;

  auto status = CheckReconnect();
  if (!status)
@@ -110,7 +107,6 @@ Status<void> Client::SendImpulse(int opcode, const void* buffer,
}

void Client::Close(int error) {
  ErrnoGuard errno_guard;
  channel_.reset();
  // Normalize error codes to negative integer space.
  error_ = error <= 0 ? error : -error;
@@ -228,37 +224,38 @@ void Transaction::SendTransaction(int opcode, Status<LocalChannelHandle>* ret,
  CheckDisconnect(*ret);
}

FileReference Transaction::PushFileHandle(const LocalHandle& handle) {
  return client_.CheckReconnect() && EnsureStateAllocated()
             ? client_.GetChannel()->PushFileHandle(state_, handle)
             : -1;
Status<FileReference> Transaction::PushFileHandle(const LocalHandle& handle) {
  if (client_.CheckReconnect() && EnsureStateAllocated())
    return client_.GetChannel()->PushFileHandle(state_, handle);
  return ErrorStatus{ESHUTDOWN};
}

FileReference Transaction::PushFileHandle(const BorrowedHandle& handle) {
  return client_.CheckReconnect() && EnsureStateAllocated()
             ? client_.GetChannel()->PushFileHandle(state_, handle)
             : -1;
Status<FileReference> Transaction::PushFileHandle(
    const BorrowedHandle& handle) {
  if (client_.CheckReconnect() && EnsureStateAllocated())
    return client_.GetChannel()->PushFileHandle(state_, handle);
  return ErrorStatus{ESHUTDOWN};
}

FileReference Transaction::PushFileHandle(const RemoteHandle& handle) {
Status<FileReference> Transaction::PushFileHandle(const RemoteHandle& handle) {
  return handle.Get();
}

ChannelReference Transaction::PushChannelHandle(
Status<ChannelReference> Transaction::PushChannelHandle(
    const LocalChannelHandle& handle) {
  return client_.CheckReconnect() && EnsureStateAllocated()
             ? client_.GetChannel()->PushChannelHandle(state_, handle)
             : -1;
  if (client_.CheckReconnect() && EnsureStateAllocated())
    return client_.GetChannel()->PushChannelHandle(state_, handle);
  return ErrorStatus{ESHUTDOWN};
}

ChannelReference Transaction::PushChannelHandle(
Status<ChannelReference> Transaction::PushChannelHandle(
    const BorrowedChannelHandle& handle) {
  return client_.CheckReconnect() && EnsureStateAllocated()
             ? client_.GetChannel()->PushChannelHandle(state_, handle)
             : -1;
  if (client_.CheckReconnect() && EnsureStateAllocated())
    return client_.GetChannel()->PushChannelHandle(state_, handle);
  return ErrorStatus{ESHUTDOWN};
}

ChannelReference Transaction::PushChannelHandle(
Status<ChannelReference> Transaction::PushChannelHandle(
    const RemoteChannelHandle& handle) {
  return handle.value();
}
+7 −6
Original line number Diff line number Diff line
@@ -518,28 +518,29 @@ TEST_F(ClientTransactionTest, PushHandle) {
  EXPECT_CALL(*mock_channel(),
              PushFileHandle(kTransactionState, A<const LocalHandle&>()))
      .WillOnce(Return(1));
  EXPECT_EQ(1, transaction_.PushFileHandle(LocalHandle{-1}));
  EXPECT_EQ(1, transaction_.PushFileHandle(LocalHandle{-1}).get());

  EXPECT_CALL(*mock_channel(),
              PushFileHandle(kTransactionState, A<const BorrowedHandle&>()))
      .WillOnce(Return(2));
  EXPECT_EQ(2, transaction_.PushFileHandle(BorrowedHandle{-1}));
  EXPECT_EQ(2, transaction_.PushFileHandle(BorrowedHandle{-1}).get());

  EXPECT_EQ(3, transaction_.PushFileHandle(RemoteHandle{3}));
  EXPECT_EQ(3, transaction_.PushFileHandle(RemoteHandle{3}).get());

  EXPECT_CALL(
      *mock_channel(),
      PushChannelHandle(kTransactionState, A<const LocalChannelHandle&>()))
      .WillOnce(Return(11));
  EXPECT_EQ(11, transaction_.PushChannelHandle(LocalChannelHandle{nullptr, 1}));
  EXPECT_EQ(
      11, transaction_.PushChannelHandle(LocalChannelHandle{nullptr, 1}).get());

  EXPECT_CALL(
      *mock_channel(),
      PushChannelHandle(kTransactionState, A<const BorrowedChannelHandle&>()))
      .WillOnce(Return(12));
  EXPECT_EQ(12, transaction_.PushChannelHandle(BorrowedChannelHandle{2}));
  EXPECT_EQ(12, transaction_.PushChannelHandle(BorrowedChannelHandle{2}).get());

  EXPECT_EQ(13, transaction_.PushChannelHandle(RemoteChannelHandle{13}));
  EXPECT_EQ(13, transaction_.PushChannelHandle(RemoteChannelHandle{13}).get());
}

TEST_F(ClientTransactionTest, GetHandle) {

libs/vr/libpdx/errno_guard.h

deleted100644 → 0
+0 −34
Original line number Diff line number Diff line
#ifndef ANDROID_PDX_ERRNO_GUARD_H_
#define ANDROID_PDX_ERRNO_GUARD_H_

#include <errno.h>

namespace android {
namespace pdx {

// Automatically saves and restores the system errno for API implementations to
// prevent internal use errno from affecting API callers.
class ErrnoGuard {
 public:
  ErrnoGuard() : saved_errno_(errno) {}
  ~ErrnoGuard() { errno = saved_errno_; }

  int saved_errno() const { return saved_errno_; }

 private:
  int saved_errno_;

  ErrnoGuard(const ErrnoGuard&) = delete;
  void operator=(const ErrnoGuard&) = delete;
};

// Checks |return_code| and returns either it or the negated system errno based
// on the return code value.
inline int ReturnCodeOrError(int return_code) {
  return return_code < 0 ? -errno : return_code;
}

}  // namespace pdx
}  // namespace android

#endif  // ANDROID_PDX_ERRNO_GUARD_H_
+7 −6
Original line number Diff line number Diff line
@@ -253,13 +253,14 @@ class Transaction final : public OutputResourceMapper,
  }

  // OutputResourceMapper
  FileReference PushFileHandle(const LocalHandle& handle) override;
  FileReference PushFileHandle(const BorrowedHandle& handle) override;
  FileReference PushFileHandle(const RemoteHandle& handle) override;
  ChannelReference PushChannelHandle(const LocalChannelHandle& handle) override;
  ChannelReference PushChannelHandle(
  Status<FileReference> PushFileHandle(const LocalHandle& handle) override;
  Status<FileReference> PushFileHandle(const BorrowedHandle& handle) override;
  Status<FileReference> PushFileHandle(const RemoteHandle& handle) override;
  Status<ChannelReference> PushChannelHandle(
      const LocalChannelHandle& handle) override;
  Status<ChannelReference> PushChannelHandle(
      const BorrowedChannelHandle& handle) override;
  ChannelReference PushChannelHandle(
  Status<ChannelReference> PushChannelHandle(
      const RemoteChannelHandle& handle) override;

  // InputResourceMapper
+8 −6
Original line number Diff line number Diff line
@@ -3,20 +3,22 @@

#include <pdx/channel_handle.h>
#include <pdx/file_handle.h>
#include <pdx/status.h>

namespace android {
namespace pdx {

class OutputResourceMapper {
 public:
  virtual FileReference PushFileHandle(const LocalHandle& handle) = 0;
  virtual FileReference PushFileHandle(const BorrowedHandle& handle) = 0;
  virtual FileReference PushFileHandle(const RemoteHandle& handle) = 0;
  virtual ChannelReference PushChannelHandle(
  virtual Status<FileReference> PushFileHandle(const LocalHandle& handle) = 0;
  virtual Status<FileReference> PushFileHandle(
      const BorrowedHandle& handle) = 0;
  virtual Status<FileReference> PushFileHandle(const RemoteHandle& handle) = 0;
  virtual Status<ChannelReference> PushChannelHandle(
      const LocalChannelHandle& handle) = 0;
  virtual ChannelReference PushChannelHandle(
  virtual Status<ChannelReference> PushChannelHandle(
      const BorrowedChannelHandle& handle) = 0;
  virtual ChannelReference PushChannelHandle(
  virtual Status<ChannelReference> PushChannelHandle(
      const RemoteChannelHandle& handle) = 0;

 protected:
Loading