source: source/ariba/utility/system/SystemEvent.h@ 12764

Last change on this file since 12764 was 12764, checked in by hock@…, 10 years ago

New SystemQueue...

... is passing all unit tests, now. :-)

File size: 4.7 KB
Line 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#ifndef SYSTEMEVENT_H_
40#define SYSTEMEVENT_H_
41
42#include <boost/date_time.hpp>
43#include <iostream>
44#include "SystemEventType.h"
45
46using boost::posix_time::ptime;
47
48namespace ariba {
49namespace utility {
50
51class SystemQueue;
52class SystemEventListener;
53
54class SystemEvent {
55 friend class SystemQueue;
56private:
57 SystemEventListener* listener; //< handler of the event
58 SystemEventType type; //< type of the event
59 const void* data; //< data attached to the event
60
61public:
62 // TODO: these should be private, but the gcc 3.4 in scratchbox for cross-compiling
63 // for Maemo (Nokia N810) gets confused when the friend class SystemQueue has a
64 // private class that accesses these variables. Therefore they are public for now.
65 ptime scheduledTime; //< time the event was originally given to the queue
66 ptime deadline; //< time when the event should be executed TODO Mario
67 uint32_t delayTime; //< time the event is scheduled at, or 0 if it is to be fired immediately
68 uint32_t remainingDelay; //< remaining delay time for sleeping
69
70public:
71 inline SystemEvent(SystemEventListener* mlistener, SystemEventType mtype =
72 SystemEventType::DEFAULT, void* mdata = NULL) :
73 listener(mlistener),
74 type(mtype),
75 data(mdata),
76 scheduledTime(boost::posix_time::not_a_date_time),
77 deadline(boost::posix_time::not_a_date_time),
78 delayTime(0),
79 remainingDelay(0)
80 {
81 }
82
83 template<typename T>
84 inline SystemEvent(SystemEventListener* mlistener, SystemEventType mtype =
85 SystemEventType::DEFAULT, T* mdata = NULL) :
86 listener(mlistener),
87 type(mtype),
88 data((void*) mdata),
89 scheduledTime(boost::posix_time::not_a_date_time),
90 deadline(boost::posix_time::not_a_date_time),
91 delayTime(0),
92 remainingDelay(0) {
93 }
94
95 inline SystemEvent(const SystemEvent& copy) {
96 this->scheduledTime = copy.scheduledTime;
97 this->deadline = copy.deadline;
98 this->delayTime = copy.delayTime;
99 this->remainingDelay = copy.remainingDelay;
100 this->listener = copy.listener;
101 this->type = copy.type;
102 this->data = copy.data;
103 }
104
105 inline void operator=(const SystemEvent& right) {
106 this->scheduledTime = right.scheduledTime;
107 this->deadline = right.deadline;
108 this->delayTime = right.delayTime;
109 this->remainingDelay = right.remainingDelay;
110 this->listener = right.listener;
111 this->type = right.type;
112 this->data = right.data;
113 }
114
115 inline ~SystemEvent() {
116 }
117
118 template<typename T>
119 inline operator T() const {
120 return (T) (data);
121 }
122
123 inline SystemEventListener* getListener() const {
124 return listener;
125 }
126
127 template<typename T>
128 inline T* getData() const {
129 return (T*) *this;
130 }
131
132 inline const SystemEventType getType() const {
133 return type;
134 }
135
136 inline const ptime getScheduledTime() const {
137 return scheduledTime;
138 }
139
140 inline const uint32_t getRemainingDelay() const {
141 return remainingDelay;
142 }
143
144 bool operator<(const SystemEvent& right) const
145 {
146 return this->deadline < right.deadline;
147 }
148
149 bool operator>(const SystemEvent& right) const
150 {
151 return this->deadline > right.deadline;
152 }
153
154};
155
156}
157} // spovnet, common
158
159#endif /* SYSTEMEVENT_H_ */
Note: See TracBrowser for help on using the repository browser.