• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sys/select.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 <sys/select.h> FD_SET() API */
68   virtual void FDSet(int fd, fd_set* set) = 0;
69 
70   /* Wrapper for <sys/select.h> FD_CLR() API */
71   virtual void FDClr(int fd, fd_set* set) = 0;
72 
73   /* Wrapper for <sys/select.h> FD_ISSET() API */
74   virtual bool FDIsSet(int fd, fd_set* set) = 0;
75 
76   /* Wrapper for <sys/select.h> FD_ZERO() API */
77   virtual void FDZero(fd_set* set) = 0;
78 
79   /* Wrapper for <sys/select.h> select() API */
80   virtual int Select(
81       int __nfds, fd_set* __readfds, fd_set* __writefds, fd_set* __exceptfds, struct timeval* __timeout) = 0;
82 };
83 
84 }  // namespace hal
85 }  // namespace bluetooth
86