blob: 8dc309374240b05f206e3c6cd446b16cc9153f60 [file] [log] [blame]
Andreas Huber28d35912017-03-24 13:14:11 -07001/*
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
17#ifndef FRAMEWORKS_NATIVE_CMDS_LSHAL_PIPE_RELAY_H_
18
19#define FRAMEWORKS_NATIVE_CMDS_LSHAL_PIPE_RELAY_H_
20
21#include <android-base/macros.h>
22#include <ostream>
23#include <utils/Errors.h>
24#include <utils/RefBase.h>
25
26namespace android {
27namespace lshal {
28
29/* Creates an AF_UNIX socketpair and spawns a thread that relays any data
30 * written to the "write"-end of the pair to the specified output stream "os".
31 */
32struct PipeRelay {
33 explicit PipeRelay(std::ostream &os);
34 ~PipeRelay();
35
36 status_t initCheck() const;
37
38 // Returns the file descriptor corresponding to the "write"-end of the
39 // connection.
40 int fd() const;
41
42private:
43 struct RelayThread;
44
Andreas Huber28d35912017-03-24 13:14:11 -070045 status_t mInitCheck;
46 int mFds[2];
47 sp<RelayThread> mThread;
48
49 static void CloseFd(int *fd);
50
51 DISALLOW_COPY_AND_ASSIGN(PipeRelay);
52};
53
54} // namespace lshal
55} // namespace android
56
57#endif // FRAMEWORKS_NATIVE_CMDS_LSHAL_PIPE_RELAY_H_
58