VPTissue Reference Manual
NodeProtocol.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 "NodeProtocol.h"
21 
22 #include "SimResult.h"
23 #include "SimTask.h"
24 
25 using boost::property_tree::ptree;
26 
27 namespace SimPT_Parex {
28 
29 NodeProtocol::NodeProtocol(QTcpSocket *s, QObject *parent)
30  : Protocol(s, parent)
31 {
32 }
33 
35 {
36 }
37 
39 {
40  ptree writer;
41  writer.put("SimResult.Exploration", result.GetExplorationName());
42  writer.put("SimResult.Id", result.GetTaskId());
43  writer.put("SimResult.Success", static_cast<int>(result.GetResult()));
44 
45  SendPtree(writer);
46 }
47 
48 void NodeProtocol::ReceivePtree(const ptree &reader)
49 {
50  if (reader.find("SimTask") != reader.not_found()) {
51  int task_id = reader.get<int>("SimTask.Id");
52  std::string tree = reader.get<std::string>("SimTask.Tree");
53  std::string workspace = reader.get<std::string>("SimTask.Workspace");
54  std::string name = reader.get<std::string>("SimTask.Exploration");
55 
56  emit TaskReceived(new SimTask(task_id, tree, workspace, name));
57  } else if (reader.find("SimResult") != reader.not_found()) {
58  std::string tree = reader.get<std::string>("SimResult.Ack");
59  emit SuccessfullySent();
60  } else if (reader.find("Control") != reader.not_found()) {
61  ptree control_pt = reader.get_child("Control");
62  if (control_pt.find("Stop") != control_pt.not_found()) {
63  emit StopTask();
64  } else if (control_pt.find("Delete") != control_pt.not_found()){
65  std::string name = control_pt.get<std::string>("Delete");
66  emit Delete(name);
67  }
68  }
69 }
70 
71 } // namespace
Base class for the XML/ptree protocols between client, server and node.
Definition: Protocol.h:35
void Delete(const std::string &name) const
Emitted to indicate an exploration must be deleted from the disk.
void StopTask() const
Emitted to indicate the current task must be stopped.
virtual ~NodeProtocol()
Destructor.
A container class for the final result of a simulation.
Definition: SimResult.h:29
void SendPtree(const boost::property_tree::ptree &pt)
Sends a ptree over the connection.
Definition: Protocol.cpp:78
int GetTaskId() const
Return the id of the finished task.
Definition: SimResult.h:50
ResultType GetResult() const
Check if the simulation was successfully completed.
Definition: SimResult.h:53
void SendSimResult(const SimResult &result)
Sends the result of a simulation back to the server.
void TaskReceived(const SimTask *task) const
Signal emitted when a SimTask is received.
Interface for SimResult.
std::string GetExplorationName() const
Returns the name of the exploration of the finished task.
Definition: SimResult.h:47
Interface for NodeProtocol.
virtual void ReceivePtree(const boost::property_tree::ptree &reader)
Receive a ptree message (implementats Protocol::ReceivePtree).
Interface for SimTask.
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
NodeProtocol(QTcpSocket *socket, QObject *parent=0)
Constructor.
Contains all information needed for a transmitable simulation task.
Definition: SimTask.h:31
void SuccessfullySent() const
Signal emitted when a SimTask is successfully sent.
see the online Qt documentation