ED247 Library  VA2.3.0
Implementation of ED247-A standard
ed247_channel.h
1 /* -*- mode: c++; c-basic-offset: 2 -*- */
2 /******************************************************************************
3  * The MIT Licence
4  *
5  * Copyright (c) 2021 Airbus Operations S.A.S
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  *****************************************************************************/
25 #ifndef ED247_CHANNEL_H_
26 #define ED247_CHANNEL_H_
27 #include "ed247.h"
28 #include "ed247_xml.h"
29 #include "ed247_cominterface.h"
30 #include "ed247_stream.h"
31 #include "ed247_frame_header.h"
32 
33 // base structures for C API
36 
37 namespace ed247
38 {
39  class Context;
40 
42  {
43  public:
44  using map_uid_stream_t = std::unordered_map<ed247_uid_t, stream_ptr_t>;
45 
46  Channel(Context* context, const xml::Channel* configuration);
47  ~Channel();
48 
49  Channel& operator=(const Channel &) = delete;
50  Channel& operator=(Channel &&) = delete;
51 
52  // Configuration accessors
53  const std::string& get_name() const { return _configuration->_name; }
54  const std::string& get_comment() const { return _configuration->_comment; }
55  ed247_standard_t get_frame_standard_revision() const { return _configuration->_frame_standard_revision; }
56 
57  // Handle user-data
58  void set_user_data(void *user_data) { _user_data = user_data; }
59  void get_user_data(void **user_data) { *user_data = _user_data; }
60 
61  // Stream access
62  stream_list_t find_streams(std::string strregex);
63  stream_ptr_t get_stream(std::string str_name);
64  ed247_internal_stream_list_t* get_client_streams() { return _client_streams.get(); }
65 
66  // Encode the channel and send it.
67  // Nothing is send if there are no data in streams.
68  // In some cases, this function may send severals packets.
69  void encode_and_send();
70 
71  // Decode frame and fill streams data
72  // Return false if the frame cannot be decoded
73  bool decode(const char* frame, uint32_t frame_size);
74 
75  private:
76  Context* _context;
77  const xml::Channel* _configuration;
78  udp::ComInterface _com_interface;
79  map_uid_stream_t _streams;
80  FrameHeader _header;
81  Sample _buffer;
82  void* _user_data;
83 
84  std::unique_ptr<ed247_internal_stream_list_t> _client_streams;
85 
86  ED247_FRIEND_TEST();
87  };
88 
89  typedef std::shared_ptr<Channel> channel_ptr_t;
90  typedef std::vector<channel_ptr_t> channel_list_t;
91  typedef std::unordered_map<std::string, channel_ptr_t> channel_map_t;
92 
93  class ChannelSet {
94  public:
95  ChannelSet(Context* context);
96  ~ChannelSet();
97 
98  ChannelSet& operator=(const ChannelSet &) = delete;
99  ChannelSet& operator=(ChannelSet &&) = delete;
100 
101  channel_ptr_t create(const xml::Channel* configuration);
102 
103  channel_ptr_t get(std::string str_name);
104  channel_list_t find(std::string str_regex);
105 
106  channel_map_t& channels() { return _channels; }
107  uint32_t size() const { return _channels.size(); }
108 
109  private:
110  Context* _context;
111  channel_map_t _channels;
112  };
113 
114 }
115 
116 #endif
Definition: ed247_channel.h:41
Definition: ed247_sample.h:14
Definition: ed247_channel.h:93
Definition: ed247_frame_header.h:9
ed247_standard_t
ED247 Standard revisions.
Definition: ed247.h:104
Definition: ed247_channel.h:34
Definition: ed247_stream.h:34
Definition: ed247_context.h:36
Definition: ed247_xml.h:252
Definition: ed247_channel.cpp:37
Definition: ed247_channel.h:35
Definition: ed247_cominterface.h:171