-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path005_observ_application.h
executable file
·155 lines (118 loc) · 3.95 KB
/
005_observ_application.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* File Name : 005_observ_application.h
* Functionality :
* Copyright (C) 2012 Divyang Patel
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _005_OBSERV_APPLICATION_H_
#define _005_OBSERV_APPLICATION_H_
// Event types
#define APP_EVENT_TYPE 111
#define SYS_EVENT_TYPE 112
#include <iostream>
#include <string>
#include <list>
using namespace std;
class IClient;
// Event framework base class aka ServerEvents
class ServerEvents
{
public:
ServerEvents(string ServerIP):m_ServerIP(ServerIP){}
ServerEvents(unsigned int eventID):m_EventID(eventID){}
// Pure virtual dtor will make sure that all derived classes
// implement the respective dtor.
// And yes, pure virtual dtor can have implementation.
virtual ~ServerEvents()=0;
unsigned int getEventID(){ return m_EventID; }
void Attach(IClient* clt);
void Detach(IClient* clt);
// We pass EventType for respective subject
void Notify(const int& EventType);
// These methods are not supposed to be called by ServerEvents object.
// They are here for just to provide virtual inheritance for derived classes.
// Methods for AppEvent class
virtual unsigned int GetAppID(){return 0;}
virtual string GetAppName(){return 0;}
virtual string GetAppVersion(){return 0;}
// Methods for SysEvent class
virtual int GetDiskSpace(){ return 0; }
virtual int GetMemoryUsage(){ return 0; }
virtual int GetTemperature(){ return 0; }
protected:
// Protected ctor will make this class abstract.
// But still accessible by derived class for inheritance.
ServerEvents(){}
private:
unsigned int m_EventID;
string m_ServerIP;
list<IClient*> m_cltList;
};
// First event type is application event.
// Whenever any application version changes, this event is raised.
// And all the observers of this event will be notified.
class AppEvent : public ServerEvents
{
public:
// This ctor will still call default ctor of base class
// i.e. ServerEvents(). That's why we made ServerEvents() protected...
// Same applies for all the derived classes.
AppEvent(const unsigned int eventID,
const unsigned int appID,
const string appName,
const string appVersion)
: ServerEvents(eventID)
, m_appID(appID)
, m_appName(appName)
, m_appVersion(appVersion)
{
#ifdef DEBUG
cout << "New AppEvent with Event ID " << getEventID() << " registered. " << endl;
#endif
}
~AppEvent();
unsigned int GetAppID();
string GetAppName();
string GetAppVersion();
void ChangeVersion(string&);
private:
unsigned int m_appID;
string m_appName;
string m_appVersion;
};
class SysEvent : public ServerEvents
{
public:
SysEvent(const unsigned int eventID,
const int ds,
const int mu,
const int tem)
: ServerEvents(eventID)
, m_diskSpace(ds)
, m_memoryUsage(mu)
, m_temperature(tem)
{
#ifdef DEBUG
cout << "New SysEvent with Event ID " << getEventID() << " registered." << endl;
#endif
}
~SysEvent();
int GetDiskSpace();
int GetMemoryUsage();
int GetTemperature();
void ChangeDiskSpace(const int&);
private:
int m_diskSpace; // In percentile
int m_memoryUsage; // In Percentile
int m_temperature; // In Celsius
};
#endif //_005_OBSERV_APPLICATION_H_