1 /******************************************************************************
2  *
3  *  Copyright (C) 2022 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 #include <poll.h>
22 #include <sys/socket.h>
23 
24 namespace bluetooth {
25 namespace hal {
26 
27 class SyscallWrapperInterface {
28 public:
29   virtual ~SyscallWrapperInterface() = default;
30 
31   /* Wrapper for  <sys/socket.h> socket() API */
32   virtual int Socket(int domain, int type, int protocol) = 0;
33 
34   /* Wrapper for <sys/socket.h> bind() API */
35   virtual int Bind(int fd, const struct sockaddr* addr, socklen_t len) = 0;
36 
37   /* Wrapper for <sys/socket.h> connect() API */
38   virtual int Connect(int fd, const struct sockaddr* addr, socklen_t len) = 0;
39 
40   /* Wrapper for <sys/socket.h> send() API */
41   virtual ssize_t Send(int fd, const void* buf, size_t n, int flags) = 0;
42 
43   /* Wrapper for <sys/socket.h> recv() API */
44   virtual ssize_t Recv(int fd, void* buf, size_t n, int flags) = 0;
45 
46   /* Wrapper for <sys/socket.h> setsockopt() API */
47   virtual int Setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen) = 0;
48 
49   /* Wrapper for <sys/socket.h> listen() API */
50   virtual int Listen(int fd, int n) = 0;
51 
52   /* Wrapper for <sys/socket.h> accept() API */
53   virtual int Accept(int fd, struct sockaddr* addr, socklen_t* addr_len, int flags) = 0;
54 
55   /* Wrapper for <unistd.h> pipe2() API */
56   virtual int Pipe2(int* pipefd, int flags) = 0;
57 
58   /* Wrapper for <errno.h> errno API */
59   virtual int GetErrno() const = 0;
60 
61   /* Wrapper for <unistd.h> write() API */
62   virtual ssize_t Write(int, const void*, size_t) = 0;
63 
64   /* Wrapper for <unistd.h> close() API */
65   virtual int Close(int fd) = 0;
66 
67   /* Wrapper for <poll.h> poll() API */
68   virtual int Poll(struct pollfd* fds, nfds_t nfds, int timeout) = 0;
69 };
70 
71 }  // namespace hal
72 }  // namespace bluetooth
73