1 /** 2 * Copyright (C) 2022 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 IMS_SOCKET_H 18 #define IMS_SOCKET_H 19 20 #include <ImsMediaDefine.h> 21 #include <stdint.h> 22 23 enum eSocketMode 24 { 25 SOCKET_MODE_TX, 26 SOCKET_MODE_RX, 27 }; 28 29 class ISocketListener 30 { 31 public: ISocketListener()32 ISocketListener() {} ~ISocketListener()33 virtual ~ISocketListener() {} 34 /** 35 * @brief Read data from the socket 36 */ 37 virtual void OnReadDataFromSocket() = 0; 38 }; 39 40 class ISocketBridgeDataListener 41 { 42 public: ISocketBridgeDataListener()43 ISocketBridgeDataListener() {} ~ISocketBridgeDataListener()44 virtual ~ISocketBridgeDataListener() {} 45 virtual void OnSocketDataFromBridge(uint8_t* pData, uint32_t nDataSize) = 0; 46 }; 47 48 enum eSocketClass 49 { 50 SOCKET_CLASS_DEFAULT = 0, 51 SOCKET_CLASS_PROXY = 1, 52 }; 53 54 class ISocket 55 { 56 public: 57 static ISocket* GetInstance(uint32_t localPort, const char* peerIpAddress, uint32_t peerPort, 58 eSocketClass eSocket = SOCKET_CLASS_DEFAULT); 59 static void ReleaseInstance(ISocket* pSocket); 60 61 protected: ~ISocket()62 virtual ~ISocket() {} 63 64 public: 65 virtual void SetLocalEndpoint(const char* ipAddress, const uint32_t port) = 0; 66 virtual void SetPeerEndpoint(const char* ipAddress, const uint32_t port) = 0; 67 virtual int GetLocalPort() = 0; 68 virtual int GetPeerPort() = 0; 69 virtual char* GetLocalIPAddress() = 0; 70 virtual char* GetPeerIPAddress() = 0; 71 virtual bool Open(int localFd = 0) = 0; 72 virtual void Listen(ISocketListener* listener) = 0; 73 virtual int32_t SendTo(uint8_t* pData, uint32_t nDataSize) = 0; 74 virtual int32_t ReceiveFrom(uint8_t* pData, uint32_t nBufferSize) = 0; 75 virtual bool RetrieveOptionMsg(uint32_t type, int32_t& value) = 0; 76 virtual void Close() = 0; 77 virtual bool SetSocketOpt(kSocketOption nOption, int32_t nOptionValue) = 0; 78 79 protected: 80 eSocketClass mSocketClass; 81 }; 82 83 #endif