1/* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 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#ifndef HDC_DAEMON_BRIDGE_H 16#define HDC_DAEMON_BRIDGE_H 17#include <cstdint> 18#include "uv.h" 19#include "uv/unix.h" 20#include "tcp.h" 21#include <linux/ioctl.h> 22#include <sys/ioctl.h> 23 24#define IOC_MAGIC 0xE6 25 26#define IOC_BIND _IOW(IOC_MAGIC, 1, int) 27#define IOC_CONNECT _IOW(IOC_MAGIC, 2, int) 28 29#define SOCKET_FD_LEN 4 30 31namespace Hdc { 32class HdcDaemonBridge : public HdcTCPBase { 33public: 34 HdcDaemonBridge(const bool serverOrDaemonIn, void *ptrMainBase); 35 ~HdcDaemonBridge() override; 36 uint16_t bridgeListenPort; 37 int Initial(); 38 void Stop(); 39 40private: 41 static void AllocBufferCallback(uv_handle_t *handle, size_t sizeSuggested, uv_buf_t *buf); 42 static void AcceptClient(uv_stream_t *uvpipe, ssize_t nread, const uv_buf_t *buf); 43 int SetBridgeListen(); 44 uv_pipe_t servPipe = {}; 45}; 46} // namespace Hdc 47 48#endif 49