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

Last change on this file since 105 was 98, checked in by morasjul, 11 years ago

2.0 windows fix

  • 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
11class GenericData {
12public:
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
23private:
24char* _data;
25size_t _size;
26};
27
28enum PacpusEventType {
29 TYPED_EVENT = 1000,
30 GENERIC_EVENT = 2000,
31 GENERIC_EVENT2 = 2002,
32 GENERIC_EVENT3 = 2003,
33 CONFIG_EVENT = 3000
34};
35
36class PACPUSLIB_API PacpusEvent : public QEvent
37{
38public:
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
45public: // TODO make protected
46 road_time_t t_;
47 road_timerange_t tr_;
48};
49
50template<class T>
51class PacpusTypedEvent : public PacpusEvent
52{
53public:
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
60public: // TODO make protected
61 T _data;
62};
63
64inline QDataStream& operator << (QDataStream& out, PacpusEvent& ev) {return ev.streamOut(out);}
65inline QDataStream& operator >> (QDataStream& in, PacpusEvent& ev) {return ev.streamIn(in);}
66
67class PACPUSLIB_API PacpusGenericEvent : public PacpusEvent
68{
69public:
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
Note: See TracBrowser for help on using the repository browser.