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

Last change on this file since 2488 was 2488, checked in by stud-tollenaere, 16 years ago

Added a test for openssl library

File size: 4.1 KB
Line 
1// [Licence]
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// [Licence]
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 SystemEventListener;
52
53class SystemEvent {
54 friend class SystemQueue;
55
56private:
57 ptime scheduledTime; //< time the event was originally given to the queue
58 uint32_t delayTime; //< time the event is scheduled at, or 0 if it is to be fired immediately
59 uint32_t remainingDelay; //< remaining delay time for sleeping
60
61 SystemEventListener* listener; //< handler of the event
62 SystemEventType type; //< type of the event
63 const void* data; //< data attached to the event
64
65public:
66 inline SystemEvent(
67 SystemEventListener* mlistener,
68 SystemEventType mtype = SystemEventType::DEFAULT,
69 void* mdata = NULL)
70 : scheduledTime(boost::posix_time::not_a_date_time),
71 delayTime(0),
72 remainingDelay(0),
73 listener(mlistener),
74 type(mtype),
75 data(mdata) {
76 }
77
78 template<typename T>
79 inline SystemEvent( SystemEventListener* mlistener,
80 SystemEventType mtype = SystemEventType::DEFAULT,
81 T* mdata = NULL)
82 : scheduledTime(boost::posix_time::not_a_date_time),
83 delayTime(0),
84 remainingDelay(0),
85 listener(mlistener),
86 type(mtype),
87 data((void*)mdata) {
88 }
89
90
91
92 inline SystemEvent(const SystemEvent& copy) {
93 this->scheduledTime = copy.scheduledTime;
94 this->delayTime = copy.delayTime;
95 this->remainingDelay = copy.remainingDelay;
96 this->listener = copy.listener;
97 this->type = copy.type;
98 this->data = copy.data;
99 }
100
101 inline void operator=(const SystemEvent& right) {
102 this->scheduledTime = right.scheduledTime;
103 this->delayTime = right.delayTime;
104 this->remainingDelay = right.remainingDelay;
105 this->listener = right.listener;
106 this->type = right.type;
107 this->data = right.data;
108 }
109
110 inline ~SystemEvent() {
111 }
112
113 template<typename T>
114 inline operator T() const {
115 return (T) (data);
116 }
117
118 inline const SystemEventListener* getListener() const {
119 return listener;
120 }
121
122 template<typename T>
123 inline T* getData() const {
124 return (T*)*this;
125 }
126
127 inline const SystemEventType getType() const {
128 return type;
129 }
130
131 inline const ptime getScheduledTime() const {
132 return scheduledTime;
133 }
134
135 inline const uint32_t getRemainingDelay() const {
136 return remainingDelay;
137 }
138
139 inline bool operator<(const SystemEvent& right) const {
140 return remainingDelay < right.remainingDelay;
141 }
142
143};
144
145}} // spovnet, common
146
147#endif /* SYSTEMEVENT_H_ */
Note: See TracBrowser for help on using the repository browser.