Commit fe521c11 authored by Pavel Vainerman's avatar Pavel Vainerman

(PGSQL): предварительная версия

parent 627ea7d9
%def_enable docs
%def_enable mysql
%def_enable sqlite
%def_enable postgresql
%def_enable pgsql
%def_enable python
%def_enable rrd
%def_enable io
......@@ -43,7 +43,7 @@ BuildRequires: libMySQL-devel
BuildRequires: libsqlite3-devel
%endif
%if_enabled postgresql
%if_enabled pgsql
BuildRequires: postgresql9.3-devel libpq5.6-devel
%endif
......@@ -180,21 +180,21 @@ Requires: %name-extension-common = %version-%release
Libraries needed to develop for uniset SQLite
%endif
%if_enabled postgresql
%package extension-postgresql
%if_enabled pgsql
%package extension-pgsql
Group: Development/Databases
Summary: PostgreSQL-dbserver implementatioin for UniSet
Requires: %name-extension-common = %version-%release
%description extension-postgresql
%description extension-pgsql
PostgreSQL dbserver for %name
%package extension-postgresql-devel
%package extension-pgsql-devel
Group: Development/Databases
Summary: Libraries needed to develop for uniset PostgreSQL
Requires: %name-extension-common-devel = %version-%release
%description extension-postgresql-devel
%description extension-pgsql-devel
Libraries needed to develop for uniset PostgreSQL
%endif
......@@ -264,7 +264,7 @@ SharedMemoryPlus extension ('all in one') for libuniset
%build
%autoreconf
%configure %{subst_enable doc} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable postgresql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%configure %{subst_enable doc} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%make
%install
......@@ -315,8 +315,8 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%if_enabled sqlite
%_includedir/%oname/sqlite/
%endif
%if_enabled postgresql
%_includedir/%oname/postgresql/
%if_enabled pgsql
%_includedir/%oname/pgsql/
%endif
%_libdir/libUniSet2.so
......@@ -341,12 +341,12 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%_pkgconfigdir/libUniSet2SQLite.pc
%endif
%if_enabled postgresql
%files extension-postgresql
%_bindir/%oname-postgresql-*dbserver
%_libdir/*-postgresql.so*
%if_enabled pgsql
%files extension-pgsql
%_bindir/%oname-pgsql-*dbserver
%_libdir/*-pgsql.so*
%files extension-postgresql-devel
%files extension-pgsql-devel
%_pkgconfigdir/libUniSet2PostgreSQL.pc
%endif
......
......@@ -81,6 +81,23 @@ fi
AM_CONDITIONAL(DISABLE_MYSQL, test ${buildmysql} = false)
#check pgsql support
AC_MSG_CHECKING([postgresql support])
buildpgsql=true
AC_ARG_ENABLE(pgsql, AC_HELP_STRING([--disable-pgsql], [disable PostgreSQL support]),
[ if test $enableval = yes; then buildpgsql=true; else buildpgsql=false; fi],[ buildpgsql=true; ])
if test ${buildpgsql} = true; then
AC_MSG_RESULT([enabled])
PKG_CHECK_MODULES(PGSQL,libpq)
AC_SUBST(PGSQL_LIBS)
AC_SUBST(PGSQL_CFLAGS)
else
AC_MSG_RESULT([disabled])
fi
AM_CONDITIONAL(DISABLE_PGSQL, test ${buildpgsql} = false)
#check rrd support
AC_MSG_CHECKING([rrd support])
......@@ -330,6 +347,8 @@ AC_CONFIG_FILES([Makefile
extensions/DBServer-MySQL/libUniSet2MySQL.pc
extensions/DBServer-SQLite/Makefile
extensions/DBServer-SQLite/libUniSet2SQLite.pc
extensions/DBServer-PostgreSQL/Makefile
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc
extensions/IOControl/Makefile
extensions/IOControl/libUniSet2IOControl.pc
extensions/ModbusMaster/Makefile
......
......@@ -36,7 +36,7 @@
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) (*(ulog().get()))[DBLogInfoLevel]
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) ulog()->debug(DBLogInfoLevel)
// --------------------------------------------------------------------------
DBServer_MySQL::DBServer_MySQL(ObjectId id):
DBServer(id),
......
......@@ -11,16 +11,22 @@ class DBServer_PostgreSQL:
public DBServer
{
public:
DBServer_PostgreSQL( UniSetTypes::ObjectId id );
DBServer_PostgreSQL( UniSetTypes::ObjectId id, const std::string& prefix );
DBServer_PostgreSQL();
~DBServer_PostgreSQL();
virtual ~DBServer_PostgreSQL();
static const Debug::type DBLogInfoLevel = Debug::LEVEL9;
/*! глобальная функция для инициализации объекта */
static std::shared_ptr<DBServer_PostgreSQL> init_dbserver( int argc, const char* const* argv, const std::string& prefix="pgsql" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
protected:
typedef std::map<int, std::string> DBTableMap;
virtual void initDB(PostgreSQLInterface *db){};
virtual void initDB( std::shared_ptr<PostgreSQLInterface>& db ){};
virtual void initDBTableMap(DBTableMap& tblMap){};
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override;
......@@ -31,7 +37,7 @@ class DBServer_PostgreSQL:
bool writeToBase( const string& query );
virtual void init_dbserver();
void createTables( PostgreSQLInterface* db );
void createTables( std::shared_ptr<PostgreSQLInterface>& db );
inline const char* tblName(int key)
{
......@@ -45,7 +51,7 @@ class DBServer_PostgreSQL:
lastNumberOfTimer
};
PostgreSQLInterface *db;
std::shared_ptr<PostgreSQLInterface> db;
int PingTime;
int ReconnectTime;
bool connect_ok; /*! признак наличия соеднинения с сервером БД */
......
......@@ -4,25 +4,25 @@ else
UPGSQL_VER=@LIBVER@
lib_LTLIBRARIES = libUniSet2-postgresql.la
libUniSet2_postgresql_la_LDFLAGS = -version-info $(UPGSQL_VER)
libUniSet2_postgresql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_postgresql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(POSTGRESQL_LIBS)
libUniSet2_postgresql_la_CXXFLAGS = $(POSTGRESQL_CFLAGS)
bin_PROGRAMS = @PACKAGE@-postgresql-dbserver
@PACKAGE@_postgresql_dbserver_LDADD = libUniSet2-postgresql.la $(top_builddir)/lib/libUniSet2.la $(POSTGRESQL_LIBS)
@PACKAGE@_postgresql_dbserver_CXXFLAGS = $(POSTGRESQL_CFLAGS)
@PACKAGE@_postgresql_dbserver_SOURCES = main.cc
noinst_PROGRAMS = postgresql-test
postgresql_test_LDADD = libUniSet2-postgresql.la $(top_builddir)/lib/libUniSet2.la $(POSTGRESQL_LIBS)
postgresql_test_CXXFLAGS = $(POSTGRESQL_CFLAGS)
postgresql_test_SOURCES = test.cc
lib_LTLIBRARIES = libUniSet2-pgsql.la
libUniSet2_pgsql_la_LDFLAGS = -version-info $(UPGSQL_VER)
libUniSet2_pgsql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_pgsql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
libUniSet2_pgsql_la_CXXFLAGS = $(PGSQL_CFLAGS)
bin_PROGRAMS = @PACKAGE@-pgsql-dbserver
@PACKAGE@_pgsql_dbserver_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
@PACKAGE@_pgsql_dbserver_CXXFLAGS = $(PGSQL_CFLAGS)
@PACKAGE@_pgsql_dbserver_SOURCES = main.cc
noinst_PROGRAMS = pgsql-test
pgsql_test_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
pgsql_test_CXXFLAGS = $(PGSQL_CFLAGS)
pgsql_test_SOURCES = test.cc
# install
devel_include_HEADERS = *.h
devel_includedir = $(includedir)/@PACKAGE@/postgresql
devel_includedir = $(includedir)/@PACKAGE@/pgsql
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libUniSet2PostgreSQL.pc
......
......@@ -10,6 +10,7 @@ using namespace UniSetTypes;
PostgreSQLInterface::PostgreSQLInterface():
db(0),
result(0),
lastQ(""),
lastE(""),
queryok(false),
......
......@@ -7,5 +7,5 @@ Name: libUniSet2PostgreSQL
Description: Support library for libUniSet2PostgreSQL
Requires: libUniSet2 libpq
Version: @VERSION@
Libs: -L${libdir} -lUniSet2-postgresql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/postgresql
Libs: -L${libdir} -lUniSet2-pgsql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/pgsql
......@@ -6,63 +6,34 @@
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
static void short_usage()
{
cout << "Usage: uniset-mysql-dbserver [--name ObjectId] [--confile configure.xml]\n";
}
// --------------------------------------------------------------------------
int main(int argc, char** argv)
{
try
{
if( argc > 1 && !strcmp(argv[1],"--help") )
{
short_usage();
DBServer_PostgreSQL::help_print(argc,argv);
return 0;
}
auto conf = uniset_init(argc,argv,"configure.xml");
ObjectId ID = conf->getDBServer();
// определяем ID объекта
string name = conf->getArgParam("--name");
if( !name.empty())
{
if( ID != UniSetTypes::DefaultObjectId )
{
ulog.warn() << "(DBServer::main): переопределяем ID заданнй в "
<< conf->getConfFileName() << endl;
}
ID = conf->oind->getIdByName(conf->getServicesSection()+"/"+name);
if( ID == UniSetTypes::DefaultObjectId )
{
cerr << "(DBServer::main): идентификатор '" << name
<< "' не найден в конф. файле!"
<< " в секции " << conf->getServicesSection() << endl;
return 1;
}
}
else if( ID == UniSetTypes::DefaultObjectId )
{
cerr << "(DBServer::main): Не удалось определить ИДЕНТИФИКАТОР сервера" << endl;
short_usage();
return 1;
}
DBServer_PostgreSQL dbs(ID);
UniSetActivatorPtr act = UniSetActivator::Instance();
act->addObject(static_cast<class UniSetObject*>(&dbs));
auto dbs = DBServer_PostgreSQL::init_dbserver(argc,argv);
auto act = UniSetActivator::Instance();
act->add(dbs);
act->run(false);
}
catch(Exception& ex)
catch( const Exception& ex )
{
cerr << "(DBServer_PosgreSQL::main): " << ex << endl;
}
catch( std::exception& ex )
{
cerr << "(DBServer::main): " << ex << endl;
cerr << "(DBServer_PosgreSQL::main): " << ex.what() << endl;
}
catch(...)
{
cerr << "(DBServer::main): catch ..." << endl;
cerr << "(DBServer_PosgreSQL::main): catch ..." << endl;
}
return 0;
......
......@@ -2,6 +2,6 @@
ulimit -Sc 1000000
uniset2-start.sh -f ./uniset2-postgresql-dbserver --confile test.xml --name DBServer1 \
uniset2-start.sh -f ./uniset2-pgsql-dbserver --confile test.xml --name DBServer1 \
--ulog-add-levels info,crit,warn,level9,system \
--dbserver-buffer-size 100
......@@ -44,7 +44,7 @@ int main(int argc, char** argv)
db.close();
}
catch( Exception& ex )
catch( const Exception& ex )
{
cerr << "(test): " << ex << endl;
}
......
......@@ -19,6 +19,14 @@ extensions/DBServer-SQLite/SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.h
extensions/DBServer-SQLite/test.cc
extensions/DBServer-SQLite/test.xml
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
extensions/DBServer-PostgreSQL/main.cc
extensions/DBServer-PostgreSQL/Makefile.am
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/test.cc
extensions/include/Calibration.h
extensions/include/ComediInterface.h
extensions/include/DigitalFilter.h
......
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