messageparser_base.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QtPlugin>
4 #include <QApplication>
5 #include <array>
6 #include <unordered_map>
7 #include <unordered_set>
8 #include <functional>
9 #include <map>
10 #include <set>
11 #include "PlotJuggler/plotdata.h"
12 #include "PlotJuggler/pj_plugin.h"
13 
14 namespace PJ {
15 
16 /*
17  * A messgaeParser is a clas that is able to convert a message received by
18  * a DataStreamer plugin into data in PlotDataMapRef.
19  *
20  * - Each data Source has its own instance of MessageParser
21  * - MessageParser objects are created by MessageParserCreator.
22  * - The actual plugin created here is the MessageParserCreator.
23  * - Each DataStreamer plugin has its own set of MessageParserCreator
24  *
25  * */
26 
28 {
29 public:
30  explicit MessageRef(uint8_t* first_ptr, size_t size) :
31  _first_ptr(first_ptr), _size(size)
32  { }
33 
34  explicit MessageRef(std::vector<uint8_t>& vect) :
35  _first_ptr(vect.data()), _size(vect.size())
36  { }
37 
38  const uint8_t* data() const {
39  return _first_ptr;
40  }
41 
42  uint8_t* data() {
43  return _first_ptr;
44  }
45 
46  size_t size() const {
47  return _size;
48  }
49 
50 private:
51  uint8_t* _first_ptr;
52  size_t _size;
53 };
54 
65 {
66 public:
67  MessageParser(const std::string& topic_name,
68  PlotDataMapRef& plot_data): _plot_data(plot_data), _topic_name(topic_name)
69  { }
70  virtual ~MessageParser() = default;
71 
72  virtual bool parseMessage(const MessageRef serialized_msg,
73  double timestamp) = 0;
74 protected:
75 
77  std::string _topic_name;
78 
79  PlotData& getSeries(const std::string& key)
80  {
81  auto plot_pair = _plot_data.numeric.find(key);
82  if (plot_pair == _plot_data.numeric.end())
83  {
84  plot_pair = _plot_data.addNumeric(key);
85  }
86  return plot_pair->second;
87  }
88 };
89 
90 using MessageParserPtr = std::shared_ptr<MessageParser>;
91 
92 //------------- This is the actual plugin interface --------------
94 {
95 public:
96 
97  virtual MessageParserPtr createInstance(const std::string& topic_name, PlotDataMapRef& data) = 0;
98 };
99 //----------------------------------------------------------------
100 
101 using MessageParserFactory = std::map<QString, std::shared_ptr<MessageParserCreator>>;
102 
103 } // end namespace
104 
105 
106 QT_BEGIN_NAMESPACE
107 #define MessageParserCreator_iid "facontidavide.PlotJuggler3.MessageParserCreator"
109 QT_END_NAMESPACE
std::map< QString, std::shared_ptr< MessageParserCreator >> MessageParserFactory
MessageParser(const std::string &topic_name, PlotDataMapRef &plot_data)
const uint8_t * data() const
MessageRef(uint8_t *first_ptr, size_t size)
PlotDataMapRef & _plot_data
std::unordered_map< std::string, PlotData > numeric
Definition: plotdata.h:495
size_t size() const
MessageRef(std::vector< uint8_t > &vect)
std::shared_ptr< MessageParser > MessageParserPtr
#define MessageParserCreator_iid
std::unordered_map< std::string, PlotData >::iterator addNumeric(const std::string &name)
Definition: plotdata.h:498
The MessageParser is the base class to create plugins that are able to parse one or multiple Message ...
PlotData & getSeries(const std::string &key)
def timestamp()
Definition: mqttsas.py:143


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09