Commit 4a845cba authored by Pavel Vaynerman's avatar Pavel Vaynerman

Merge branch 'master' of git.eter:/projects/uniset

Conflicts: conf/libuniset.spec tests/Makefile.am
parents c159a4ac 7c32b51c
...@@ -182,6 +182,18 @@ interface IOController_i : ObjectsManager_i ...@@ -182,6 +182,18 @@ interface IOController_i : ObjectsManager_i
ӣ . ӣ .
*/ */
UniSetTypes::IDSeq setOutputSeq( in OutSeq lst, in UniSetTypes::ObjectId sup_id ); UniSetTypes::IDSeq setOutputSeq( in OutSeq lst, in UniSetTypes::ObjectId sup_id );
/*! */
struct ShortIOInfo
{
long value;
long tv_sec; /*!< , (gettimeofday) */
long tv_usec; /*!< , (gettimeofday) */
};
ShortIOInfo getChangedTime(in SensorInfo si) raises(NameNotFound);
}; };
// -------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------
......
...@@ -211,7 +211,7 @@ bool reOpen() ...@@ -211,7 +211,7 @@ bool reOpen()
int i,k=0; int i,k=0;
char *str = new char[30]; char *str = new char[30];
printf("the same after reopen:\n"); printf("the same after reopen:\n");
if(!j.open("big_file.test",30,32000,seek)) if(!j.open("big_file.test",30,33000,seek))
{ {
printf("Reopen file error\n"); printf("Reopen file error\n");
delete str; delete str;
...@@ -237,7 +237,7 @@ bool testJournal1(void) ...@@ -237,7 +237,7 @@ bool testJournal1(void)
int i,k=0; int i,k=0;
char *str = new char[30]; char *str = new char[30];
printf("journal test 1\n"); printf("journal test 1\n");
for(i=1;i<33000;i++) for(i=1;i<64001;i++)
{ {
sprintf(str,"%d",i); sprintf(str,"%d",i);
j.addRow(str); j.addRow(str);
...@@ -257,7 +257,8 @@ bool testJournal1(void) ...@@ -257,7 +257,8 @@ bool testJournal1(void)
return false; return false;
} }
k = 0; k = 0;
printf("size changed to 33000 rows (increased)\n");
j.setSize(33000);
TableBlockStorage t("big_file.test", 4, 40, 100, 5,28,0); TableBlockStorage t("big_file.test", 4, 40, 100, 5,28,0);
printf("test of 2 classes working in 1 file together\n"); printf("test of 2 classes working in 1 file together\n");
char *val = new char[40]; char *val = new char[40];
...@@ -294,7 +295,7 @@ bool testJournal1(void) ...@@ -294,7 +295,7 @@ bool testJournal1(void)
k = 0; k = 0;
printf("first 20 after adding 10 elements\n"); printf("first 20 after adding 10 elements\n");
for(i=10001;i<10011;i++) for(i=10000001;i<10000011;i++)
{ {
sprintf(str,"%d",i); sprintf(str,"%d",i);
j.addRow(str); j.addRow(str);
...@@ -319,6 +320,23 @@ bool testJournal1(void) ...@@ -319,6 +320,23 @@ bool testJournal1(void)
if(!reOpen()) return false; if(!reOpen()) return false;
printf("size changed back to 32000 rows\n");
j.setSize(32000);
for(i=0;i<20;i++)
{
if(j.readRow(i,str))
{
printf("%s\n",str);
k++;
}
}
if(k != 10)
{
delete str;
return false;
}
k = 0;
delete str; delete str;
return true; return true;
} }
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
Name: libuniset Name: libuniset
Version: 0.96 Version: 0.96
Release: eter47 Release: eter47
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
...@@ -180,6 +179,15 @@ rm -f %buildroot%_libdir/*.la ...@@ -180,6 +179,15 @@ rm -f %buildroot%_libdir/*.la
* Tue Aug 18 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter46 * Tue Aug 18 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter46
- new build - new build
* Thu Aug 13 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter41
- new build
* Wed Aug 12 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter40
- new build
* Wed Aug 12 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter39
- new build
* Thu Aug 06 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter38 * Thu Aug 06 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter38
- new build - new build
......
...@@ -122,6 +122,8 @@ class IOController: ...@@ -122,6 +122,8 @@ class IOController:
UniSetTypes::Message::Priority getPriority(const IOController_i::SensorInfo& si, UniSetTypes::Message::Priority getPriority(const IOController_i::SensorInfo& si,
UniversalIO::IOTypes type); UniversalIO::IOTypes type);
virtual IOController_i::ShortIOInfo getChangedTime(const IOController_i::SensorInfo& si);
public: public:
struct DependsInfo; struct DependsInfo;
......
...@@ -182,6 +182,9 @@ class CycleStorage ...@@ -182,6 +182,9 @@ class CycleStorage
/*! - / ( ) */ /*! - / ( ) */
int getIter(void); int getIter(void);
/*! ( ) */
bool setSize(int count);
inline int getByteSize() { return (size*full_size + sizeof(CycleStorageAttr)); } inline int getByteSize() { return (size*full_size + sizeof(CycleStorageAttr)); }
inline int getSize(){ return size; } inline int getSize(){ return size; }
......
...@@ -176,7 +176,7 @@ class UniversalInterface ...@@ -176,7 +176,7 @@ class UniversalInterface
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId ); UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId );
void askRemoteOutput( UniSetTypes::ObjectId id, UniversalIO::UIOCommand cmd, UniSetTypes::ObjectId node, void askRemoteOutput( UniSetTypes::ObjectId id, UniversalIO::UIOCommand cmd, UniSetTypes::ObjectId node,
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId )throw(IO_THROW_EXCEPTIONS); UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId )throw(IO_THROW_EXCEPTIONS);
//! //!
void askTimer( UniSetTypes::TimerId timerid, CORBA::Long timeMS, CORBA::Short ticks=-1, void askTimer( UniSetTypes::TimerId timerid, CORBA::Long timeMS, CORBA::Short ticks=-1,
...@@ -191,11 +191,14 @@ class UniversalInterface ...@@ -191,11 +191,14 @@ class UniversalInterface
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId ) throw(IO_THROW_EXCEPTIONS); UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId ) throw(IO_THROW_EXCEPTIONS);
UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS); UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id); UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id);
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS); UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id); UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id);
IOController_i::ShortIOInfo getChangedTime( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node );
// /*! */ // /*! */
void registered(UniSetTypes::ObjectId id, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed); void registered(UniSetTypes::ObjectId id, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed);
void registered(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed); void registered(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed);
......
...@@ -2188,6 +2188,78 @@ void UniversalInterface::fastSaveState( IOController_i::SensorInfo& si, bool sta ...@@ -2188,6 +2188,78 @@ void UniversalInterface::fastSaveState( IOController_i::SensorInfo& si, bool sta
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
IOController_i::ShortIOInfo UniversalInterface::getChangedTime( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node )
{
if( id == DefaultObjectId )
throw ORepFailed("UI(getChangedTime): Unknown id=UniSetTypes::DefaultObjectId");
IOController_i::SensorInfo si;
si.id = id;
si.node = node;
try
{
CORBA::Object_var oref;
try
{
oref = rcache.resolve(si.id, si.node);
}
catch( NameNotFound ){}
for (unsigned int i=0; i<uconf->getRepeatCount(); i++)
{
try
{
if( CORBA::is_nil(oref) )
oref = resolve( si.id, si.node );
IOController_i_var iom = IOController_i::_narrow(oref);
return iom->getChangedTime(si);
}
catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){}
msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil();
}
}
catch(UniSetTypes::TimeOut){}
catch(IOController_i::NameNotFound &ex)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << "UI(getChangedTime): " << ex.err << endl;
}
catch(ORepFailed)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << set_err("UI(getChangedTime): ",si.id,si.node) << endl;
}
catch(CORBA::NO_IMPLEMENT)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << set_err("UI(getChangedTime): ",si.id,si.node) << endl;
}
catch(CORBA::OBJECT_NOT_EXIST)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << set_err("UI(getChangedTime): ",si.id,si.node) << endl;
}
catch(CORBA::COMM_FAILURE)
{
//
// unideb[Debug::WARN] << "UI(saveState): CORBA::COMM_FAILURE " << endl;
}
catch(CORBA::SystemException& ex)
{
//
// unideb[Debug::WARN] << "UI(saveState): CORBA::SystemException" << endl;
}
catch(...){}
rcache.erase(si.id, si.node);
throw UniSetTypes::TimeOut(set_err("UI(getChangedTime): TimeOut ",si.id, si.node));
}
// ------------------------------------------------------------------------------------------------------------
ObjectPtr UniversalInterface::CacheOfResolve::resolve( ObjectId id, ObjectId node ) ObjectPtr UniversalInterface::CacheOfResolve::resolve( ObjectId id, ObjectId node )
throw(NameNotFound) throw(NameNotFound)
......
...@@ -235,7 +235,7 @@ void ObjectsManager::managers(OManagerCommand cmd) ...@@ -235,7 +235,7 @@ void ObjectsManager::managers(OManagerCommand cmd)
} }
catch( Exception& ex ) catch( Exception& ex )
{ {
unideb[Debug::CRIT] << myname << "(managers): " << ex << endl; unideb[Debug::CRIT] << myname << "(managers): " << ex << endl;
unideb[Debug::CRIT] << myname << "(managers): () -->"<< (*li)->getName() << endl; unideb[Debug::CRIT] << myname << "(managers): () -->"<< (*li)->getName() << endl;
} }
catch(CORBA::SystemException& ex) catch(CORBA::SystemException& ex)
...@@ -304,7 +304,9 @@ void ObjectsManager::objects(OManagerCommand cmd) ...@@ -304,7 +304,9 @@ void ObjectsManager::objects(OManagerCommand cmd)
} }
catch( CORBA::Exception& ex ) catch( CORBA::Exception& ex )
{ {
unideb[Debug::CRIT] << myname << "(objects): Caught CORBA::Exception." << endl; unideb[Debug::CRIT] << myname << "(objects): Caught CORBA::Exception. "
<< ex._name()
<< " (" << (*li)->getName() << ")" << endl;
} }
catch( omniORB::fatalException& fe ) catch( omniORB::fatalException& fe )
{ {
......
...@@ -913,7 +913,10 @@ IOController_i::DigitalIOInfo IOController::getDInfo(const IOController_i::Senso ...@@ -913,7 +913,10 @@ IOController_i::DigitalIOInfo IOController::getDInfo(const IOController_i::Senso
{ {
DIOStateList::iterator it = dioList.find( key(si.id, si.node) ); DIOStateList::iterator it = dioList.find( key(si.id, si.node) );
if( it!=dioList.end() ) if( it!=dioList.end() )
{
uniset_spin_lock lock(it->second.val_lock,checkLockValuePause);
return it->second; return it->second;
}
// ------------- // -------------
ostringstream err; ostringstream err;
...@@ -926,7 +929,10 @@ IOController_i::AnalogIOInfo IOController::getAInfo(const IOController_i::Sensor ...@@ -926,7 +929,10 @@ IOController_i::AnalogIOInfo IOController::getAInfo(const IOController_i::Sensor
{ {
AIOStateList::iterator it = aioList.find( key(si.id, si.node) ); AIOStateList::iterator it = aioList.find( key(si.id, si.node) );
if( it!=aioList.end() ) if( it!=aioList.end() )
{
uniset_spin_lock lock(it->second.val_lock,checkLockValuePause);
return it->second; return it->second;
}
// ------------- // -------------
ostringstream err; ostringstream err;
...@@ -1362,3 +1368,35 @@ IDSeq* IOController::setOutputSeq(const IOController_i::OutSeq& lst, ObjectId su ...@@ -1362,3 +1368,35 @@ IDSeq* IOController::setOutputSeq(const IOController_i::OutSeq& lst, ObjectId su
return badlist.getIDSeq(); return badlist.getIDSeq();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i::SensorInfo& si )
{
DIOStateList::iterator dit = dioList.find( key(si.id, si.node) );
if( dit!=dioList.end() )
{
IOController_i::ShortIOInfo i;
uniset_spin_lock lock(dit->second.val_lock,checkLockValuePause);
i.value = dit->second.state ? 1 : 0;
i.tv_sec = dit->second.tv_sec;
i.tv_usec = dit->second.tv_usec;
return i;
}
AIOStateList::iterator ait = aioList.find( key(si.id, si.node) );
if( ait!=aioList.end() )
{
IOController_i::ShortIOInfo i;
uniset_spin_lock lock(ait->second.val_lock,checkLockValuePause);
i.value = ait->second.value;
i.tv_sec = ait->second.tv_sec;
i.tv_usec = ait->second.tv_usec;
return i;
}
// -------------
ostringstream err;
err << myname << "(getChangedTime): () "
<< conf->oind->getNameById(si.id) << " ";
unideb[Debug::INFO] << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str());
}
// -----------------------------------------------------------------------------
...@@ -365,7 +365,7 @@ void* CycleStorage::readRow(int num, void* str) ...@@ -365,7 +365,7 @@ void* CycleStorage::readRow(int num, void* str)
int j=(head+num)%size; int j=(head+num)%size;
if((file==NULL)||(num>=size)) return 0; if((file==NULL)||(num>=size)) return 0;
if((head!=tail+1)&&(num>tail)) return 0; if((head!=tail+1)&&(num>tail)&&(head!=tail)) return 0;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size]; CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
fseek(file,seekpos+j*full_size,0); fseek(file,seekpos+j*full_size,0);
...@@ -385,3 +385,77 @@ int CycleStorage::getIter() ...@@ -385,3 +385,77 @@ int CycleStorage::getIter()
{ {
return iter; return iter;
} }
/*! . , .
, , . , . .
, */
bool CycleStorage::setSize(int count)
{
if( file==NULL ) return false;
if( count==size ) return true;
fseek(file,seekpos-sizeof(CycleStorageAttr),0);
/*! */
CycleStorageAttr csa;
csa.inf_size=inf_size;
csa.size=count;
csa.seekpos=seekpos-sizeof(CycleStorageAttr);
fwrite(&csa,sizeof(CycleStorageAttr),1,file);
fflush(file);
if(count<size)
{
if( head>count-1 )
{
head = 0;
tail = count - 1;
}
if( tail>count-1 )
tail = count - 1;
size=count;
return true;
}
int num = count - size;
size = count;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
if(( head==tail+1 ) || (( tail==size-num-1 ) && ( head==0 )))
{
if( head<size-num-1 )
fseek(file, seekpos + (size-num-1)*full_size, 0);
else
fseek(file, seekpos, 0);
fread(jrn, full_size, 1, file);
if(( jrn->status==2 ) || (jrn->status==3 ))
jrn->status = ( head<size-num-1 ) ? 3 : 5;
else if(( jrn->status==4 ) || (jrn->status==5 ))
jrn->status = ( head<size-num-1 ) ? 5 : 3;
else
{
delete[] jrn;
return false;
}
for( int i=num; i>0; i-- )
{
filewrite(jrn, size-i, false);
}
fflush(file);
if( head==0 )
tail = size-1;
}
else
{
jrn->status=0;
for( int i=num; i>0; i-- )
filewrite(jrn, size-i, false);
fflush(file);
}
delete[] jrn;
return true;
}
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
# This file is part of the UniSet library # # This file is part of the UniSet library #
############################################################################ ############################################################################
noinst_PROGRAMS = passivetimer unixml noinst_PROGRAMS = passivetimer unixml ui
passivetimer_SOURCES = passivetimer.cc passivetimer_SOURCES = passivetimer.cc
passivetimer_LDADD = $(top_builddir)/lib/libUniSet.la passivetimer_LDADD = $(top_builddir)/lib/libUniSet.la
...@@ -13,5 +12,10 @@ unixml_SOURCES = unixml.cc ...@@ -13,5 +12,10 @@ unixml_SOURCES = unixml.cc
unixml_LDADD = $(top_builddir)/lib/libUniSet.la unixml_LDADD = $(top_builddir)/lib/libUniSet.la
unixml_CPPFLAGS = -I$(top_builddir)/include unixml_CPPFLAGS = -I$(top_builddir)/include
ui_SOURCES = ui.cc
ui_LDADD = $(top_builddir)/lib/libUniSet.la
ui_CPPFLAGS = -I$(top_builddir)/include
include $(top_builddir)/conf/setting.mk include $(top_builddir)/conf/setting.mk
#!/bin/sh
ln -s -f /usr/bin/uniset-stop.sh stop.sh
ln -s -f ../conf/test.xml test.xml
#include <time.h>
#include "UniversalInterface.h"
#include "UniSetTypes.h"
using namespace std;
using namespace UniSetTypes;
int main( int argc, const char **argv )
{
try
{
uniset_init(argc,argv,"test.xml");
int id = conf->getArgInt("--sid");
if( id <=0 )
{
cerr << "unknown sensor ID. Use --sid " << endl;
return 1;
}
UniversalInterface ui;
cout << "getChangedTime for ID=" << id << ":" << endl;
IOController_i::ShortIOInfo inf = ui.getChangedTime(id,conf->getLocalNode());
struct tm* tms = localtime(&inf.tv_sec);
char t_str[ 150 ];
strftime( t_str, sizeof(t_str), "%d %b %Y %H:%M:%S", tms );
cout << "id=" << id
<< " value=" << inf.value
<< " last changed: " << string(t_str) << endl;
}
catch( Exception& ex )
{
cout << "(uitest):" << ex << endl;
}
catch(...)
{
cout << "(uitest): catch ..."<< endl;
}
return 0;
}
#!/bin/sh
SID=$1
[ -z "$SID" ] && SID=1
uniset-start.sh -f ./ui --confile test.xml --sid $SID
#--unideb-add-levels system,info,level9
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