Commit b8688490 authored by Pavel Vainerman's avatar Pavel Vainerman

(VMonit): сделана сортировка по алфафиту, переписана реализация функций

вывода на экран.
parent 6b5e42ab
......@@ -1036,18 +1036,44 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO()
ostringstream s;
s &lt;&lt; myname &lt;&lt; ": " &lt;&lt; endl;
std::vector&lt;std::string&gt; v;
std::list&lt;std::string&gt; v_in;
ostringstream s1;
<xsl:for-each select="//smap/item">
<xsl:sort select="@name" order="ascending" data-type="text"/>
<xsl:if test="normalize-space(@vartype)='in'">
s1.str("");
s1 &lt;&lt; " " &lt;&lt; setw(30) &lt;&lt; std::right &lt;&lt; "<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>"
&lt;&lt; "(" &lt;&lt; setw(30) &lt;&lt; std::left &lt;&lt; ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>)) &lt;&lt; ")"
&lt;&lt; " ( " &lt;&lt; setw(30) &lt;&lt; std::left &lt;&lt; ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>)) &lt;&lt; " )"
&lt;&lt; std::right &lt;&lt; " = " &lt;&lt; setw(6) &lt;&lt; <xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>;
v.push_back(s1.str());
v_in.push_back(s1.str());
</xsl:if>
</xsl:for-each>
std::list&lt;std::string&gt; v_out;
<xsl:for-each select="//smap/item">
<xsl:sort select="@name" order="ascending" data-type="text"/>
<xsl:if test="normalize-space(@vartype)='out'">
s1.str("");
s1 &lt;&lt; " " &lt;&lt; setw(30) &lt;&lt; std::right &lt;&lt; "<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>"
&lt;&lt; " ( " &lt;&lt; setw(30) &lt;&lt; std::left &lt;&lt; ORepHelpers::getShortName( uniset_conf()->oind->getMapName(<xsl:value-of select="@name"/>)) &lt;&lt; " )"
&lt;&lt; std::right &lt;&lt; " = " &lt;&lt; setw(6) &lt;&lt; <xsl:call-template name="setprefix"/><xsl:value-of select="@name"/>;
v_out.push_back(s1.str());
</xsl:if>
</xsl:for-each>
s &lt;&lt; endl;
int n = 0;
for( const auto&amp; e: v )
for( const auto&amp; e: v_in )
{
s &lt;&lt; e;
if( (n++)%2 )
s &lt;&lt; std::endl;
}
s &lt;&lt; endl;
n = 0;
for( const auto&amp; e: v_out )
{
s &lt;&lt; e;
if( (n++)%2 )
......@@ -1354,6 +1380,7 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO()
vector&lt;std::string&gt; v;
<xsl:for-each select="//sensors/item/consumers/consumer">
<xsl:sort select="../../@name" order="ascending" data-type="text"/>
<xsl:if test="normalize-space(../../@msg)!='1'">
<xsl:if test="normalize-space(@name)=$OID">
s1.str("");
......@@ -1363,6 +1390,7 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::dumpIO()
</xsl:if>
</xsl:for-each>
std::sort(std::begin(v),std::end(v));
int n=0;
for( const auto&amp; e: v )
{
......@@ -1401,7 +1429,7 @@ std::string <xsl:value-of select="$CLASSNAME"/>_SK::strval( UniSetTypes::Object
if( id == <xsl:value-of select="../../@name"/> )
{
s &lt;&lt; "<xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>";
if( showLinkName ) s &lt;&lt; "(<xsl:value-of select="../../@name"/>)";
if( showLinkName ) s &lt;&lt; " ( <xsl:value-of select="../../@name"/> )";
s &lt;&lt; "=" &lt;&lt; <xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>;
return std::move(s.str());
}
......
......@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.2
Release: alt8
Release: alt8.1
Summary: UniSet - library for building distributed industrial control systems
......@@ -456,6 +456,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Wed Oct 14 2015 Pavel Vainerman <pv@altlinux.ru> 2.2-alt8.1
- (VMonit): sort output
* Thu Oct 08 2015 Pavel Vainerman <pv@altlinux.ru> 2.2-alt8
- (uniset-codegen): minor fixes in resetMsg() mechanism
......
......@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2015-06-08+03:00
// generate timestamp: 2015-10-14+03:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
......@@ -31,7 +31,7 @@ class UObject_SK:
public LT_Object
{
public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node = UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix = "" );
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix="" );
UObject_SK();
virtual ~UObject_SK();
......@@ -45,60 +45,54 @@ class UObject_SK:
virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true );
inline std::shared_ptr<DebugStream> log()
{
return mylog;
}
inline std::shared_ptr<LogAgregator> logAgregator()
{
return loga;
}
inline std::shared_ptr<DebugStream> log(){ return mylog; }
inline std::shared_ptr<LogAgregator> logAgregator(){ return loga; }
void init_dlog( std::shared_ptr<DebugStream> d );
// "синтаксический сахар"..для логов
#ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif
#ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif
#ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif
#ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif
#ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif
#ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif
#ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif
#ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif
#ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif
#ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif
#ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif
#ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif
#ifndef mylogany
#define mylogany log()->any()
#endif
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
#ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif
#ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif
#ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif
#ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif
#ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif
#ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif
#ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif
#ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif
#ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif
#ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif
#ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif
#ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif
#ifndef mylogany
#define mylogany log()->any()
#endif
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
// Вспомогательные функции для удобства логирования
// ------------------------------------------------------------
......@@ -115,20 +109,18 @@ class UObject_SK:
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std::string str( UniSetTypes::ObjectId id, bool showLinkName = true );
std::string str( UniSetTypes::ObjectId id, bool showLinkName=true );
/*! Вывод значения входа/выхода в формате: in_xxx(SensorName)=val
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std::string strval( UniSetTypes::ObjectId id, bool showLinkName = true );
std::string strval( UniSetTypes::ObjectId id, bool showLinkName=true );
/*! Вывод состояния внутренних переменных */
inline std::string dumpVars()
{
return std::move(vmon.pretty_str());
}
inline std::string dumpVars(){ return std::move(vmon.pretty_str()); }
// ------------------------------------------------------------
std::string help();
......@@ -155,16 +147,13 @@ class UObject_SK:
virtual void callback() override;
virtual void processingMessage( UniSetTypes::VoidMessage* msg ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) {};
virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override {}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override {}
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ){};
virtual void askSensors( UniversalIO::UIOCommand cmd ){}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override{}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override{}
virtual void sigterm( int signo ) override;
virtual bool activateObject() override;
virtual std::string getMonitInfo()
{
return ""; /*!< пользовательская информация выводимая в getInfo() */
}
virtual std::string getMonitInfo(){ return ""; } /*!< пользовательская информация выводимая в getInfo() */
virtual void testMode( bool state );
void updatePreviousValues();
......@@ -183,7 +172,7 @@ class UObject_SK:
int resetMsgTime;
// Выполнение очередного шага программы
virtual void step() {}
virtual void step(){}
int sleep_msec; /*!< пауза между итерациями */
bool active;
......@@ -198,15 +187,9 @@ class UObject_SK:
xmlNode* confnode;
/*! получить числовое свойство из конф. файла по привязанной confnode */
int getIntProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getIntProp(confnode, name);
}
int getIntProp(const std::string& name) { return UniSetTypes::uniset_conf()->getIntProp(confnode, name); }
/*! получить текстовое свойство из конф. файла по привязанной confnode */
inline const std::string getProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getProp(confnode, name);
}
inline const std::string getProp(const std::string& name) { return UniSetTypes::uniset_conf()->getProp(confnode, name); }
int smReadyTimeout; /*!< время ожидания готовности SM */
std::atomic_bool activated;
......
......@@ -24,6 +24,7 @@
#define VMonitor_H_
// --------------------------------------------------------------------------
#include <string>
#include <list>
#include <ostream>
#include <unordered_map>
#include "UniSetTypes.h"
......@@ -120,8 +121,14 @@ class VMonitor
static const int NameWidth = { 30 };
static const int ColCount = { 2 };
/*! вывести все элементы в "простом формате" (строки "varname = value") */
std::string str();
std::string pretty_str();
/*! вывести все элементы "с форматированием" (отсортированные по алфавиту)
* \param namewidth - ширина резервируемая под "имя"
* \param colnum - количество столбцов вывода
*/
std::string pretty_str( int namewidth=NameWidth, int colnum=ColCount );
// функции добавления..
VMON_DEF_FUNC2(int);
......@@ -138,6 +145,8 @@ class VMonitor
static const std::string pretty_str( const std::string& name, const std::string* v, int width = NameWidth );
static const std::string pretty_str( const std::string& name, const std::string& v, int width = NameWidth );
std::list<std::pair<std::string,std::string>> getList();
protected:
private:
......@@ -149,7 +158,6 @@ class VMonitor
VMON_DEF_MAP(bool);
VMON_DEF_MAP(float);
VMON_DEF_MAP(double);
// VMON_DEF_MAP3(UniSetTypes::ObjectId,ObjectId); // <-- long
VMON_DEF_MAP3(std::string, string);
};
// --------------------------------------------------------------------------
......
......@@ -3,6 +3,7 @@
#include <sstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include "VMonitor.h"
// --------------------------------------------------------------------------
#define VMON_IMPL_ADD(T) void VMonitor::add( const std::string& name, const T& v ) \
......@@ -13,7 +14,7 @@
const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(10) << *(v); \
return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
......@@ -33,13 +34,13 @@
const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(10) << *(v); \
return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const unsigned T* v, int nwidth ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(10) << *(v); \
return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
......@@ -58,7 +59,7 @@
const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(10) << *(v); \
return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
......@@ -66,102 +67,36 @@
return pretty_str(name,&v,nwidth); \
}
// --------------------------------------------------------------------------
#define VMON_IMPL_PRN(M,T) \
#define VMON_MAKE_PAIR(vlist, T) \
{\
for( const auto& e: M.m_##T ) \
os << e.second << "=" << *(e.first) << std::endl;\
}
// --------------------------------------------------------------------------
#define VMON_IMPL_PRN2(M,T) \
{\
for( const auto& e: M.m_##T ) \
os << e.second << "=" << *(e.first) << std::endl;\
\
for( const auto& e: M.m_unsigned_##T ) \
os << e.second << "=" << *(e.first) << std::endl;\
}
// --------------------------------------------------------------------------
#define VMON_IMPL_PRN_CHAR(M) \
{\
for( const auto& e: M.m_char ) \
os << e.second << "=" << (int)(*(e.first)) << std::endl;\
\
for( const auto& e: M.m_unsigned_char) \
os << e.second << "=" << (int)(*(e.first)) << std::endl;\
for( const auto& e: m_##T ) \
vlist.push_back( std::make_pair(e.second, std::to_string(*(e.first))) );\
}
// --------------------------------------------------------------------------
#define VMON_IMPL_PRET(T) \
#define VMON_MAKE_PAIR_S(vlist, T) \
{\
std::vector<std::string> v(m_char.size()+m_unsigned_char.size());\
std::ostringstream s;\
for( const auto& e: m_##T ) \
{\
s.str("");\
s << pretty_str(e.second,e.first);\
v.push_back(s.str()); \
}\
\
int n = 0;\
for( const auto& e: v ) \
{\
os << e; \
if( (n++)%ColCount ) \
os << std::endl; \
} \
vlist.push_back( std::make_pair(e.second,*e.first) );\
}
// --------------------------------------------------------------------------
#define VMON_IMPL_PRET2(T) \
#define VMON_MAKE_PAIR2(vlist, T) \
{\
std::vector<std::string> v(m_char.size()+m_unsigned_char.size());\
std::ostringstream s;\
for( const auto& e: m_##T ) \
{\
s.str("");\
s << pretty_str(e.second,e.first);\
v.push_back(s.str());\
}\
vlist.push_back( std::make_pair(e.second, std::to_string(*(e.first))) );\
\
for( const auto& e: m_unsigned_##T ) \
{\
s.str("");\
s << pretty_str(e.second,e.first);\
v.push_back(s.str());\
}\
\
int n = 0;\
for( const auto& e: v ) \
{\
os << e; \
if( (n++)%ColCount ) \
os << std::endl; \
} \
vlist.push_back( std::make_pair(e.second, std::to_string(*(e.first))) );\
}
// --------------------------------------------------------------------------
#define VMON_IMPL_PRET_CHAR \
#define VMON_MAKE_PAIR_CHAR(vlist) \
{\
std::vector<std::string> v(m_char.size()+m_unsigned_char.size());\
std::ostringstream s;\
for( const auto& e: m_char ) \
{\
s.str("");\
s << std::right << std::setw(NameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first));\
v.push_back(s.str());\
}\
vlist.push_back(std::make_pair(e.second,std::to_string((int)(*(e.first)))) );\
\
for( const auto& e: m_unsigned_char ) \
{\
s.str("");\
s << std::right << std::setw(NameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first));\
v.push_back(s.str()); \
}\
\
int n = 0;\
for( const auto& e: v ) \
{\
os << e; \
if( (n++)%ColCount ) \
os << std::endl; \
} \
vlist.push_back(std::make_pair(e.second,std::to_string((int)(*(e.first)))) );\
}
// --------------------------------------------------------------------------
VMON_IMPL_ADD2(int)
......@@ -174,21 +109,17 @@ VMON_IMPL_ADD(double)
VMON_IMPL_ADD3(std::string, string)
//VMON_IMPL_ADD3(UniSetTypes::ObjectId,ObjectId)
// --------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, VMonitor& m )
std::ostream& operator<<( std::ostream& os, VMonitor& m )
{
VMON_IMPL_PRN2(m, int);
VMON_IMPL_PRN2(m, long);
VMON_IMPL_PRN2(m, short);
VMON_IMPL_PRN_CHAR(m);
VMON_IMPL_PRN(m, bool);
VMON_IMPL_PRN(m, float);
VMON_IMPL_PRN(m, double);
VMON_IMPL_PRN(m, string);
// VMON_IMPL_PRN(m,ObjectId);
auto vlist = m.getList();
// сортируем по алфавиту
vlist.sort( []( const std::pair<std::string,std::string> &a, const std::pair<std::string,std::string> &b ) { return a.first < b.first; });
for( const auto& e: vlist )
os << e.first << " = " << e.second;
return os;
}
// --------------------------------------------------------------------------
std::string VMonitor::str()
{
......@@ -197,18 +128,35 @@ std::string VMonitor::str()
return std::move(s.str());
}
// --------------------------------------------------------------------------
std::string VMonitor::pretty_str()
std::list<std::pair<std::string, std::string> > VMonitor::getList()
{
std::list<std::pair<std::string,std::string>> vlist;
VMON_MAKE_PAIR2(vlist,int);
VMON_MAKE_PAIR2(vlist,long);
VMON_MAKE_PAIR2(vlist,short);
VMON_MAKE_PAIR_CHAR(vlist);
VMON_MAKE_PAIR(vlist,bool);
VMON_MAKE_PAIR(vlist,float);
VMON_MAKE_PAIR(vlist,double);
VMON_MAKE_PAIR_S(vlist,string);
return std::move(vlist);
}
// --------------------------------------------------------------------------
std::string VMonitor::pretty_str( int namewidth, int colnum )
{
auto vlist = getList();
std::ostringstream os;
VMON_IMPL_PRET2(int);
VMON_IMPL_PRET2(long);
VMON_IMPL_PRET2(short);
VMON_IMPL_PRET_CHAR;
VMON_IMPL_PRET(bool);
VMON_IMPL_PRET(float);
VMON_IMPL_PRET(double);
VMON_IMPL_PRET(string);
// VMON_IMPL_PRET(ObjectId);
// сортируем по алфавиту
vlist.sort( []( const std::pair<std::string,std::string> &a, const std::pair<std::string,std::string> &b ) { return a.first < b.first; });
int n = 0;
for( const auto& e: vlist )
{
os << std::right << std::setw(namewidth) << e.first << std::left << " = " << std::right << std::setw(10) << e.second;
if( (n++)%colnum )
os << std::endl;
}
return std::move(os.str());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment