• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/include/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     // Start listening to sockets that have been registered via the
34     // AddSocket(..) API.
35     virtual bool Start() = 0;
36     // Stop listening to sockets.
37     virtual bool Stop() = 0;
38 
39     virtual uint8_t WorkThreads() const;
40 
41     // Register a socket with the socket manager.
42     virtual bool AddSocket(UdpSocketWrapper* s) = 0;
43     // Unregister a socket from the manager.
44     virtual bool RemoveSocket(UdpSocketWrapper* s) = 0;
45 
46 protected:
47     UdpSocketManager();
~UdpSocketManager()48     virtual ~UdpSocketManager() {}
49 
50     uint8_t _numOfWorkThreads;
51 
52     // Factory method.
53     static UdpSocketManager* CreateInstance();
54 
55 private:
56     // Friend function to allow the UDP destructor to be accessed from the
57     // instance template.
58     friend UdpSocketManager* webrtc::GetStaticInstance<UdpSocketManager>(
59         CountOperation count_operation);
60 
61     static UdpSocketManager* StaticInstance(
62         CountOperation count_operation,
63         const int32_t id,
64         uint8_t& numOfWorkThreads);
65 };
66 
67 }  // namespace test
68 }  // namespace webrtc
69 
70 #endif  // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_WRAPPER_H_
71