1 | #ifndef PACPUS_EVENT_H
|
---|
2 | #define PACPUS_EVENT_H
|
---|
3 |
|
---|
4 | #include <QEvent>
|
---|
5 | #include "Pacpus/kernel/road_time.h"
|
---|
6 | #include <Pacpus/kernel/pacpus.h>
|
---|
7 | #include <QDataStream>
|
---|
8 |
|
---|
9 | namespace pacpus {
|
---|
10 |
|
---|
11 | // registerEventType // TODO
|
---|
12 |
|
---|
13 | class GenericData {
|
---|
14 | public:
|
---|
15 | GenericData(char* data, size_t size) {
|
---|
16 | data_ = (char*)malloc(size);
|
---|
17 | memcpy(data_,data,size);
|
---|
18 | _size = size;}
|
---|
19 |
|
---|
20 | ~GenericData() {free(data_);}
|
---|
21 |
|
---|
22 | char * data() { return data_;}
|
---|
23 | size_t size() {return _size;}
|
---|
24 |
|
---|
25 | private:
|
---|
26 | char* data_;
|
---|
27 | size_t _size;
|
---|
28 | };
|
---|
29 |
|
---|
30 | enum PacpusEventType {
|
---|
31 | TYPED_EVENT = 1000,
|
---|
32 | GENERIC_EVENT = 2000,
|
---|
33 | GENERIC_EVENT2 = 2002,
|
---|
34 | GENERIC_EVENT3 = 2003,
|
---|
35 | CONFIG_EVENT = 3000
|
---|
36 | };
|
---|
37 |
|
---|
38 | class PACPUSLIB_API PacpusEvent
|
---|
39 | : public QEvent
|
---|
40 | {
|
---|
41 | Q_GADGET // permits to use signals and slots (using Q_SIGNAL, Q_SLOT) without inheriting from QObject
|
---|
42 |
|
---|
43 | public:
|
---|
44 | PacpusEvent(PacpusEventType type, road_time_t t = road_time(), road_timerange_t tr = 0):QEvent(QEvent::Type(type)),t_(t),tr_(tr) {}
|
---|
45 | virtual ~PacpusEvent() {}
|
---|
46 |
|
---|
47 | virtual QDataStream& streamOut(QDataStream& out) {return out;}; // NOTE virtual pure ??
|
---|
48 | virtual QDataStream& streamIn(QDataStream& in) {return in;};
|
---|
49 |
|
---|
50 | public: // TODO make protected
|
---|
51 | road_time_t t_;
|
---|
52 | road_timerange_t tr_;
|
---|
53 | };
|
---|
54 |
|
---|
55 | template<class T>
|
---|
56 | class PacpusTypedEvent : public PacpusEvent
|
---|
57 | {
|
---|
58 | public:
|
---|
59 | PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),data_(data) {}
|
---|
60 | ~PacpusTypedEvent() {}
|
---|
61 |
|
---|
62 | QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<<data_*/;} // FIXME Stream Data errors
|
---|
63 | QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> data_*/;}
|
---|
64 |
|
---|
65 | public: // TODO make protected
|
---|
66 | T data_;
|
---|
67 | };
|
---|
68 |
|
---|
69 | class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
|
---|
70 | {
|
---|
71 | public:
|
---|
72 | PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) {
|
---|
73 | data_ = (char*)malloc(size);
|
---|
74 | memcpy(data_,data,size);
|
---|
75 | _size = size;
|
---|
76 |
|
---|
77 | }
|
---|
78 | virtual ~PacpusGenericEvent() {free(data_);}
|
---|
79 | char* data_;
|
---|
80 | size_t _size;
|
---|
81 | };
|
---|
82 |
|
---|
83 |
|
---|
84 | } // namespace pacpus
|
---|
85 |
|
---|
86 | inline QDataStream& operator << (QDataStream& out, pacpus::PacpusEvent& ev) {/*return ev.streamOut(out);*/ return out;}
|
---|
87 | inline QDataStream& operator >> (QDataStream& in, pacpus::PacpusEvent& ev) {/*return ev.streamIn(in);*/ return in;}
|
---|
88 |
|
---|
89 | #endif // PACPUS_EVENT_H
|
---|