-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConnectCommand.cpp
More file actions
59 lines (50 loc) · 1.84 KB
/
ConnectCommand.cpp
File metadata and controls
59 lines (50 loc) · 1.84 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
#include <regex>
#include "ConnectCommand.h"
#include "DataCommands.h"
#include "DataWriterClient.h"
#include "ExpressionUtils.h"
#include <pthread.h>
ConnectCommand::ConnectCommand(DataCommands *dataCommands, DataBinds *dataBinds, DataVars *dataVars,
pthread_mutex_t &mutex) {
this->dataCommands = dataCommands;
this->dataBinds = dataBinds;
this->dataVars = dataVars;
this->mutex = mutex;
}
void ConnectCommand::doCommand() {
// get the index from dataCommands
unsigned long index = this->dataCommands->getIndex();
// skip the command
index++;
// get the ip from the vector in dataCommands
string ip = this->dataCommands->getSeparated().at(index);
// skip the ip
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()));
// create a struct of the thread params
struct Params *params;
params = new Params();
this->deathMap2.push_back(params);
// put values into the params
DataWriterClient* temp;
temp = new DataWriterClient(ip, port, this->dataBinds, this->dataVars, this->mutex);
params->dataWriterClient = temp;
this->deathMap1.push_back(temp);
pthread_t tId;
// Launch a thread
pthread_create(&tId, nullptr, openClient_thread_callback, params);
// set the new index of dataCommands
this->dataCommands->setIndex(index);
}
void *ConnectCommand::openClient_thread_callback(void *params) {
DataWriterClient *dataWriterClient;
dataWriterClient = static_cast<Params *>(params)->dataWriterClient;
dataWriterClient->openClient();
delete static_cast<Params *>(params);
return nullptr;
}