Loading libs/vr/libpdx/client.cpp +19 −22 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ #include <log/log.h> #include <pdx/trace.h> #include "errno_guard.h" namespace android { namespace pdx { Loading Loading @@ -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) Loading @@ -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) Loading @@ -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; Loading Loading @@ -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(); } Loading libs/vr/libpdx/client_tests.cpp +7 −6 Original line number Diff line number Diff line Loading @@ -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) { Loading libs/vr/libpdx/errno_guard.hdeleted 100644 → 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_ libs/vr/libpdx/private/pdx/client.h +7 −6 Original line number Diff line number Diff line Loading @@ -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 Loading libs/vr/libpdx/private/pdx/message_writer.h +8 −6 Original line number Diff line number Diff line Loading @@ -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 Loading
libs/vr/libpdx/client.cpp +19 −22 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ #include <log/log.h> #include <pdx/trace.h> #include "errno_guard.h" namespace android { namespace pdx { Loading Loading @@ -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) Loading @@ -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) Loading @@ -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; Loading Loading @@ -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(); } Loading
libs/vr/libpdx/client_tests.cpp +7 −6 Original line number Diff line number Diff line Loading @@ -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) { Loading
libs/vr/libpdx/errno_guard.hdeleted 100644 → 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_
libs/vr/libpdx/private/pdx/client.h +7 −6 Original line number Diff line number Diff line Loading @@ -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 Loading
libs/vr/libpdx/private/pdx/message_writer.h +8 −6 Original line number Diff line number Diff line Loading @@ -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