Lingfeng Yang | e38d15c | 2018-09-24 16:24:01 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | #include "qemu_pipe.h" |
| 15 | |
| 16 | #include "android/emulation/hostpipe/HostGoldfishPipe.h" |
| 17 | |
Luca Stefani | 1cb647a | 2019-03-07 21:58:17 +0100 | [diff] [blame] | 18 | #if PLATFORM_SDK_VERSION < 26 |
Lingfeng Yang | e38d15c | 2018-09-24 16:24:01 -0700 | [diff] [blame] | 19 | #include <cutils/log.h> |
Luca Stefani | 1cb647a | 2019-03-07 21:58:17 +0100 | [diff] [blame] | 20 | #else |
| 21 | #include <log/log.h> |
| 22 | #endif |
Lingfeng Yang | e38d15c | 2018-09-24 16:24:01 -0700 | [diff] [blame] | 23 | |
| 24 | using android::HostGoldfishPipeDevice; |
| 25 | |
| 26 | QEMU_PIPE_HANDLE qemu_pipe_open(const char* pipeName) { |
| 27 | return HostGoldfishPipeDevice::get()->connect(pipeName); |
| 28 | } |
| 29 | |
| 30 | void qemu_pipe_close(QEMU_PIPE_HANDLE pipe) { |
| 31 | HostGoldfishPipeDevice::get()->close(pipe); |
| 32 | } |
| 33 | |
| 34 | ssize_t qemu_pipe_read(QEMU_PIPE_HANDLE pipe, void* buffer, size_t len) { |
| 35 | return HostGoldfishPipeDevice::get()->read(pipe, buffer, len); |
| 36 | } |
| 37 | |
| 38 | ssize_t qemu_pipe_write(QEMU_PIPE_HANDLE pipe, const void* buffer, size_t len) { |
| 39 | return HostGoldfishPipeDevice::get()->write(pipe, buffer, len); |
| 40 | } |
| 41 | |
| 42 | bool qemu_pipe_try_again() { |
| 43 | int err = HostGoldfishPipeDevice::get()->getErrno(); |
| 44 | return err == EINTR || err == EAGAIN; |
| 45 | } |
| 46 | |
| 47 | bool qemu_pipe_valid(QEMU_PIPE_HANDLE pipe) { |
| 48 | return pipe != NULL; |
| 49 | } |
| 50 | |
| 51 | void qemu_pipe_print_error(QEMU_PIPE_HANDLE pipe) { |
| 52 | int err = HostGoldfishPipeDevice::get()->getErrno(); |
| 53 | ALOGE("pipe error: pipe %p err %d", pipe, err); |
| 54 | } |