Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
router.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Roc authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_packet/router.h
10 //! @brief Route packets to writers.
11 
12 #ifndef ROC_PACKET_ROUTER_H_
13 #define ROC_PACKET_ROUTER_H_
14 
15 #include "roc_core/array.h"
16 #include "roc_core/iallocator.h"
17 #include "roc_core/noncopyable.h"
18 #include "roc_core/stddefs.h"
19 #include "roc_packet/iwriter.h"
20 #include "roc_packet/packet.h"
21 
22 namespace roc {
23 namespace packet {
24 
25 //! Route packets to writers.
26 class Router : public IWriter, public core::NonCopyable<> {
27 public:
28  //! Initialize.
29  Router(core::IAllocator& allocator, size_t max_routes);
30 
31  //! Check if object is successfully constructed.
32  bool valid() const;
33 
34  //! Add route.
35  //! @remarks
36  //! Packets that has given @p flags set will be routed to @p writer.
37  bool add_route(IWriter& writer, unsigned flags);
38 
39  //! Write next packet.
40  //! @remarks
41  //! Route @p packet to a writer or drop it if no routes found.
42  virtual void write(const PacketPtr& packet);
43 
44 private:
45  struct Route {
46  IWriter* writer;
47  unsigned flags;
48  source_t source;
49  bool has_source;
50  };
51 
52  core::Array<Route> routes_;
53 
54  bool valid_;
55 };
56 
57 } // namespace packet
58 } // namespace roc
59 
60 #endif // ROC_PACKET_ROUTER_H_
Memory allocator interface.
Definition: iallocator.h:23
Root namespace.
bool add_route(IWriter &writer, unsigned flags)
Add route.
bool valid() const
Check if object is successfully constructed.
Dynamic array.
Packet writer interface.
uint32_t source_t
Packet source ID identifying packet stream.
Definition: units.h:22
virtual void write(const PacketPtr &packet)
Write next packet.
Commonly used types and functions.
Packet writer interface.
Definition: iwriter.h:21
Base class for non-copyable objects.
Definition: noncopyable.h:23
Route packets to writers.
Definition: router.h:26
Router(core::IAllocator &allocator, size_t max_routes)
Initialize.
Packet.
Non-copyable object.
Memory allocator interface.