-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosableFacilityTest.cpp
55 lines (45 loc) · 1.04 KB
/
closableFacilityTest.cpp
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
//
// Created by david on 25.11.16.
//
#include <iostream>
#include "simlib.h"
#include "ClosableFacility.h"
#include "FacilityNotOpenException.h"
class MyCondition : public ClosableFacilityCondition {
virtual bool closingCondition(ClosableFacility * fac){
return true;
}
};
ClosableFacility fac(new MyCondition());
class MyProc : public Process{
void Behavior(){
Seize(fac);
Wait(Exponential(60));
Release(fac);
fac.close();
bool except = false;
try {
Seize(fac);
Wait(Exponential(60));
Release(fac);
} catch (FacilityNotOpenException & e){
except = true;
}
if(!except){
std::cerr << "Facility should not work now" << std::endl;
}
fac.open();
}
};
class Generator : public Event {
void Behavior() {
(new MyProc)->Activate();
Activate(Time + Exponential(30));
}
};
int main(void){
Init(0, 1000);
(new Generator)->Activate();
Run();
fac.Output();
}