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

Last change on this file since 124 was 110, checked in by morasjul, 11 years ago

Beta-2 : Fix CMakeList (link), remove useless code and add improvement

  • Property svn:executable set to *
File size: 2.2 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 : public QEvent
39{
40public:
41 PacpusEvent(PacpusEventType type, road_time_t t = road_time(), road_timerange_t tr = 0):QEvent(QEvent::Type(type)),t_(t),tr_(tr) {}
42 virtual ~PacpusEvent() {}
43
44 virtual QDataStream& streamOut(QDataStream& out) {return out;}; // NOTE virtual pure ??
45 virtual QDataStream& streamIn(QDataStream& in) {return in;};
46
47public: // TODO make protected
48 road_time_t t_;
49 road_timerange_t tr_;
50};
51
52template<class T>
53class PacpusTypedEvent : public PacpusEvent
54{
55public:
56 PacpusTypedEvent(PacpusEventType type, T data = T(), road_time_t t = road_time(), road_timerange_t tr = 0 ):PacpusEvent(type, t, tr),data_(data) {}
57 ~PacpusTypedEvent() {}
58
59 QDataStream& streamOut(QDataStream& out) {return out << (quint64)t_ << tr_ /*<<data_*/;} // FIXME Stream Data errors
60 QDataStream& streamIn(QDataStream& in) {return in >> (quint64&)t_ >> tr_ /*>> data_*/;}
61
62public: // TODO make protected
63 T data_;
64};
65
66class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
67{
68public:
69 PacpusGenericEvent(PacpusEventType type, char* data, size_t size):PacpusEvent(type) {
70 data_ = (char*)malloc(size);
71 memcpy(data_,data,size);
72 _size = size;
73
74 }
75 virtual ~PacpusGenericEvent() {free(data_);}
76 char* data_;
77 size_t _size;
78};
79
80
81} // namespace pacpus
82
83inline QDataStream& operator << (QDataStream& out, pacpus::PacpusEvent& ev) {/*return ev.streamOut(out);*/ return out;}
84inline QDataStream& operator >> (QDataStream& in, pacpus::PacpusEvent& ev) {/*return ev.streamIn(in);*/ return in;}
85
86#endif // PACPUS_EVENT_H
Note: See TracBrowser for help on using the repository browser.