Commit 527661d2 authored by Pavel Vainerman's avatar Pavel Vainerman

(netdata-plugin): Исправил ошибку в работе с argc,argv (сделал копирование).

(uniset): рефакторинг
parent 77b6dc12
...@@ -183,7 +183,7 @@ namespace UniSetTypes ...@@ -183,7 +183,7 @@ namespace UniSetTypes
std::shared_ptr<UniXML> unixml; std::shared_ptr<UniXML> unixml;
int _argc = { 0 }; int _argc = { 0 };
const char* const* _argv; const char** _argv = { nullptr };
CORBA::ORB_var orb; CORBA::ORB_var orb;
CORBA::PolicyList policyList; CORBA::PolicyList policyList;
......
...@@ -53,7 +53,7 @@ class UniSetActivator: ...@@ -53,7 +53,7 @@ class UniSetActivator:
{ {
public: public:
static UniSetActivatorPtr Instance( const UniSetTypes::ObjectId id = UniSetTypes::DefaultObjectId ); static UniSetActivatorPtr Instance();
void Destroy(); void Destroy();
std::shared_ptr<UniSetActivator> get_aptr(); std::shared_ptr<UniSetActivator> get_aptr();
...@@ -92,7 +92,6 @@ class UniSetActivator: ...@@ -92,7 +92,6 @@ class UniSetActivator:
// уносим в protected, т.к. Activator должен быть только один.. // уносим в protected, т.к. Activator должен быть только один..
UniSetActivator(); UniSetActivator();
UniSetActivator( const UniSetTypes::ObjectId id );
static std::shared_ptr<UniSetActivator> inst; static std::shared_ptr<UniSetActivator> inst;
......
...@@ -241,7 +241,7 @@ namespace UniSetTypes ...@@ -241,7 +241,7 @@ namespace UniSetTypes
inline int getArgInt( const std::string& name, inline int getArgInt( const std::string& name,
int _argc, const char* const* _argv, int _argc, const char* const* _argv,
const std::string defval = "" ) noexcept const std::string& defval = "" ) noexcept
{ {
return uni_atoi(getArgParam(name, _argc, _argv, defval)); return uni_atoi(getArgParam(name, _argc, _argv, defval));
} }
......
...@@ -35,6 +35,9 @@ void pyUInterface::uniset_init_params( UTypes::Params* p, const std::string& xml ...@@ -35,6 +35,9 @@ void pyUInterface::uniset_init_params( UTypes::Params* p, const std::string& xml
void pyUInterface::uniset_init( int argc, char* argv[], const std::string& xmlfile )throw(UException) void pyUInterface::uniset_init( int argc, char* argv[], const std::string& xmlfile )throw(UException)
{ {
if( uInterface )
return;
try try
{ {
UniSetTypes::uniset_init(argc, argv, xmlfile); UniSetTypes::uniset_init(argc, argv, xmlfile);
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
using namespace std; using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
UConnector::UConnector( UTypes::Params* p, const std::string& xfile )throw(UException): UConnector::UConnector( UTypes::Params* p, const std::string& xfile )throw(UException):
conf(0),
ui(0),
xmlfile(xfile) xmlfile(xfile)
{ {
try try
...@@ -29,19 +27,17 @@ UConnector::UConnector( UTypes::Params* p, const std::string& xfile )throw(UExce ...@@ -29,19 +27,17 @@ UConnector::UConnector( UTypes::Params* p, const std::string& xfile )throw(UExce
conf = UniSetTypes::uniset_init(p->argc, p->argv, xmlfile); conf = UniSetTypes::uniset_init(p->argc, p->argv, xmlfile);
ui = make_shared<UInterface>(conf); ui = make_shared<UInterface>(conf);
} }
catch( UniSetTypes::Exception& ex ) catch( std::exception& ex )
{ {
throw UException(ex.what()); throw UException(ex.what());
} }
catch( ... ) catch( ... )
{ {
throw UException(); throw UException("(UConnector): Unknown exception");
} }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
UConnector::UConnector(int argc, char** argv, const string& xfile )throw(UException): UConnector::UConnector(int argc, char** argv, const string& xfile )throw(UException):
conf(0),
ui(0),
xmlfile(xfile) xmlfile(xfile)
{ {
try try
...@@ -49,13 +45,13 @@ UConnector::UConnector(int argc, char** argv, const string& xfile )throw(UExcept ...@@ -49,13 +45,13 @@ UConnector::UConnector(int argc, char** argv, const string& xfile )throw(UExcept
conf = UniSetTypes::uniset_init(argc, argv, xmlfile); conf = UniSetTypes::uniset_init(argc, argv, xmlfile);
ui = make_shared<UInterface>(conf); ui = make_shared<UInterface>(conf);
} }
catch( UniSetTypes::Exception& ex ) catch( std::exception& ex )
{ {
throw UException(ex.what()); throw UException(ex.what());
} }
catch( ... ) catch( ... )
{ {
throw UException(); throw UException("(UConnector): Unknown exception");
} }
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -158,6 +154,19 @@ string UConnector::getTextName( long id ) ...@@ -158,6 +154,19 @@ string UConnector::getTextName( long id )
return ""; return "";
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void UConnector::activate_objects() throw(UException)
{
try
{
auto act = UniSetActivator::Instance();
act->run(true);
}
catch( const std::exception& ex )
{
throw UException("(activate_objects): catch " + std::string(ex.what()) );
}
}
//---------------------------------------------------------------------------
long UConnector::getObjectID(const string& name ) long UConnector::getObjectID(const string& name )
{ {
if( conf ) if( conf )
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "UInterface.h" #include "UInterface.h"
#include "UTypes.h" #include "UTypes.h"
#include "UExceptions.h" #include "UExceptions.h"
#include "UniSetActivator.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class UConnector class UConnector
{ {
...@@ -48,6 +49,8 @@ class UConnector ...@@ -48,6 +49,8 @@ class UConnector
std::string getName( long id ); std::string getName( long id );
std::string getTextName( long id ); std::string getTextName( long id );
void activate_objects() throw(UException);
private: private:
std::shared_ptr<UniSetTypes::Configuration> conf; std::shared_ptr<UniSetTypes::Configuration> conf;
std::shared_ptr<UInterface> ui; std::shared_ptr<UInterface> ui;
......
...@@ -3567,7 +3567,7 @@ SWIGINTERN PyObject *_wrap_Params_add_str(PyObject *SWIGUNUSEDPARM(self), PyObje ...@@ -3567,7 +3567,7 @@ SWIGINTERN PyObject *_wrap_Params_add_str(PyObject *SWIGUNUSEDPARM(self), PyObje
std::string *ptr = (std::string *)0; std::string *ptr = (std::string *)0;
int res = SWIG_AsPtr_std_string(obj1, &ptr); int res = SWIG_AsPtr_std_string(obj1, &ptr);
if (!SWIG_IsOK(res) || !ptr) { if (!SWIG_IsOK(res) || !ptr) {
SWIG_exception_fail(SWIG_ArgError((ptr ? res : SWIG_TypeError)), "in method '" "Params_add_str" "', argument " "2"" of type '" "std::string""'"); SWIG_exception_fail(SWIG_ArgError((ptr ? res : SWIG_TypeError)), "in method '" "Params_add_str" "', argument " "2"" of type '" "std::string const""'");
} }
arg2 = *ptr; arg2 = *ptr;
if (SWIG_IsNewObj(res)) delete ptr; if (SWIG_IsNewObj(res)) delete ptr;
...@@ -4400,6 +4400,33 @@ fail: ...@@ -4400,6 +4400,33 @@ fail:
} }
SWIGINTERN PyObject *_wrap_UConnector_activate_objects(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
UConnector *arg1 = (UConnector *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"O:UConnector_activate_objects",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_UConnector, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "UConnector_activate_objects" "', argument " "1"" of type '" "UConnector *""'");
}
arg1 = reinterpret_cast< UConnector * >(argp1);
try {
(arg1)->activate_objects();
}
catch(UException &_e) {
SWIG_Python_Raise(SWIG_NewPointerObj((new UException(static_cast< const UException& >(_e))),SWIGTYPE_p_UException,SWIG_POINTER_OWN), "UException", SWIGTYPE_p_UException); SWIG_fail;
}
resultobj = SWIG_Py_Void();
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *UConnector_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { SWIGINTERN PyObject *UConnector_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *obj; PyObject *obj;
if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL; if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL;
...@@ -4431,6 +4458,7 @@ static PyMethodDef SwigMethods[] = { ...@@ -4431,6 +4458,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"UConnector_getShortName", _wrap_UConnector_getShortName, METH_VARARGS, NULL}, { (char *)"UConnector_getShortName", _wrap_UConnector_getShortName, METH_VARARGS, NULL},
{ (char *)"UConnector_getName", _wrap_UConnector_getName, METH_VARARGS, NULL}, { (char *)"UConnector_getName", _wrap_UConnector_getName, METH_VARARGS, NULL},
{ (char *)"UConnector_getTextName", _wrap_UConnector_getTextName, METH_VARARGS, NULL}, { (char *)"UConnector_getTextName", _wrap_UConnector_getTextName, METH_VARARGS, NULL},
{ (char *)"UConnector_activate_objects", _wrap_UConnector_activate_objects, METH_VARARGS, NULL},
{ (char *)"UConnector_swigregister", UConnector_swigregister, METH_VARARGS, NULL}, { (char *)"UConnector_swigregister", UConnector_swigregister, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
......
...@@ -69,13 +69,28 @@ UProxyObject::UProxyObject() throw(UException) ...@@ -69,13 +69,28 @@ UProxyObject::UProxyObject() throw(UException)
throw UException("(UProxyObject): Unknown 'name'' or 'ID'"); throw UException("(UProxyObject): Unknown 'name'' or 'ID'");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
UProxyObject::UProxyObject( const std::string& name ) throw( UException ): UProxyObject::UProxyObject( const std::string& name ) throw( UException )
UProxyObject::UProxyObject(uniset_conf()->getObjectID(name))
{ {
auto conf = uniset_conf();
if ( !conf )
{
std::ostringstream err;
err << "(UProxyObject:init): Create '" << name << "' failed. Unknown configuration";
std::cerr << err.str() << std::endl;
throw UException(err.str());
}
long id = conf->getObjectID(name);
init(id);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
UProxyObject::UProxyObject( long id ) throw( UException ) UProxyObject::UProxyObject( long id ) throw( UException )
{ {
init(id);
}
// --------------------------------------------------------------------------
void UProxyObject::init( long id ) throw( UException )
{
try try
{ {
uobj = std::make_shared<UProxyObject_impl>(id); uobj = std::make_shared<UProxyObject_impl>(id);
...@@ -86,6 +101,7 @@ UProxyObject::UProxyObject( long id ) throw( UException ) ...@@ -86,6 +101,7 @@ UProxyObject::UProxyObject( long id ) throw( UException )
{ {
std::ostringstream err; std::ostringstream err;
err << "(UProxyObject): id='" << id << "' error: " << std::string(ex.what()); err << "(UProxyObject): id='" << id << "' error: " << std::string(ex.what());
std::cerr << err.str() << std::endl;
throw UException(err.str()); throw UException(err.str());
} }
} }
...@@ -144,7 +160,7 @@ void UProxyObject::addToAsk( long id ) throw(UException) ...@@ -144,7 +160,7 @@ void UProxyObject::addToAsk( long id ) throw(UException)
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
UProxyObject_impl::UProxyObject_impl( ObjectId id ): UProxyObject_impl::UProxyObject_impl( ObjectId id ):
UObject_SK(id) UObject_SK(id,nullptr)
{ {
} }
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#define UProxyObject_H_ #define UProxyObject_H_
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <memory> #include <memory>
#include "Configuration.h"
#include "UExceptions.h" #include "UExceptions.h"
#include "UTypes.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class UProxyObject_impl; // PIMPL class UProxyObject_impl; // PIMPL
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -67,6 +69,7 @@ class UProxyObject ...@@ -67,6 +69,7 @@ class UProxyObject
bool smIsOK(); bool smIsOK();
protected: protected:
void init( long id ) throw( UException );
private: private:
UProxyObject()throw(UException); UProxyObject()throw(UException);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define UTypes_H_ #define UTypes_H_
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <string> #include <string>
#include "Configuration.h"
#include "UniSetTypes.h" #include "UniSetTypes.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
namespace UTypes namespace UTypes
...@@ -38,7 +39,7 @@ namespace UTypes ...@@ -38,7 +39,7 @@ namespace UTypes
{ {
if( argc < Params::max ) if( argc < Params::max )
{ {
argv[argc++] = s; argv[argc++] = UniSetTypes::uni_strdup(s);
return true; return true;
} }
......
...@@ -155,6 +155,9 @@ class UConnector: ...@@ -155,6 +155,9 @@ class UConnector:
def getTextName(self, id): def getTextName(self, id):
return _pyUConnector.UConnector_getTextName(self, id) return _pyUConnector.UConnector_getTextName(self, id)
def activate_objects(self):
return _pyUConnector.UConnector_activate_objects(self)
UConnector_swigregister = _pyUConnector.UConnector_swigregister UConnector_swigregister = _pyUConnector.UConnector_swigregister
UConnector_swigregister(UConnector) UConnector_swigregister(UConnector)
......
...@@ -9,6 +9,7 @@ import random ...@@ -9,6 +9,7 @@ import random
import uniset2 import uniset2
from uniset2 import UniXML from uniset2 import UniXML
from uniset2 import UProxyObject from uniset2 import UProxyObject
from uniset2 import UConnector
sys.path.append("./python_modules") sys.path.append("./python_modules")
from base import SimpleService from base import SimpleService
...@@ -24,6 +25,7 @@ class Service(SimpleService): ...@@ -24,6 +25,7 @@ class Service(SimpleService):
sensors = [] sensors = []
uproxy = None uproxy = None
uconnector = None
smOK = False smOK = False
def __init__(self, configuration=None, name=None): def __init__(self, configuration=None, name=None):
...@@ -41,8 +43,8 @@ class Service(SimpleService): ...@@ -41,8 +43,8 @@ class Service(SimpleService):
self.error("uniset plugin: Not found confile '%s'"%confile) self.error("uniset plugin: Not found confile '%s'"%confile)
raise RuntimeError raise RuntimeError
self.name = self.get_conf_param('name', name) #self.name = self.get_conf_param('name', name)
self.info("%s: uniset plugin: read from %s"%(name,confile)) self.info("%s: read from %s"%(name,confile))
self.create_charts(confile) self.create_charts(confile)
self.init_uniset(confile) self.init_uniset(confile)
# добавляем датчики в опрос.. # добавляем датчики в опрос..
...@@ -51,24 +53,22 @@ class Service(SimpleService): ...@@ -51,24 +53,22 @@ class Service(SimpleService):
def init_uniset(self, confile): def init_uniset(self, confile):
lst = uniset2.Params_inst() arglist= uniset2.Params_inst()
for i in range(0, len(sys.argv)): for i in range(0, len(sys.argv)):
if i >= uniset2.Params.max: if i >= uniset2.Params.max:
break; break;
lst.add(sys.argv[i]) arglist.add(sys.argv[i])
port = self.get_conf_param('port', '') port = self.get_conf_param('port', '')
if port != '': if port != '':
self.info("%s: uniset plugin: --uniset-port %s" % (self.name,port))
p = '--uniset-port' p = '--uniset-port'
lst.add_str(p) arglist.add_str(p)
lst.add_str( str(port) ) arglist.add_str( str(port) )
uname = self.get_conf_param('uname', 'TestProc') uname = self.get_conf_param('uname', 'TestProc')
self.info("%s: uniset plugin: init ObjectID '%s'" % (self.name,uname))
try: try:
uniset2.uniset_init_params(lst, confile); self.uconnector = UConnector(arglist,confile)
self.uproxy = UProxyObject(uname) self.uproxy = UProxyObject(uname)
except uniset2.UException, e: except uniset2.UException, e:
self.error("uniset plugin: error: %s"% e.getError()) self.error("uniset plugin: error: %s"% e.getError())
...@@ -86,7 +86,7 @@ class Service(SimpleService): ...@@ -86,7 +86,7 @@ class Service(SimpleService):
def find_section(self, xml, secname): def find_section(self, xml, secname):
node = xml.findNode(xml.getDoc(), secname)[0] node = xml.findNode(xml.getDoc(), secname)[0]
if node == None: if node == None:
self.error("uniset plugin: not found %s section" % secname) self.error("not found '%s' section in %s" % (secname,xml.getFileName()))
raise RuntimeError raise RuntimeError
return node.children return node.children
...@@ -107,7 +107,7 @@ class Service(SimpleService): ...@@ -107,7 +107,7 @@ class Service(SimpleService):
# CHART type.id name title units [family [context [charttype [priority [update_every]]]]] # CHART type.id name title units [family [context [charttype [priority [update_every]]]]]
id = node.prop('id') id = node.prop('id')
if id == '' or id == None: if id == '' or id == None:
self.error("uniset plugin: IGNORE CHART.. Unknown id=''.") self.error("IGNORE CHART.. Unknown id=''.")
node = xml.nextNode(node) node = xml.nextNode(node)
continue continue
...@@ -138,7 +138,7 @@ class Service(SimpleService): ...@@ -138,7 +138,7 @@ class Service(SimpleService):
self.order = myOrder self.order = myOrder
except uniset2.UniXMLException, e: except uniset2.UniXMLException, e:
self.error("uniset plugin: FAILED load xmlfile=%s err='%s'" % (confile, e.getError())) self.error("FAILED load xmlfile=%s err='%s'" % (confile, e.getError()))
raise RuntimeError raise RuntimeError
def build_lines(self, chart, lnode, xml, snode): def build_lines(self, chart, lnode, xml, snode):
...@@ -151,7 +151,7 @@ class Service(SimpleService): ...@@ -151,7 +151,7 @@ class Service(SimpleService):
fv = node.prop('filter_value') fv = node.prop('filter_value')
if ff == '' or ff == None: if ff == '' or ff == None:
self.error("uniset plugin: Unknown filter_fileld for chart id='%s'" % node.parent.prop('id')) self.error("Unknown filter_fileld for chart id='%s'" % node.parent.prop('id'))
raise RuntimeError raise RuntimeError
self.read_sensors(snode,ff,fv,xml, chart) self.read_sensors(snode,ff,fv,xml, chart)
...@@ -174,7 +174,7 @@ class Service(SimpleService): ...@@ -174,7 +174,7 @@ class Service(SimpleService):
params = [] params = []
id = self.get_param(node, 'netdata_id', node.prop('name')) id = self.get_param(node, 'netdata_id', node.prop('name'))
if id == '' or id == None: if id == '' or id == None:
self.error("uniset plugin: Unknown 'id' for sensor %s" % node.prop('name')) self.error("Unknown 'id' for sensor %s" % node.prop('name'))
raise RuntimeError raise RuntimeError
params.append(id) params.append(id)
...@@ -216,9 +216,10 @@ class Service(SimpleService): ...@@ -216,9 +216,10 @@ class Service(SimpleService):
def check(self): def check(self):
self.info("**** uniset_activate_objects")
# ret = super(self.__class__, self).check() # ret = super(self.__class__, self).check()
try: try:
uniset2.uniset_activate_objects() self.uconnector.activate_objects()
except uniset2.UException, e: except uniset2.UException, e:
self.error("%s"% e.getError()) self.error("%s"% e.getError())
raise False raise False
...@@ -262,3 +263,13 @@ if __name__ == "__main__": ...@@ -262,3 +263,13 @@ if __name__ == "__main__":
config['retries'] = retries config['retries'] = retries
serv = Service(config,"test") serv = Service(config,"test")
config2 = {}
config2['confile'] = './test.xml'
config2['port'] = 2809
config2['uname'] = 'TestProc1'
config2['update_every'] = update_every
config2['priority'] = priority
config2['retries'] = retries
serv2 = Service(config2,"test")
...@@ -12,18 +12,34 @@ from lib import * ...@@ -12,18 +12,34 @@ from lib import *
if __name__ == "__main__": if __name__ == "__main__":
lst = Params_inst() lst = Params_inst()
lst2 = Params_inst()
for i in range(0, len(sys.argv)): for i in range(0, len(sys.argv)):
if i >= Params.max: if i >= Params.max:
break; break;
lst.add( sys.argv[i] ) lst.add( sys.argv[i] )
lst2.add( sys.argv[i] )
pstr = "--uniset-port"
pstr2= "12"
lst.add_str(pstr)
lst.add_str(pstr2)
lst2.add_str(pstr)
lst2.add_str(pstr2)
p = [] p = []
print "lst: class: " + str(p.__class__.__name__) print "lst: class: " + str(p.__class__.__name__)
try: try:
uc1 = UConnector( lst, "test.xml" ) uc1 = UConnector( lst, "test.xml" )
uc2 = UConnector( lst2, "test.xml" )
obj1 = UProxyObject("TestProc",uc1.getConfID())
obj2 = UProxyObject("TestProc1",uc2.getConfID())
# print "(0)UIType: %s" % uc1.getUIType() # print "(0)UIType: %s" % uc1.getUIType()
......
...@@ -28,7 +28,14 @@ if __name__ == "__main__": ...@@ -28,7 +28,14 @@ if __name__ == "__main__":
uniset_init_params( lst, "test.xml"); uniset_init_params( lst, "test.xml");
obj1 = UProxyObject("TestProc") obj1 = UProxyObject("TestProc")
obj2 = UProxyObject("TestProc1")
uniset_activate_objects() uniset_activate_objects()
while True:
print "sleep..."
print "getValue: %d=%d" % ( 1, getValue(1) )
time.sleep(2)
print "getShortName: id=%d name=%s" % (1, getShortName(1)) print "getShortName: id=%d name=%s" % (1, getShortName(1))
print " getName: id=%d name=%s" % (1, getName(1)) print " getName: id=%d name=%s" % (1, getName(1))
......
...@@ -483,11 +483,11 @@ void terminate_thread() ...@@ -483,11 +483,11 @@ void terminate_thread()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
UniSetActivatorPtr UniSetActivator::inst; UniSetActivatorPtr UniSetActivator::inst;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
UniSetActivatorPtr UniSetActivator::Instance( const UniSetTypes::ObjectId id ) UniSetActivatorPtr UniSetActivator::Instance()
{ {
if( inst == nullptr ) if( inst == nullptr )
{ {
inst = shared_ptr<UniSetActivator>( new UniSetActivator(id) ); inst = shared_ptr<UniSetActivator>( new UniSetActivator() );
g_act = inst; g_act = inst;
} }
...@@ -505,13 +505,6 @@ std::shared_ptr<UniSetActivator> UniSetActivator::get_aptr() ...@@ -505,13 +505,6 @@ std::shared_ptr<UniSetActivator> UniSetActivator::get_aptr()
return std::dynamic_pointer_cast<UniSetActivator>(get_ptr()); return std::dynamic_pointer_cast<UniSetActivator>(get_ptr());
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
UniSetActivator::UniSetActivator( const ObjectId id ):
UniSetManager(id),
omDestroy(false)
{
UniSetActivator::init();
}
// ------------------------------------------------------------------------------------------
UniSetActivator::UniSetActivator(): UniSetActivator::UniSetActivator():
UniSetManager(UniSetTypes::DefaultObjectId), UniSetManager(UniSetTypes::DefaultObjectId),
omDestroy(false) omDestroy(false)
......
...@@ -134,13 +134,19 @@ void UniSetObject::initObject() ...@@ -134,13 +134,19 @@ void UniSetObject::initObject()
auto conf = uniset_conf(); auto conf = uniset_conf();
if( !conf )
{
ostringstream err;
err << myname << "(initObject): Unknown configuration!!";
throw SystemError(err.str());
}
int sz = conf->getArgPInt("--uniset-object-size-message-queue", conf->getField("SizeOfMessageQueue"), 1000); int sz = conf->getArgPInt("--uniset-object-size-message-queue", conf->getField("SizeOfMessageQueue"), 1000);
if( sz > 0 ) if( sz > 0 )
setMaxSizeOfMessageQueue(sz); setMaxSizeOfMessageQueue(sz);
uinfo << myname << "(init): SizeOfMessageQueue=" << getMaxSizeOfMessageQueue() uinfo << myname << "(init): SizeOfMessageQueue=" << getMaxSizeOfMessageQueue() << endl;
<< endl;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -511,10 +511,10 @@ int UniSetTypes::uni_atoi( const char* str ) noexcept ...@@ -511,10 +511,10 @@ int UniSetTypes::uni_atoi( const char* str ) noexcept
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
char* UniSetTypes::uni_strdup( const string& src ) char* UniSetTypes::uni_strdup( const string& src )
{ {
const char* s = src.c_str(); size_t len = src.size();
size_t len = strlen(s);
char* d = new char[len + 1]; char* d = new char[len + 1];
memcpy(d, s, len + 1); memcpy(d, src.data(), len);
d[len] = '\0';
return d; return d;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -98,7 +98,8 @@ namespace UniSetTypes ...@@ -98,7 +98,8 @@ namespace UniSetTypes
Configuration::Configuration(): Configuration::Configuration():
oind(NULL), oind(NULL),
_argv(nullptr), // _argc(0),
// _argv(nullptr),
NSName("NameService"), NSName("NameService"),
repeatCount(2), repeatTimeout(100), repeatCount(2), repeatTimeout(100),
localDBServer(UniSetTypes::DefaultObjectId), localDBServer(UniSetTypes::DefaultObjectId),
...@@ -118,14 +119,19 @@ namespace UniSetTypes ...@@ -118,14 +119,19 @@ namespace UniSetTypes
if( unixml ) if( unixml )
unixml.reset(); unixml.reset();
for( int i=0; i<_argc; i++ )
delete[] _argv[i];
delete[] _argv;
} }
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
Configuration::Configuration( int argc, const char* const* argv, const string& xmlfile ): Configuration::Configuration( int argc, const char* const* argv, const string& xmlfile ):
oind(nullptr), oind(nullptr),
unixml(nullptr), unixml(nullptr),
_argc(argc), // _argc(argc),
_argv(argv), // _argv(argv),
NSName("NameService"), NSName("NameService"),
repeatCount(2), repeatTimeout(100), repeatCount(2), repeatTimeout(100),
localDBServer(UniSetTypes::DefaultObjectId), localDBServer(UniSetTypes::DefaultObjectId),
...@@ -143,8 +149,8 @@ namespace UniSetTypes ...@@ -143,8 +149,8 @@ namespace UniSetTypes
const string& fileConf ): const string& fileConf ):
oind(nullptr), oind(nullptr),
unixml(nullptr), unixml(nullptr),
_argc(argc), // _argc(argc),
_argv(argv), // _argv(argv),
NSName("NameService"), NSName("NameService"),
repeatCount(2), repeatTimeout(100), repeatCount(2), repeatTimeout(100),
localDBServer(UniSetTypes::DefaultObjectId), localDBServer(UniSetTypes::DefaultObjectId),
...@@ -162,8 +168,8 @@ namespace UniSetTypes ...@@ -162,8 +168,8 @@ namespace UniSetTypes
Configuration::Configuration( int argc, const char* const* argv, const string& fileConf, Configuration::Configuration( int argc, const char* const* argv, const string& fileConf,
UniSetTypes::ObjectInfo* omap ): UniSetTypes::ObjectInfo* omap ):
oind(NULL), oind(NULL),
_argc(argc), // _argc(argc),
_argv(argv), // _argv(argv),
NSName("NameService"), NSName("NameService"),
repeatCount(2), repeatTimeout(100), repeatCount(2), repeatTimeout(100),
localDBServer(UniSetTypes::DefaultObjectId), localDBServer(UniSetTypes::DefaultObjectId),
...@@ -185,6 +191,13 @@ namespace UniSetTypes ...@@ -185,6 +191,13 @@ namespace UniSetTypes
// PassiveTimer pt(UniSetTimer::WaitUpTime); // PassiveTimer pt(UniSetTimer::WaitUpTime);
ulogsys << "*** configure from file: " << fileConfName << endl; ulogsys << "*** configure from file: " << fileConfName << endl;
// т.к. мы не знаем откуда эти argc и argv и может они будут удалены сразу после завершения функции
// то надёжнее скопировать себе всё..
_argc = argc;
_argv = new const char*[argc];
for( int i=0; i<argc; i++ )
_argv[i] = UniSetTypes::uni_strdup(argv[i]);
iorfile = make_shared<IORFile>(); iorfile = make_shared<IORFile>();
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -223,8 +236,10 @@ namespace UniSetTypes ...@@ -223,8 +236,10 @@ namespace UniSetTypes
} }
catch(...) catch(...)
{ {
ulogany << "(Configuration): FAILED open configuration from " << fileConfName << endl; ostringstream err;
throw; err << "(Configuration): FAILED open configuration from " << fileConfName;
ulogany << err.str() << endl;
throw UniSetTypes::SystemError(err.str());
} }
...@@ -240,7 +255,7 @@ namespace UniSetTypes ...@@ -240,7 +255,7 @@ namespace UniSetTypes
if( !it ) if( !it )
{ {
ucrit << "(Configuration:init): not found <ObjectsMap> node in " << fileConfName << endl; ucrit << "(Configuration:init): not found <ObjectsMap> node in " << fileConfName << endl;
throw SystemError("(Configuration:init): not found <ObjectsMap> node in " + fileConfName ); throw UniSetTypes::SystemError("(Configuration:init): not found <ObjectsMap> node in " + fileConfName );
} }
try try
...@@ -258,7 +273,7 @@ namespace UniSetTypes ...@@ -258,7 +273,7 @@ namespace UniSetTypes
} }
catch( const UniSetTypes::Exception& ex ) catch( const UniSetTypes::Exception& ex )
{ {
ucrit << "(Configuration:init): INIT FAILED! from " << fileConfName << endl; ucrit << ex << endl;
throw; throw;
} }
} }
...@@ -516,7 +531,7 @@ namespace UniSetTypes ...@@ -516,7 +531,7 @@ namespace UniSetTypes
if( !root ) if( !root )
{ {
ucrit << "Configuration: INIT PARAM`s FAILED! <UniSet>...</UniSet> not found" << endl; ucrit << "Configuration: INIT PARAM`s FAILED! <UniSet>...</UniSet> not found" << endl;
throw Exception("Configuration: INIT PARAM`s FAILED! <UniSet>...</UniSet> not found!"); throw UniSetTypes::SystemError("Configuration: INIT PARAM`s FAILED! <UniSet>...</UniSet> not found!");
} }
UniXML::iterator it(root); UniXML::iterator it(root);
...@@ -524,7 +539,7 @@ namespace UniSetTypes ...@@ -524,7 +539,7 @@ namespace UniSetTypes
if( !it.goChildren() ) if( !it.goChildren() )
{ {
ucrit << "Configuration: INIT PARAM`s FAILED!!!!" << endl; ucrit << "Configuration: INIT PARAM`s FAILED!!!!" << endl;
throw Exception("Configuration: INIT PARAM`s FAILED!!!!"); throw UniSetTypes::SystemError("Configuration: INIT PARAM`s FAILED!!!!");
} }
for( ; it.getCurrent(); it.goNext() ) for( ; it.getCurrent(); it.goNext() )
...@@ -551,7 +566,7 @@ namespace UniSetTypes ...@@ -551,7 +566,7 @@ namespace UniSetTypes
ostringstream msg; ostringstream msg;
msg << "Configuration: DBServer '" << secDB << "' not found ServiceID in <services>!"; msg << "Configuration: DBServer '" << secDB << "' not found ServiceID in <services>!";
ucrit << msg.str() << endl; ucrit << msg.str() << endl;
throw Exception(msg.str()); throw UniSetTypes::SystemError(msg.str());
} }
} }
else if( name == "CountOfNet" ) else if( name == "CountOfNet" )
...@@ -637,7 +652,7 @@ namespace UniSetTypes ...@@ -637,7 +652,7 @@ namespace UniSetTypes
stringstream err; stringstream err;
err << "(Configuration::setLocalNode): Not found node '" << nodename << "'"; err << "(Configuration::setLocalNode): Not found node '" << nodename << "'";
ucrit << err.str() << endl; ucrit << err.str() << endl;
throw Exception(err.str()); throw UniSetTypes::SystemError(err.str());
} }
localNodeName = nodename; localNodeName = nodename;
...@@ -762,7 +777,7 @@ namespace UniSetTypes ...@@ -762,7 +777,7 @@ namespace UniSetTypes
if( !omapnode ) if( !omapnode )
{ {
ucrit << "(Configuration): <ObjectsMap> not found!!!" << endl; ucrit << "(Configuration): <ObjectsMap> not found!!!" << endl;
throw Exception("(Configuration): <ObjectsMap> not found!"); throw UniSetTypes::SystemError("(Configuration): <ObjectsMap> not found!");
} }
...@@ -771,7 +786,7 @@ namespace UniSetTypes ...@@ -771,7 +786,7 @@ namespace UniSetTypes
if(!node) if(!node)
{ {
ucrit << "(Configuration): <nodes> section not found!" << endl; ucrit << "(Configuration): <nodes> section not found!" << endl;
throw Exception("(Configiuration): <nodes> section not found"); throw UniSetTypes::SystemError("(Configiuration): <nodes> section not found");
} }
UniXML::iterator it(node); UniXML::iterator it(node);
...@@ -789,7 +804,7 @@ namespace UniSetTypes ...@@ -789,7 +804,7 @@ namespace UniSetTypes
if(sname.empty()) if(sname.empty())
{ {
ucrit << "Configuration(createNodesList): unknown name='' in <nodes> " << endl; ucrit << "Configuration(createNodesList): unknown name='' in <nodes> " << endl;
throw Exception("Configuration(createNodesList: unknown name='' in <nodes>"); throw UniSetTypes::SystemError("Configuration(createNodesList: unknown name='' in <nodes>");
} }
string nodename(sname); string nodename(sname);
...@@ -803,7 +818,7 @@ namespace UniSetTypes ...@@ -803,7 +818,7 @@ namespace UniSetTypes
if( ninf.id == DefaultObjectId ) if( ninf.id == DefaultObjectId )
{ {
ucrit << "Configuration(createNodesList): Not found ID for node '" << nodename << "'" << endl; ucrit << "Configuration(createNodesList): Not found ID for node '" << nodename << "'" << endl;
throw Exception("Configuration(createNodesList): Not found ID for node '" + nodename + "'"); throw UniSetTypes::SystemError("Configuration(createNodesList): Not found ID for node '" + nodename + "'");
} }
ninf.host = getProp(it, "ip").c_str(); ninf.host = getProp(it, "ip").c_str();
...@@ -826,7 +841,7 @@ namespace UniSetTypes ...@@ -826,7 +841,7 @@ namespace UniSetTypes
if( ninf.dbserver == DefaultObjectId ) if( ninf.dbserver == DefaultObjectId )
{ {
ucrit << "Configuration(createNodesList): Not found ID for DBServer name='" << dname << "'" << endl; ucrit << "Configuration(createNodesList): Not found ID for DBServer name='" << dname << "'" << endl;
throw Exception("Configuration(createNodesList: Not found ID for DBServer name='" + dname + "'"); throw UniSetTypes::SystemError("Configuration(createNodesList: Not found ID for DBServer name='" + dname + "'");
} }
} }
...@@ -1007,7 +1022,7 @@ namespace UniSetTypes ...@@ -1007,7 +1022,7 @@ namespace UniSetTypes
ostringstream msg; ostringstream msg;
msg << "Configuration(initRepSections): Not found section <RootSection> in " << fileConfName; msg << "Configuration(initRepSections): Not found section <RootSection> in " << fileConfName;
ucrit << msg.str() << endl; ucrit << msg.str() << endl;
throw SystemError(msg.str()); throw UniSetTypes::SystemError(msg.str());
} }
secRoot = unixml->getProp(node, "name"); secRoot = unixml->getProp(node, "name");
...@@ -1028,7 +1043,7 @@ namespace UniSetTypes ...@@ -1028,7 +1043,7 @@ namespace UniSetTypes
ostringstream msg; ostringstream msg;
msg << "Configuration(initRepSections): Not found section '" << sec << "' in " << fileConfName; msg << "Configuration(initRepSections): Not found section '" << sec << "' in " << fileConfName;
ucrit << msg.str() << endl; ucrit << msg.str() << endl;
throw SystemError(msg.str()); throw UniSetTypes::SystemError(msg.str());
} }
string ret(unixml->getProp(secnode, "section")); string ret(unixml->getProp(secnode, "section"));
...@@ -1068,7 +1083,7 @@ namespace UniSetTypes ...@@ -1068,7 +1083,7 @@ namespace UniSetTypes
<< " Use --confile filename " << endl << " Use --confile filename " << endl
<< " OR define enviropment variable UNISET_CONFILE" << endl; << " OR define enviropment variable UNISET_CONFILE" << endl;
ucrit << msg.str(); ucrit << msg.str();
throw SystemError(msg.str()); throw UniSetTypes::SystemError(msg.str());
} }
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -1306,15 +1321,16 @@ namespace UniSetTypes ...@@ -1306,15 +1321,16 @@ namespace UniSetTypes
return UniSetTypes::uconf; return UniSetTypes::uconf;
} }
// инициализация исключений для libcommoncpp
// ost::Thread::setException(ost::Thread::throwException);
atexit( UniSetActivator::normalexit ); atexit( UniSetActivator::normalexit );
set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений
string confile = UniSetTypes::getArgParam( "--confile", argc, argv, xmlfile ); string confile = UniSetTypes::getArgParam( "--confile", argc, argv, xmlfile );
UniSetTypes::uconf = make_shared<Configuration>(argc, argv, confile); UniSetTypes::uconf = make_shared<Configuration>(argc, argv, confile);
return UniSetTypes::uconf; return UniSetTypes::uconf;
} }
// -------------------------------------------------------------------------
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
} // end of UniSetTypes namespace } // end of UniSetTypes namespace
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