-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.cpp
123 lines (108 loc) · 3.25 KB
/
task.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
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
/*
* task.cpp
*
* \date 14/mag/2010
* \author Daniele De Sensi ([email protected])
* =========================================================================
* Copyright (C) 2010-2014, Daniele De Sensi ([email protected])
*
* This file is part of ffProbe.
*
* ffProbe is free software: you can redistribute it and/or
* modify it under the terms of the Lesser GNU General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
* ffProbe 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
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the Lesser GNU General Public
* License along with ffProbe.
* If not, see <http://www.gnu.org/licenses/>.
*
* =========================================================================
*
* This file contains the definition of the task passed by the stages of the pipeline.
*/
#include "task.hpp"
/**
* Constructor of the task.
* \param numWorkers Number of workers of the pipeline.
*/
Task::Task(uint numWorkers):numWorkers(numWorkers),eof(false){
flowsToAdd=new ff::squeue<hashElement>*[numWorkers];
for(uint i=0; i<numWorkers; i++)
flowsToAdd[i]=new ff::squeue<hashElement>;
flowsToExport=new ff::squeue<hashElement>;
}
/**
* Denstructor of the task.
*/
Task::~Task(){
if(flowsToExport!=NULL) delete flowsToExport;
if(flowsToAdd!=NULL){
for(uint i=0; i<numWorkers; i++)
delete flowsToAdd[i];
delete[] flowsToAdd;
}
}
/**
* Sets the timestamp of the task.
* \param t The timestamp.
*/
void Task::setTimestamp(time_t t){
timestamp=t;
}
/**
* Returns the timestamp of the task.
* \return The timestamp of the task.
*/
time_t Task::getTimestamp(){
return timestamp;
}
/**
* Adds an hashElement to the list of flows to export.
* \param h The hashElement.
*/
void Task::addFlowToExport(hashElement& h){
flowsToExport->push_back(h);
}
/**
* Returns a pointer to the list of flows to export.
* \return A pointer to the list of flows to export.
*/
ff::squeue<hashElement>* Task::getFlowsToExport(){
return flowsToExport;
}
/**
* Returns a pointer to the list of the flows to add.
* \return A pointer to the list of the flows to add.
*/
ff::squeue<hashElement>* Task::getFlowsToAdd(const int i){
return flowsToAdd[i];
}
/**
* Adds the hashElement h for the i-th worker.
* \param h The hashElement to add.
* \param i The worker that have to add the flow.
*/
void Task::setFlowToAdd(hashElement& h, const int i){
flowsToAdd[i]->push_back(h);
}
/**Sets EOF. **/
void Task::setEof(){eof=true;}
/**Resets EOF.**/
void Task::resetEof(){eof=false;}
/**
* Returns true if EOF of a .pcap file is arrived.
* \return True if EOF is arrived, otherwise returns false.
*/
bool Task::isEof(){return eof;}
/**
* Returns the number of workers.
* \return The number of workers.
*/
int Task::getNumWorkers(){
return numWorkers;
}