Commit 078df423 authored by Pavel Vainerman's avatar Pavel Vainerman

(LProcessor): небольшой рефакоринг

* getScheme() --> getSchema() * help_print() * init_plproc()
parent 347b73f5
......@@ -112,12 +112,11 @@ class LProcessor
canceled = true;
}
inline std::shared_ptr<SchemaXML> getScheme()
inline std::shared_ptr<SchemaXML> getSchema()
{
return sch;
}
inline int getSleepTime()
{
return sleepTime;
......
......@@ -14,7 +14,6 @@ libUniSet2LProcessor_la_CXXFLAGS = -I$(top_builddir)/extensions/include \
libUniSet2LProcessor_la_SOURCES = Element.cc TOR.cc TAND.cc TDelay.cc TNOT.cc \
Schema.cc SchemaXML.cc LProcessor.cc PassiveLProcessor.cc
bin_PROGRAMS = @PACKAGE@-logicproc @PACKAGE@-plogicproc
@PACKAGE@_logicproc_SOURCES = logicproc.cc
......
......@@ -6,7 +6,7 @@ using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// -------------------------------------------------------------------------
PassiveLProcessor::PassiveLProcessor( std::string lfile, UniSetTypes::ObjectId objId,
PassiveLProcessor::PassiveLProcessor( UniSetTypes::ObjectId objId,
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic, const std::string& prefix ):
UniSetObject_LT(objId),
shm(nullptr)
......@@ -15,6 +15,25 @@ PassiveLProcessor::PassiveLProcessor( std::string lfile, UniSetTypes::ObjectId o
logname = myname;
shm = make_shared<SMInterface>(shmID, UniSetObject_LT::ui, objId, ic);
string conf_name(conf->getArgParam("--" + prefix + "-confnode", myname));
xmlNode* confnode = conf->getNode(conf_name);
if( confnode == NULL )
throw SystemError("Not found conf-node for " + conf_name );
UniXML::iterator it(confnode);
confnode = conf->getNode(myname);
string lfile = conf->getArgParam("--" + prefix + "-schema",it.getProp("schema"));
if( lfile.empty() )
{
ostringstream err;
err << myname << "(init): Unknown schema file.. Use: --" << prefix + "-schema";
throw SystemError(err.str());
}
build(lfile);
// ********** HEARTBEAT *************
......@@ -232,3 +251,41 @@ void PassiveLProcessor::sigterm( int signo )
}
}
// -------------------------------------------------------------------------
void PassiveLProcessor::help_print( int argc, const char* const* argv )
{
cout << "Default: prefix='plproc'" << endl;
cout << "--prefix-name name - ObjectID. По умолчанию: PassiveProcessor1" << endl;
cout << "--prefix-confnode cnode - Возможность задать настроечный узел в configure.xml. По умолчанию: name" << endl;
cout << endl;
cout << "--prefix-schema file - Файл с логической схемой." << endl;
cout << "--prefix-heartbeat-id - Данный процесс связан с указанным аналоговым heartbeat-дачиком." << endl;
cout << "--prefix-heartbeat-max - Максимальное значение heartbeat-счётчика для данного процесса. По умолчанию 10." << endl;
}
// -----------------------------------------------------------------------------
std::shared_ptr<PassiveLProcessor> PassiveLProcessor::init_plproc( int argc, const char* const* argv,
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic,
const std::string& prefix )
{
auto conf = uniset_conf();
string name = conf->getArgParam("--" + prefix + "-name", "PassiveProcessor1");
if( name.empty() )
{
cerr << "(plproc): Не задан name'" << endl;
return 0;
}
ObjectId ID = conf->getObjectID(name);
if( ID == UniSetTypes::DefaultObjectId )
{
cerr << "(plproc): идентификатор '" << name
<< "' не найден в конф. файле!"
<< " в секции " << conf->getObjectsSection() << endl;
return 0;
}
dinfo << "(plproc): name = " << name << "(" << ID << ")" << endl;
return make_shared<PassiveLProcessor>(ID, shmID, ic, prefix);
}
......@@ -18,7 +18,7 @@ class PassiveLProcessor:
{
public:
PassiveLProcessor( std::string schema, UniSetTypes::ObjectId objId,
PassiveLProcessor( UniSetTypes::ObjectId objId,
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic = nullptr, const std::string& prefix = "lproc" );
virtual ~PassiveLProcessor();
......@@ -27,6 +27,12 @@ class PassiveLProcessor:
tidStep
};
static void help_print( int argc, const char* const* argv );
static std::shared_ptr<PassiveLProcessor> init_plproc( int argc, const char* const* argv,
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic = nullptr,
const std::string& prefix = "plproc" );
protected:
PassiveLProcessor(): shm(0), maxHeartBeat(0) {};
......
......@@ -13,11 +13,21 @@ int main(int argc, const char** argv)
{
std::ios::sync_with_stdio(false);
if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) )
{
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--plproc-logfile filename - logfilename. Default: mbslave.log" << endl;
cout << endl;
PassiveLProcessor::help_print(argc, argv);
return 0;
}
try
{
auto conf = uniset_init( argc, argv );
string logfilename(conf->getArgParam("--logicproc-logfile"));
string logfilename(conf->getArgParam("--plproc-logfile"));
if( logfilename.empty() )
logfilename = "logicproc.log";
......@@ -50,32 +60,10 @@ int main(int argc, const char** argv)
return 1;
}
cout << "init smemory: " << sID << " ID: " << shmID << endl;
string name = conf->getArgParam("--name", "LProcessor");
if( name.empty() )
{
cerr << "(plogicproc): Не задан name'" << endl;
return 1;
}
ObjectId ID = conf->getObjectID(name);
if( ID == UniSetTypes::DefaultObjectId )
{
cerr << "(plogicproc): идентификатор '" << name
<< "' не найден в конф. файле!"
<< " в секции " << conf->getObjectsSection() << endl;
return 1;
}
cout << "init name: " << name << " ID: " << ID << endl;
PassiveLProcessor plc(schema, ID, shmID);
auto plp = PassiveLProcessor::init_plproc(argc,argv,shmID);
auto act = UniSetActivator::Instance();
act->add(plc.get_ptr());
act->add(plp);
SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() );
......
......@@ -176,7 +176,7 @@ TEST_CASE("Logic processor: lp", "[LogicProcessor][logic]")
LPRunner p;
auto lp = p.get();
auto sch = lp->getScheme();
auto sch = lp->getSchema();
CHECK( sch != nullptr );
......
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