blob: 5d5572be198668e28c73cfe450ee48dda7d781f7 [file] [log] [blame]
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +00001/*
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
17namespace webrtc {
18namespace test {
19
20class UdpSocketWrapper;
21
22class UdpSocketManager
23{
24public:
pbos@webrtc.org91cab712013-04-09 11:10:21 +000025 static UdpSocketManager* Create(const int32_t id,
26 uint8_t& numOfWorkThreads);
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +000027 static void Return();
28
29 // Initializes the socket manager. Returns true if the manager wasn't
30 // already initialized.
pbos@webrtc.org91cab712013-04-09 11:10:21 +000031 virtual bool Init(int32_t id, uint8_t& numOfWorkThreads) = 0;
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +000032
pbos@webrtc.org91cab712013-04-09 11:10:21 +000033 virtual int32_t ChangeUniqueId(const int32_t id) = 0;
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +000034
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
pbos@webrtc.org91cab712013-04-09 11:10:21 +000041 virtual uint8_t WorkThreads() const;
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +000042
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
48protected:
49 UdpSocketManager();
50 virtual ~UdpSocketManager() {}
51
pbos@webrtc.org91cab712013-04-09 11:10:21 +000052 uint8_t _numOfWorkThreads;
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +000053
54 // Factory method.
55 static UdpSocketManager* CreateInstance();
56
57private:
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,
pbos@webrtc.org91cab712013-04-09 11:10:21 +000065 const int32_t id,
66 uint8_t& numOfWorkThreads);
pwestin@webrtc.orgaf6aa7b2013-03-21 16:38:05 +000067};
68
69} // namespace test
70} // namespace webrtc
71
72#endif // WEBRTC_TEST_CHANNEL_TRANSPORT_UDP_SOCKET_MANAGER_WRAPPER_H_