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 | class GenericData {
|
---|
12 | public:
|
---|
13 | GenericData(char* data, size_t size) {
|
---|
14 | _data = (char*)malloc(size);
|
---|
15 | memcpy(_data,data,size);
|
---|
16 | _size = size;}
|
---|
17 |
|
---|
18 | ~GenericData() {free(_data);}
|
---|
19 |
|
---|
20 | char * data() { return _data;}
|
---|
21 | size_t size() {return _size;}
|
---|
22 |
|
---|
23 | private:
|
---|
24 | char* _data;
|
---|
25 | size_t _size;
|
---|
26 | };
|
---|
27 |
|
---|
28 | enum PacpusEventType {
|
---|
29 | TYPED_EVENT = 1000,
|
---|
30 | GENERIC_EVENT = 2000,
|
---|
31 | GENERIC_EVENT2 = 2002,
|
---|
32 | GENERIC_EVENT3 = 2003,
|
---|
33 | CONFIG_EVENT = 3000
|
---|
34 | };
|
---|
35 |
|
---|
36 | class PACPUSLIB_API PacpusEvent : public QEvent
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | PacpusEvent(PacpusEventType type, road_time_t t = road_time(), road_timerange_t tr = 0):QEvent(QEvent::Type(type)),t_(t),tr_(tr) {}
|
---|
40 | virtual ~PacpusEvent() {}
|
---|
41 |
|
---|
42 | virtual QDataStream& streamOut(QDataStream& out) {return out;}; // NOTE virtual pure ??
|
---|
43 | virtual QDataStream& streamIn(QDataStream& in) {return in;};
|
---|
44 |
|
---|
45 | public: // TODO make protected
|
---|
46 | road_time_t t_;
|
---|
47 | road_timerange_t tr_;
|
---|
48 | };
|
---|
49 |
|
---|
50 | template<class T>
|
---|
51 | class PacpusTypedEvent : public PacpusEvent
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),_data(data) {}
|
---|
55 | ~PacpusTypedEvent() {}
|
---|
56 |
|
---|
57 | QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<<_data*/;} // FIXME Stream Data errors
|
---|
58 | QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> _data*/;}
|
---|
59 |
|
---|
60 | public: // TODO make protected
|
---|
61 | T _data;
|
---|
62 | };
|
---|
63 |
|
---|
64 | inline QDataStream& operator << (QDataStream& out, PacpusEvent& ev) {return ev.streamOut(out);}
|
---|
65 | inline QDataStream& operator >> (QDataStream& in, PacpusEvent& ev) {return ev.streamIn(in);}
|
---|
66 |
|
---|
67 | class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
|
---|
68 | {
|
---|
69 | public:
|
---|
70 | PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) {
|
---|
71 | _data = (char*)malloc(size);
|
---|
72 | memcpy(_data,data,size);
|
---|
73 | _size = size;
|
---|
74 |
|
---|
75 | }
|
---|
76 | virtual ~PacpusGenericEvent() {free(_data);}
|
---|
77 | char* _data;
|
---|
78 | size_t _size;
|
---|
79 | };
|
---|
80 |
|
---|
81 |
|
---|
82 | } // namespace pacpus
|
---|
83 |
|
---|
84 | #endif // PACPUS_EVENT_H
|
---|