-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScanner.cc
More file actions
45 lines (38 loc) · 1.54 KB
/
Scanner.cc
File metadata and controls
45 lines (38 loc) · 1.54 KB
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
#include "Scanner.h"
#include "Job_m.h"
Define_Module(Scanner);
Scanner::Scanner() {
sendEvent = nullptr;
}
Scanner::~Scanner() {
cancelAndDelete(sendEvent);
}
void Scanner::initialize() {
numJobsCreated = 0;
sendEvent = new cMessage("sendJob");
jobCreatedSignal = registerSignal("messagesCreatedCount");
collector = check_and_cast<StatsCollector*>(getModuleByPath("statsCollector")); // initialize pointer to statistics collection module
scheduleAt(simTime() + par("interArrivalTime").doubleValue(), sendEvent);
updateDisplay();
}
void Scanner::handleMessage(cMessage *msg) {
if (msg == sendEvent) {
Job *job = new Job(("msg-" + std::to_string(numJobsCreated)).c_str());
job->setStartTime(simTime()); // Store the initialization time of the job into it
send(job, "out",0);
numJobsCreated++;
emit(jobCreatedSignal, numJobsCreated); //emit number of individual jobs created
collector->collectGeneratedJobs(1); // increment overall generated jobs counter
scheduleAt(simTime() + par("interArrivalTime").doubleValue(), sendEvent); //next time we create a message will take interArrivalTime
updateDisplay();
}
}
void Scanner::updateDisplay() {
if (hasGUI()) {
char buf[64];
sprintf(buf, "Jobs created: %d", numJobsCreated);
getDisplayString().setTagArg("t", 0, buf); // tag "t" is for text
getDisplayString().setTagArg("t", 1, "above"); // position above
getDisplayString().setTagArg("t", 2, "darkblue"); // text color
}
}