Commit da428026 authored by Pavel Vainerman's avatar Pavel Vainerman

Рефакторинг: ушёл от лишних классов xxx_LT

(перевёл функциональность в базовый UniSetObject)
parent d0d9967c
......@@ -43,7 +43,6 @@
#include <unordered_map>
<xsl:if test="normalize-space($BASECLASS)!=''">#include <xsl:call-template name="preinclude"/><xsl:value-of select="normalize-space($BASECLASS)"/>.h<xsl:call-template name="postinclude"/></xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">#include <xsl:call-template name="preinclude"/>UniSetObject.h<xsl:call-template name="postinclude"/></xsl:if>
#include <xsl:call-template name="preinclude"/>LT_Object.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>UniXML.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>Trigger.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>UInterface.h<xsl:call-template name="postinclude"/>
......@@ -53,9 +52,8 @@
#include <xsl:call-template name="preinclude"/>VMonitor.h<xsl:call-template name="postinclude"/>
// -----------------------------------------------------------------------------
class <xsl:value-of select="$CLASSNAME"/>_SK:
<xsl:if test="normalize-space($BASECLASS)!=''">public <xsl:value-of select="normalize-space($BASECLASS)"/>,</xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">public UniSetObject,</xsl:if>
public LT_Object
<xsl:if test="normalize-space($BASECLASS)!=''">public <xsl:value-of select="normalize-space($BASECLASS)"/></xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">public UniSetObject</xsl:if>
{
public:
<xsl:if test="not(normalize-space($OID))=''">
......
......@@ -43,7 +43,6 @@
#include &lt;sstream&gt;
<xsl:if test="normalize-space($BASECLASS)!=''">#include <xsl:call-template name="preinclude"/><xsl:value-of select="normalize-space($BASECLASS)"/>.h<xsl:call-template name="postinclude"/></xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">#include <xsl:call-template name="preinclude"/>UniSetObject.h<xsl:call-template name="postinclude"/></xsl:if>
#include <xsl:call-template name="preinclude"/>LT_Object.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>UniXML.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>Trigger.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>DebugStream.h<xsl:call-template name="postinclude"/>
......@@ -52,9 +51,8 @@
#include <xsl:call-template name="preinclude"/>VMonitor.h<xsl:call-template name="postinclude"/>
// -----------------------------------------------------------------------------
class <xsl:value-of select="$CLASSNAME"/>_SK:
<xsl:if test="normalize-space($BASECLASS)!=''">public <xsl:value-of select="normalize-space($BASECLASS)"/>,</xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">public UniSetObject,</xsl:if>
public LT_Object
<xsl:if test="normalize-space($BASECLASS)!=''">public <xsl:value-of select="normalize-space($BASECLASS)"/></xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">public UniSetObject</xsl:if>
{
public:
<xsl:if test="not(normalize-space($OID))=''">
......
......@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.2
Release: alt11
Release: alt12
Summary: UniSet - library for building distributed industrial control systems
......@@ -452,6 +452,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Mon Dec 14 2015 Pavel Vainerman <pv@altlinux.ru> 2.2-alt12
- refactoring: remove xxx_LT classes
- add new function for LT_Object
* Tue Nov 03 2015 Pavel Vainerman <pv@altlinux.ru> 2.2-alt11
- RRDServer: add support 'dsname', check RRD_MAX_DSNAME_LEN
......
......@@ -3,9 +3,12 @@
# See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html
# AC_PREREQ(2.59)
AC_INIT([uniset2], [2.2.0], pv@etersoft.ru)
AC_INIT([uniset2], [2.2.1], pv@etersoft.ru)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME,AC_PACKAGE_VERSION)
LIBVER=2:2:1
AC_SUBST(LIBVER)
# AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADER(uniset-config.h)
......@@ -30,9 +33,6 @@ AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
AM_PROG_LIBTOOL
LIBVER=2:2:0
AC_SUBST(LIBVER)
ASTYLE_OPT="-A1 -T -C -S -N -L -w -Y -M -f -p --mode=c --lineend=linux --align-reference=type --align-pointer=type --suffix=none --style=ansi"
AC_SUBST(ASTYLE_OPT)
......
......@@ -10,7 +10,7 @@
#include "PassiveTimer.h"
#include "Trigger.h"
#include "IONotifyController.h"
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "Mutex.h"
#include "MessageType.h"
#include "ComediInterface.h"
......
......@@ -8,13 +8,13 @@ using namespace UniSetExtensions;
// -------------------------------------------------------------------------
PassiveLProcessor::PassiveLProcessor( UniSetTypes::ObjectId objId,
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic, const std::string& prefix ):
UniSetObject_LT(objId),
UniSetObject(objId),
shm(nullptr)
{
auto conf = uniset_conf();
logname = myname;
shm = make_shared<SMInterface>(shmID, UniSetObject_LT::ui, objId, ic);
shm = make_shared<SMInterface>(shmID, UniSetObject::ui, objId, ic);
string conf_name(conf->getArgParam("--" + prefix + "-confnode", myname));
......@@ -199,7 +199,7 @@ bool PassiveLProcessor::activateObject()
// см. sysCommand()
{
UniSetTypes::uniset_mutex_lock l(mutex_start, 5000);
UniSetObject_LT::activateObject();
UniSetObject::activateObject();
initIterators();
}
......
......@@ -4,7 +4,7 @@
#include <map>
#include <memory>
#include "UniSetTypes.h"
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "Extensions.h"
#include "SharedMemory.h"
#include "UInterface.h"
......@@ -13,7 +13,7 @@
// --------------------------------------------------------------------------
/*! Реализация LogicProccessor основанная на заказе датчиков */
class PassiveLProcessor:
public UniSetObject_LT,
public UniSetObject,
protected LProcessor
{
public:
......
......@@ -15,7 +15,7 @@ using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
MBExchange::MBExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId,
const std::shared_ptr<SharedMemory>& _ic, const std::string& prefix ):
UniSetObject_LT(objId),
UniSetObject(objId),
allInitOK(false),
initPause(3000),
force(false),
......@@ -327,7 +327,7 @@ void MBExchange::sigterm( int signo )
try
{
UniSetObject_LT::sigterm(signo);
UniSetObject::sigterm(signo);
}
catch( std::exception& ex)
{
......@@ -2766,7 +2766,7 @@ bool MBExchange::activateObject()
{
setProcActive(false);
UniSetTypes::uniset_rwmutex_rlock l(mutex_start);
UniSetObject_LT::activateObject();
UniSetObject::activateObject();
if( !shm->isLocalwork() )
rtuQueryOptimization(devices);
......@@ -3257,7 +3257,7 @@ std::ostream& operator<<( std::ostream& os, const MBExchange::ExchangeMode& em )
// -----------------------------------------------------------------------------
UniSetTypes::SimpleInfo* MBExchange::getInfo()
{
UniSetTypes::SimpleInfo_var i = UniSetObject_LT::getInfo();
UniSetTypes::SimpleInfo_var i = UniSetObject::getInfo();
ostringstream inf;
......
......@@ -7,7 +7,7 @@
#include <unordered_map>
#include <memory>
#include "IONotifyController.h"
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "PassiveTimer.h"
#include "DelayTimer.h"
#include "Trigger.h"
......@@ -34,7 +34,7 @@
\par Базовый класс для реализация обмена по протоколу Modbus [RTU|TCP].
*/
class MBExchange:
public UniSetObject_LT
public UniSetObject
{
public:
MBExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
......
......@@ -13,7 +13,7 @@ using namespace UniSetExtensions;
using namespace ModbusRTU;
// -----------------------------------------------------------------------------
MBSlave::MBSlave(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory>& ic, const string& prefix ):
UniSetObject_LT(objId),
UniSetObject(objId),
initPause(3000),
test_id(DefaultObjectId),
askcount_id(DefaultObjectId),
......@@ -883,7 +883,7 @@ bool MBSlave::activateObject()
{
activated = false;
UniSetTypes::uniset_rwmutex_wrlock l(mutex_start);
UniSetObject_LT::activateObject();
UniSetObject::activateObject();
initIterators();
activated = true;
startNotifyEvent.notify_all();
......@@ -909,7 +909,7 @@ bool MBSlave::deactivateObject()
mbwarn << myname << "(deactivateObject): " << ex.what() << endl;
}
return UniSetObject_LT::deactivateObject();
return UniSetObject::deactivateObject();
}
// ------------------------------------------------------------------------------------------
void MBSlave::sigterm( int signo )
......@@ -928,7 +928,7 @@ void MBSlave::sigterm( int signo )
mbwarn << myname << "SIGTERM(" << signo << "): " << ex.what() << endl;
}
UniSetObject_LT::sigterm(signo);
UniSetObject::sigterm(signo);
}
// ------------------------------------------------------------------------------------------
void MBSlave::readConfiguration()
......@@ -2377,7 +2377,7 @@ ModbusRTU::mbErrCode MBSlave::read4314( ModbusRTU::MEIMessageRDI& query,
// -------------------------------------------------------------------------
UniSetTypes::SimpleInfo* MBSlave::getInfo()
{
UniSetTypes::SimpleInfo_var i = UniSetObject_LT::getInfo();
UniSetTypes::SimpleInfo_var i = UniSetObject::getInfo();
ostringstream inf;
......
......@@ -11,7 +11,7 @@
#include <condition_variable>
#include <atomic>
#include <mutex>
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "modbus/ModbusTypes.h"
#include "modbus/ModbusServerSlot.h"
#include "PassiveTimer.h"
......@@ -289,7 +289,7 @@ namespace std
// -----------------------------------------------------------------------------
/*! Реализация slave-интерфейса */
class MBSlave:
public UniSetObject_LT
public UniSetObject
{
public:
MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "mbs" );
......
......@@ -45,7 +45,7 @@ void SharedMemory::help_print( int argc, const char* const* argv )
}
// -----------------------------------------------------------------------------
SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std::string& confname ):
IONotifyController_LT(id),
IONotifyController(id),
heartbeatCheckTime(5000),
histSaveTime(0),
activated(false),
......@@ -263,7 +263,7 @@ bool SharedMemory::deactivateObject()
if( logserv )
logserv = nullptr;
return IONotifyController_LT::deactivateObject();
return IONotifyController::deactivateObject();
}
// ------------------------------------------------------------------------------------------
bool SharedMemory::activateObject()
......@@ -278,7 +278,7 @@ bool SharedMemory::activateObject()
activated = false;
UniSetTypes::uniset_rwmutex_wrlock l(mutex_start);
res = IONotifyController_LT::activateObject();
res = IONotifyController::activateObject();
// инициализируем указатели
for( auto && it : hlist )
......@@ -316,7 +316,7 @@ void SharedMemory::sigterm( int signo )
wdt->stop();
// raise(SIGKILL);
IONotifyController_LT::sigterm(signo);
IONotifyController::sigterm(signo);
}
// ------------------------------------------------------------------------------------------
void SharedMemory::checkHeartBeat()
......@@ -570,7 +570,7 @@ void SharedMemory::addReadItem( Restorer_XML::ReaderSlot sl )
void SharedMemory::loggingInfo( SensorMessage& sm )
{
if( dblogging )
IONotifyController_LT::loggingInfo(sm);
IONotifyController::loggingInfo(sm);
}
// -----------------------------------------------------------------------------
void SharedMemory::buildHistoryList( xmlNode* cnode )
......@@ -957,7 +957,7 @@ bool SharedMemory::initFromSM( UniSetTypes::ObjectId sm_id, UniSetTypes::ObjectI
// ----------------------------------------------------------------------------
UniSetTypes::SimpleInfo* SharedMemory::getInfo()
{
UniSetTypes::SimpleInfo_var i = IONotifyController_LT::getInfo();
UniSetTypes::SimpleInfo_var i = IONotifyController::getInfo();
ostringstream inf;
......
......@@ -6,7 +6,7 @@
#include <string>
#include <memory>
#include <deque>
#include "IONotifyController_LT.h"
#include "IONotifyController.h"
#include "Mutex.h"
#include "PassiveTimer.h"
#include "NCRestorer.h"
......@@ -282,7 +282,7 @@
\endcode
*/
class SharedMemory:
public IONotifyController_LT
public IONotifyController
{
public:
SharedMemory( UniSetTypes::ObjectId id, const std::string& datafile, const std::string& confname = "" );
......
......@@ -10,7 +10,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
UNetExchange::UNetExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory>& ic, const std::string& prefix ):
UniSetObject_LT(objId),
UniSetObject(objId),
initPause(0),
activated(false),
no_sender(false)
......@@ -689,7 +689,7 @@ bool UNetExchange::activateObject()
{
activated = false;
UniSetTypes::uniset_rwmutex_wrlock l(mutex_start);
UniSetObject_LT::activateObject();
UniSetObject::activateObject();
initIterators();
activated = true;
}
......@@ -733,7 +733,7 @@ void UNetExchange::sigterm( int signo )
}
catch(...) {}
UniSetObject_LT::sigterm(signo);
UniSetObject::sigterm(signo);
}
// ------------------------------------------------------------------------------------------
void UNetExchange::initIterators()
......@@ -895,7 +895,7 @@ void UNetExchange::receiverEvent( const shared_ptr<UNetReceiver>& r, UNetReceive
// -----------------------------------------------------------------------------
UniSetTypes::SimpleInfo* UNetExchange::getInfo()
{
UniSetTypes::SimpleInfo_var i = UniSetObject_LT::getInfo();
UniSetTypes::SimpleInfo_var i = UniSetObject::getInfo();
ostringstream inf;
......
......@@ -6,7 +6,7 @@
#include <queue>
#include <deque>
#include <cc++/socket.h>
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "Trigger.h"
#include "Mutex.h"
#include "SMInterface.h"
......@@ -99,7 +99,7 @@
*/
// -----------------------------------------------------------------------------
class UNetExchange:
public UniSetObject_LT
public UniSetObject
{
public:
UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "unet" );
......
......@@ -8,7 +8,7 @@
#include <unordered_map>
#include <cc++/socket.h>
#include <sigc++/sigc++.h>
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "Trigger.h"
#include "Mutex.h"
#include "SMInterface.h"
......
......@@ -6,7 +6,7 @@
#include <vector>
#include <unordered_map>
#include <cc++/socket.h>
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "Trigger.h"
#include "Mutex.h"
#include "SMInterface.h"
......
......@@ -18,7 +18,6 @@
#include <unordered_map>
#include <sstream>
#include "UniSetObject.h"
#include "LT_Object.h"
#include "UniXML.h"
#include "Trigger.h"
#include "DebugStream.h"
......@@ -27,8 +26,7 @@
#include "VMonitor.h"
// -----------------------------------------------------------------------------
class UObject_SK:
public UniSetObject,
public LT_Object
public UniSetObject
{
public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix="" );
......
......@@ -365,10 +365,10 @@ void UObject_SK::preSysCommand( const SystemMessage* _sm )
waitSM(smReadyTimeout);
ptStartUpTimeout.reset();
// т.к. для io-переменных важно соблюдать последовательность!
// сперва обновить входы.. а потом уже выходы
// сперва обновить входы..
updateValues();
initFromSM(); // потом обновить, то, что помеченно как инициализируемое из SM
updateOutputs(true); // принудительное обновление выходов
initFromSM(); // потом обновить значения переменных, помеченных как инициализируемые из SM
updateOutputs(true); // а потом уже выходы (принудительное обновление)
preAskSensors(UniversalIO::UIONotify);
askSensors(UniversalIO::UIONotify);
active = true;
......
......@@ -25,7 +25,7 @@
#define DBServer_H_
// --------------------------------------------------------------------------
#include "UniSetTypes.h"
#include "UniSetObject_LT.h"
#include "UniSetObject.h"
#include "LogServer.h"
#include "DebugStream.h"
#include "LogAgregator.h"
......@@ -50,7 +50,7 @@
/*! Прототип реализации сервиса ведения БД */
class DBServer:
public UniSetObject_LT
public UniSetObject
{
public:
DBServer( UniSetTypes::ObjectId id, const std::string& prefix = "db" );
......
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Pavel Vainerman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
//---------------------------------------------------------------------------
#ifndef IONotifyController_LT_H_
#define IONotifyController_LT_H_
//--------------------------------------------------------------------------
#include "UniSetTypes.h"
#include "IONotifyController.h"
#include "LT_Object.h"
//---------------------------------------------------------------------------
/*!
Реализация базового класса с использованием локальных таймеров
*/
class IONotifyController_LT:
public IONotifyController
{
public:
IONotifyController_LT( UniSetTypes::ObjectId id );
IONotifyController_LT();
virtual ~IONotifyController_LT();
protected:
/*! заказ локального таймера
\param timerid - идентификатор таймера
\param timeMS - период. 0 - означает отказ от таймера
\param ticks - количество уведомлений. "-1"- постоянно
\return Возвращает время [мсек] оставшееся до срабатывания
очередного таймера
*/
void askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, short ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High );
/*! функция вызываемая из потока */
virtual void callback();
timeout_t sleepTime;
LT_Object lt;
private:
};
//--------------------------------------------------------------------------
#endif
......@@ -44,7 +44,7 @@ class UniSetObject;
\par Основной принцип
Проверяет список таймеров и при срабатывании формирует стандартное уведомление UniSetTypes::TimerMessage,
которое помещается в очередь указанному объекту. Каждый раз пересортировывает список и возвращает время оставшееся
которое помещается в очередь указанному объекту. При проверке таймеров, определяется минимальное время оставшееся
до очередного срабатывания. Если в списке не остаётся ни одного таймера - возвращает UniSetTimers::WaitUpTime.
Примерный код использования выглядит так:
......@@ -91,6 +91,8 @@ class UniSetObject;
\warning Точность работы определяется переодичностью вызова обработчика.
\sa TimerService
\todo Подумать.. может перейти на unordered_map
*/
class LT_Object
{
......@@ -106,7 +108,7 @@ class LT_Object
\param p - приоритет присылаемого сообщения
\return Возвращает время [мсек] оставшееся до срабатывания очередного таймера
*/
timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
virtual timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High );
......@@ -120,6 +122,19 @@ class LT_Object
/*! получить текущее время ожидания */
//inline timeout_t getSleepTimeMS(){ return sleepTime; }
/*! получить время на которое установлен таймер timerid
* \param timerid - идентификатор таймера
* \return 0 - если таймер не найден, время (мсек) если таймер есть.
*/
timeout_t getTimeInterval( UniSetTypes::TimerId timerid );
/*! получить оставшееся время для таймера timerid
* \param timerid - идентификатор таймера
* \return 0 - если таймер не найден, время (мсек) если таймер есть.
*/
timeout_t getTimeLeft( UniSetTypes::TimerId timerid );
protected:
/*! Информация о таймере */
......@@ -176,11 +191,12 @@ class LT_Object
typedef std::deque<TimerInfo> TimersList;
timeout_t sleepTime; /*!< текущее время ожидания */
private:
TimersList tlst;
/*! замок для блокирования совместного доступа к cписку таймеров */
UniSetTypes::uniset_rwmutex lstMutex;
timeout_t sleepTime; /*!< текущее время ожидания */
PassiveTimer tmLast;
};
//--------------------------------------------------------------------------
......
......@@ -2,11 +2,11 @@
#define SMonitor_H_
// -----------------------------------------------------------------------------
#include <list>
#include <UniSetObject_LT.h>
#include <UniSetObject.h>
#include "UniSetTypes.h"
// -----------------------------------------------------------------------------
class SMonitor:
public UniSetObject_LT
public UniSetObject
{
public:
......
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Pavel Vainerman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
//---------------------------------------------------------------------------
#ifndef UniSetManager_LT_H_
#define UniSetManager_LT_H_
//--------------------------------------------------------------------------
#include "UniSetTypes.h"
#include "UniSetManager.h"
#include "LT_Object.h"
//---------------------------------------------------------------------------
/*!
Реализация базового класса с использованием локальных таймеров
*/
class UniSetManager_LT:
public UniSetManager
{
public:
UniSetManager_LT( UniSetTypes::ObjectId id );
UniSetManager_LT();
virtual ~UniSetManager_LT();
protected:
/*! заказ локального таймера
\param timerid - идентификатор таймера
\param timeMS - период. 0 - означает отказ от таймера
\param ticks - количество уведомлений. "-1"- постоянно
\return Возвращает время [мсек] оставшееся до срабатывания
очередного таймера
*/
void askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, short ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High );
/*! функция вызываемая из потока */
virtual void callback();
timeout_t sleepTime;
LT_Object lt;
private:
};
//--------------------------------------------------------------------------
#endif
......@@ -45,6 +45,7 @@
#include "UInterface.h"
#include "UniSetObject_i.hh"
#include "ThreadCreator.h"
#include "LT_Object.h"
//---------------------------------------------------------------------------
//#include <omnithread.h>
......@@ -68,7 +69,8 @@ typedef std::list< std::shared_ptr<UniSetObject> > ObjectsList; /*!< Спи
*/
class UniSetObject:
public std::enable_shared_from_this<UniSetObject>,
public POA_UniSetObject_i
public POA_UniSetObject_i,
public LT_Object
{
public:
UniSetObject(const std::string& name, const std::string& section);
......@@ -121,6 +123,9 @@ class UniSetObject:
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) {}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) {}
virtual timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High ) override;
/*! Получить сообщение */
bool receiveMessage( UniSetTypes::VoidMessage& vm );
......
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Pavel Vainerman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
//---------------------------------------------------------------------------
#ifndef UniSetObject_LT_H_
#define UniSetObject_LT_H_
//--------------------------------------------------------------------------
#include "UniSetTypes.h"
#include "UniSetObject.h"
#include "LT_Object.h"
//---------------------------------------------------------------------------
/*!
Реализация базового класса с использованием локальных таймеров
*/
class UniSetObject_LT:
public UniSetObject
{
public:
UniSetObject_LT( UniSetTypes::ObjectId id );
UniSetObject_LT();
virtual ~UniSetObject_LT();
protected:
/*! заказ локального таймера
\param timerid - идентификатор таймера
\param timeMS - период. 0 - означает отказ от таймера
\param ticks - количество уведомлений. "-1"- постоянно
\return Возвращает время [мсек] оставшееся до срабатывания
очередного таймера
*/
void askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, short ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High );
/*! функция вызываемая из потока */
virtual void callback();
timeout_t sleepTime;
LT_Object lt;
private:
};
//--------------------------------------------------------------------------
#endif
......@@ -3,7 +3,7 @@ libObjectsRepository_la_SOURCES = UniSetTypes_iSK.cc UniSetObject_iSK.cc UniSetT
UniSetManager_iSK.cc ObjectIndex.cc ObjectIndex_Array.cc ObjectIndex_XML.cc ObjectIndex_idXML.cc \
ORepHelpers.cc UniSetObject.cc UniSetManager.cc \
UniSetActivator.cc ObjectRepository.cc ObjectRepositoryFactory.cc \
ProxyManager.cc PassiveObject.cc UniSetObject_LT.cc UniSetManager_LT.cc IORFile.cc
ProxyManager.cc PassiveObject.cc IORFile.cc
# ServiceActivator.cc
include $(top_builddir)/include.mk
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Pavel Vainerman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
// --------------------------------------------------------------------------
#include "Exceptions.h"
#include "UniSetManager_LT.h"
#include "Debug.h"
#include "PassiveTimer.h"
// ------------------------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// ------------------------------------------------------------------------------------------
UniSetManager_LT::UniSetManager_LT( UniSetTypes::ObjectId id ):
UniSetManager(id),
sleepTime(UniSetTimer::WaitUpTime)
{
}
// ------------------------------------------------------------------------------------------
UniSetManager_LT::UniSetManager_LT():
sleepTime(UniSetTimer::WaitUpTime)
{
}
// ------------------------------------------------------------------------------------------
UniSetManager_LT::~UniSetManager_LT()
{
}
// ------------------------------------------------------------------------------------------
void UniSetManager_LT::callback()
{
// При реализации с использованием waitMessage() каждый раз при вызове askTimer() необходимо
// проверять возвращаемое значение на UniSetTimers::WaitUpTime и вызывать termWaiting(),
// чтобы избежать ситуации, когда процесс до заказа таймера 'спал'(в функции waitMessage()) и после
// заказа продолжит спать(т.е. обработчик вызван не будет)...
try
{
if( waitMessage(msg, sleepTime) )
processingMessage(&msg);
sleepTime = lt.checkTimers(this);
}
catch( const Exception& ex )
{
ucrit << myname << "(callback): " << ex << endl;
}
}
// ------------------------------------------------------------------------------------------
void UniSetManager_LT::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, short ticks, UniSetTypes::Message::Priority p )
{
// проверяйте возвращаемое значение
if( lt.askTimer(timerid, timeMS, ticks, p) != UniSetTimer::WaitUpTime )
termWaiting();
}
// ------------------------------------------------------------------------------------------
......@@ -840,18 +840,20 @@ void UniSetObject::work()
// ------------------------------------------------------------------------------------------
void UniSetObject::callback()
{
// При реализации с использованием waitMessage() каждый раз при вызове askTimer() необходимо
// проверять возвращаемое значение на UniSetTimers::WaitUpTime и вызывать termWaiting(),
// чтобы избежать ситуации, когда процесс до заказа таймера 'спал'(в функции waitMessage()) и после
// заказа продолжит спать(т.е. обработчик вызван не будет)...
try
{
if( waitMessage(msg) )
if( waitMessage(msg, sleepTime) )
processingMessage(&msg);
sleepTime = checkTimers(this);
}
catch( const Exception& ex )
{
ucrit << ex << endl;
}
catch( const std::exception& ex )
{
ucrit << ex.what() << endl;
ucrit << myname << "(callback): " << ex << endl;
}
}
// ------------------------------------------------------------------------------------------
......@@ -913,6 +915,16 @@ void UniSetObject::processingMessage( UniSetTypes::VoidMessage* msg )
*/
}
// ------------------------------------------------------------------------------------------
timeout_t UniSetObject::askTimer( TimerId timerid, timeout_t timeMS, clock_t ticks, Message::Priority p )
{
timeout_t tsleep = LT_Object::askTimer(timerid, timeMS, ticks, p);
if( tsleep != UniSetTimer::WaitUpTime )
termWaiting();
return tsleep;
}
// ------------------------------------------------------------------------------------------
UniSetTypes::SimpleInfo* UniSetObject::getInfo()
{
......
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Pavel Vainerman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
// --------------------------------------------------------------------------
#include "Exceptions.h"
#include "Debug.h"
#include "PassiveTimer.h"
#include "UniSetObject_LT.h"
// ------------------------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// ------------------------------------------------------------------------------------------
UniSetObject_LT::UniSetObject_LT( UniSetTypes::ObjectId id ):
UniSetObject(id),
sleepTime(UniSetTimer::WaitUpTime)
{
}
// ------------------------------------------------------------------------------------------
UniSetObject_LT::UniSetObject_LT():
sleepTime(UniSetTimer::WaitUpTime)
{
}
// ------------------------------------------------------------------------------------------
UniSetObject_LT::~UniSetObject_LT()
{
}
// ------------------------------------------------------------------------------------------
void UniSetObject_LT::callback()
{
// При реализации с использованием waitMessage() каждый раз при вызове askTimer() необходимо
// проверять возвращаемое значение на UniSetTimers::WaitUpTime и вызывать termWaiting(),
// чтобы избежать ситуации, когда процесс до заказа таймера 'спал'(в функции waitMessage()) и после
// заказа продолжит спать(т.е. обработчик вызван не будет)...
try
{
if( waitMessage(msg, sleepTime) )
processingMessage(&msg);
sleepTime = lt.checkTimers(this);
}
catch( const Exception& ex )
{
ucrit << myname << "(callback): " << ex << endl;
}
}
// ------------------------------------------------------------------------------------------
void UniSetObject_LT::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, short ticks, UniSetTypes::Message::Priority p )
{
// проверяйте возвращаемое значение
if( lt.askTimer(timerid, timeMS, ticks, p) != UniSetTimer::WaitUpTime )
termWaiting();
}
// ------------------------------------------------------------------------------------------
/* This file is part of the UniSet project
* Copyright (c) 2002 Free Software Foundation, Inc.
* Copyright (c) 2002 Pavel Vainerman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
// --------------------------------------------------------------------------
#include "Exceptions.h"
#include "Debug.h"
#include "PassiveTimer.h"
#include "IONotifyController_LT.h"
// ------------------------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// ------------------------------------------------------------------------------------------
IONotifyController_LT::IONotifyController_LT( UniSetTypes::ObjectId id ):
IONotifyController(id),
sleepTime(UniSetTimer::WaitUpTime)
{
}
// ------------------------------------------------------------------------------------------
IONotifyController_LT::IONotifyController_LT():
sleepTime(UniSetTimer::WaitUpTime)
{
}
// ------------------------------------------------------------------------------------------
IONotifyController_LT::~IONotifyController_LT()
{
}
// ------------------------------------------------------------------------------------------
void IONotifyController_LT::callback()
{
// При реализации с использованием waitMessage() каждый раз при вызове askTimer() необходимо
// проверять возвращаемое значение на UniSetTimers::WaitUpTime и вызывать termWaiting(),
// чтобы избежать ситуации, когда процесс до заказа таймера 'спал'(в функции waitMessage()) и после
// заказа продолжит спать(т.е. обработчик вызван не будет)...
try
{
if( waitMessage(msg, sleepTime) )
processingMessage(&msg);
sleepTime = lt.checkTimers(this);
}
catch( const Exception& ex )
{
ucrit << myname << "(callback): " << ex << endl;
}
}
// ------------------------------------------------------------------------------------------
void IONotifyController_LT::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, short ticks, UniSetTypes::Message::Priority p )
{
// проверяйте возвращаемое значение
if( lt.askTimer(timerid, timeMS, ticks, p) != UniSetTimer::WaitUpTime )
termWaiting();
}
// ------------------------------------------------------------------------------------------
......@@ -5,7 +5,7 @@
noinst_LTLIBRARIES = libProcesses.la
libProcesses_la_CXXFLAGS = $(SIGC_CFLAGS)
libProcesses_la_LIBADD = $(SIGC_LIBS)
libProcesses_la_SOURCES = IOController_iSK.cc IOController.cc IONotifyController.cc IONotifyController_LT.cc \
libProcesses_la_SOURCES = IOController_iSK.cc IOController.cc IONotifyController.cc \
NCRestorer.cc NCRestorer_XML.cc
local-clean:
......
......@@ -38,7 +38,7 @@ using namespace UniSetTypes;
using namespace std;
// ------------------------------------------------------------------------------------------
DBServer::DBServer( ObjectId id, const std::string& prefix ):
UniSetObject_LT(id)
UniSetObject(id)
{
if( getId() == DefaultObjectId )
{
......@@ -96,7 +96,7 @@ void DBServer::processingMessage( UniSetTypes::VoidMessage* msg )
break;
default:
UniSetObject_LT::processingMessage(msg);
UniSetObject::processingMessage(msg);
break;
}
......@@ -104,14 +104,14 @@ void DBServer::processingMessage( UniSetTypes::VoidMessage* msg )
//--------------------------------------------------------------------------------------------
bool DBServer::activateObject()
{
UniSetObject_LT::activateObject();
UniSetObject::activateObject();
initDBServer();
return true;
}
//--------------------------------------------------------------------------------------------
void DBServer::sysCommand( const UniSetTypes::SystemMessage* sm )
{
UniSetObject_LT::sysCommand(sm);
UniSetObject::sysCommand(sm);
if( sm->command == SystemMessage::StartUp )
{
......
......@@ -126,6 +126,32 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj )
return sleepTime;
}
// ------------------------------------------------------------------------------------------
timeout_t LT_Object::getTimeInterval( TimerId timerid )
{
// lock
uniset_rwmutex_rlock lock(lstMutex);
for( const auto& li: tlst )
{
if( li.id == timerid )
return li.tmr.getInterval();
}
return 0;
}
// ------------------------------------------------------------------------------------------
timeout_t LT_Object::getTimeLeft(TimerId timerid)
{
// lock
uniset_rwmutex_rlock lock(lstMutex);
for( const auto& li: tlst )
{
if( li.id == timerid )
return li.curTimeMS;
}
return 0;
}
// ------------------------------------------------------------------------------------------
timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks, UniSetTypes::Message::Priority p )
{
......
......@@ -17,7 +17,7 @@ SMonitor::SMonitor():
}
SMonitor::SMonitor(ObjectId id):
UniSetObject_LT(id),
UniSetObject(id),
script("")
{
string sid(uniset_conf()->getArgParam("--sid"));
......
......@@ -261,7 +261,6 @@ include/Exceptions.h
include/HourGlass.h
include/IOController.h
include/IONotifyController.h
include/IONotifyController_LT.h
include/IORFile.h
include/LogAgregator.h
include/LogReader.h
......@@ -299,9 +298,7 @@ include/TriggerOUT.h
include/UInterface.h
include/UniSetActivator.h
include/UniSetManager.h
include/UniSetManager_LT.h
include/UniSetObject.h
include/UniSetObject_LT.h
include/UniSetTypes.h
include/UniXML.h
include/UTCPStream.h
......@@ -370,13 +367,10 @@ src/ObjectRepository/PassiveObject.cc
src/ObjectRepository/ProxyManager.cc
src/ObjectRepository/UniSetActivator.cc
src/ObjectRepository/UniSetManager.cc
src/ObjectRepository/UniSetManager_LT.cc
src/ObjectRepository/UniSetObject.cc
src/ObjectRepository/UniSetObject_LT.cc
src/ObjectRepository/UniSetTypes.cc
src/Processes/IOController.cc
src/Processes/IONotifyController.cc
src/Processes/IONotifyController_LT.cc
src/Processes/Makefile.am
src/Processes/NCRestorer.cc
src/Processes/NCRestorer_XML.cc
......
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