Skip to content

Commit

Permalink
fix save
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca committed Mar 25, 2020
1 parent 9668791 commit e9c3c4f
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 53 deletions.
2 changes: 2 additions & 0 deletions src/diagnosticdaemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(DiagnosticDaemonSrc main.cpp
ComponentConsole.cpp
pugixml.cpp
Component.cpp
ComponentDisabled.cpp
ConfigurationDepot.cpp
Decoder.cpp
${EM_DIR}/embot/eprot/ROPstream.cpp
Expand All @@ -30,6 +31,7 @@ set(DiagnosticDaemonHdr ComponentUdp.h
ComponentFile.h
ComponentConsole.h
Component.h
ComponentDisabled.h
ConfigurationDepot.h
ElapsedTime.h
pugixml.hpp
Expand Down
11 changes: 1 addition & 10 deletions src/diagnosticdaemon/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <iostream>

Component::Component(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot):depot_(depot),parametersMap_(attributes),parameters_(pugi::xml_node())
Component::Component(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot):depot_(depot),parametersMap_(attributes)
{
name_=asString(confsintax::name,attributes);
protocol_=asString(confsintax::protocol,attributes);
Expand All @@ -18,15 +18,6 @@ Component::Component(const std::map<std::string,std::string>& attributes,Configu
destination_=asString(confsintax::destination,attributes);
}

Component::Component(const pugi::xml_node& node,ConfigurationDepot& depot):depot_(depot),parameters_(node)
{
name_=node.attribute(confsintax::name).value();
protocol_=node.attribute(confsintax::protocol).value();
mode_=node.attribute(confsintax::mode).value();
enable_=node.attribute(confsintax::enable).as_bool();
destination_=node.attribute(confsintax::destination).value();
}

const std::map<std::string,std::string> Component::getParameterMap() const
{
return parametersMap_;
Expand Down
4 changes: 1 addition & 3 deletions src/diagnosticdaemon/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ class Component
static constexpr unsigned int maxMsgLenght_{1500};
public:
Component(const std::map<std::string,std::string>& attributes,ConfigurationDepot&);
Component(const pugi::xml_node& node,ConfigurationDepot& depot);
virtual ~Component(){};

virtual void acceptMsg(std::array<uint8_t,maxMsgLenght_>& msg,unsigned int size,udp::endpoint senderEndPoint)=0;
std::string getName() const {return name_;};

const std::map<std::string,std::string> getParameterMap() const;

protected:

ConfigurationDepot& depot_;
const pugi::xml_node& parameters_;
const std::map<std::string,std::string> parametersMap_;

std::string name_;
Expand Down
6 changes: 0 additions & 6 deletions src/diagnosticdaemon/ComponentConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

#include "Decoder.h"

ComponentConsole::ComponentConsole(const pugi::xml_node& node,ConfigurationDepot& depot):Component(node,depot)
{
decoder_.init({});
thread_=std::make_unique<std::thread>(&ComponentConsole::inputLoop,this);
}

ComponentConsole::ComponentConsole(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot):Component(attributes,depot)
{
decoder_.init({});
Expand Down
1 change: 0 additions & 1 deletion src/diagnosticdaemon/ComponentConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
class ComponentConsole: public Component
{
public:
ComponentConsole(const pugi::xml_node& node,ConfigurationDepot&);
ComponentConsole(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot);
virtual ~ComponentConsole(){};

Expand Down
18 changes: 18 additions & 0 deletions src/diagnosticdaemon/ComponentDisabled.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2019 iCub Tech - Istituto Italiano di Tecnologia
* Author: Luca Tricerri
* email: luca.tricerri@iit.it
*/

#include "ComponentDisabled.h"
#include "ConfigurationDepot.h"
#include <iomanip>


ComponentDisabled::ComponentDisabled(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot):Component(attributes,depot)
{
}

void ComponentDisabled::acceptMsg(std::array<uint8_t,maxMsgLenght_>& msg,unsigned int size,udp::endpoint senderEndPoint)
{
}
28 changes: 28 additions & 0 deletions src/diagnosticdaemon/ComponentDisabled.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2019 iCub Tech - Istituto Italiano di Tecnologia
* Author: Luca Tricerri
* email: luca.tricerri@iit.it
*/

// - brief
// File component class
//

#pragma once

#include <iostream>
#include <fstream>
#include <memory>

#include "Component.h"

class ComponentDisabled: public Component
{
public:
ComponentDisabled(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot);
virtual ~ComponentDisabled(){};

void acceptMsg(std::array<uint8_t,maxMsgLenght_>& msg,unsigned int size,udp::endpoint senderEndPoint) override;
};

using ComponentDisabled_sptr=std::shared_ptr<ComponentDisabled>;
5 changes: 0 additions & 5 deletions src/diagnosticdaemon/ComponentFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#include "ConfigurationDepot.h"
#include <iomanip>

ComponentFile::ComponentFile(const pugi::xml_node& node,ConfigurationDepot& depot):Component(node,depot)
{
filename_=node.attribute(confsintax::value).value();
fstream_.open(filename_);
}

ComponentFile::ComponentFile(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot):Component(attributes,depot)
{
Expand Down
1 change: 0 additions & 1 deletion src/diagnosticdaemon/ComponentFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
class ComponentFile: public Component
{
public:
ComponentFile(const pugi::xml_node& node,ConfigurationDepot&);
ComponentFile(const std::map<std::string,std::string>& attributes,ConfigurationDepot& depot);
virtual ~ComponentFile(){};

Expand Down
22 changes: 0 additions & 22 deletions src/diagnosticdaemon/ComponentUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,6 @@

using namespace boost::asio;

ComponentUdp::ComponentUdp(boost::asio::io_service &ios,const pugi::xml_node& node,ConfigurationDepot& depot)
: Component(node,depot),
port_(node.attribute(confsintax::rxport).as_int()),
txport_(node.attribute(confsintax::txport).as_int()),
rxSocket_(ios, udp::endpoint(udp::v4(), port_)),
txSocket_(ios),
receiverEndpoint_(udp::endpoint(ip::address::from_string(node.attribute(confsintax::address).value()), txport_)),
ios_(ios)
{
emsAddress_=node.attribute(confsintax::address).value();
std::string addressfilter=node.attribute(confsintax::addressfilter).value();
analyzeAddress(addressfilter);

txSocket_.open(boost::asio::ip::udp::v4());

rxSocket_.async_receive_from(
boost::asio::buffer(rxData_, maxMsgLenght_), senderEndpoint_,
boost::bind(&ComponentUdp::handleReceiveFrom, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}

ComponentUdp::ComponentUdp(boost::asio::io_service &ios,const std::map<std::string,std::string>&attributes,ConfigurationDepot&depot)
: Component(attributes,depot),
port_(asInt(confsintax::rxport,attributes)),
Expand Down
1 change: 0 additions & 1 deletion src/diagnosticdaemon/ComponentUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ComponentUdp: public Component
{
public:
ComponentUdp(boost::asio::io_service &ios,const std::map<std::string,std::string>&attributes,ConfigurationDepot&depot);
ComponentUdp(boost::asio::io_service &ios,const pugi::xml_node& node,ConfigurationDepot&);
virtual ~ComponentUdp(){};

void acceptMsg(std::array<uint8_t,maxMsgLenght_>& msg,unsigned int size,udp::endpoint senderEndPoint) override;
Expand Down
5 changes: 4 additions & 1 deletion src/diagnosticdaemon/ConfigurationConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace confsintax
static constexpr char udp[]{"udp"};
static constexpr char file[]{"file"};
static constexpr char console[]{"console"};
static constexpr char disabled[]{"disabled"};
};

enum class ComponentType: uint8_t
Expand All @@ -38,11 +39,13 @@ enum class ComponentType: uint8_t
udp,
file,
console,
disabled
};

inline std::map<std::string,uint8_t> componentTypeLookup{
{confsintax::udpbroadcast,(uint8_t)ComponentType::udpbroadcast},
{confsintax::udp,(uint8_t)ComponentType::udp},
{confsintax::file,(uint8_t)ComponentType::file},
{confsintax::console,(uint8_t)ComponentType::console}
{confsintax::console,(uint8_t)ComponentType::console},
{confsintax::disabled,(uint8_t)ComponentType::disabled}
};
10 changes: 8 additions & 2 deletions src/diagnosticdaemon/ConfigurationDepot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ComponentUdp.h"
#include "ComponentFile.h"
#include "ComponentConsole.h"
#include "ComponentDisabled.h"

ConfigurationDepot::ConfigurationDepot(boost::asio::io_service &io_service): ios_(io_service)
{}
Expand Down Expand Up @@ -52,7 +53,7 @@ InOut_sptr ConfigurationDepot::createComponent(const std::map<std::string,std::s
bool enable =asBool(confsintax::enable,attributes);

if(!enable)
return InOut_sptr();
protocol=confsintax::disabled;

switch(componentTypeLookup[protocol])
{
Expand All @@ -71,7 +72,12 @@ InOut_sptr ConfigurationDepot::createComponent(const std::map<std::string,std::s
{
components=std::make_shared<ComponentConsole>(attributes,*this);
return components;
}
}
case (uint8_t)ComponentType::disabled:
{
components=std::make_shared<ComponentDisabled>(attributes,*this);
return components;
}
default:
{
//TODO error
Expand Down
1 change: 0 additions & 1 deletion src/diagnosticdaemon/ConfigurationDepot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ConfigurationDepot
pugi::xml_document doc_;
boost::asio::io_service &ios_;
std::list<InOut_sptr> depot_;
InOut_sptr createComponent(const pugi::xml_node& node);
InOut_sptr createComponent(const std::map<std::string,std::string>& attributes);
};

Expand Down

0 comments on commit e9c3c4f

Please sign in to comment.