blob: e1a3b450de09f9f14ade4c502bb08575a60a17ea [file] [log] [blame]
Lingfeng Yange38d15c2018-09-24 16:24:01 -07001// 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 Stefani1cb647a2019-03-07 21:58:17 +010018#if PLATFORM_SDK_VERSION < 26
Lingfeng Yange38d15c2018-09-24 16:24:01 -070019#include <cutils/log.h>
Luca Stefani1cb647a2019-03-07 21:58:17 +010020#else
21#include <log/log.h>
22#endif
Lingfeng Yange38d15c2018-09-24 16:24:01 -070023
24using android::HostGoldfishPipeDevice;
25
26QEMU_PIPE_HANDLE qemu_pipe_open(const char* pipeName) {
27 return HostGoldfishPipeDevice::get()->connect(pipeName);
28}
29
30void qemu_pipe_close(QEMU_PIPE_HANDLE pipe) {
31 HostGoldfishPipeDevice::get()->close(pipe);
32}
33
34ssize_t qemu_pipe_read(QEMU_PIPE_HANDLE pipe, void* buffer, size_t len) {
35 return HostGoldfishPipeDevice::get()->read(pipe, buffer, len);
36}
37
38ssize_t qemu_pipe_write(QEMU_PIPE_HANDLE pipe, const void* buffer, size_t len) {
39 return HostGoldfishPipeDevice::get()->write(pipe, buffer, len);
40}
41
42bool qemu_pipe_try_again() {
43 int err = HostGoldfishPipeDevice::get()->getErrno();
44 return err == EINTR || err == EAGAIN;
45}
46
47bool qemu_pipe_valid(QEMU_PIPE_HANDLE pipe) {
48 return pipe != NULL;
49}
50
51void 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}