forked from NarkisShallev/FlightSimulator-Interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenDataServerCommand.cpp
More file actions
61 lines (51 loc) · 2.01 KB
/
OpenDataServerCommand.cpp
File metadata and controls
61 lines (51 loc) · 2.01 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <regex>
#include "OpenDataServerCommand.h"
#include "DataCommands.h"
#include "DataReaderServer.h"
#include "ExpressionUtils.h"
#include <pthread.h>
OpenDataServerCommand::OpenDataServerCommand(DataCommands *dataCommands, DataBinds *dataBinds, DataVars *dataVars,
pthread_mutex_t &mutex) {
this->dataCommands = dataCommands;
this->dataBinds = dataBinds;
this->dataVars = dataVars;
this->mutex = mutex;
}
void OpenDataServerCommand::doCommand() {
// get the index from dataCommands
unsigned long index = this->dataCommands->getIndex();
// skip the command
index++;
ExpressionUtils expUtils;
// get the port from the vector in dataCommands
string portStr = this->dataCommands->getSeparated().at(index);
// skip the port
index++;
int port = static_cast<int>(expUtils.calculateInfixStr(portStr, this->dataVars->getSymbolTable()));
// get the perSec from the vector in dataCommands
string perSecStr = this->dataCommands->getSeparated().at(index);
// skip the perSec
index++;
int perSec = static_cast<int>(expUtils.calculateInfixStr(perSecStr, this->dataVars->getSymbolTable()));
// create a struct of the thread params
struct Params *params;
params = new Params();
this->deathMap2.push_back(params);
DataReaderServer* temp;
temp = new DataReaderServer(port, perSec, this->dataBinds, this->dataVars, this->mutex);
// put values into the params
params->dataReaderServer = temp;
this->deathMap1.push_back(temp);
pthread_t tId;
// Launch a thread
pthread_create(&tId, nullptr, openServer_thread_callback, params);
// set the new index of dataCommands
this->dataCommands->setIndex(index);
}
void *OpenDataServerCommand::openServer_thread_callback(void *params) {
DataReaderServer *dataReaderServer;
dataReaderServer = static_cast<Params *>(params)->dataReaderServer;
dataReaderServer->openServer();
delete static_cast<Params *>(params);
return nullptr;
}