Commit e6058bb4 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

make style

parent 6f13253b
...@@ -33,997 +33,997 @@ ...@@ -33,997 +33,997 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace omni; using namespace omni;
using namespace UniversalIO; using namespace UniversalIO;
using namespace std; using namespace std;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UInterface::UInterface( const std::shared_ptr<uniset::Configuration>& _uconf ): UInterface::UInterface( const std::shared_ptr<uniset::Configuration>& _uconf ):
rep(_uconf), rep(_uconf),
myid(uniset::DefaultObjectId), myid(uniset::DefaultObjectId),
orb(CORBA::ORB::_nil()), orb(CORBA::ORB::_nil()),
rcache(100, 20), rcache(100, 20),
oind(_uconf->oind), oind(_uconf->oind),
uconf(_uconf) uconf(_uconf)
{ {
init(); init();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UInterface::UInterface( const uniset::ObjectId backid, CORBA::ORB_var orb, const shared_ptr<uniset::ObjectIndex> _oind ): UInterface::UInterface( const uniset::ObjectId backid, CORBA::ORB_var orb, const shared_ptr<uniset::ObjectIndex> _oind ):
rep(uniset::uniset_conf()), rep(uniset::uniset_conf()),
myid(backid), myid(backid),
orb(orb), orb(orb),
rcache(200, 40), rcache(200, 40),
oind(_oind), oind(_oind),
uconf(uniset::uniset_conf()) uconf(uniset::uniset_conf())
{ {
if( oind == nullptr ) if( oind == nullptr )
oind = uconf->oind; oind = uconf->oind;
init(); init();
} }
UInterface::~UInterface() UInterface::~UInterface()
{ {
} }
void UInterface::init() void UInterface::init()
{ {
// пытаемся получить ссылку на NameService // пытаемся получить ссылку на NameService
// в любом случае. даже если включён режим // в любом случае. даже если включён режим
// localIOR // localIOR
localctx = CosNaming::NamingContext::_nil(); localctx = CosNaming::NamingContext::_nil();
try try
{ {
ostringstream s; ostringstream s;
s << uconf << oind->getNodeName(uconf->getLocalNode()); s << uconf << oind->getNodeName(uconf->getLocalNode());
if( CORBA::is_nil(orb) ) if( CORBA::is_nil(orb) )
{ {
CORBA::ORB_var _orb = uconf->getORB(); CORBA::ORB_var _orb = uconf->getORB();
localctx = ORepHelpers::getRootNamingContext( _orb, s.str() ); localctx = ORepHelpers::getRootNamingContext( _orb, s.str() );
} }
else else
localctx = ORepHelpers::getRootNamingContext( orb, s.str() ); localctx = ORepHelpers::getRootNamingContext( orb, s.str() );
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
// if( !uconf->isLocalIOR() ) // if( !uconf->isLocalIOR() )
// throw ex; // throw ex;
localctx = CosNaming::NamingContext::_nil(); localctx = CosNaming::NamingContext::_nil();
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
// if( !uconf->isLocalIOR() ) // if( !uconf->isLocalIOR() )
// throw; // throw;
localctx = CosNaming::NamingContext::_nil(); localctx = CosNaming::NamingContext::_nil();
} }
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
void UInterface::initBackId( const uniset::ObjectId backid ) void UInterface::initBackId( const uniset::ObjectId backid )
{ {
myid = backid; myid = backid;
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
/*! /*!
* \param id - идентификатор датчика * \param id - идентификатор датчика
* \return текущее значение датчика * \return текущее значение датчика
* \exception IOBadParam - генерируется если указано неправильное имя датчика или секции * \exception IOBadParam - генерируется если указано неправильное имя датчика или секции
* \exception IOTimeOut - генерируется если в течение времени timeout не был получен ответ * \exception IOTimeOut - генерируется если в течение времени timeout не был получен ответ
*/ */
long UInterface::getValue( const uniset::ObjectId id, const uniset::ObjectId node ) const long UInterface::getValue( const uniset::ObjectId id, const uniset::ObjectId node ) const
{ {
if ( id == uniset::DefaultObjectId ) if ( id == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(getValue): error id=uniset::DefaultObjectId"); throw uniset::ORepFailed("UI(getValue): error id=uniset::DefaultObjectId");
if( node == uniset::DefaultObjectId ) if( node == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(getValue): id='" << id << "' error: node=uniset::DefaultObjectId"; err << "UI(getValue): id='" << id << "' error: node=uniset::DefaultObjectId";
throw uniset::ORepFailed(err.str()); throw uniset::ORepFailed(err.str());
} }
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(id, node); oref = rcache.resolve(id, node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for( size_t i = 0; i < uconf->getRepeatCount(); i++) for( size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( id, node ); oref = resolve( id, node );
IOController_i_var iom = IOController_i::_narrow(oref); IOController_i_var iom = IOController_i::_narrow(oref);
return iom->getValue(id); return iom->getValue(id);
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex) {} catch( const CORBA::SystemException& ex) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
catch( const IOController_i::NameNotFound& ex ) catch( const IOController_i::NameNotFound& ex )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::NameNotFound("UI(getValue): " + string(ex.err)); throw uniset::NameNotFound("UI(getValue): " + string(ex.err));
} }
catch( const IOController_i::IOBadParam& ex ) catch( const IOController_i::IOBadParam& ex )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam("UI(getValue): " + string(ex.err)); throw uniset::IOBadParam("UI(getValue): " + string(ex.err));
} }
catch( const uniset::ORepFailed& ) catch( const uniset::ORepFailed& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw uniset::IOBadParam(set_err("UI(getValue): uniset::ORepFailed", id, node)); throw uniset::IOBadParam(set_err("UI(getValue): uniset::ORepFailed", id, node));
} }
catch( const CORBA::NO_IMPLEMENT& ) catch( const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(getValue): method no implement", id, node)); throw uniset::IOBadParam(set_err("UI(getValue): method no implement", id, node));
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(getValue): object not exist", id, node)); throw uniset::IOBadParam(set_err("UI(getValue): object not exist", id, node));
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getValue): CORBA::SystemException" << endl; // uwarn << "UI(getValue): CORBA::SystemException" << endl;
} }
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::TimeOut(set_err("UI(getValue): TimeOut", id, node)); throw uniset::TimeOut(set_err("UI(getValue): TimeOut", id, node));
} }
long UInterface::getValue( const uniset::ObjectId name ) const long UInterface::getValue( const uniset::ObjectId name ) const
{ {
return getValue(name, uconf->getLocalNode()); return getValue(name, uconf->getLocalNode());
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
void UInterface::setUndefinedState( const IOController_i::SensorInfo& si, bool undefined, uniset::ObjectId sup_id ) void UInterface::setUndefinedState( const IOController_i::SensorInfo& si, bool undefined, uniset::ObjectId sup_id )
{ {
if( si.id == uniset::DefaultObjectId ) if( si.id == uniset::DefaultObjectId )
{ {
uwarn << "UI(setUndefinedState): ID=uniset::DefaultObjectId" << endl; uwarn << "UI(setUndefinedState): ID=uniset::DefaultObjectId" << endl;
return; return;
} }
if( sup_id == uniset::DefaultObjectId ) if( sup_id == uniset::DefaultObjectId )
sup_id = myid; sup_id = myid;
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(si.id, si.node); oref = rcache.resolve(si.id, si.node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( si.id, si.node ); oref = resolve( si.id, si.node );
IOController_i_var iom = IOController_i::_narrow(oref); IOController_i_var iom = IOController_i::_narrow(oref);
iom->setUndefinedState(si.id, undefined, sup_id ); iom->setUndefinedState(si.id, undefined, sup_id );
return; return;
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(setUndefinedState):" + string(ex.err), si.id, si.node) << endl; uwarn << set_err("UI(setUndefinedState):" + string(ex.err), si.id, si.node) << endl;
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
throw uniset::IOBadParam("UI(setUndefinedState): " + string(ex.err)); throw uniset::IOBadParam("UI(setUndefinedState): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
uwarn << set_err("UI(setUndefinedState): resolve failed", si.id, si.node) << endl; uwarn << set_err("UI(setUndefinedState): resolve failed", si.id, si.node) << endl;
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(setUndefinedState): method no implement", si.id, si.node) << endl; uwarn << set_err("UI(setUndefinedState): method no implement", si.id, si.node) << endl;
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(setUndefinedState): object not exist", si.id, si.node) << endl; uwarn << set_err("UI(setUndefinedState): object not exist", si.id, si.node) << endl;
} }
catch( const CORBA::COMM_FAILURE& ) {} catch( const CORBA::COMM_FAILURE& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
catch(...) {} catch(...) {}
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(setUndefinedState): Timeout", si.id, si.node) << endl; uwarn << set_err("UI(setUndefinedState): Timeout", si.id, si.node) << endl;
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
void UInterface::freezeValue( const IOController_i::SensorInfo& si, bool set, long value, uniset::ObjectId sup_id ) void UInterface::freezeValue( const IOController_i::SensorInfo& si, bool set, long value, uniset::ObjectId sup_id )
{ {
if( si.id == uniset::DefaultObjectId ) if( si.id == uniset::DefaultObjectId )
{ {
uwarn << "UI(freezeValue): ID=uniset::DefaultObjectId" << endl; uwarn << "UI(freezeValue): ID=uniset::DefaultObjectId" << endl;
return; return;
} }
if( sup_id == uniset::DefaultObjectId ) if( sup_id == uniset::DefaultObjectId )
sup_id = myid; sup_id = myid;
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(si.id, si.node); oref = rcache.resolve(si.id, si.node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( si.id, si.node ); oref = resolve( si.id, si.node );
IOController_i_var iom = IOController_i::_narrow(oref); IOController_i_var iom = IOController_i::_narrow(oref);
iom->freezeValue(si.id, set, value, sup_id ); iom->freezeValue(si.id, set, value, sup_id );
return; return;
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(freezeValue):" + string(ex.err), si.id, si.node) << endl; uwarn << set_err("UI(freezeValue):" + string(ex.err), si.id, si.node) << endl;
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
throw uniset::IOBadParam("UI(freezeValue): " + string(ex.err)); throw uniset::IOBadParam("UI(freezeValue): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
uwarn << set_err("UI(freezeValue): resolve failed", si.id, si.node) << endl; uwarn << set_err("UI(freezeValue): resolve failed", si.id, si.node) << endl;
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(freezeValue): method no implement", si.id, si.node) << endl; uwarn << set_err("UI(freezeValue): method no implement", si.id, si.node) << endl;
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(freezeValue): object not exist", si.id, si.node) << endl; uwarn << set_err("UI(freezeValue): object not exist", si.id, si.node) << endl;
} }
catch( const CORBA::COMM_FAILURE& ) {} catch( const CORBA::COMM_FAILURE& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
catch(...) {} catch(...) {}
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(freezeValue): Timeout", si.id, si.node) << endl; uwarn << set_err("UI(freezeValue): Timeout", si.id, si.node) << endl;
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
/*! /*!
* \param id - идентификатор датчика * \param id - идентификатор датчика
* \param value - значение, которое необходимо установить * \param value - значение, которое необходимо установить
* \return текущее значение датчика * \return текущее значение датчика
* \exception IOBadParam - генерируется, если указано неправильное имя вывода или секции * \exception IOBadParam - генерируется, если указано неправильное имя вывода или секции
*/ */
void UInterface::setValue( const uniset::ObjectId id, long value, const uniset::ObjectId node, const uniset::ObjectId sup_id ) const void UInterface::setValue( const uniset::ObjectId id, long value, const uniset::ObjectId node, const uniset::ObjectId sup_id ) const
{ {
if ( id == uniset::DefaultObjectId ) if ( id == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(setValue): error: id=uniset::DefaultObjectId"); throw uniset::ORepFailed("UI(setValue): error: id=uniset::DefaultObjectId");
if ( node == uniset::DefaultObjectId ) if ( node == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(setValue): id='" << id << "' error: node=uniset::DefaultObjectId"; err << "UI(setValue): id='" << id << "' error: node=uniset::DefaultObjectId";
throw uniset::ORepFailed(err.str()); throw uniset::ORepFailed(err.str());
} }
/* /*
if ( sup_id == uniset::DefaultObjectId ) if ( sup_id == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(setValue): id='" << id << "' error: supplier=uniset::DefaultObjectId"; err << "UI(setValue): id='" << id << "' error: supplier=uniset::DefaultObjectId";
throw uniset::ORepFailed(err.str()); throw uniset::ORepFailed(err.str());
} }
*/ */
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(id, node); oref = rcache.resolve(id, node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( id, node ); oref = resolve( id, node );
IOController_i_var iom = IOController_i::_narrow(oref); IOController_i_var iom = IOController_i::_narrow(oref);
iom->setValue(id, value, sup_id); iom->setValue(id, value, sup_id);
return; return;
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::NameNotFound(set_err("UI(setValue): const uniset::NameNotFound& для объекта", id, node)); throw uniset::NameNotFound(set_err("UI(setValue): const uniset::NameNotFound& для объекта", id, node));
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam("UI(setValue): " + string(ex.err)); throw uniset::IOBadParam("UI(setValue): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw uniset::IOBadParam(set_err("UI(setValue): resolve failed ", id, node)); throw uniset::IOBadParam(set_err("UI(setValue): resolve failed ", id, node));
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(setValue): method no implement", id, node)); throw uniset::IOBadParam(set_err("UI(setValue): method no implement", id, node));
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(setValue): object not exist", id, node)); throw uniset::IOBadParam(set_err("UI(setValue): object not exist", id, node));
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
} }
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::TimeOut(set_err("UI(setValue): Timeout", id, node)); throw uniset::TimeOut(set_err("UI(setValue): Timeout", id, node));
} }
void UInterface::setValue( const uniset::ObjectId name, long value ) const void UInterface::setValue( const uniset::ObjectId name, long value ) const
{ {
setValue(name, value, uconf->getLocalNode(), myid); setValue(name, value, uconf->getLocalNode(), myid);
} }
void UInterface::setValue( const IOController_i::SensorInfo& si, long value, const uniset::ObjectId sup_id ) const void UInterface::setValue( const IOController_i::SensorInfo& si, long value, const uniset::ObjectId sup_id ) const
{ {
setValue(si.id, value, si.node, sup_id); setValue(si.id, value, si.node, sup_id);
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
// функция не вырабатывает исключений! // функция не вырабатывает исключений!
void UInterface::fastSetValue( const IOController_i::SensorInfo& si, long value, uniset::ObjectId sup_id ) const void UInterface::fastSetValue( const IOController_i::SensorInfo& si, long value, uniset::ObjectId sup_id ) const
{ {
if ( si.id == uniset::DefaultObjectId ) if ( si.id == uniset::DefaultObjectId )
{ {
uwarn << "UI(fastSetValue): ID=uniset::DefaultObjectId" << endl; uwarn << "UI(fastSetValue): ID=uniset::DefaultObjectId" << endl;
return; return;
} }
if( sup_id == uniset::DefaultObjectId ) if( sup_id == uniset::DefaultObjectId )
sup_id = myid; sup_id = myid;
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(si.id, si.node); oref = rcache.resolve(si.id, si.node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( si.id, si.node ); oref = resolve( si.id, si.node );
IOController_i_var iom = IOController_i::_narrow(oref); IOController_i_var iom = IOController_i::_narrow(oref);
iom->setValue(si.id, value, sup_id); iom->setValue(si.id, value, sup_id);
return; return;
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(fastSetValue): const uniset::NameNotFound& для объекта", si.id, si.node) << endl; uwarn << set_err("UI(fastSetValue): const uniset::NameNotFound& для объекта", si.id, si.node) << endl;
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
throw uniset::IOBadParam("UI(fastSetValue): " + string(ex.err)); throw uniset::IOBadParam("UI(fastSetValue): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
uwarn << set_err("UI(fastSetValue): resolve failed ", si.id, si.node) << endl; uwarn << set_err("UI(fastSetValue): resolve failed ", si.id, si.node) << endl;
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(fastSetValue): method no implement", si.id, si.node) << endl; uwarn << set_err("UI(fastSetValue): method no implement", si.id, si.node) << endl;
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(fastSetValue): object not exist", si.id, si.node) << endl; uwarn << set_err("UI(fastSetValue): object not exist", si.id, si.node) << endl;
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(setValue): CORBA::SystemException" << endl; // uwarn << "UI(setValue): CORBA::SystemException" << endl;
} }
catch(...) {} catch(...) {}
rcache.erase(si.id, si.node); rcache.erase(si.id, si.node);
uwarn << set_err("UI(fastSetValue): Timeout", si.id, si.node) << endl; uwarn << set_err("UI(fastSetValue): Timeout", si.id, si.node) << endl;
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
/*! /*!
* \param id - идентификатор датчика * \param id - идентификатор датчика
* \param node - идентификатор узла на котором заказывается датчик * \param node - идентификатор узла на котором заказывается датчик
* \param cmd - команда см. \ref UniversalIO::UIOCommand * \param cmd - команда см. \ref UniversalIO::UIOCommand
* \param backid - обратный адрес (идентификатор заказчика) * \param backid - обратный адрес (идентификатор заказчика)
*/ */
void UInterface::askRemoteSensor( const uniset::ObjectId id, UniversalIO::UIOCommand cmd, void UInterface::askRemoteSensor( const uniset::ObjectId id, UniversalIO::UIOCommand cmd,
const uniset::ObjectId node, const uniset::ObjectId node,
uniset::ObjectId backid ) const uniset::ObjectId backid ) const
{ {
if( backid == uniset::DefaultObjectId ) if( backid == uniset::DefaultObjectId )
backid = myid; backid = myid;
if( backid == uniset::DefaultObjectId ) if( backid == uniset::DefaultObjectId )
throw uniset::IOBadParam("UI(askRemoteSensor): unknown back ID"); throw uniset::IOBadParam("UI(askRemoteSensor): unknown back ID");
if ( id == uniset::DefaultObjectId ) if ( id == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(askRemoteSensor): error: id=uniset::DefaultObjectId"); throw uniset::ORepFailed("UI(askRemoteSensor): error: id=uniset::DefaultObjectId");
if ( node == uniset::DefaultObjectId ) if ( node == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(askRemoteSensor): id='" << id << "' error: node=uniset::DefaultObjectId"; err << "UI(askRemoteSensor): id='" << id << "' error: node=uniset::DefaultObjectId";
throw uniset::ORepFailed(err.str()); throw uniset::ORepFailed(err.str());
} }
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(id, node); oref = rcache.resolve(id, node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( id, node ); oref = resolve( id, node );
IONotifyController_i_var inc = IONotifyController_i::_narrow(oref); IONotifyController_i_var inc = IONotifyController_i::_narrow(oref);
uniset::ConsumerInfo_var ci; uniset::ConsumerInfo_var ci;
ci->id = backid; ci->id = backid;
ci->node = uconf->getLocalNode(); ci->node = uconf->getLocalNode();
inc->askSensor(id, ci, cmd ); inc->askSensor(id, ci, cmd );
return; return;
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::NameNotFound("UI(askSensor): " + string(ex.err) ); throw uniset::NameNotFound("UI(askSensor): " + string(ex.err) );
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam("UI(askSensor): " + string(ex.err)); throw uniset::IOBadParam("UI(askSensor): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw uniset::IOBadParam(set_err("UI(askSensor): resolve failed ", id, node)); throw uniset::IOBadParam(set_err("UI(askSensor): resolve failed ", id, node));
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(askSensor): method no implement", id, node)); throw uniset::IOBadParam(set_err("UI(askSensor): method no implement", id, node));
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(askSensor): object not exist", id, node)); throw uniset::IOBadParam(set_err("UI(askSensor): object not exist", id, node));
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(askSensor): ошибка системы коммуникации" << endl; // uwarn << "UI(askSensor): ошибка системы коммуникации" << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(askSensor): CORBA::SystemException" << endl; // uwarn << "UI(askSensor): CORBA::SystemException" << endl;
} }
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::TimeOut(set_err("UI(askSensor): Timeout", id, node)); throw uniset::TimeOut(set_err("UI(askSensor): Timeout", id, node));
} }
void UInterface::askSensor( const uniset::ObjectId name, UniversalIO::UIOCommand cmd, const uniset::ObjectId backid ) const void UInterface::askSensor( const uniset::ObjectId name, UniversalIO::UIOCommand cmd, const uniset::ObjectId backid ) const
{ {
askRemoteSensor(name, cmd, uconf->getLocalNode(), backid); askRemoteSensor(name, cmd, uconf->getLocalNode(), backid);
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
/*! /*!
* \param id - идентификатор объекта * \param id - идентификатор объекта
* \param node - идентификатор узла * \param node - идентификатор узла
*/ */
IOType UInterface::getIOType( const uniset::ObjectId id, const uniset::ObjectId node ) const IOType UInterface::getIOType( const uniset::ObjectId id, const uniset::ObjectId node ) const
{ {
if ( id == uniset::DefaultObjectId ) if ( id == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(getIOType): error: id=uniset::DefaultObjectId"); throw uniset::ORepFailed("UI(getIOType): error: id=uniset::DefaultObjectId");
if( node == uniset::DefaultObjectId ) if( node == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(getIOType): id='" << id << "' error: node=uniset::DefaultObjectId"; err << "UI(getIOType): id='" << id << "' error: node=uniset::DefaultObjectId";
throw uniset::ORepFailed(err.str()); throw uniset::ORepFailed(err.str());
} }
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(id, node); oref = rcache.resolve(id, node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve(id, node); oref = resolve(id, node);
IOController_i_var inc = IOController_i::_narrow(oref); IOController_i_var inc = IOController_i::_narrow(oref);
return inc->getIOType(id); return inc->getIOType(id);
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::NameNotFound("UI(getIOType): " + string(ex.err)); throw uniset::NameNotFound("UI(getIOType): " + string(ex.err));
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam("UI(getIOType): " + string(ex.err)); throw uniset::IOBadParam("UI(getIOType): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw uniset::IOBadParam(set_err("UI(getIOType): resolve failed ", id, node)); throw uniset::IOBadParam(set_err("UI(getIOType): resolve failed ", id, node));
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(getIOType): method no implement", id, node)); throw uniset::IOBadParam(set_err("UI(getIOType): method no implement", id, node));
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::IOBadParam(set_err("UI(getIOType): object not exist", id, node)); throw uniset::IOBadParam(set_err("UI(getIOType): object not exist", id, node));
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getIOType): ошибка системы коммуникации" << endl; // uwarn << "UI(getIOType): ошибка системы коммуникации" << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getIOType): CORBA::SystemException" << endl; // uwarn << "UI(getIOType): CORBA::SystemException" << endl;
} }
rcache.erase(id, node); rcache.erase(id, node);
throw uniset::TimeOut(set_err("UI(getIOType): Timeout", id, node)); throw uniset::TimeOut(set_err("UI(getIOType): Timeout", id, node));
} }
IOType UInterface::getIOType( const uniset::ObjectId id ) const IOType UInterface::getIOType( const uniset::ObjectId id ) const
{ {
return getIOType(id, uconf->getLocalNode() ); return getIOType(id, uconf->getLocalNode() );
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
/*! /*!
* \param id - идентификатор объекта * \param id - идентификатор объекта
* \param node - идентификатор узла * \param node - идентификатор узла
*/ */
uniset::ObjectType UInterface::getType( const uniset::ObjectId name, const uniset::ObjectId node) const uniset::ObjectType UInterface::getType( const uniset::ObjectId name, const uniset::ObjectId node) const
{ {
if ( name == uniset::DefaultObjectId ) if ( name == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(getType): попытка обратиться к объекту с id=uniset::DefaultObjectId"); throw uniset::ORepFailed("UI(getType): попытка обратиться к объекту с id=uniset::DefaultObjectId");
if( node == uniset::DefaultObjectId ) if( node == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(getType): id='" << name << "' error: node=uniset::DefaultObjectId"; err << "UI(getType): id='" << name << "' error: node=uniset::DefaultObjectId";
throw uniset::ORepFailed(err.str()); throw uniset::ORepFailed(err.str());
} }
try try
{ {
CORBA::Object_var oref; CORBA::Object_var oref;
try try
{ {
oref = rcache.resolve(name, node); oref = rcache.resolve(name, node);
} }
catch( const uniset::NameNotFound& ) {} catch( const uniset::NameNotFound& ) {}
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
if( CORBA::is_nil(oref) ) if( CORBA::is_nil(oref) )
oref = resolve( name, node ); oref = resolve( name, node );
UniSetObject_i_var uo = UniSetObject_i::_narrow(oref); UniSetObject_i_var uo = UniSetObject_i::_narrow(oref);
return uo->getType(); return uo->getType();
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {} catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {} catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil(); oref = CORBA::Object::_nil();
} }
} }
catch(const IOController_i::NameNotFound& ex) catch(const IOController_i::NameNotFound& ex)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw uniset::NameNotFound("UI(getType): " + string(ex.err)); throw uniset::NameNotFound("UI(getType): " + string(ex.err));
} }
catch(const IOController_i::IOBadParam& ex) catch(const IOController_i::IOBadParam& ex)
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw uniset::IOBadParam("UI(getType): " + string(ex.err)); throw uniset::IOBadParam("UI(getType): " + string(ex.err));
} }
catch(const uniset::ORepFailed& ) catch(const uniset::ORepFailed& )
{ {
rcache.erase(name, node); rcache.erase(name, node);
// не смогли получить ссылку на объект // не смогли получить ссылку на объект
throw uniset::IOBadParam(set_err("UI(getType): resolve failed ", name, node)); throw uniset::IOBadParam(set_err("UI(getType): resolve failed ", name, node));
} }
catch(const CORBA::NO_IMPLEMENT& ) catch(const CORBA::NO_IMPLEMENT& )
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw uniset::IOBadParam(set_err("UI(getType): method no implement", name, node)); throw uniset::IOBadParam(set_err("UI(getType): method no implement", name, node));
} }
catch( const CORBA::OBJECT_NOT_EXIST& ) catch( const CORBA::OBJECT_NOT_EXIST& )
{ {
rcache.erase(name, node); rcache.erase(name, node);
throw uniset::IOBadParam(set_err("UI(getType): object not exist", name, node)); throw uniset::IOBadParam(set_err("UI(getType): object not exist", name, node));
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getType): ошибка системы коммуникации" << endl; // uwarn << "UI(getType): ошибка системы коммуникации" << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(getType): CORBA::SystemException" << endl; // uwarn << "UI(getType): CORBA::SystemException" << endl;
} }
catch( const uniset::TimeOut& ) {} catch( const uniset::TimeOut& ) {}
rcache.erase(name, node); rcache.erase(name, node);
throw uniset::TimeOut(set_err("UI(getType): Timeout", name, node)); throw uniset::TimeOut(set_err("UI(getType): Timeout", name, node));
} }
uniset::ObjectType UInterface::getType( const uniset::ObjectId name ) const uniset::ObjectType UInterface::getType( const uniset::ObjectId name ) const
{ {
return getType(name, uconf->getLocalNode()); return getType(name, uconf->getLocalNode());
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
void UInterface::registered( const uniset::ObjectId id, const uniset::ObjectPtr oRef, bool force ) const void UInterface::registered( const uniset::ObjectId id, const uniset::ObjectPtr oRef, bool force ) const
{ {
// если включён режим использования локальных файлов // если включён режим использования локальных файлов
// то пишем IOR в файл // то пишем IOR в файл
if( uconf->isLocalIOR() ) if( uconf->isLocalIOR() )
{ {
if( CORBA::is_nil(orb) ) if( CORBA::is_nil(orb) )
orb = uconf->getORB(); orb = uconf->getORB();
uconf->iorfile->setIOR(id, orb->object_to_string(oRef)); uconf->iorfile->setIOR(id, orb->object_to_string(oRef));
return; return;
} }
try try
{ {
rep.registration( oind->getNameById(id), oRef, force ); rep.registration( oind->getNameById(id), oRef, force );
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
throw; throw;
} }
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
void UInterface::unregister( const uniset::ObjectId id ) void UInterface::unregister( const uniset::ObjectId id )
{ {
if( uconf->isLocalIOR() ) if( uconf->isLocalIOR() )
{ {
uconf->iorfile->unlinkIOR(id); uconf->iorfile->unlinkIOR(id);
return; return;
} }
try try
{ {
rep.unregistration( oind->getNameById(id) ); rep.unregistration( oind->getNameById(id) );
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
throw; throw;
} }
} }
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
uniset::ObjectPtr UInterface::resolve( const uniset::ObjectId rid, const uniset::ObjectId node ) const uniset::ObjectPtr UInterface::resolve( const uniset::ObjectId rid, const uniset::ObjectId node ) const
{ {
if( rid == uniset::DefaultObjectId ) if( rid == uniset::DefaultObjectId )
throw uniset::ResolveNameError("UI(resolve): ID=uniset::DefaultObjectId"); throw uniset::ResolveNameError("UI(resolve): ID=uniset::DefaultObjectId");
if( node == uniset::DefaultObjectId ) if( node == uniset::DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << "UI(resolve): id='" << rid << "' error: node=uniset::DefaultObjectId"; err << "UI(resolve): id='" << rid << "' error: node=uniset::DefaultObjectId";
throw uniset::ResolveNameError(err.str()); throw uniset::ResolveNameError(err.str());
} }
CosNaming::NamingContext_var ctx; CosNaming::NamingContext_var ctx;
rcache.erase(rid, node); rcache.erase(rid, node);
try try
{ {
if( uconf->isLocalIOR() ) if( uconf->isLocalIOR() )
{ {
if( CORBA::is_nil(orb) ) if( CORBA::is_nil(orb) )
orb = uconf->getORB(); orb = uconf->getORB();
string sior; string sior;
if( node == uconf->getLocalNode() ) if( node == uconf->getLocalNode() )
sior = uconf->iorfile->getIOR(rid); sior = uconf->iorfile->getIOR(rid);
else else
sior = httpResolve(rid, node); sior = httpResolve(rid, node);
if( !sior.empty() ) if( !sior.empty() )
{ {
CORBA::Object_var nso = orb->string_to_object(sior.c_str()); CORBA::Object_var nso = orb->string_to_object(sior.c_str());
rcache.cache(rid, node, nso); // заносим в кэш rcache.cache(rid, node, nso); // заносим в кэш
return nso._retn(); return nso._retn();
} }
uwarn << "not found IOR-file for " << uconf->oind->getNameById(rid) uwarn << "not found IOR-file for " << uconf->oind->getNameById(rid)
<< " node=" << uconf->oind->getNameById(node) << " node=" << uconf->oind->getNameById(node)
<< endl; << endl;
throw uniset::ResolveNameError(); throw uniset::ResolveNameError();
} }
if( node != uconf->getLocalNode() ) if( node != uconf->getLocalNode() )
{ {
// Получаем доступ к NameService на данном узле // Получаем доступ к NameService на данном узле
ostringstream s; ostringstream s;
s << uconf << oind->getNodeName(node); s << uconf << oind->getNodeName(node);
string nodeName(s.str()); string nodeName(s.str());
const string bname(nodeName); // сохраняем базовое название const string bname(nodeName); // сохраняем базовое название
for( size_t curNet = 1; curNet <= uconf->getCountOfNet(); curNet++) for( size_t curNet = 1; curNet <= uconf->getCountOfNet(); curNet++)
{ {
try try
{ {
if( CORBA::is_nil(orb) ) if( CORBA::is_nil(orb) )
orb = uconf->getORB(); orb = uconf->getORB();
ctx = ORepHelpers::getRootNamingContext( orb, nodeName ); ctx = ORepHelpers::getRootNamingContext( orb, nodeName );
break; break;
} }
// catch( const CORBA::COMM_FAILURE& ex ) // catch( const CORBA::COMM_FAILURE& ex )
catch( const uniset::ORepFailed& ex ) catch( const uniset::ORepFailed& ex )
{ {
// нет связи с этим узлом // нет связи с этим узлом
// пробуем связаться по другой сети // пробуем связаться по другой сети
// ПО ПРАВИЛАМ узел в другой должен иметь имя NodeName1...NodeNameX // ПО ПРАВИЛАМ узел в другой должен иметь имя NodeName1...NodeNameX
ostringstream s; ostringstream s;
s << bname << curNet; s << bname << curNet;
nodeName = s.str(); nodeName = s.str();
} }
} }
if( CORBA::is_nil(ctx) ) if( CORBA::is_nil(ctx) )
{ {
// uwarn << "NameService недоступен на узле "<< node << endl; // uwarn << "NameService недоступен на узле "<< node << endl;
throw uniset::NSResolveError(); throw uniset::NSResolveError();
} }
} }
else else
{ {
if( CORBA::is_nil(localctx) ) if( CORBA::is_nil(localctx) )
{ {
ostringstream s; ostringstream s;
s << uconf << oind->getNodeName(node); s << uconf << oind->getNodeName(node);
const string nodeName(s.str()); const string nodeName(s.str());
if( CORBA::is_nil(orb) ) if( CORBA::is_nil(orb) )
{ {
CORBA::ORB_var _orb = uconf->getORB(); CORBA::ORB_var _orb = uconf->getORB();
localctx = ORepHelpers::getRootNamingContext( _orb, nodeName ); localctx = ORepHelpers::getRootNamingContext( _orb, nodeName );
} }
else else
localctx = ORepHelpers::getRootNamingContext( orb, nodeName ); localctx = ORepHelpers::getRootNamingContext( orb, nodeName );
} }
ctx = localctx; ctx = localctx;
} }
CosNaming::Name_var oname = omniURI::stringToName( oind->getNameById(rid).c_str() ); CosNaming::Name_var oname = omniURI::stringToName( oind->getNameById(rid).c_str() );
for (size_t i = 0; i < uconf->getRepeatCount(); i++) for (size_t i = 0; i < uconf->getRepeatCount(); i++)
{ {
try try
{ {
CORBA::Object_var nso = ctx->resolve(oname); CORBA::Object_var nso = ctx->resolve(oname);
if( CORBA::is_nil(nso) ) if( CORBA::is_nil(nso) )
throw uniset::ResolveNameError(); throw uniset::ResolveNameError();
// Для var // Для var
rcache.cache(rid, node, nso); // заносим в кэш rcache.cache(rid, node, nso); // заносим в кэш
return nso._retn(); return nso._retn();
} }
catch( const CORBA::TRANSIENT& ) {} catch( const CORBA::TRANSIENT& ) {}
msleep(uconf->getRepeatTimeout()); msleep(uconf->getRepeatTimeout());
} }
throw uniset::TimeOut(); throw uniset::TimeOut();
} }
catch(const CosNaming::NamingContext::NotFound& nf) {} catch(const CosNaming::NamingContext::NotFound& nf) {}
catch(const CosNaming::NamingContext::InvalidName& nf) {} catch(const CosNaming::NamingContext::InvalidName& nf) {}
catch(const CosNaming::NamingContext::CannotProceed& cp) {} catch(const CosNaming::NamingContext::CannotProceed& cp) {}
catch( const CORBA::OBJECT_NOT_EXIST& ex ) catch( const CORBA::OBJECT_NOT_EXIST& ex )
{ {
throw uniset::ResolveNameError("ObjectNOTExist"); throw uniset::ResolveNameError("ObjectNOTExist");
} }
catch( const CORBA::COMM_FAILURE& ex ) catch( const CORBA::COMM_FAILURE& ex )
{ {
throw uniset::ResolveNameError("CORBA::CommFailure"); throw uniset::ResolveNameError("CORBA::CommFailure");
} }
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
// ошибка системы коммуникации // ошибка системы коммуникации
// uwarn << "UI(resolve): CORBA::SystemException" << endl; // uwarn << "UI(resolve): CORBA::SystemException" << endl;
throw uniset::TimeOut(); throw uniset::TimeOut();
} }
catch( const uniset::Exception& ex ) {} catch( const uniset::Exception& ex ) {}
catch( std::exception& ex ) catch( std::exception& ex )
{ {
ucrit << "UI(resolve): myID=" << myid << ": resolve id=" << rid << "@" << node ucrit << "UI(resolve): myID=" << myid << ": resolve id=" << rid << "@" << node
<< " catch " << ex.what() << endl; << " catch " << ex.what() << endl;
} }
throw uniset::ResolveNameError(); throw uniset::ResolveNameError();
} }
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
std::string UInterface::httpResolve( const uniset::ObjectId id, const uniset::ObjectId node ) const std::string UInterface::httpResolve( const uniset::ObjectId id, const uniset::ObjectId node ) const
{ {
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
size_t port = uconf->getHttpResovlerPort(); size_t port = uconf->getHttpResovlerPort();
......
...@@ -277,9 +277,9 @@ std::vector<std::string> uniset::explode_str( const std::string& str, char sep ) ...@@ -277,9 +277,9 @@ std::vector<std::string> uniset::explode_str( const std::string& str, char sep )
pos = str.find(sep, prev); pos = str.find(sep, prev);
if( pos == string::npos ) if( pos == string::npos )
{ {
const string s(str.substr(prev, sz - prev)); const string s(str.substr(prev, sz - prev));
if( !s.empty() ) if( !s.empty() )
v.emplace_back( std::move(s) ); v.emplace_back( std::move(s) );
...@@ -293,7 +293,7 @@ std::vector<std::string> uniset::explode_str( const std::string& str, char sep ) ...@@ -293,7 +293,7 @@ std::vector<std::string> uniset::explode_str( const std::string& str, char sep )
continue; continue;
} }
const string s(str.substr(prev, pos - prev)); const string s(str.substr(prev, pos - prev));
if( !s.empty() ) if( !s.empty() )
{ {
...@@ -323,72 +323,72 @@ bool uniset::is_digit( const std::string& s ) noexcept ...@@ -323,72 +323,72 @@ bool uniset::is_digit( const std::string& s ) noexcept
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
std::list<uniset::ParamSInfo> uniset::getSInfoList( const string& str, std::shared_ptr<Configuration> conf ) std::list<uniset::ParamSInfo> uniset::getSInfoList( const string& str, std::shared_ptr<Configuration> conf )
{ {
std::list<uniset::ParamSInfo> res; std::list<uniset::ParamSInfo> res;
auto lst = uniset::explode_str(str, ','); auto lst = uniset::explode_str(str, ',');
for( const auto& it : lst ) for( const auto& it : lst )
{ {
uniset::ParamSInfo item; uniset::ParamSInfo item;
auto p = uniset::explode_str(it, '='); auto p = uniset::explode_str(it, '=');
std::string s = ""; std::string s = "";
if( p.size() == 1 ) if( p.size() == 1 )
{ {
s = *(p.begin()); s = *(p.begin());
item.val = 0; item.val = 0;
} }
else if( p.size() == 2 ) else if( p.size() == 2 )
{ {
s = *(p.begin()); s = *(p.begin());
item.val = uni_atoi(*(++p.begin())); item.val = uni_atoi(*(++p.begin()));
} }
else else
{ {
cerr << "WARNING: parse error for '" << it << "'. IGNORE..." << endl; cerr << "WARNING: parse error for '" << it << "'. IGNORE..." << endl;
continue; continue;
} }
item.fname = s; item.fname = s;
auto t = uniset::explode_str(s, '@'); auto t = uniset::explode_str(s, '@');
if( t.size() == 1 ) if( t.size() == 1 )
{ {
const std::string s_id = *(t.begin()); const std::string s_id = *(t.begin());
if( is_digit(s_id) || !conf ) if( is_digit(s_id) || !conf )
item.si.id = uni_atoi(s_id); item.si.id = uni_atoi(s_id);
else else
item.si.id = conf->getSensorID(s_id); item.si.id = conf->getSensorID(s_id);
item.si.node = DefaultObjectId; item.si.node = DefaultObjectId;
} }
else if( t.size() == 2 ) else if( t.size() == 2 )
{ {
const std::string s_id = *(t.begin()); const std::string s_id = *(t.begin());
const std::string s_node = *(++t.begin()); const std::string s_node = *(++t.begin());
if( is_digit(s_id) || !conf ) if( is_digit(s_id) || !conf )
item.si.id = uni_atoi(s_id); item.si.id = uni_atoi(s_id);
else else
item.si.id = conf->getSensorID(s_id); item.si.id = conf->getSensorID(s_id);
if( is_digit(s_node) || !conf ) if( is_digit(s_node) || !conf )
item.si.node = uni_atoi(s_node); item.si.node = uni_atoi(s_node);
else else
item.si.node = conf->getNodeID(s_node); item.si.node = conf->getNodeID(s_node);
} }
else else
{ {
cerr << "WARNING: parse error for '" << s << "'. IGNORE..." << endl; cerr << "WARNING: parse error for '" << s << "'. IGNORE..." << endl;
continue; continue;
} }
res.emplace_back( std::move(item) ); res.emplace_back( std::move(item) );
} }
return res; return res;
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
std::list<uniset::ConsumerInfo> uniset::getObjectsList( const string& str, std::shared_ptr<Configuration> conf ) std::list<uniset::ConsumerInfo> uniset::getObjectsList( const string& str, std::shared_ptr<Configuration> conf )
...@@ -406,9 +406,9 @@ std::list<uniset::ConsumerInfo> uniset::getObjectsList( const string& str, std:: ...@@ -406,9 +406,9 @@ std::list<uniset::ConsumerInfo> uniset::getObjectsList( const string& str, std::
auto t = uniset::explode_str(it, '@'); auto t = uniset::explode_str(it, '@');
if( t.size() == 1 ) if( t.size() == 1 )
{ {
const std::string s_id(*(t.begin())); const std::string s_id(*(t.begin()));
if( is_digit(s_id) ) if( is_digit(s_id) )
item.id = uni_atoi(s_id); item.id = uni_atoi(s_id);
...@@ -423,12 +423,12 @@ std::list<uniset::ConsumerInfo> uniset::getObjectsList( const string& str, std:: ...@@ -423,12 +423,12 @@ std::list<uniset::ConsumerInfo> uniset::getObjectsList( const string& str, std::
item.id = conf->getServiceID(s_id); item.id = conf->getServiceID(s_id);
} }
item.node = DefaultObjectId; item.node = DefaultObjectId;
} }
else if( t.size() == 2 ) else if( t.size() == 2 )
{ {
const std::string s_id = *(t.begin()); const std::string s_id = *(t.begin());
const std::string s_node = *(++t.begin()); const std::string s_node = *(++t.begin());
if( is_digit(s_id) ) if( is_digit(s_id) )
item.id = uni_atoi(s_id); item.id = uni_atoi(s_id);
...@@ -732,20 +732,21 @@ string uniset::BadSymbolsToStr() ...@@ -732,20 +732,21 @@ string uniset::BadSymbolsToStr()
return bad; return bad;
} }
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
struct keys_t { struct keys_t
uniset::ObjectId id; {
uniset::ObjectId node; uniset::ObjectId id;
uniset::ObjectId node;
keys_t( const uniset::ObjectId& _id, const uniset::ObjectId& _node ): keys_t( const uniset::ObjectId& _id, const uniset::ObjectId& _node ):
id(_id), id(_id),
node(_node) node(_node)
{} {}
}; } __attribute__((packed));
uniset::KeyType uniset::key( const uniset::ObjectId id, const uniset::ObjectId node ) uniset::KeyType uniset::key( const uniset::ObjectId id, const uniset::ObjectId node )
{ {
keys_t k(id,node); keys_t k(id, node);
return uniset::hash64( reinterpret_cast<char*>(&k), sizeof(k) ); return uniset::hash64( reinterpret_cast<char*>(&k), sizeof(k) );
} }
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
uniset::KeyType uniset::key( const IOController_i::SensorInfo& si ) uniset::KeyType uniset::key( const IOController_i::SensorInfo& si )
...@@ -755,20 +756,20 @@ uniset::KeyType uniset::key( const IOController_i::SensorInfo& si ) ...@@ -755,20 +756,20 @@ uniset::KeyType uniset::key( const IOController_i::SensorInfo& si )
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
uint64_t uniset::hash64( const std::string& str ) noexcept uint64_t uniset::hash64( const std::string& str ) noexcept
{ {
return CityHash_v1_0_2::CityHash64(str.data(), str.size()); return CityHash_v1_0_2::CityHash64(str.data(), str.size());
} }
uint64_t uniset::hash64( const char* buf, size_t sz ) noexcept uint64_t uniset::hash64( const char* buf, size_t sz ) noexcept
{ {
return CityHash_v1_0_2::CityHash64(buf, sz); return CityHash_v1_0_2::CityHash64(buf, sz);
} }
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
uint32_t uniset::hash32( const std::string& str ) noexcept uint32_t uniset::hash32( const std::string& str ) noexcept
{ {
return NAMESPACE_FOR_HASH_FUNCTIONS::Hash32(str.data(), str.size()); return NAMESPACE_FOR_HASH_FUNCTIONS::Hash32(str.data(), str.size());
} }
uint32_t uniset::hash32( const char* buf, size_t sz ) noexcept uint32_t uniset::hash32( const char* buf, size_t sz ) noexcept
{ {
return NAMESPACE_FOR_HASH_FUNCTIONS::Hash32(buf, sz); return NAMESPACE_FOR_HASH_FUNCTIONS::Hash32(buf, sz);
} }
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