VPTissue Reference Manual
ServerNodeProtocol.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "ServerNodeProtocol.h"
21 
22 namespace SimPT_Parex {
23 
24 using boost::property_tree::ptree;
25 
26 ServerNodeProtocol::ServerNodeProtocol(QTcpSocket *socket, QObject *parent)
27  : Protocol(socket, parent)
28 {
29 }
30 
31 ServerNodeProtocol::~ServerNodeProtocol()
32 {
33 }
34 
36 {
37  ptree writer;
38  writer.put("SimResult.Ack", "");
39  SendPtree(writer);
40 }
41 
43 {
44  ptree writer;
45  writer.put("SimTask.Id", task.GetId());
46  writer.put("SimTask.Tree", task.ToString());
47  writer.put("SimTask.Workspace", task.WorkspaceToString());
48  writer.put("SimTask.Exploration", task.GetExploration());
49  SendPtree(writer);
50 }
51 
53 {
54  ptree writer;
55  writer.put("Control.Stop", "");
56  SendPtree(writer);
57 }
58 
59 void ServerNodeProtocol::Delete(const std::string &name)
60 {
61  ptree writer;
62  writer.put("Control.Delete", name);
63  SendPtree(writer);
64 }
65 
66 void ServerNodeProtocol::ReceivePtree(const boost::property_tree::ptree &reader)
67 {
68  if (reader.find("SimResult") != reader.not_found()) {
69  std::string exploration = reader.get<std::string>("SimResult.Exploration");
70  int task_id = reader.get<int>("SimResult.Id");
71  SimResult::ResultType success = static_cast<SimResult::ResultType>(reader.get<int>("SimResult.Success"));
72  SimResult result(exploration, task_id, success, this->GetClientIP(), this->GetClientPort());
73 
74  SendAck();
75 
76  emit ResultReceived(result);
77  }
78 }
79 
80 } // namespace
void StopTask()
Orders the node to stop its current task.
virtual void ReceivePtree(const boost::property_tree::ptree &reader)
Receive a ptree message (implements of Protocol::ReceivePtree).
A container class for the final result of a simulation.
Definition: SimResult.h:29
void SendTask(const SimTask &task)
Sends a task to the server.
void SendPtree(const boost::property_tree::ptree &pt)
Sends a ptree over the connection.
Definition: Protocol.cpp:78
std::string ToString() const
Get the simulation in string representation (ptree xml).
Definition: SimTask.cpp:91
void SendAck()
Sends an acknowledgment of a received result to the server.
void ResultReceived(const SimResult &result)
Signals emitted when a sim result was received.
Interface for ServerNodeProtocol.
std::string WorkspaceToString() const
Get the workspace settings in string representation (ptree xml).
Definition: SimTask.cpp:98
void Delete(const std::string &name)
Orders the node to delete all files it has for a certain exploration.
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
std::string GetExploration() const
Get the name of the exploration.
Definition: SimTask.cpp:71
Contains all information needed for a transmitable simulation task.
Definition: SimTask.h:31
int GetId() const
Get the id of the task in the exploration.
Definition: SimTask.cpp:76
see the online Qt documentation