1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_WRAPPER_H_ 12 #define WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_WRAPPER_H_ 13 14 #include "webrtc/system_wrappers/interface/static_instance.h" 15 #include "webrtc/typedefs.h" 16 17 namespace webrtc { 18 namespace test { 19 20 class UdpSocketWrapper; 21 22 class UdpSocketManager 23 { 24 public: 25 static UdpSocketManager* Create(const int32_t id, 26 uint8_t& numOfWorkThreads); 27 static void Return(); 28 29 // Initializes the socket manager. Returns true if the manager wasn't 30 // already initialized. 31 virtual bool Init(int32_t id, uint8_t& numOfWorkThreads) = 0; 32 33 virtual int32_t ChangeUniqueId(const int32_t id) = 0; 34 35 // Start listening to sockets that have been registered via the 36 // AddSocket(..) API. 37 virtual bool Start() = 0; 38 // Stop listening to sockets. 39 virtual bool Stop() = 0; 40 41 virtual uint8_t WorkThreads() const; 42 43 // Register a socket with the socket manager. 44 virtual bool AddSocket(UdpSocketWrapper* s) = 0; 45 // Unregister a socket from the manager. 46 virtual bool RemoveSocket(UdpSocketWrapper* s) = 0; 47 48 protected: 49 UdpSocketManager(); ~UdpSocketManager()50 virtual ~UdpSocketManager() {} 51 52 uint8_t _numOfWorkThreads; 53 54 // Factory method. 55 static UdpSocketManager* CreateInstance(); 56 57 private: 58 // Friend function to allow the UDP destructor to be accessed from the 59 // instance template. 60 friend UdpSocketManager* webrtc::GetStaticInstance<UdpSocketManager>( 61 CountOperation count_operation); 62 63 static UdpSocketManager* StaticInstance( 64 CountOperation count_operation, 65 const int32_t id, 66 uint8_t& numOfWorkThreads); 67 }; 68 69 } // namespace test 70 } // namespace webrtc 71 72 #endif // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_WRAPPER_H_ 73