Commit 1d72749d authored by Pavel Vainerman's avatar Pavel Vainerman

Потихоньку избавляюсь от char*

parent 89edf1eb
......@@ -169,7 +169,7 @@ class DBServer_MySQL:
bool writeToBase( const string& query );
void createTables( MySQLInterface* db );
inline const char* tblName(int key)
inline std::string tblName( int key )
{
return tblMap[key].c_str();
}
......
......@@ -46,9 +46,9 @@ class DBServer_PostgreSQL:
bool writeToBase( const string& query );
void createTables( std::shared_ptr<PostgreSQLInterface>& db );
inline const char* tblName(int key)
inline std::string tblName(int key)
{
return tblMap[key].c_str();
return tblMap[key];
}
enum Timers
......
......@@ -169,9 +169,9 @@ class DBServer_SQLite:
bool writeToBase( const string& query );
void createTables( SQLiteInterface* db );
inline const char* tblName(int key)
inline std::string tblName(int key)
{
return tblMap[key].c_str();
return tblMap[key];
}
enum Timers
......
......@@ -38,21 +38,16 @@
class ObjectRepositoryFactory: private ObjectRepository
{
public:
// ObjectRepositoryFactory();
// ObjectRepositoryFactory(int* argc=argc_ptr, char* **argv=argv_ptr); // параметры инициализации ORB
ObjectRepositoryFactory( const std::shared_ptr<UniSetTypes::Configuration>& conf );
~ObjectRepositoryFactory();
//! Создание секции
bool createSection(const char* name, const char* in_section )throw(UniSetTypes::ORepFailed, UniSetTypes::InvalidObjectName);
/*! \overload */
bool createSection(const std::string& name, const std::string& in_section)throw(UniSetTypes::ORepFailed, UniSetTypes::InvalidObjectName);
/*! Создание секции по полному имени */
bool createSectionF(const std::string& fullName)throw(UniSetTypes::ORepFailed, UniSetTypes::InvalidObjectName);
//! Функция создания секции в корневом 'каталоге'
bool createRootSection(const char* name);
/*! \overload */
bool createRootSection(const std::string& name);
......@@ -76,7 +71,7 @@ class ObjectRepositoryFactory: private ObjectRepository
private:
/*! Создание нового контекста(секции) */
bool createContext(const char* cname, CosNaming::NamingContext_ptr ctx);
bool createContext( const std::string& cname, CosNaming::NamingContext_ptr ctx);
};
//};
......
......@@ -112,11 +112,6 @@ class ThreadCreator:
ost::PosixThread::setName( name.c_str() );
}
inline void setName( const char* name )
{
ost::PosixThread::setName( name );
}
inline void setCancel( ost::Thread::Cancel mode )
{
ost::PosixThread::setCancel(mode);
......
......@@ -199,13 +199,9 @@ class UInterface
// Работа с ID, Name
/*! получение идентификатора объекта по имени */
inline UniSetTypes::ObjectId getIdByName( const char* name ) const
{
return oind->getIdByName(name);
}
inline UniSetTypes::ObjectId getIdByName( const std::string& name ) const
{
return getIdByName(name.c_str());
return oind->getIdByName(name);
}
/*! получение имени по идентификатору объекта */
......
......@@ -189,7 +189,7 @@ namespace UniSetTypes
/*! Функция разбора строки вида: id1@node1=val1,id2@node2=val2,...
Если '=' не указано, возвращается val=0
Если @node не указано, возвращается node=DefaultObjectId */
Если @node не указано, возвращается node=DefaultObjectId */
std::list<ParamSInfo> getSInfoList( const std::string& s, std::shared_ptr<UniSetTypes::Configuration> conf = nullptr );
......
......@@ -109,7 +109,7 @@
\endcode
*
*
* \todo Нужно добавить поддержку "пользователских типов" (возможно нужно использовать variadic templates)
* \todo Нужно добавить поддержку "пользовательских типов" (возможно нужно использовать variadic templates)
*/
class VMonitor
{
......
......@@ -10,13 +10,13 @@ using namespace std;
//---------------------------------------------------------------------------
static UInterface* ui = 0;
//---------------------------------------------------------------------------
void pyUInterface::uniset_init_params( UTypes::Params* p, const char* xmlfile )throw(UException)
void pyUInterface::uniset_init_params( UTypes::Params* p, const std::string& xmlfile )throw(UException)
{
pyUInterface::uniset_init(p->argc, p->argv, xmlfile);
}
//---------------------------------------------------------------------------
void pyUInterface::uniset_init( int argc, char* argv[], const char* xmlfile )throw(UException)
void pyUInterface::uniset_init( int argc, char* argv[], const std::string& xmlfile )throw(UException)
{
try
{
......@@ -118,7 +118,7 @@ void pyUInterface::setValue( long id, long val )throw(UException)
}
}
//---------------------------------------------------------------------------
long pyUInterface::getSensorID( const char* name )
long pyUInterface::getSensorID(const string& name )
{
auto conf = UniSetTypes::uniset_conf();
......@@ -128,42 +128,42 @@ long pyUInterface::getSensorID( const char* name )
return UniSetTypes::DefaultObjectId;
}
//---------------------------------------------------------------------------
const char* pyUInterface::getName( long id )
std::string pyUInterface::getName( long id )
{
auto conf = UniSetTypes::uniset_conf();
if( conf )
return UniSetTypes::uni_strdup(conf->oind->getMapName(id));
return conf->oind->getMapName(id);
return "";
}
//---------------------------------------------------------------------------
const char* pyUInterface::getShortName( long id )
string pyUInterface::getShortName( long id )
{
auto conf = UniSetTypes::uniset_conf();
if( conf )
return UniSetTypes::uni_strdup(ORepHelpers::getShortName(conf->oind->getMapName(id)));
return ORepHelpers::getShortName(conf->oind->getMapName(id));
return "";
}
//---------------------------------------------------------------------------
const char* pyUInterface::getTextName( long id )
std::string pyUInterface::getTextName( long id )
{
auto conf = UniSetTypes::uniset_conf();
if( conf )
return UniSetTypes::uni_strdup(conf->oind->getTextName(id));
return conf->oind->getTextName(id);
return "";
}
//---------------------------------------------------------------------------
const char* pyUInterface::getConfFileName()
string pyUInterface::getConfFileName()
{
auto conf = UniSetTypes::uniset_conf();
if( conf )
return UniSetTypes::uni_strdup(conf->getConfFileName());
return conf->getConfFileName();
return "";
......
......@@ -7,20 +7,20 @@
// --------------------------------------------------------------------------
namespace pyUInterface
{
void uniset_init_params( UTypes::Params* p, const char* xmlfile )throw(UException);
void uniset_init( int argc, char** argv, const char* xmlfile )throw(UException);
void uniset_init_params( UTypes::Params* p, const std::string& xmlfile )throw(UException);
void uniset_init( int argc, char** argv, const std::string& xmlfile )throw(UException);
//---------------------------------------------------------------------------
long getValue( long id )throw(UException);
void setValue( long id, long val )throw(UException);
long getSensorID( const char* );
long getSensorID( const std::string& name );
const char* getShortName( long id );
const char* getName( long id );
const char* getTextName( long id );
std::string getShortName( long id );
std::string getName( long id );
std::string getTextName( long id );
const char* getConfFileName();
std::string getConfFileName();
}
//---------------------------------------------------------------------------
......
......@@ -3,7 +3,7 @@
// --------------------------------------------------------------------------
using namespace std;
// --------------------------------------------------------------------------
UConnector::UConnector( UTypes::Params* p, const char* xfile )throw(UException):
UConnector::UConnector( UTypes::Params* p, const std::string& xfile )throw(UException):
conf(0),
ui(0),
xmlfile(xfile)
......@@ -23,7 +23,7 @@ UConnector::UConnector( UTypes::Params* p, const char* xfile )throw(UException):
}
}
//---------------------------------------------------------------------------
UConnector::UConnector( int argc, char** argv, const char* xfile )throw(UException):
UConnector::UConnector(int argc, char** argv, const string& xfile )throw(UException):
conf(0),
ui(0),
xmlfile(xfile)
......@@ -47,11 +47,11 @@ UConnector::~UConnector()
{
}
// --------------------------------------------------------------------------
const char* UConnector::getConfFileName()
string UConnector::getConfFileName()
{
// return xmlfile;
if( conf )
return UniSetTypes::uni_strdup(conf->getConfFileName());
return conf->getConfFileName();
return "";
......@@ -102,7 +102,7 @@ void UConnector::setValue( long id, long val, long node )throw(UException)
}
}
//---------------------------------------------------------------------------
long UConnector::getSensorID( const char* name )
long UConnector::getSensorID(const string& name )
{
if( conf )
return conf->getSensorID(name);
......@@ -110,7 +110,7 @@ long UConnector::getSensorID( const char* name )
return UTypes::DefaultID;
}
//---------------------------------------------------------------------------
long UConnector::getNodeID( const char* name )
long UConnector::getNodeID(const string& name )
{
if( conf )
return conf->getNodeID(name);
......@@ -118,26 +118,26 @@ long UConnector::getNodeID( const char* name )
return UTypes::DefaultID;
}
//---------------------------------------------------------------------------
const char* UConnector::getName( long id )
string UConnector::getName( long id )
{
if( conf )
return UniSetTypes::uni_strdup(conf->oind->getMapName(id));
return conf->oind->getMapName(id);
return "";
}
//---------------------------------------------------------------------------
const char* UConnector::getShortName( long id )
string UConnector::getShortName( long id )
{
if( conf )
return UniSetTypes::uni_strdup(ORepHelpers::getShortName(conf->oind->getMapName(id)));
return ORepHelpers::getShortName(conf->oind->getMapName(id));
return "";
}
//---------------------------------------------------------------------------
const char* UConnector::getTextName( long id )
string UConnector::getTextName( long id )
{
if( conf )
return UniSetTypes::uni_strdup(conf->oind->getTextName(id));
return conf->oind->getTextName(id);
return "";
}
......
......@@ -11,31 +11,30 @@
class UConnector
{
public:
UConnector( int argc, char** argv, const char* xmlfile )throw(UException);
UConnector( UTypes::Params* p, const char* xmlfile )throw(UException);
UConnector( int argc, char** argv, const std::string& xmlfile )throw(UException);
UConnector( UTypes::Params* p, const std::string& xmlfile )throw(UException);
~UConnector();
inline const char* getUIType()
inline std::string getUIType()
{
return "uniset";
return string("uniset");
}
const char* getConfFileName();
std::string getConfFileName();
long getValue( long id, long node )throw(UException);
void setValue( long id, long val, long node )throw(UException);
long getSensorID( const char* );
long getNodeID( const char* );
const char* getShortName( long id );
const char* getName( long id );
const char* getTextName( long id );
long getSensorID( const std::string& name );
long getNodeID( const std::string& name );
std::string getShortName( long id );
std::string getName( long id );
std::string getTextName( long id );
private:
std::shared_ptr<UniSetTypes::Configuration> conf;
std::shared_ptr<UInterface> ui;
const char* xmlfile;
std::string xmlfile;
};
//---------------------------------------------------------------------------
#endif
......
......@@ -3,6 +3,7 @@
* to regenerate the wrappers run:
* swig -python UInterface.i
***********************************************************/
%include <std_string.i>
%module pyUConnector
%{
......
......@@ -8,9 +8,9 @@ struct UException
explicit UException( const char* e ): err( std::string(e)) {}
~UException() {}
const char* getError()
const std::string getError()
{
return err.c_str();
return err;
}
std::string err;
......
......@@ -3,6 +3,7 @@
* to regenerate the wrappers run:
* swig -python UException.i
***********************************************************/
%include <std_string.i>
%module pyUExceptions
%{
......
......@@ -52,16 +52,14 @@ UModbus::~UModbus()
delete mb;
}
// --------------------------------------------------------------------------
void UModbus::prepare( const char* _ip, int _port )throw(UException)
void UModbus::prepare( const string& _ip, int _port )throw(UException)
{
if( !mb )
throw UException("(connect): mb=NULL?!");
string s(_ip);
if( mb->isConnection() )
{
if( _port == port && s == ip )
if( _port == port && _ip == ip )
return;
mb->disconnect();
......@@ -69,28 +67,26 @@ void UModbus::prepare( const char* _ip, int _port )throw(UException)
//cerr << "************** Prepare: " << string(_ip) << ":" << port << endl;
// strncpy(char *dest, const char *src, size_t n);
ip = s;
ip = _ip;
port = _port;
}
// --------------------------------------------------------------------------
void UModbus::connect( const char* _ip, int _port )throw(UException)
void UModbus::connect( const string& _ip, int _port )throw(UException)
{
if( !mb )
throw UException("(connect): mb=NULL?!");
string s(_ip);
if( mb->isConnection() )
{
if( _port == port && s == ip )
if( _port == port && _ip == ip )
return;
mb->disconnect();
}
ip = s;
ip = _ip;
port = _port;
ost::InetAddress ia(_ip);
ost::InetAddress ia(_ip.c_str());
try
{
......@@ -126,13 +122,12 @@ bool UModbus::getBit( int addr, int mbreg, int mbfunc )throw(UException)
return mbread(addr, mbreg, mbfunc, "unsigned");
}
// --------------------------------------------------------------------------
long UModbus::mbread( int mbaddr, int mbreg, int mbfunc, const char* s_vtype, int nbit,
const char* new_ip, int new_port )throw(UException)
long UModbus::mbread(int mbaddr, int mbreg, int mbfunc, const string& s_vtype, int nbit,
const string& new_ip, int new_port )throw(UException)
{
using namespace VTypes;
// const char* n_ip = strcmp(new_ip,"") ? new_ip : ip;
const char* n_ip = (new_ip != 0) ? new_ip : ip.c_str();
string n_ip( ( new_ip.empty() ? ip : new_ip ) );
int n_port = ( new_port > 0 ) ? new_port : port;
connect(n_ip, n_port);
......@@ -290,9 +285,9 @@ long UModbus::data2value( VTypes::VType vtype, ModbusRTU::ModbusData* data )
return 0;
}
//---------------------------------------------------------------------------
void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const char* new_ip, int new_port )throw(UException)
void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const string& new_ip, int new_port )throw(UException)
{
const char* n_ip = (new_ip != 0) ? new_ip : ip.c_str();
string n_ip( ( new_ip.empty() ? ip : new_ip ) );
int n_port = ( new_port > 0 ) ? new_port : port;
connect(n_ip, n_port);
......
......@@ -13,14 +13,13 @@
class UModbus
{
public:
// UModbus( int argc, char** argv )throw(UException);
// UModbus( UTypes::Params* p )throw(UException);
UModbus();
~UModbus();
inline const char* getUIType()
inline std::string getUIType()
{
return "modbus";
return string("modbus");
}
inline bool isWriteFunction( int mbfunc )
......@@ -29,9 +28,9 @@ class UModbus
}
// выставление паметров связи, без установления соединения (!)
void prepare( const char* ip, int port )throw(UException);
void prepare( const std::string& ip, int port )throw(UException);
void connect( const char* ip, int port )throw(UException);
void connect( const std::string& ip, int port )throw(UException);
inline int conn_port()
{
return port;
......@@ -56,8 +55,8 @@ class UModbus
* будет сделано переподключение..
*/
long mbread( int addr, int mbreg, int mbfunc,
const char* vtype, int nbit = -1,
const char* ip = 0, int port = -1 )throw(UException);
const std::string& vtype, int nbit = -1,
const std::string& ip = "", int port = -1 )throw(UException);
long getWord( int addr, int mbreg, int mbfunc = 0x4 )throw(UException);
long getByte( int addr, int mbreg, int mbfunc = 0x4 )throw(UException);
......@@ -68,7 +67,7 @@ class UModbus
* чтобы были заданы в UModbus::connect(). Если заданы другие ip и port,
* будет сделана переподключение..
*/
void mbwrite( int addr, int mbreg, int val, int mbfunc, const char* ip = 0, int port = -1 )throw(UException);
void mbwrite( int addr, int mbreg, int val, int mbfunc, const std::string& ip = "", int port = -1 )throw(UException);
protected:
long data2value( VTypes::VType vt, ModbusRTU::ModbusData* data );
......
......@@ -3,6 +3,7 @@
* to regenerate the wrappers run:
* swig -python UInterface.i
***********************************************************/
%include <std_string.i>
%module pyUModbus
%{
......
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.6
# Version 3.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
......@@ -134,11 +134,11 @@ class UConnector:
def setValue(self, id, val, node):
return _pyUConnector.UConnector_setValue(self, id, val, node)
def getSensorID(self, arg2):
return _pyUConnector.UConnector_getSensorID(self, arg2)
def getSensorID(self, name):
return _pyUConnector.UConnector_getSensorID(self, name)
def getNodeID(self, arg2):
return _pyUConnector.UConnector_getNodeID(self, arg2)
def getNodeID(self, name):
return _pyUConnector.UConnector_getNodeID(self, name)
def getShortName(self, id):
return _pyUConnector.UConnector_getShortName(self, id)
......
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.6
# Version 3.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
......
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.6
# Version 3.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
......@@ -113,8 +113,8 @@ class UModbus:
def setTimeout(self, msec):
return _pyUModbus.UModbus_setTimeout(self, msec)
def mbread(self, addr, mbreg, mbfunc, vtype, nbit=-1, ip=None, port=-1):
return _pyUModbus.UModbus_mbread(self, addr, mbreg, mbfunc, vtype, nbit, ip, port)
def mbread(self, *args):
return _pyUModbus.UModbus_mbread(self, *args)
def getWord(self, addr, mbreg, mbfunc=0x4):
return _pyUModbus.UModbus_getWord(self, addr, mbreg, mbfunc)
......@@ -125,8 +125,8 @@ class UModbus:
def getBit(self, addr, mbreg, mbfunc=0x2):
return _pyUModbus.UModbus_getBit(self, addr, mbreg, mbfunc)
def mbwrite(self, addr, mbreg, val, mbfunc, ip=None, port=-1):
return _pyUModbus.UModbus_mbwrite(self, addr, mbreg, val, mbfunc, ip, port)
def mbwrite(self, *args):
return _pyUModbus.UModbus_mbwrite(self, *args)
UModbus_swigregister = _pyUModbus.UModbus_swigregister
UModbus_swigregister(UModbus)
......
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.6
# Version 3.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
......@@ -90,8 +90,8 @@ def setValue(id, val):
return _pyUniSet.setValue(id, val)
setValue = _pyUniSet.setValue
def getSensorID(arg1):
return _pyUniSet.getSensorID(arg1)
def getSensorID(name):
return _pyUniSet.getSensorID(name)
getSensorID = _pyUniSet.getSensorID
def getShortName(id):
......
......@@ -51,25 +51,23 @@ ObjectRepositoryFactory::~ObjectRepositoryFactory()
* \param section - полное имя секции начиная с Root.
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool ObjectRepositoryFactory::createSection( const char* name, const char* in_section)throw(ORepFailed, InvalidObjectName )
bool ObjectRepositoryFactory::createSection(const string& name, const string& in_section)throw(ORepFailed, InvalidObjectName)
{
const string str(name);
char bad = ORepHelpers::checkBadSymbols(str);
char bad = ORepHelpers::checkBadSymbols(name);
if (bad != 0)
{
ostringstream err;
err << "ObjectRepository(registration): (InvalidObjectName) " << str;
err << "ObjectRepository(registration): (InvalidObjectName) " << name;
err << " содержит недопустимый символ " << bad;
throw ( InvalidObjectName(err.str().c_str()) );
}
ulogrep << "CreateSection: name = " << name << " in section = " << in_section << endl;
if( sizeof(in_section) == 0 )
if( in_section.empty() )
{
ulogrep << "CreateSection: in_section=0" << endl;
ulogrep << "CreateSection: in_section..empty" << endl;
return createRootSection(name);
}
......@@ -78,12 +76,6 @@ bool ObjectRepositoryFactory::createSection( const char* name, const char* in_se
CosNaming::NamingContext_var ctx = ORepHelpers::getContext(in_section, argc, argv, uconf->getNSName() );
return createContext( name, ctx.in() );
}
bool ObjectRepositoryFactory::createSection(const string& name, const string& in_section)throw(ORepFailed, InvalidObjectName)
{
return createSection(name.c_str(), in_section.c_str());
}
// -------------------------------------------------------------------------------------------------------
/*!
* \param fullName - полное имя создаваемой секции
......@@ -108,23 +100,16 @@ bool ObjectRepositoryFactory::createSectionF(const string& fullName)throw(ORepFa
}
// ---------------------------------------------------------------------------------------------------------------
bool ObjectRepositoryFactory::createRootSection(const char* name)
bool ObjectRepositoryFactory::createRootSection( const string& name )
{
CORBA::ORB_var orb = uconf->getORB();
CosNaming::NamingContext_var ctx = ORepHelpers::getRootNamingContext(orb, uconf->getNSName());
return createContext(name, ctx);
}
bool ObjectRepositoryFactory::createRootSection(const string& name)
{
return createRootSection( name.c_str() );
}
// -----------------------------------------------------------------------------------------------------------
bool ObjectRepositoryFactory::createContext(const char* cname, CosNaming::NamingContext_ptr ctx)
bool ObjectRepositoryFactory::createContext( const string& cname, CosNaming::NamingContext_ptr ctx )
{
CosNaming::Name_var nc = omniURI::stringToName(cname);
CosNaming::Name_var nc = omniURI::stringToName(cname.c_str());
try
{
......
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