• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
16 #ifndef HDC_RUST_BRIDGE_H
17 #define HDC_RUST_BRIDGE_H
18 
19 #include "arpa/inet.h"
20 #include "netinet/in.h"
21 #include "sys/socket.h"
22 #include <linux/ioctl.h>
23 #include <sys/ioctl.h>
24 #include "ffi_utils.h"
25 
26 namespace Hdc {
27 #define IOC_MAGIC 0xE6
28 #define IOC_BIND _IOW(IOC_MAGIC, 1, int)
29 #define IOC_CONNECT _IOW(IOC_MAGIC, 2, int)
30 
31 struct PersistBuffer {
32     char* ptr;
33     uint64_t size;
34 };
35 
36 class HdcBridge {
37 public:
38     HdcBridge();
39     ~HdcBridge();
40     int StartListen();
41     int HandleClient(int socketFd);
42     int ReadPipeFd(int fd, char* buf, int size);
43     PersistBuffer ReadClient(int fd, int size);
44     int WriteClient(int fd, SerializedBuffer buf);
45     void Stop();
46 
47 private:
48     int bridgeListenPort = 0;
49     int bridgeFd = 0;
50 };
51 }
52 #endif