Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

Commit

Permalink
Merge previous unstable version: 3.14.12+13rc
Browse files Browse the repository at this point in the history
  • Loading branch information
Newterm-coders committed Nov 1, 2014
2 parents fed1cf1 + 5aabc88 commit a4dd428
Show file tree
Hide file tree
Showing 34 changed files with 621 additions and 109 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ AC_OUTPUT( \
wx/draw3/Makefile \
wx/ekstraktor3/Makefile \
wx/filler/Makefile \
wx/filler2/Makefile \
wx/isledit/Makefile \
wx/scc/Makefile \
wx/raporter3/Makefile \
Expand Down
1 change: 1 addition & 0 deletions debian/packs.files
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Files: opt/szarp/resources/scc.desktop
Files: opt/szarp/resources/regulators
Files: etc/xdg/autostart/scc.desktop
Files: usr/share/autostart/scc.desktop
Files: usr/share/applications/scc.desktop

Package: szarp-paramd
Files: etc/pam.d/paramd
Expand Down
6 changes: 6 additions & 0 deletions iks/server/data/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ void Config::from_xml( const bp::ptree& ptree ) throw(xml_parse_error)
emit_changed();
}

void Config::from_pairs( const CfgPairs& pairs )
{
std::copy(pairs.begin(), pairs.end(), std::inserter(cfg, cfg.end()));
emit_changed();
}

2 changes: 2 additions & 0 deletions iks/server/data/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "utils/signals.h"
#include "utils/exception.h"
#include "utils/config.h"

class Config {
typedef std::unordered_map<std::string,std::string> CfgMap;
Expand All @@ -16,6 +17,7 @@ class Config {

void from_file( const std::string& path ) throw(xml_parse_error);
void from_xml( const boost::property_tree::ptree& cfg_ptree ) throw(xml_parse_error);
void from_pairs( const CfgPairs& pairs );

CfgMap::const_iterator begin() const { return cfg.cbegin(); }
CfgMap::const_iterator end () const { return cfg.cend (); }
Expand Down
70 changes: 38 additions & 32 deletions iks/server/data/param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,44 @@ void Param::from_params_xml( const bp::ptree& ptree ) throw(xml_parse_error)
* Add type which is its parent section
*/
param_desc.put("@type",parent_tag);

/**
* Initialize draw_name
*/
draw_name = param_desc.get<std::string>( "@draw_name", name );

/**
* Get summaric values description
*/
summaric = get_summaric_from_xml();
summaric_unit = get_summaric_unit_from_xml();
}

bool Param::get_summaric_from_xml() const
{
const auto unit = param_desc.get<std::string>( "@unit", "-" );
if( unit.rfind("/h") != std::string::npos )
return true;
if( summaric_units.find( unit ) != summaric_units.end() )
return true;
if( param_desc.count("draw") )
for( const auto& c : param_desc.get_child("draw") ) {
const auto special = c.second.get<std::string>( "@special", "" );
if ( special == "hoursum" )
return true;
}
return false;
}

std::string Param::get_summaric_unit_from_xml() const
{
auto unit = param_desc.get<std::string>( "@unit", "-" );
const auto pos = unit.rfind("/h");
if( pos != std::string::npos )
return unit.erase(pos);
if( summaric_units.find( unit ) != summaric_units.end() )
return unit + "h";
return unit;
}

void Param::to_json( std::ostream& stream , bool pretty ) const
Expand Down Expand Up @@ -105,33 +143,6 @@ std::string Param::to_xml( bool pretty ) const
return ss.str();
}

bool Param::is_summaric() const
{
const auto unit = param_desc.get<std::string>( "@unit", "-" );
if( unit.rfind("/h") != std::string::npos )
return true;
if( summaric_units.find( unit ) != summaric_units.end() )
return true;
if( param_desc.count("draw") )
for( const auto& c : param_desc.get_child("draw") ) {
const auto special = c.second.get<std::string>( "@special", "" );
if ( special == "hoursum" )
return true;
}
return false;
}

std::string Param::get_summaric_unit() const
{
auto unit = param_desc.get<std::string>( "@unit", "-" );
const auto pos = unit.rfind("/h");
if( pos != std::string::npos )
return unit.erase(pos);
if( summaric_units.find( unit ) != summaric_units.end() )
return unit + "h";
return unit;
}

double Param::get_value( ProbeType pt ) const
{
auto itr = values.find( pt );
Expand All @@ -146,9 +157,4 @@ void Param::set_value( double v , ProbeType pt )
values[ pt ] = v;
}

