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 
15 #include <qemu_pipe_bp.h>
16 
17 #include "android/emulation/hostdevices/HostGoldfishPipe.h"
18 
19 #if PLATFORM_SDK_VERSION < 26
20 #include <cutils/log.h>
21 #else
22 #include <log/log.h>
23 #endif
24 
25 #include <errno.h>
26 
27 using android::HostGoldfishPipeDevice;
28 
qemu_pipe_open(const char * pipeName)29 QEMU_PIPE_HANDLE qemu_pipe_open(const char* pipeName) {
30     return HostGoldfishPipeDevice::get()->connect(pipeName);
31 }
32 
qemu_pipe_close(QEMU_PIPE_HANDLE pipe)33 void qemu_pipe_close(QEMU_PIPE_HANDLE pipe) {
34     HostGoldfishPipeDevice::get()->close(pipe);
35 }
36 
qemu_pipe_read(QEMU_PIPE_HANDLE pipe,void * buffer,int len)37 int qemu_pipe_read(QEMU_PIPE_HANDLE pipe, void* buffer, int len) {
38     return HostGoldfishPipeDevice::get()->read(pipe, buffer, len);
39 }
40 
qemu_pipe_write(QEMU_PIPE_HANDLE pipe,const void * buffer,int len)41 int qemu_pipe_write(QEMU_PIPE_HANDLE pipe, const void* buffer, int len) {
42     return HostGoldfishPipeDevice::get()->write(pipe, buffer, len);
43 }
44 
qemu_pipe_try_again(int ret)45 int qemu_pipe_try_again(int ret) {
46     if (ret < 0) {
47         int err = HostGoldfishPipeDevice::get()->getErrno();
48         return err == EINTR || err == EAGAIN;
49     } else {
50         return false;
51     }
52 }
53 
qemu_pipe_print_error(QEMU_PIPE_HANDLE pipe)54 void qemu_pipe_print_error(QEMU_PIPE_HANDLE pipe) {
55     int err = HostGoldfishPipeDevice::get()->getErrno();
56     ALOGE("pipe error: pipe %p err %d", pipe, err);
57 }
58