• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SOCKET_READER_NODE_H
18 #define SOCKET_READER_NODE_H
19 
20 #include <BaseNode.h>
21 #include <ISocket.h>
22 #include <mutex>
23 
24 class SocketReaderNode : public BaseNode, public ISocketListener
25 {
26 public:
27     SocketReaderNode(BaseSessionCallback* callback = nullptr);
28     virtual ~SocketReaderNode();
29     virtual kBaseNodeId GetNodeId();
30     virtual bool Prepare();
31     virtual ImsMediaResult Start();
32     virtual void Stop();
33     virtual void ProcessData();
34     virtual bool IsRunTime();
35     virtual bool IsSourceNode();
36     void SetConfig(void* config);
37     virtual bool IsSameConfig(void* config);
38     virtual ImsMediaResult UpdateConfig(void* config);
39     virtual void OnReadDataFromSocket();
40 
41     /**
42      * @brief Set the local socket file descriptor
43      */
44     void SetLocalFd(int fd);
45 
46     /**
47      * @brief Set the local ip address and port number
48      */
49     void SetLocalAddress(const RtpAddress& address);
50 
51     /**
52      * @brief Set the peer ip address and port number
53      */
54     void SetPeerAddress(const RtpAddress& address);
55 
56     /**
57      * @brief Set the protocol type defined as kProtocolType
58      */
SetProtocolType(kProtocolType type)59     void SetProtocolType(kProtocolType type) { mProtocolType = type; }
60 
61     /* Get socket is opened */
IsSocketOpened()62     bool IsSocketOpened() { return mSocketOpened; }
63 
64 protected:
65     bool OpenSocket();
66     void CloseSocket();
67 
68     int mLocalFd;
69     kProtocolType mProtocolType;
70     ISocket* mSocket;
71     RtpAddress mLocalAddress;
72     RtpAddress mPeerAddress;
73     bool mSocketOpened;
74     std::mutex mMutex;
75     uint8_t mBuffer[DEFAULT_MTU];
76     bool mReceiveTtl;
77 };
78 
79 #endif