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 ...@@ -112,12 +112,11 @@ class LProcessor
canceled = true; canceled = true;
} }
inline std::shared_ptr<SchemaXML> getScheme() inline std::shared_ptr<SchemaXML> getSchema()
{ {
return sch; return sch;
} }
inline int getSleepTime() inline int getSleepTime()
{ {
return sleepTime; return sleepTime;
......
...@@ -5,7 +5,7 @@ else ...@@ -5,7 +5,7 @@ else
# не забывайте править версию в2.pc-файле # не забывайте править версию в2.pc-файле
ULPROC_VER=@LIBVER@ ULPROC_VER=@LIBVER@
lib_LTLIBRARIES = libUniSet2LProcessor.la lib_LTLIBRARIES = libUniSet2LProcessor.la
libUniSet2LProcessor_la_LDFLAGS = -version-info $(ULPROC_VER) libUniSet2LProcessor_la_LDFLAGS = -version-info $(ULPROC_VER)
libUniSet2LProcessor_la_LIBADD = $(top_builddir)/lib/libUniSet2.la \ libUniSet2LProcessor_la_LIBADD = $(top_builddir)/lib/libUniSet2.la \
$(top_builddir)/extensions/lib/libUniSet2Extensions.la $(SIGC_LIBS) $(top_builddir)/extensions/lib/libUniSet2Extensions.la $(SIGC_LIBS)
...@@ -14,8 +14,7 @@ libUniSet2LProcessor_la_CXXFLAGS = -I$(top_builddir)/extensions/include \ ...@@ -14,8 +14,7 @@ libUniSet2LProcessor_la_CXXFLAGS = -I$(top_builddir)/extensions/include \
libUniSet2LProcessor_la_SOURCES = Element.cc TOR.cc TAND.cc TDelay.cc TNOT.cc \ libUniSet2LProcessor_la_SOURCES = Element.cc TOR.cc TAND.cc TDelay.cc TNOT.cc \
Schema.cc SchemaXML.cc LProcessor.cc PassiveLProcessor.cc Schema.cc SchemaXML.cc LProcessor.cc PassiveLProcessor.cc
bin_PROGRAMS = @PACKAGE@-logicproc @PACKAGE@-plogicproc
bin_PROGRAMS = @PACKAGE@-logicproc @PACKAGE@-plogicproc
@PACKAGE@_logicproc_SOURCES = logicproc.cc @PACKAGE@_logicproc_SOURCES = logicproc.cc
@PACKAGE@_logicproc_LDADD = libUniSet2LProcessor.la \ @PACKAGE@_logicproc_LDADD = libUniSet2LProcessor.la \
......
...@@ -6,7 +6,7 @@ using namespace std; ...@@ -6,7 +6,7 @@ using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace UniSetExtensions; 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 ): UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic, const std::string& prefix ):
UniSetObject_LT(objId), UniSetObject_LT(objId),
shm(nullptr) shm(nullptr)
...@@ -15,6 +15,25 @@ PassiveLProcessor::PassiveLProcessor( std::string lfile, UniSetTypes::ObjectId o ...@@ -15,6 +15,25 @@ PassiveLProcessor::PassiveLProcessor( std::string lfile, UniSetTypes::ObjectId o
logname = myname; logname = myname;
shm = make_shared<SMInterface>(shmID, UniSetObject_LT::ui, objId, ic); 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); build(lfile);
// ********** HEARTBEAT ************* // ********** HEARTBEAT *************
...@@ -232,3 +251,41 @@ void PassiveLProcessor::sigterm( int signo ) ...@@ -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: ...@@ -18,7 +18,7 @@ class PassiveLProcessor:
{ {
public: 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" ); UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic = nullptr, const std::string& prefix = "lproc" );
virtual ~PassiveLProcessor(); virtual ~PassiveLProcessor();
...@@ -27,6 +27,12 @@ class PassiveLProcessor: ...@@ -27,6 +27,12 @@ class PassiveLProcessor:
tidStep 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: protected:
PassiveLProcessor(): shm(0), maxHeartBeat(0) {}; PassiveLProcessor(): shm(0), maxHeartBeat(0) {};
......
...@@ -13,11 +13,21 @@ int main(int argc, const char** argv) ...@@ -13,11 +13,21 @@ int main(int argc, const char** argv)
{ {
std::ios::sync_with_stdio(false); 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 try
{ {
auto conf = uniset_init( argc, argv ); auto conf = uniset_init( argc, argv );
string logfilename(conf->getArgParam("--logicproc-logfile")); string logfilename(conf->getArgParam("--plproc-logfile"));
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "logicproc.log"; logfilename = "logicproc.log";
...@@ -50,32 +60,10 @@ int main(int argc, const char** argv) ...@@ -50,32 +60,10 @@ int main(int argc, const char** argv)
return 1; return 1;
} }
cout << "init smemory: " << sID << " ID: " << shmID << endl; auto plp = PassiveLProcessor::init_plproc(argc,argv,shmID);
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 act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->add(plc.get_ptr()); act->add(plp);
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
......
...@@ -176,7 +176,7 @@ TEST_CASE("Logic processor: lp", "[LogicProcessor][logic]") ...@@ -176,7 +176,7 @@ TEST_CASE("Logic processor: lp", "[LogicProcessor][logic]")
LPRunner p; LPRunner p;
auto lp = p.get(); auto lp = p.get();
auto sch = lp->getScheme(); auto sch = lp->getSchema();
CHECK( sch != nullptr ); 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