source: pacpusframework/branches/2.0-beta1/include/Pacpus/kernel/PacpusEvent.h@ 139

Last change on this file since 139 was 131, checked in by Marek Kurdej, 11 years ago

Update: using Q_GADGET instead of Q_OBJECT to have signals/slot support.

  • Property svn:executable set to *
File size: 2.3 KB
Line 
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
9namespace pacpus {
10
11// registerEventType // TODO
12
13class GenericData {
14public:
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
25private:
26char* data_;
27size_t _size;
28};
29
30enum PacpusEventType {
31 TYPED_EVENT = 1000,
32 GENERIC_EVENT = 2000,
33 GENERIC_EVENT2 = 2002,
34 GENERIC_EVENT3 = 2003,
35 CONFIG_EVENT = 3000
36};
37
38class 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
43public:
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
50public: // TODO make protected
51 road_time_t t_;
52 road_timerange_t tr_;
53};
54
55template<class T>
56class PacpusTypedEvent : public PacpusEvent
57{
58public:
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
65public: // TODO make protected
66 T data_;
67};
68
69class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
70{
71public:
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
86inline QDataStream& operator << (QDataStream& out, pacpus::PacpusEvent& ev) {/*return ev.streamOut(out);*/ return out;}
87inline QDataStream& operator >> (QDataStream& in, pacpus::PacpusEvent& ev) {/*return ev.streamIn(in);*/ return in;}
88
89#endif // PACPUS_EVENT_H
Note: See TracBrowser for help on using the repository browser.