Loading libs/binder/ndk/include_cpp/android/binder_auto_utils.h +26 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,14 @@ #include <assert.h> // defined differently by liblog #pragma push_macro("LOG_PRI") #ifdef LOG_PRI #undef LOG_PRI #endif #include <syslog.h> #pragma pop_macro("LOG_PRI") #include <unistd.h> #include <cstddef> #include <string> Loading Loading @@ -130,7 +138,7 @@ namespace impl { /** * This baseclass owns a single object, used to make various classes RAII. */ template <typename T, typename R, R (*Destroy)(T), T DEFAULT> template <typename T, void (*Destroy)(T), T DEFAULT> class ScopedAResource { public: /** Loading Loading @@ -198,7 +206,7 @@ class ScopedAResource { /** * Convenience wrapper. See AParcel. */ class ScopedAParcel : public impl::ScopedAResource<AParcel*, void, AParcel_delete, nullptr> { class ScopedAParcel : public impl::ScopedAResource<AParcel*, AParcel_delete, nullptr> { public: /** * Takes ownership of a. Loading @@ -219,7 +227,7 @@ class ScopedAParcel : public impl::ScopedAResource<AParcel*, void, AParcel_delet /** * Convenience wrapper. See AStatus. */ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delete, nullptr> { class ScopedAStatus : public impl::ScopedAResource<AStatus*, AStatus_delete, nullptr> { public: /** * Takes ownership of a. Loading Loading @@ -291,7 +299,7 @@ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delet * Convenience wrapper. See AIBinder_DeathRecipient. */ class ScopedAIBinder_DeathRecipient : public impl::ScopedAResource<AIBinder_DeathRecipient*, void, AIBinder_DeathRecipient_delete, : public impl::ScopedAResource<AIBinder_DeathRecipient*, AIBinder_DeathRecipient_delete, nullptr> { public: /** Loading @@ -308,7 +316,7 @@ class ScopedAIBinder_DeathRecipient * Convenience wrapper. See AIBinder_Weak. */ class ScopedAIBinder_Weak : public impl::ScopedAResource<AIBinder_Weak*, void, AIBinder_Weak_delete, nullptr> { : public impl::ScopedAResource<AIBinder_Weak*, AIBinder_Weak_delete, nullptr> { public: /** * Takes ownership of a. Loading @@ -324,10 +332,22 @@ class ScopedAIBinder_Weak SpAIBinder promote() { return SpAIBinder(AIBinder_Weak_promote(get())); } }; namespace internal { static void closeWithError(int fd) { if (fd == -1) return; int ret = close(fd); if (ret != 0) { syslog(LOG_ERR, "Could not close FD %d: %s", fd, strerror(errno)); } } } // namespace internal /** * Convenience wrapper for a file descriptor. */ class ScopedFileDescriptor : public impl::ScopedAResource<int, int, close, -1> { class ScopedFileDescriptor : public impl::ScopedAResource<int, internal::closeWithError, -1> { public: /** * Takes ownership of a. Loading Loading
libs/binder/ndk/include_cpp/android/binder_auto_utils.h +26 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,14 @@ #include <assert.h> // defined differently by liblog #pragma push_macro("LOG_PRI") #ifdef LOG_PRI #undef LOG_PRI #endif #include <syslog.h> #pragma pop_macro("LOG_PRI") #include <unistd.h> #include <cstddef> #include <string> Loading Loading @@ -130,7 +138,7 @@ namespace impl { /** * This baseclass owns a single object, used to make various classes RAII. */ template <typename T, typename R, R (*Destroy)(T), T DEFAULT> template <typename T, void (*Destroy)(T), T DEFAULT> class ScopedAResource { public: /** Loading Loading @@ -198,7 +206,7 @@ class ScopedAResource { /** * Convenience wrapper. See AParcel. */ class ScopedAParcel : public impl::ScopedAResource<AParcel*, void, AParcel_delete, nullptr> { class ScopedAParcel : public impl::ScopedAResource<AParcel*, AParcel_delete, nullptr> { public: /** * Takes ownership of a. Loading @@ -219,7 +227,7 @@ class ScopedAParcel : public impl::ScopedAResource<AParcel*, void, AParcel_delet /** * Convenience wrapper. See AStatus. */ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delete, nullptr> { class ScopedAStatus : public impl::ScopedAResource<AStatus*, AStatus_delete, nullptr> { public: /** * Takes ownership of a. Loading Loading @@ -291,7 +299,7 @@ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delet * Convenience wrapper. See AIBinder_DeathRecipient. */ class ScopedAIBinder_DeathRecipient : public impl::ScopedAResource<AIBinder_DeathRecipient*, void, AIBinder_DeathRecipient_delete, : public impl::ScopedAResource<AIBinder_DeathRecipient*, AIBinder_DeathRecipient_delete, nullptr> { public: /** Loading @@ -308,7 +316,7 @@ class ScopedAIBinder_DeathRecipient * Convenience wrapper. See AIBinder_Weak. */ class ScopedAIBinder_Weak : public impl::ScopedAResource<AIBinder_Weak*, void, AIBinder_Weak_delete, nullptr> { : public impl::ScopedAResource<AIBinder_Weak*, AIBinder_Weak_delete, nullptr> { public: /** * Takes ownership of a. Loading @@ -324,10 +332,22 @@ class ScopedAIBinder_Weak SpAIBinder promote() { return SpAIBinder(AIBinder_Weak_promote(get())); } }; namespace internal { static void closeWithError(int fd) { if (fd == -1) return; int ret = close(fd); if (ret != 0) { syslog(LOG_ERR, "Could not close FD %d: %s", fd, strerror(errno)); } } } // namespace internal /** * Convenience wrapper for a file descriptor. */ class ScopedFileDescriptor : public impl::ScopedAResource<int, int, close, -1> { class ScopedFileDescriptor : public impl::ScopedAResource<int, internal::closeWithError, -1> { public: /** * Takes ownership of a. Loading