PipeRelay.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2017 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FRAMEWORKS_NATIVE_CMDS_LSHAL_PIPE_RELAY_H_
  17. #define FRAMEWORKS_NATIVE_CMDS_LSHAL_PIPE_RELAY_H_
  18. #include <android-base/macros.h>
  19. #include <ostream>
  20. #include <utils/Errors.h>
  21. #include <utils/RefBase.h>
  22. namespace android {
  23. namespace lshal {
  24. /* Creates an AF_UNIX socketpair and spawns a thread that relays any data
  25. * written to the "write"-end of the pair to the specified output stream "os".
  26. */
  27. struct PipeRelay {
  28. explicit PipeRelay(std::ostream &os);
  29. ~PipeRelay();
  30. status_t initCheck() const;
  31. // Returns the file descriptor corresponding to the "write"-end of the
  32. // connection.
  33. int fd() const;
  34. private:
  35. struct RelayThread;
  36. status_t mInitCheck;
  37. int mFds[2];
  38. sp<RelayThread> mThread;
  39. static void CloseFd(int *fd);
  40. DISALLOW_COPY_AND_ASSIGN(PipeRelay);
  41. };
  42. } // namespace lshal
  43. } // namespace android
  44. #endif // FRAMEWORKS_NATIVE_CMDS_LSHAL_PIPE_RELAY_H_