WPILibC++  unspecified
MjpegServerImpl.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef CSCORE_MJPEGSERVERIMPL_H_
9 #define CSCORE_MJPEGSERVERIMPL_H_
10 
11 #include <atomic>
12 #include <memory>
13 #include <string>
14 #include <thread>
15 #include <vector>
16 
17 #include <llvm/SmallVector.h>
18 #include <llvm/StringRef.h>
19 #include <llvm/raw_ostream.h>
20 #include <support/SafeThread.h>
21 #include <support/raw_istream.h>
22 #include <support/raw_socket_ostream.h>
23 #include <tcpsockets/NetworkAcceptor.h>
24 #include <tcpsockets/NetworkStream.h>
25 
26 #include "SinkImpl.h"
27 
28 namespace cs {
29 
30 class SourceImpl;
31 
32 class MjpegServerImpl : public SinkImpl {
33  public:
34  MjpegServerImpl(llvm::StringRef name, llvm::StringRef listenAddress, int port,
35  std::unique_ptr<wpi::NetworkAcceptor> acceptor);
36  ~MjpegServerImpl() override;
37 
38  void Stop();
39  std::string GetListenAddress() { return m_listenAddress; }
40  int GetPort() { return m_port; }
41 
42  private:
43  void SetSourceImpl(std::shared_ptr<SourceImpl> source) override;
44 
45  void ServerThreadMain();
46 
47  class ConnThread;
48 
49  // Never changed, so not protected by mutex
50  std::string m_listenAddress;
51  int m_port;
52 
53  std::unique_ptr<wpi::NetworkAcceptor> m_acceptor;
54  std::atomic_bool m_active; // set to false to terminate threads
55  std::thread m_serverThread;
56 
57  std::vector<wpi::SafeThreadOwner<ConnThread>> m_connThreads;
58 };
59 
60 } // namespace cs
61 
62 #endif // CSCORE_MJPEGSERVERIMPL_H_
Definition: MjpegServerImpl.cpp:74
Definition: SinkImpl.h:19
Definition: SinkImpl.h:23
Definition: MjpegServerImpl.h:32
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42