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

(IOController): direct use DBServer (optimization)

parent 5dec0299
...@@ -5,7 +5,7 @@ includedir=@includedir@ ...@@ -5,7 +5,7 @@ includedir=@includedir@
Name: libUniSet2BackendOpenTSDB Name: libUniSet2BackendOpenTSDB
Description: Support library for UniSet2BackendOpenTSDB Description: Support library for UniSet2BackendOpenTSDB
Requires: libUniSet2Extensions Requires: libUniSet2Extensions libUniSet2SharedMemory
Version: @VERSION@ Version: @VERSION@
Libs: -L${libdir} -lUniSet2BackendOpenTSDB Libs: -L${libdir} -lUniSet2BackendOpenTSDB
Cflags: -I${includedir}/@PACKAGE@/extensions Cflags: -I${includedir}/@PACKAGE@/extensions
...@@ -531,7 +531,7 @@ string DBServer_PostgreSQL::getMonitInfo( const string& params ) ...@@ -531,7 +531,7 @@ string DBServer_PostgreSQL::getMonitInfo( const string& params )
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
std::shared_ptr<DBServer_PostgreSQL> DBServer_PostgreSQL::init_dbserver( int argc, const char* const* argv, std::shared_ptr<DBServer_PostgreSQL> DBServer_PostgreSQL::init_dbserver( int argc, const char* const* argv,
const std::string& prefix ) const std::shared_ptr<uniset::SharedMemory>& shm, const std::string& prefix )
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
...@@ -551,7 +551,10 @@ std::shared_ptr<DBServer_PostgreSQL> DBServer_PostgreSQL::init_dbserver( int arg ...@@ -551,7 +551,10 @@ std::shared_ptr<DBServer_PostgreSQL> DBServer_PostgreSQL::init_dbserver( int arg
} }
uinfo << "(DBServer_PostgreSQL): name = " << name << "(" << ID << ")" << endl; uinfo << "(DBServer_PostgreSQL): name = " << name << "(" << ID << ")" << endl;
return make_shared<DBServer_PostgreSQL>(ID, prefix); auto db = make_shared<DBServer_PostgreSQL>(ID, prefix);
if( shm )
shm->setDBServer(db);
return db;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void DBServer_PostgreSQL::help_print( int argc, const char* const* argv ) void DBServer_PostgreSQL::help_print( int argc, const char* const* argv )
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "PostgreSQLInterface.h" #include "PostgreSQLInterface.h"
#include "DBServer.h" #include "DBServer.h"
#include "SharedMemory.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
...@@ -61,7 +62,7 @@ namespace uniset ...@@ -61,7 +62,7 @@ namespace uniset
virtual ~DBServer_PostgreSQL(); virtual ~DBServer_PostgreSQL();
/*! глобальная функция для инициализации объекта */ /*! глобальная функция для инициализации объекта */
static std::shared_ptr<DBServer_PostgreSQL> init_dbserver( int argc, const char* const* argv, const std::string& prefix = "pgsql" ); static std::shared_ptr<DBServer_PostgreSQL> init_dbserver( int argc, const char* const* argv, const std::shared_ptr<uniset::SharedMemory>& ic = nullptr, const std::string& prefix = "pgsql" );
/*! глобальная функция для вывода help-а */ /*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv ); static void help_print( int argc, const char* const* argv );
......
...@@ -4,17 +4,17 @@ UPGSQL_VER=@LIBVER@ ...@@ -4,17 +4,17 @@ UPGSQL_VER=@LIBVER@
lib_LTLIBRARIES = libUniSet2-pgsql.la lib_LTLIBRARIES = libUniSet2-pgsql.la
libUniSet2_pgsql_la_LDFLAGS = -version-info $(UPGSQL_VER) libUniSet2_pgsql_la_LDFLAGS = -version-info $(UPGSQL_VER)
libUniSet2_pgsql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc libUniSet2_pgsql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_pgsql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS) libUniSet2_pgsql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la $(PGSQL_LIBS)
libUniSet2_pgsql_la_CXXFLAGS = -std=c++17 $(PGSQL_CFLAGS) libUniSet2_pgsql_la_CXXFLAGS = -std=c++17 -I$(top_builddir)/extensions/SharedMemory $(PGSQL_CFLAGS)
bin_PROGRAMS = @PACKAGE@-pgsql-dbserver bin_PROGRAMS = @PACKAGE@-pgsql-dbserver
@PACKAGE@_pgsql_dbserver_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS) @PACKAGE@_pgsql_dbserver_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la $(PGSQL_LIBS)
@PACKAGE@_pgsql_dbserver_CXXFLAGS = -std=c++17 $(PGSQL_CFLAGS) @PACKAGE@_pgsql_dbserver_CXXFLAGS = -std=c++17 -I$(top_builddir)/extensions/SharedMemory $(PGSQL_CFLAGS)
@PACKAGE@_pgsql_dbserver_SOURCES = main.cc @PACKAGE@_pgsql_dbserver_SOURCES = main.cc
noinst_PROGRAMS = pgsql-test noinst_PROGRAMS = pgsql-test
pgsql_test_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS) pgsql_test_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la $(PGSQL_LIBS)
pgsql_test_CXXFLAGS = -std=c++17 $(PGSQL_CFLAGS) pgsql_test_CXXFLAGS = -std=c++17 -I$(top_builddir)/extensions/SharedMemory $(PGSQL_CFLAGS)
pgsql_test_SOURCES = test.cc pgsql_test_SOURCES = test.cc
# install # install
......
...@@ -5,7 +5,7 @@ includedir=@includedir@ ...@@ -5,7 +5,7 @@ includedir=@includedir@
Name: libUniSet2PostgreSQL Name: libUniSet2PostgreSQL
Description: Support library for libUniSet2PostgreSQL Description: Support library for libUniSet2PostgreSQL
Requires: libUniSet2 libpqxx Requires: libUniSet2 libpqxx libUniSet2SharedMemory
Version: @VERSION@ Version: @VERSION@
Libs: -L${libdir} -lUniSet2-pgsql Libs: -L${libdir} -lUniSet2-pgsql
Cflags: -std=c++17 -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/extensions/pgsql Cflags: -std=c++17 -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/extensions/pgsql
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "UniSetManager.h" #include "UniSetManager.h"
#include "Configuration.h" #include "Configuration.h"
#include "Mutex.h" #include "Mutex.h"
#include "DBServer.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
...@@ -41,7 +42,7 @@ namespace uniset ...@@ -41,7 +42,7 @@ namespace uniset
* Поэтому неизменность ioList во время всей жизни объекта должна гарантироваться. * Поэтому неизменность ioList во время всей жизни объекта должна гарантироваться.
* В частности, очень важной является структура USensorInfo, а также userdata, * В частности, очень важной является структура USensorInfo, а также userdata,
* которые используются для "кэширования" (сохранения) указателей на специальные данные. * которые используются для "кэширования" (сохранения) указателей на специальные данные.
* (см. также IONotifyContoller). * (см. также IONotifyController).
*/ */
class IOController: class IOController:
public UniSetManager, public UniSetManager,
...@@ -53,6 +54,8 @@ namespace uniset ...@@ -53,6 +54,8 @@ namespace uniset
IOController( const uniset::ObjectId id ); IOController( const uniset::ObjectId id );
virtual ~IOController(); virtual ~IOController();
void setDBServer( const std::shared_ptr<uniset::DBServer>& dbserver );
virtual uniset::ObjectType getType() override virtual uniset::ObjectType getType() override
{ {
return uniset::ObjectType("IOController"); return uniset::ObjectType("IOController");
...@@ -293,6 +296,7 @@ namespace uniset ...@@ -293,6 +296,7 @@ namespace uniset
bool isPingDBServer; // флаг связи с DBServer-ом bool isPingDBServer; // флаг связи с DBServer-ом
uniset::ObjectId dbserverID = { uniset::DefaultObjectId }; uniset::ObjectId dbserverID = { uniset::DefaultObjectId };
std::shared_ptr<uniset::DBServer> dbserver = { nullptr };
std::mutex loggingMutex; /*!< logging info mutex */ std::mutex loggingMutex; /*!< logging info mutex */
......
...@@ -493,12 +493,25 @@ void IOController::ioUnRegistration( const uniset::ObjectId sid ) ...@@ -493,12 +493,25 @@ void IOController::ioUnRegistration( const uniset::ObjectId sid )
ui->unregister(sid); ui->unregister(sid);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
void IOController::setDBServer( const std::shared_ptr<DBServer>& db )
{
dbserver = db;
}
// ---------------------------------------------------------------------------
void IOController::logging( uniset::SensorMessage& sm ) void IOController::logging( uniset::SensorMessage& sm )
{ {
std::lock_guard<std::mutex> l(loggingMutex); std::lock_guard<std::mutex> l(loggingMutex);
try try
{ {
if( dbserver )
{
sm.consumer = dbserverID;
dbserver->push(sm.transport_msg());
isPingDBServer = true;
return;
}
// значит на этом узле нет DBServer-а // значит на этом узле нет DBServer-а
if( dbserverID == uniset::DefaultObjectId ) if( dbserverID == uniset::DefaultObjectId )
{ {
......
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