-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.h
94 lines (81 loc) · 2.27 KB
/
event.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// -*- C++ -*-
//
// Event and derived classes, interfaces.
//
// Copyright 1992-2021 Deven T. Corzine <[email protected]>
//
// SPDX-License-Identifier: MIT
//
// Check if previously included.
#ifndef _EVENT_H
#define _EVENT_H 1
// Types of Event subclasses.
enum EventType {
Unknown_Event, Shutdown_Event, Restart_Event, Login_Timeout_Event
};
class Event: public Object {
friend class EventQueue;
protected:
EventType type; // Event type.
Timestamp time; // Time event is scheduled for.
public:
Event(time_t when, EventType t): type(t), time(when) { } // Absolute time.
Event(EventType t, time_t when): type(t) { // Relative time.
Timestamp now;
time = now + when;
}
virtual ~Event() { } // destructor
virtual boolean Execute() { // Execute event, return true to reschedule.
abort(); return false;
}
EventType Type() { return type; }
time_t Time() { return time; }
void SetAbsTime(time_t when) { time = when; }
void SetRelTime(int when) { Timestamp now; time = now + when;
}
};
class ShutdownEvent: public Event {
protected:
boolean final;
public:
static const int FinalWarningTime = 3;
ShutdownEvent(char *by, time_t when): Event(Shutdown_Event, when) {
ShutdownWarning(by, when);
}
ShutdownEvent(char *by): Event(Shutdown_Event, 0) {
Log("Immediate shutdown requested by %s.", by);
FinalWarning();
}
boolean Execute();
void ShutdownWarning(char *by, time_t when);
void FinalWarning();
void ShutdownServer();
};
class RestartEvent: public Event {
protected:
boolean final;
public:
static const int FinalWarningTime = 3;
RestartEvent(char *by, time_t when): Event(Restart_Event, when) {
RestartWarning(by, when);
}
RestartEvent(char *by): Event(Restart_Event, 0) {
Log("Immediate restart requested by %s.", by);
FinalWarning();
}
boolean Execute();
void RestartWarning(char *by, time_t when);
void FinalWarning();
void RestartServer();
};
class LoginTimeoutEvent: public Event {
protected:
Pointer<Telnet> telnet;
public:
LoginTimeoutEvent(Telnet *t, time_t when):
Event(Login_Timeout_Event, when) {
telnet = t;
}
boolean Execute();
};
#endif // event.h