Commit 13b33b33 authored by Pavel Vainerman's avatar Pavel Vainerman

Переименовал xxx_template.h --> xxx.tcc

parent 62f54d37
......@@ -15,7 +15,7 @@ Source: /var/ftp/pvt/Etersoft/Ourside/unstable/sources/tarball/%name-%version.ta
# manually removed: glibc-devel-static
# Automatically added by buildreq on Fri Nov 26 2010
BuildRequires: glibc-devel-static libcomedi-devel libcommoncpp2-devel libomniORB-devel libsigc++2.0-devel python-modules xsltproc
BuildRequires: libcomedi-devel libcommoncpp2-devel libomniORB-devel libsigc++2.0-devel python-modules xsltproc
# Using old package name instead of libmysqlclient-devel it absent in branch 5.0 for yauza
BuildRequires: libMySQL-devel
......@@ -138,6 +138,7 @@ rm -f %buildroot%_libdir/*.la
%dir %_includedir/%oname/
%_includedir/%oname/*.h
%_includedir/%oname/*.hh
%_includedir/%oname/*.tcc
%_includedir/%oname/IOs/
%_includedir/%oname/modbus/
%_includedir/%oname/mysql/
......
......@@ -21,8 +21,8 @@
* \author Pavel Vainerman
*/
// --------------------------------------------------------------------------
# ifndef CallBackTimer_TCC_H_
# define CallBackTimer_TCC_H_
# ifndef CallBackTimer_TEMPLATE_H_
# define CallBackTimer_TEMPLATE_H_
// --------------------------------------------------------------------------
#include <unistd.h>
#include <sstream>
......@@ -180,4 +180,4 @@ int CallBackTimer<Caller>::getCurrent( int id )
}
// ------------------------------------------------------------------------------------------
# endif //CallBackTimer_TCC_H_
# endif //CallBackTimer_H_
/* 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 CallBackTimer_TEMPLATE_H_
# define CallBackTimer_TEMPLATE_H_
// --------------------------------------------------------------------------
#include <unistd.h>
#include <sstream>
#include "CallBackTimer.h"
// ------------------------------------------------------------------------------------------
template <class Caller> class CallBackTimer;
// ------------------------------------------------------------------------------------------
/*! Создание таймера
\param r - указатель на заказчика
*/
template <class Caller>
CallBackTimer<Caller>::CallBackTimer( Caller* r, Action a ):
cal(r),
act(a),
terminated(false)
{
thr = new ThreadCreator<CallBackTimer>(this, &CallBackTimer<Caller>::work);
}
// ------------------------------------------------------------------------------------------
template <class Caller>
CallBackTimer<Caller>::CallBackTimer():
cal(null),
terminated(false)
{
thr = new ThreadCreator<CallBackTimer>(this, &CallBackTimer<Caller>::work);
}
// ------------------------------------------------------------------------------------------
template <class Caller>
CallBackTimer<Caller>::~CallBackTimer()
{
terminate();
clearTimers();
delete thr;
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::work()
{
terminated = false;
while( !terminated )
{
usleep(UniSetTimer::MIN_QUANTITY_TIME_MKS);
for( typename TimersList::iterator li=lst.begin(); li!=lst.end(); ++li )
{
if( li->pt.checkTime() )
{
(cal->*act)( li->id );
li->pt.reset();
}
}
}
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::run()
{
if( !terminated )
terminate();
startTimers();
// PosixThread::start(static_cast<PosixThread*>(this));
thr->start();
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::terminate()
{
// timeAct = 0;
terminated = true;
usleep(1000);
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::add( int id, int timeMS )throw(UniSetTypes::LimitTimers)
{
if( lst.size() >= MAXCallBackTimer )
{
ostringstream err;
err << "CallBackTimers: превышено максимальное количество таймеров" << MAXCallBackTimer;
throw UniSetTypes::LimitTimers(err.str());
}
PassiveTimer pt(timeMS);
TimerInfo ti(id, pt);
lst.push_back(ti);
// lst[id] = ti;
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::remove( int id )
{
// STL - способ поиска
typename TimersList::iterator li= find_if(lst.begin(),lst.end(),FindId_eq(id));
if( li!=lst.end() )
lst.erase(li);
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::startTimers()
{
for( typename TimersList::iterator li=lst.begin(); li!=lst.end(); ++li)
{
li->pt.reset();
}
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::clearTimers()
{
lst.clear();
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::reset( int id )
{
typename TimersList::iterator li= find_if(lst.begin(),lst.end(),FindId_eq(id));
if( li!=lst.end() )
li->pt.reset();
}
// ------------------------------------------------------------------------------------------
template <class Caller>
void CallBackTimer<Caller>::setTiming( int id, int timeMS )
{
typename TimersList::iterator li= find_if(lst.begin(),lst.end(),FindId_eq(id));
if( li!=lst.end() )
li->pt.setTimer(timeMS);
}
// ------------------------------------------------------------------------------------------
template <class Caller>
int CallBackTimer<Caller>::getInterval( int id )
{
typename TimersList::iterator li= find_if(lst.begin(),lst.end(),FindId_eq(id));
if( li!=lst.end() )
return li->pt.getInterval();
return -1;
}
// ------------------------------------------------------------------------------------------
template <class Caller>
int CallBackTimer<Caller>::getCurrent( int id )
{
typename TimersList::iterator li= find_if(lst.begin(),lst.end(),FindId_eq(id));
if( li!=lst.end() )
return li->pt.getCurrent();
return -1;
}
// ------------------------------------------------------------------------------------------
# endif //CallBackTimer_H_
/* 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 "TriggerAND.h"
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
TriggerAND<Caller,InputType>::TriggerAND(Caller* c, Action a):
cal(c),
act(a)
{
}
template<class Caller, typename InputType>
TriggerAND<Caller,InputType>::~TriggerAND()
{
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
bool TriggerAND<Caller,InputType>::commit(InputType num, bool state)
{
typename InputMap::iterator it=inputs.find(num);
if( it!=inputs.end() )
{
inputs[num] = state;
check();
return true;
}
return false;
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerAND<Caller,InputType>::add(InputType num, bool state)
{
inputs[num] = state;
check();
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerAND<Caller,InputType>::remove(InputType num)
{
typename InputMap::iterator it=inputs.find(num);
if( it!=inputs.end() )
inputs.erase(it);
check();
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
bool TriggerAND<Caller,InputType>::getState(InputType num)
{
typename InputMap::iterator it=inputs.find(num);
if( it!=inputs.end() )
return it->second;
return false; // throw NotFound
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerAND<Caller,InputType>::check()
{
bool old = out;
for( typename InputMap::iterator it=inputs.begin(); it!=inputs.end(); ++it )
{
if( !it->second )
{
// если хоть один вход "0" на выходе "0"
// и прекращаем дальнейший поиск
out = false;
if( old != out )
{
// try
// {
(cal->*act)(out);
// }
// catch(...){}
}
return;
}
}
out = true;
if( old != out )
{
// try
// {
(cal->*act)(out);
// }
// catch(...){}
}
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerAND<Caller,InputType>::update()
{
(cal->*act)(out);
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerAND<Caller,InputType>::reset()
{
out = false;
(cal->*act)(out);
}
//---------------------------------------------------------------------------
/* 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 "TriggerOR.h"
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
TriggerOR<Caller,InputType>::TriggerOR(Caller* c, Action a):
cal(c),
act(a)
{
}
template<class Caller, typename InputType>
TriggerOR<Caller,InputType>::~TriggerOR()
{
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
bool TriggerOR<Caller,InputType>::commit(InputType num, bool state)
{
typename InputMap::iterator it=inputs.find(num);
if( it!=inputs.end() )
{
inputs[num] = state;
check();
return true;
}
return false;
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::add(InputType num, bool state)
{
inputs[num] = state;
check();
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::remove(InputType num)
{
typename InputMap::iterator it=inputs.find(num);
if( it!=inputs.end() )
inputs.erase(it);
check();
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
bool TriggerOR<Caller,InputType>::getState(InputType num)
{
typename InputMap::iterator it=inputs.find(num);
if( it!=inputs.end() )
return it->second;
return false; // throw NotFound
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::check()
{
bool old = out;
for( typename InputMap::iterator it=inputs.begin(); it!=inputs.end(); ++it )
{
if( it->second )
{
// если хоть один вход "1" на выходе "1"
// и прекращаем дальнейший поиск
out = true;
if( old != out )
{
// try
// {
(cal->*act)(out);
// }
// catch(...){}
}
return;
}
}
out = false;
if( old != out )
{
// try
// {
(cal->*act)(out);
// }
// catch(...){}
}
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::update()
{
(cal->*act)(out);
}
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::reset()
{
out = false;
(cal->*act)(out);
}
//---------------------------------------------------------------------------
/* 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 "TriggerOutput.h"
//---------------------------------------------------------------------------
template<class Caller, typename OutIdType, typename ValueType>
TriggerOutput<Caller,OutIdType,ValueType>::TriggerOutput( Caller* r, Action a):
cal(r),
act(a)
{
}
template <class Caller, typename OutIdType, typename ValueType>
TriggerOutput<Caller,OutIdType,ValueType>::~TriggerOutput()
{
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
void TriggerOutput<Caller,OutIdType,ValueType>::add(OutIdType num, ValueType val)
{
outs[num] = val;
set(num,val);
try
{
(cal->*act)(num,val);
}
catch(...){}
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
void TriggerOutput<Caller,OutIdType,ValueType>::remove(OutIdType num)
{
typename OutList::iterator it=outs.find(num);
if( it!=outs.end() )
outs.erase(it);
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
bool TriggerOutput<Caller,OutIdType,ValueType>::getState(OutIdType out)
{
typename OutList::iterator it=outs.find(out);
if( it!=outs.end() )
return it->second;
return false;
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
void TriggerOutput<Caller,OutIdType,ValueType>::set(OutIdType out, ValueType val)
{
typename OutList::iterator it=outs.find(out);
if( it==outs.end() )
return;
// потом val
ValueType prev(it->second);
it->second = val;
if( prev != val )
{
check(out); // выставляем сперва все нули
try
{
(cal->*act)(it->first, it->second);
}
catch(...){}
}
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
void TriggerOutput<Caller,OutIdType,ValueType>::check(OutIdType newout)
{
for( typename OutList::iterator it=outs.begin(); it!=outs.end(); ++it )
{
if( it->first != newout && it->second )
{
it->second = 0;
// try
// {
(cal->*act)(it->first, it->second);
// }
// catch(...){}
}
}
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
void TriggerOutput<Caller,OutIdType,ValueType>::update()
{
for( typename OutList::iterator it=outs.begin(); it!=outs.end(); ++it )
(cal->*act)(it->first, it->second);
}
//---------------------------------------------------------------------------
template <class Caller, typename OutIdType, typename ValueType>
void TriggerOutput<Caller,OutIdType,ValueType>::reset()
{
for( typename OutList::iterator it=outs.begin(); it!=outs.end(); ++it )
{
it->second = 0;
(cal->*act)(it->first, it->second);
}
}
//---------------------------------------------------------------------------
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