std::string Param::get_draw_name() const
{
return param_desc.get<std::string>( "@draw_name", name );
}

const std::set<std::string> Param::summaric_units {"MW", "kW"};
18 changes: 14 additions & 4 deletions iks/server/data/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,28 @@ class Param {
const boost::property_tree::ptree& get_ptree() const
{ return param_desc; }

bool is_summaric() const;
std::string get_summaric_unit() const;
bool is_summaric() const
{ return summaric; }

std::string get_summaric_unit() const
{ return summaric_unit; }

std::string get_draw_name() const
{ return draw_name; }

double get_value( ProbeType pt = ProbeType::Type::LIVE ) const;
void set_value( double v , ProbeType pt );

std::string get_draw_name() const;

private:
bool get_summaric_from_xml() const;
std::string get_summaric_unit_from_xml() const;

static const std::set<std::string> summaric_units;
std::string parent_tag;
std::string name;
std::string draw_name;
bool summaric;
std::string summaric_unit;

std::map<ProbeType,double> values;

Expand Down
28 changes: 28 additions & 0 deletions iks/server/locations/config_container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef __CONFIG_CONTAINER_H__
#define __CONFIG_CONTAINER_H__

#include "data/config.h"

/** Class for storing config, added to decompose config storage
* from Protocol, as WelcomeProtocol needs to host Config */
class ConfigContainer {
public:
ConfigContainer( Config& config )
: config(config)
{}

virtual ~ConfigContainer()
{}

Config& get_config()
{
return config;
}

protected:
Config & config;

};

#endif /* end of include guard: __CONFIG_CONTAINER_H__ */

9 changes: 7 additions & 2 deletions iks/server/locations/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void LocationsMgr::add_locations( const CfgSections& cfg )
void LocationsMgr::add_location( const std::string& name , const CfgPairs& cfg )
{
try {
if( cfg.at("type") == "szbase" )
if( cfg.at("type") == "szbase" )
add_szbase( name , cfg );
else if( cfg.at("type") == "proxy" )
add_proxy( name , cfg );
Expand All @@ -41,6 +41,11 @@ void LocationsMgr::add_location( const std::string& name , const CfgPairs& cfg )
}
}

void LocationsMgr::add_config( const CfgPairs& cfg )
{
server_config.from_pairs(cfg);
}

void LocationsMgr::add_szbase( const std::string& name , const CfgPairs& cfg )
{
auto pa = cfg.count("prober_address") ? cfg.at("prober_address") : "127.0.0.1";
Expand Down Expand Up @@ -90,7 +95,7 @@ void LocationsMgr::add_proxy( const std::string& name , const CfgPairs& cfg )

void LocationsMgr::on_new_connection( Connection* con )
{
new_location( std::make_shared<ProtocolLocation>( "welcome" , std::make_shared<WelcomeProt>(loc_factory) , con ) );
new_location( std::make_shared<ProtocolLocation>( "welcome" , std::make_shared<WelcomeProt>(loc_factory, server_config) , con ) );
}

void LocationsMgr::on_disconnected( Connection* con )
Expand Down
3 changes: 3 additions & 0 deletions iks/server/locations/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class LocationsMgr {
void add_locations( const CfgSections& cfg );
void add_location( const std::string& name , const CfgPairs& cfg );

void add_config( const CfgPairs& cfg );

void on_new_connection( Connection* conn );
void on_disconnected ( Connection* conn );

Expand All @@ -33,6 +35,7 @@ class LocationsMgr {

LocationsList loc_factory;
VarsCache vars_cache;
Config server_config; /**< config of the proxy server */

std::unordered_map<Connection*,Location::ptr> locations;
std::unordered_map<std::string,RemotesUpdater::ptr> updaters;
Expand Down
1 change: 1 addition & 0 deletions iks/server/locations/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "utils/signals.h"
#include "locations/location.h"
#include "utils/config.h"

class Protocol;

Expand Down
13 changes: 9 additions & 4 deletions iks/server/locations/protocol_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void ProtocolLocation::parse_line( const std::string& line )
erase_cmd( cmd_id );
} else if( cmd_name == "r" || cmd_name == "k" ) {
if( !commands.count(cmd_id) ) {
send_fail( ErrorCodes::invalid_id );
send_fail( cmd_id , ErrorCodes::invalid_id );
return;
}

Expand All @@ -117,7 +117,7 @@ void ProtocolLocation::parse_line( const std::string& line )
auto cmd = protocol->cmd_from_tag( cmd_name );

if( !cmd ) {
send_fail( ErrorCodes::unknown_command );
send_fail( cmd_id , ErrorCodes::unknown_command );
return;
}

Expand Down Expand Up @@ -239,10 +239,15 @@ void ProtocolLocation::send_response(
}

void ProtocolLocation::send_fail( ErrorCodes code , const std::string& msg )
{
send_fail( 0 , code , msg );
}

void ProtocolLocation::send_fail( id_t id , ErrorCodes code , const std::string& msg )
{
if( msg.empty() )
write_line( str( format("e 0 %u") % (unsigned)code ) );
write_line( str( format("e %u %u") % (unsigned)id % (unsigned)code ) );
else
write_line( str( format("e 0 %u \"%s\"") % (unsigned)code % msg ) );
write_line( str( format("e %u %u \"%s\"") % (unsigned)id % (unsigned)code % msg ) );
}

1 change: 1 addition & 0 deletions iks/server/locations/protocol_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ProtocolLocation : public Location {
Command* cmd );

void send_fail( ErrorCodes code , const std::string& msg = "" );
void send_fail( id_t id , ErrorCodes code , const std::string& msg = "" );

virtual void parse_line( const std::string& line );

Expand Down
46 changes: 46 additions & 0 deletions iks/server/locations/welcome/cmd_get_server_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef __SERVER_CMD_GET_SERVER_CONFIG_H__
#define __SERVER_CMD_GET_SERVER_CONFIG_H__

#include "locations/command.h"
#include "locations/config_container.h"

#include "utils/ptree.h"

class GetServerConfigRcv : public Command {
public:
GetServerConfigRcv( Protocol& prot , LocationsList& locs )
: prot(prot) , locs(locs)
{
(void)prot;
set_next( std::bind(&GetServerConfigRcv::parse_command,this,std::placeholders::_1) );
}

virtual ~GetServerConfigRcv()
{
}

void parse_command( const std::string& line )
{
namespace bp = boost::property_tree;

bp::ptree opts;

/** Send all options */
Config& config = dynamic_cast<ConfigContainer*>(&prot)->get_config();

for( auto io=config.begin() ; io!=config.end() ; ++io )
/** prevent '.' from being path separator */
opts.put( boost::property_tree::path(io->first,'\0') , io->second );

apply( ptree_to_json( opts ) );
return;
}

protected:
Protocol& prot;
LocationsList& locs;
};

#endif /* end of include guard: __SERVER_CMD_GET_SERVER_CONFIG_H__ */


6 changes: 4 additions & 2 deletions iks/server/locations/welcome/welcome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cmd_list_remotes.h"
#include "cmd_update_remotes.h"
#include "cmd_connect_remote.h"
#include "cmd_get_server_config.h"

#define MAP_CMD_TAG( _tag , cmd ) \
if( _tag == tag ) return new cmd(*this,locs);
Expand All @@ -14,8 +15,8 @@

namespace p = std::placeholders;

WelcomeProt::WelcomeProt( LocationsList& locs )
: locs(locs)
WelcomeProt::WelcomeProt( LocationsList& locs, Config& config )
: ConfigContainer(config), locs(locs)
{
conn_add = locs.on_location_added(
std::bind( &WelcomeProt::on_remote_added , this , p::_1 ) );
Expand All @@ -31,6 +32,7 @@ Command* WelcomeProt::cmd_from_tag( const std::string& tag )
{
MAP_CMD_TAG( "connect" , CmdConnectRemoteRcv );
MAP_CMD_TAG( "list_remotes" , CmdListRemotesRcv );
MAP_CMD_TAG( "get_server_options" , GetServerConfigRcv );
return NULL;
}

Expand Down
5 changes: 3 additions & 2 deletions iks/server/locations/welcome/welcome.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include "locations/protocol.h"
#include "locations/locations_list.h"
#include "locations/config_container.h"

class WelcomeProt : public Protocol {
class WelcomeProt : public Protocol, public ConfigContainer {
public:
WelcomeProt( LocationsList& locs );
WelcomeProt( LocationsList& locs, Config& config );
virtual ~WelcomeProt();

virtual Command* cmd_from_tag( const std::string& tag );
Expand Down
Loading

0 comments on commit a4dd428

Please sign in to comment.