Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
protocol_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Roc Streaming 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_address/protocol_map.h
10 //! @brief Protocol attributes map.
11 
12 #ifndef ROC_ADDRESS_PROTOCOL_MAP_H_
13 #define ROC_ADDRESS_PROTOCOL_MAP_H_
14 
15 #include "roc_address/interface.h"
16 #include "roc_address/protocol.h"
17 #include "roc_core/array.h"
18 #include "roc_core/noncopyable.h"
19 #include "roc_core/singleton.h"
20 #include "roc_core/stddefs.h"
21 #include "roc_core/string_list.h"
22 #include "roc_packet/fec.h"
23 
24 namespace roc {
25 namespace address {
26 
27 //! Protocol attributes.
28 struct ProtocolAttrs {
29  //! Protocol ID.
31 
32  //! Endpoint type.
34 
35  //! Scheme name in URI.
36  const char* scheme_name;
37 
38  //! Whether path is supported in URI.
40 
41  //! Default port number of -1 if not specified.
43 
44  //! FEC scheme associated wit the protocol, if any.
46 
50  , scheme_name(NULL)
51  , path_supported(false)
52  , default_port(-1)
53  , fec_scheme(packet::FEC_None) {
54  }
55 };
56 
57 //! Protocol attributes map.
58 class ProtocolMap : public core::NonCopyable<> {
59 public:
60  //! Get instance.
61  static ProtocolMap& instance() {
63  }
64 
65  //! Get protocol attributes by ID.
66  const ProtocolAttrs* find_by_id(Protocol proto) const;
67 
68  //! Get protocol attributes by scheme name.
69  const ProtocolAttrs* find_by_scheme(const char* scheme) const;
70 
71  //! Get list of interfaces with at least one protocol.
73 
74  //! Get all supported protocols.
76 
77 private:
78  friend class core::Singleton<ProtocolMap>;
79 
80  enum { MaxProtos = 8 };
81 
82  ProtocolMap();
83 
84  void add_proto_(const ProtocolAttrs&);
85 
86  ProtocolAttrs protos_[MaxProtos];
87 };
88 
89 } // namespace address
90 } // namespace roc
91 
92 #endif // ROC_ADDRESS_PROTOCOL_MAP_H_
Dynamic array.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Protocol attributes map.
Definition: protocol_map.h:58
const ProtocolAttrs * find_by_scheme(const char *scheme) const
Get protocol attributes by scheme name.
static ProtocolMap & instance()
Get instance.
Definition: protocol_map.h:61
const ProtocolAttrs * find_by_id(Protocol proto) const
Get protocol attributes by ID.
ROC_ATTR_NODISCARD bool get_supported_interfaces(core::Array< Interface > &)
Get list of interfaces with at least one protocol.
ROC_ATTR_NODISCARD bool get_supported_protocols(Interface, core::StringList &)
Get all supported protocols.
Dynamic array.
Definition: array.h:39
Base class for non-copyable objects.
Definition: noncopyable.h:23
static T & instance()
Get singleton instance.
Definition: singleton.h:29
Dynamic list of strings.
Definition: string_list.h:36
FEC packet.
Interface ID.
Interface
Interface ID.
Definition: interface.h:19
@ Iface_Invalid
Invalid interface.
Definition: interface.h:21
Protocol
Protocol ID.
Definition: protocol.h:19
@ Proto_None
Protocol is not set.
Definition: protocol.h:21
FecScheme
FECFRAME scheme.
Definition: fec.h:23
@ FEC_None
No FEC.
Definition: fec.h:25
Root namespace.
Non-copyable object.
Protocol ID.
Singleton.
Commonly used types and functions.
Dynamic list of strings.
Protocol attributes.
Definition: protocol_map.h:28
Protocol protocol
Protocol ID.
Definition: protocol_map.h:30
Interface iface
Endpoint type.
Definition: protocol_map.h:33
const char * scheme_name
Scheme name in URI.
Definition: protocol_map.h:36
packet::FecScheme fec_scheme
FEC scheme associated wit the protocol, if any.
Definition: protocol_map.h:45
bool path_supported
Whether path is supported in URI.
Definition: protocol_map.h:39
int default_port
Default port number of -1 if not specified.
Definition: protocol_map.h:42