You need to sign in or sign up before continuing.
Commit 016c01b5 authored by Pavel Vainerman's avatar Pavel Vainerman

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

(eterbug #8842)
parent f2fe49dc
......@@ -3,7 +3,7 @@
Name: libuniset
Version: 1.5
Release: alt1
Release: alt2
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
......@@ -211,6 +211,9 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc
%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
- add depends for IOBase
......
......@@ -3,7 +3,7 @@
# See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html
# 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)
# AC_CONFIG_MACRO_DIR([m4])
......@@ -30,7 +30,7 @@ AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
AM_PROG_LIBTOOL
LIBVER=1:5:0
LIBVER=1:5:1
AC_SUBST(LIBVER)
# Checks for libraries.
......
......@@ -337,24 +337,27 @@ namespace UniSetTypes
{
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
{
return transport(*this);
}
MessageCode code; /*!< id подтвержденного события */
MessageCode orig_cause; /*!< причина */
timeval orig_tm; /*!< время сообщения */
int orig_type; /*!< тип подтвержденного сообщения */
ObjectId orig_node; /*!< узел */
ObjectId orig_id; /*!< от кого оно было */
ConfirmMessage( const VoidMessage *msg );
ConfirmMessage(long in_sensor_id,
double in_value,
time_t in_time,
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;
/*!
......
......@@ -270,16 +270,6 @@ struct MsgInfo
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;
ObjectId id; // от кого
MessageCode acode; // код сообщения
......@@ -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)
{
......@@ -497,7 +530,7 @@ struct tmpConsumerInfo
map<int,VoidMessage> sysmap;
map<MsgInfo,VoidMessage> amap;
map<MsgInfo,VoidMessage> imap;
map<MsgInfo,VoidMessage> cmap;
map<CInfo,VoidMessage> cmap;
list<VoidMessage> lstOther;
};
......@@ -571,13 +604,14 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q )
}
break;
case Message::Confirm:
{
ConfirmMessage cm(&m);
MsgInfo mi(cm);
CInfo ci(cm);
// т.к. из очереди сообщений сперва вынимаются самые старые, потом свежее и т.п.
// то достаточно просто сохранять последнее сообщение для одинаковых MsgInfo
consumermap[cm.consumer].cmap[mi] = m;
consumermap[cm.consumer].cmap[ci] = m;
}
break;
......@@ -586,7 +620,7 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q )
break;
default:
// сразу пизаем
// сразу помещаем в очередь
consumermap[m.consumer].lstOther.push_front(m);
break;
......@@ -642,7 +676,7 @@ void UniSetObject::cleanMsgQueue( MessagesQueue& q )
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 )
{
q.push(it5->second);
......
......@@ -334,7 +334,7 @@ void InfoServer::processingMessage( UniSetTypes::VoidMessage *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
{
// если это не пересланное сообщение
......@@ -356,7 +356,7 @@ void InfoServer::processingMessage( UniSetTypes::VoidMessage *msg )
// посылаем всем зазкачикам уведомление
event(cm.code, cm, true);
event(cm.sensor_id, cm, true);
try
{
......
......@@ -311,7 +311,6 @@ TimerMessage::TimerMessage(UniSetTypes::TimerId id, Priority prior, ObjectId con
id(id)
{
type = Message::Timer;
this->priority = prior;
this->consumer = cons;
}
......@@ -321,53 +320,28 @@ TimerMessage::TimerMessage(const VoidMessage *msg)
assert(this->type == Message::Timer);
}
//--------------------------------------------------------------------------------------------
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)
ConfirmMessage::ConfirmMessage( const VoidMessage *msg )
{
type = Message::Confirm;
this->priority = prior;
this->consumer = cons;
// struct timeb tm;
memcpy(this,msg,sizeof(*this));
assert(this->type == Message::Confirm);
}
ConfirmMessage::ConfirmMessage(const AlarmMessage& msg, Priority prior, ObjectId cons):
code(msg.alarmcode),
orig_cause(msg.causecode),
orig_tm(msg.tm),
orig_type(msg.type),
orig_node(msg.node),
orig_id(msg.id),
broadcast(msg.broadcast),
route(false)
//--------------------------------------------------------------------------------------------
ConfirmMessage::ConfirmMessage(long in_sensor_id,
double in_value,
time_t in_time,
time_t in_time_usec,
time_t in_confirm,
Priority in_priority ):
sensor_id(in_sensor_id),
value(in_value),
time(in_time),
time_usec(in_time_usec),
confirm(in_confirm),
broadcast(false),
route(false)
{
type = Message::Confirm;
this->priority = prior;
this->consumer = cons;
}
ConfirmMessage::ConfirmMessage(const VoidMessage *msg)
{
memcpy(this,msg,sizeof(*this));
assert(this->type == Message::Confirm);
priority = in_priority;
}
//--------------------------------------------------------------------------------------------
......
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