Commit 016c01b5 authored by Pavel Vainerman's avatar Pavel Vainerman

Новый формат ConfirmMessage (основанный на том, что сообщение это тоже датчик).

(eterbug #8842)
parent f2fe49dc
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 1.5 Version: 1.5
Release: alt1 Release: alt2
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
...@@ -211,6 +211,9 @@ rm -f %buildroot%_libdir/*.la ...@@ -211,6 +211,9 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc %exclude %_pkgconfigdir/libUniSet.pc
%changelog %changelog
* Wed Nov 21 2012 Pavel Vainerman <pv@altlinux.ru> 1.5-alt2
- new ConfirmMessage format (eterbug #8842)
* Tue Nov 06 2012 Pavel Vainerman <pv@altlinux.ru> 1.5-alt1 * Tue Nov 06 2012 Pavel Vainerman <pv@altlinux.ru> 1.5-alt1
- add depends for IOBase - add depends for IOBase
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html # See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html
# AC_PREREQ(2.59) # AC_PREREQ(2.59)
AC_INIT([uniset], [1.5.0], pv@etersoft.ru) AC_INIT([uniset], [1.5.1], pv@etersoft.ru)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME,AC_PACKAGE_VERSION) AM_INIT_AUTOMAKE(AC_PACKAGE_NAME,AC_PACKAGE_VERSION)
# AC_CONFIG_MACRO_DIR([m4]) # AC_CONFIG_MACRO_DIR([m4])
...@@ -30,7 +30,7 @@ AC_ENABLE_SHARED(yes) ...@@ -30,7 +30,7 @@ AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no) AC_ENABLE_STATIC(no)
AM_PROG_LIBTOOL AM_PROG_LIBTOOL
LIBVER=1:5:0 LIBVER=1:5:1
AC_SUBST(LIBVER) AC_SUBST(LIBVER)
# Checks for libraries. # Checks for libraries.
......
...@@ -337,24 +337,27 @@ namespace UniSetTypes ...@@ -337,24 +337,27 @@ namespace UniSetTypes
{ {
public: public:
ConfirmMessage(const InfoMessage& msg, Priority prior = Message::High,
ObjectId cons=UniSetTypes::DefaultObjectId);
ConfirmMessage(const AlarmMessage& msg, Priority prior = Message::High,
ObjectId cons=UniSetTypes::DefaultObjectId);
ConfirmMessage(const VoidMessage *msg);
inline TransportMessage transport_msg() const inline TransportMessage transport_msg() const
{ {
return transport(*this); return transport(*this);
} }
MessageCode code; /*!< id подтвержденного события */ ConfirmMessage( const VoidMessage *msg );
MessageCode orig_cause; /*!< причина */
timeval orig_tm; /*!< время сообщения */ ConfirmMessage(long in_sensor_id,
int orig_type; /*!< тип подтвержденного сообщения */ double in_value,
ObjectId orig_node; /*!< узел */ time_t in_time,
ObjectId orig_id; /*!< от кого оно было */ time_t in_time_usec,
time_t in_confirm,
Priority in_priority = Message::Medium);
long sensor_id; /* ID датчика */
double value; /* значение датчика */
time_t time; /* время, когда датчик получил сигнал */
time_t time_usec; /* время в микросекундах */
time_t confirm; /* время, когда произошло квитирование */
bool broadcast; bool broadcast;
/*! /*!
......
...@@ -270,16 +270,6 @@ struct MsgInfo ...@@ -270,16 +270,6 @@ struct MsgInfo
node(am.node) node(am.node)
{} {}
MsgInfo( ConfirmMessage& am ):
type(am.orig_type),
id(am.orig_id),
acode(am.code),
ccode(am.orig_cause),
ch(0),
tm(am.orig_tm),
node(am.orig_node)
{}
int type; int type;
ObjectId id; // от кого ObjectId id; // от кого
MessageCode acode; // код сообщения MessageCode acode; // код сообщения
...@@ -313,6 +303,49 @@ struct MsgInfo ...@@ -313,6 +303,49 @@ struct MsgInfo
}; };
// структура определяющая минимальное количество полей
// по которым можно судить о схожести сообщений
// используется локально и только в функции очистки очереди сообщений
struct CInfo
{
CInfo():
sensor_id(DefaultObjectId),
value(0),
time(0),
time_usec(0),
confirm(0)
{
}
CInfo( ConfirmMessage& cm ):
sensor_id(cm.sensor_id),
value(cm.value),
time(cm.time),
time_usec(cm.time_usec),
confirm(cm.confirm)
{}
long sensor_id; /* ID датчика */
double value; /* значение датчика */
time_t time; /* время, когда датчик получил сигнал */
time_t time_usec; /* время в микросекундах */
time_t confirm; /* время, когда произошло квитирование */
inline bool operator < ( const CInfo& mi ) const
{
if( sensor_id != mi.sensor_id )
return sensor_id < mi.sensor_id;
if( value != mi.value )
return value < mi.value;
if( time != time )
return time < mi.time;
return time_usec < mi.time_usec;
}
};
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool UniSetObject::waitMessage(VoidMessage& vm, timeout_t timeMS) bool UniSetObject::waitMessage(VoidMessage& vm, timeout_t timeMS)
{ {
...@@ -497,7 +530,7 @@ struct tmpConsumerInfo ...@@ -497,7 +530,7 @@ struct tmpConsumerInfo
map<int,VoidMessage> sysmap; map<int,VoidMessage> sysmap;
map<MsgInfo,VoidMessage> amap; map<MsgInfo,VoidMessage> amap;
map<MsgInfo,VoidMessage> imap; map<MsgInfo,VoidMessage> imap;
map<MsgInfo,VoidMessage> cmap; map<CInfo,VoidMessage> cmap;
list<VoidMessage> lstOther; list<VoidMessage> lstOther;
}; };
...@@ -571,13 +604,14 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q ) ...@@ -571,13 +604,14 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q )
} }
break; break;
case Message::Confirm: case Message::Confirm:
{ {
ConfirmMessage cm(&m); ConfirmMessage cm(&m);
MsgInfo mi(cm); CInfo ci(cm);
// т.к. из очереди сообщений сперва вынимаются самые старые, потом свежее и т.п. // т.к. из очереди сообщений сперва вынимаются самые старые, потом свежее и т.п.
// то достаточно просто сохранять последнее сообщение для одинаковых MsgInfo // то достаточно просто сохранять последнее сообщение для одинаковых MsgInfo
consumermap[cm.consumer].cmap[mi] = m; consumermap[cm.consumer].cmap[ci] = m;
} }
break; break;
...@@ -586,7 +620,7 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q ) ...@@ -586,7 +620,7 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q )
break; break;
default: default:
// сразу пизаем // сразу помещаем в очередь
consumermap[m.consumer].lstOther.push_front(m); consumermap[m.consumer].lstOther.push_front(m);
break; break;
...@@ -642,7 +676,7 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q ) ...@@ -642,7 +676,7 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q )
q.push(it4->second); q.push(it4->second);
} }
map<MsgInfo,VoidMessage>::iterator it5=it0->second.cmap.begin(); map<CInfo,VoidMessage>::iterator it5=it0->second.cmap.begin();
for( ; it5!=it0->second.cmap.end(); ++it5 ) for( ; it5!=it0->second.cmap.end(); ++it5 )
{ {
q.push(it5->second); q.push(it5->second);
......
...@@ -334,7 +334,7 @@ void InfoServer::processingMessage( UniSetTypes::VoidMessage *msg ) ...@@ -334,7 +334,7 @@ void InfoServer::processingMessage( UniSetTypes::VoidMessage *msg )
{ {
UniSetTypes::ConfirmMessage cm(msg); UniSetTypes::ConfirmMessage cm(msg);
unideb[Debug::INFO] << myname << " ConfirmMessage на сообщение code= "<< cm.code << endl; unideb[Debug::INFO] << myname << " ConfirmMessage на сообщение sensor_id= "<< cm.sensor_id << endl;
try try
{ {
// если это не пересланное сообщение // если это не пересланное сообщение
...@@ -356,7 +356,7 @@ void InfoServer::processingMessage( UniSetTypes::VoidMessage *msg ) ...@@ -356,7 +356,7 @@ void InfoServer::processingMessage( UniSetTypes::VoidMessage *msg )
// посылаем всем зазкачикам уведомление // посылаем всем зазкачикам уведомление
event(cm.code, cm, true); event(cm.sensor_id, cm, true);
try try
{ {
......
...@@ -311,7 +311,6 @@ TimerMessage::TimerMessage(UniSetTypes::TimerId id, Priority prior, ObjectId con ...@@ -311,7 +311,6 @@ TimerMessage::TimerMessage(UniSetTypes::TimerId id, Priority prior, ObjectId con
id(id) id(id)
{ {
type = Message::Timer; type = Message::Timer;
this->priority = prior;
this->consumer = cons; this->consumer = cons;
} }
...@@ -321,53 +320,28 @@ TimerMessage::TimerMessage(const VoidMessage *msg) ...@@ -321,53 +320,28 @@ TimerMessage::TimerMessage(const VoidMessage *msg)
assert(this->type == Message::Timer); assert(this->type == Message::Timer);
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
ConfirmMessage::ConfirmMessage( const VoidMessage *msg )
ConfirmMessage::ConfirmMessage():
code(UniSetTypes::DefaultMessageCode),
orig_cause(DefaultMessageCode),
orig_type(Message::Info),
orig_node(DefaultObjectId),
orig_id(UniSetTypes::DefaultMessageCode),
broadcast(false),
route(false)
{
}
ConfirmMessage::ConfirmMessage(const InfoMessage& msg, Priority prior, ObjectId cons):
code(msg.infocode),
orig_cause(DefaultMessageCode),
orig_tm(msg.tm),
orig_type(msg.type),
orig_node(msg.node),
orig_id(msg.id),
broadcast(msg.broadcast),
route(false)
{ {
type = Message::Confirm; memcpy(this,msg,sizeof(*this));
this->priority = prior; assert(this->type == Message::Confirm);
this->consumer = cons;
// struct timeb tm;
} }
//--------------------------------------------------------------------------------------------
ConfirmMessage::ConfirmMessage(const AlarmMessage& msg, Priority prior, ObjectId cons): ConfirmMessage::ConfirmMessage(long in_sensor_id,
code(msg.alarmcode), double in_value,
orig_cause(msg.causecode), time_t in_time,
orig_tm(msg.tm), time_t in_time_usec,
orig_type(msg.type), time_t in_confirm,
orig_node(msg.node), Priority in_priority ):
orig_id(msg.id), sensor_id(in_sensor_id),
broadcast(msg.broadcast), value(in_value),
route(false) time(in_time),
time_usec(in_time_usec),
confirm(in_confirm),
broadcast(false),
route(false)
{ {
type = Message::Confirm; type = Message::Confirm;
this->priority = prior; priority = in_priority;
this->consumer = cons;
}
ConfirmMessage::ConfirmMessage(const VoidMessage *msg)
{
memcpy(this,msg,sizeof(*this));
assert(this->type == Message::Confirm);
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
......
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