Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
d5ff6808
Commit
d5ff6808
authored
Apr 04, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(SQL): починил запуск для MySQL и SQLite dbserver-ов.
parent
c21ba9d0
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
107 deletions
+119
-107
TODO
TODO
+3
-0
libuniset2.spec
conf/libuniset2.spec
+4
-1
DBServer_MySQL.cc
extensions/DBServer-MySQL/DBServer_MySQL.cc
+38
-8
DBServer_MySQL.h
extensions/DBServer-MySQL/DBServer_MySQL.h
+10
-4
main.cc
extensions/DBServer-MySQL/main.cc
+8
-39
DBServer_SQLite.cc
extensions/DBServer-SQLite/DBServer_SQLite.cc
+38
-11
DBServer_SQLite.h
extensions/DBServer-SQLite/DBServer_SQLite.h
+10
-4
main.cc
extensions/DBServer-SQLite/main.cc
+8
-40
No files found.
TODO
View file @
d5ff6808
...
...
@@ -44,6 +44,9 @@ Version 2.0
uniset-codegen: добавить ключ --gen-sensor-name для генерирования name_Item.. (чтобы можно было в логах использовать текстовые названия)
SQL:
====
- добавить работу с History (при передаче указателя на SM в конструкторе).
Version 2.1
============
...
...
conf/libuniset2.spec
View file @
d5ff6808
...
...
@@ -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 pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%configure %{subst_enable doc
s
} %{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
...
...
@@ -444,6 +444,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Sat Apr 04 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt24.1
- test pgsql extension build
* Thu Apr 02 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt24
- codegen: modify interface for messages (setMsg())
- remove alarm() function (deprecated)
...
...
extensions/DBServer-MySQL/DBServer_MySQL.cc
View file @
d5ff6808
...
...
@@ -38,9 +38,8 @@ using namespace std;
// --------------------------------------------------------------------------
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) ulog()->debug(DBLogInfoLevel)
// --------------------------------------------------------------------------
DBServer_MySQL
::
DBServer_MySQL
(
ObjectId
id
)
:
DBServer_MySQL
::
DBServer_MySQL
(
ObjectId
id
,
const
std
::
string
&
prefix
)
:
DBServer
(
id
),
db
(
new
MySQLInterface
()),
PingTime
(
300000
),
ReconnectTime
(
180000
),
connect_ok
(
false
),
...
...
@@ -48,6 +47,8 @@ DBServer_MySQL::DBServer_MySQL(ObjectId id):
qbufSize
(
200
),
lastRemove
(
false
)
{
db
=
make_shared
<
MySQLInterface
>
();
if
(
getId
()
==
DefaultObjectId
)
{
ostringstream
msg
;
...
...
@@ -55,12 +56,12 @@ DBServer_MySQL::DBServer_MySQL(ObjectId id):
throw
Exception
(
msg
.
str
());
}
mqbuf
.
setName
(
myname
+
"_qbufMutex"
);
}
DBServer_MySQL
::
DBServer_MySQL
()
:
DBServer
(
uniset_conf
()
->
getDBServer
()),
db
(
new
MySQLInterface
()),
PingTime
(
300000
),
ReconnectTime
(
180000
),
connect_ok
(
false
),
...
...
@@ -68,6 +69,7 @@ DBServer_MySQL::DBServer_MySQL():
qbufSize
(
200
),
lastRemove
(
false
)
{
db
=
make_shared
<
MySQLInterface
>
();
// init();
if
(
getId
()
==
DefaultObjectId
)
{
...
...
@@ -81,11 +83,8 @@ DBServer_MySQL::DBServer_MySQL():
//--------------------------------------------------------------------------------------------
DBServer_MySQL
::~
DBServer_MySQL
()
{
if
(
db
!=
NULL
)
{
if
(
db
)
db
->
close
();
delete
db
;
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_MySQL
::
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
...
...
@@ -329,7 +328,7 @@ void DBServer_MySQL::init_dbserver()
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_MySQL
::
createTables
(
MySQLInterface
*
db
)
void
DBServer_MySQL
::
createTables
(
std
::
shared_ptr
<
MySQLInterface
>&
db
)
{
auto
conf
=
uniset_conf
();
...
...
@@ -399,3 +398,34 @@ void DBServer_MySQL::timerInfo( const UniSetTypes::TimerMessage* tm )
}
}
//--------------------------------------------------------------------------------------------
std
::
shared_ptr
<
DBServer_MySQL
>
DBServer_MySQL
::
init_dbserver
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
prefix
)
{
auto
conf
=
uniset_conf
();
ObjectId
ID
=
conf
->
getDBServer
();
string
name
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-name"
,
""
);
if
(
!
name
.
empty
()
)
{
ObjectId
ID
=
conf
->
getObjectID
(
name
);
if
(
ID
==
UniSetTypes
::
DefaultObjectId
)
{
ucrit
<<
"(DBServer_SQLite): Unknown ObjectID for '"
<<
name
<<
endl
;
return
0
;
}
}
uinfo
<<
"(DBServer_MySQL): name = "
<<
name
<<
"("
<<
ID
<<
")"
<<
endl
;
return
make_shared
<
DBServer_MySQL
>
(
ID
,
prefix
);
}
// -----------------------------------------------------------------------------
void
DBServer_MySQL
::
help_print
(
int
argc
,
const
char
*
const
*
argv
)
{
auto
conf
=
uniset_conf
();
cout
<<
"Default: prefix='mysql'"
<<
endl
;
cout
<<
"--prefix-name objectID - ObjectID. Default: 'conf->getDBServer()'"
<<
endl
;
}
// -----------------------------------------------------------------------------
extensions/DBServer-MySQL/DBServer_MySQL.h
View file @
d5ff6808
...
...
@@ -135,16 +135,22 @@ class DBServer_MySQL:
public
DBServer
{
public
:
DBServer_MySQL
(
UniSetTypes
::
ObjectId
id
);
DBServer_MySQL
(
UniSetTypes
::
ObjectId
id
,
const
std
::
string
&
prefix
);
DBServer_MySQL
();
~
DBServer_MySQL
();
static
const
Debug
::
type
DBLogInfoLevel
=
Debug
::
LEVEL9
;
/*! глобальная функция для инициализации объекта */
static
std
::
shared_ptr
<
DBServer_MySQL
>
init_dbserver
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
prefix
=
"mysql"
);
/*! глобальная функция для вывода help-а */
static
void
help_print
(
int
argc
,
const
char
*
const
*
argv
);
protected
:
typedef
std
::
map
<
int
,
std
::
string
>
DBTableMap
;
virtual
void
initDB
(
MySQLInterface
*
db
){};
virtual
void
initDB
(
std
::
shared_ptr
<
MySQLInterface
>&
db
){};
virtual
void
initDBTableMap
(
DBTableMap
&
tblMap
){};
virtual
void
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
;
...
...
@@ -154,7 +160,7 @@ class DBServer_MySQL:
bool
writeToBase
(
const
string
&
query
);
virtual
void
init_dbserver
();
void
createTables
(
MySQLInterface
*
db
);
void
createTables
(
std
::
shared_ptr
<
MySQLInterface
>&
db
);
inline
const
char
*
tblName
(
int
key
)
{
...
...
@@ -169,7 +175,7 @@ class DBServer_MySQL:
};
MySQLInterface
*
db
;
std
::
shared_ptr
<
MySQLInterface
>
db
;
int
PingTime
;
int
ReconnectTime
;
bool
connect_ok
;
/*! признак наличия соеднинения с сервером БД */
...
...
extensions/DBServer-MySQL/main.cc
View file @
d5ff6808
...
...
@@ -6,11 +6,6 @@
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
)
{
std
::
ios
::
sync_with_stdio
(
false
);
...
...
@@ -18,53 +13,27 @@ int main(int argc, char** argv)
{
if
(
argc
>
1
&&
!
strcmp
(
argv
[
1
],
"--help"
)
)
{
short_usage
(
);
DBServer_MySQL
::
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
)
{
uwarn
<<
"(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_MySQL
dbs
(
ID
);
auto
dbs
=
DBServer_MySQL
::
init_dbserver
(
argc
,
argv
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
dbs
.
get_ptr
());
act
->
add
(
dbs
);
act
->
run
(
false
);
return
0
;
}
catch
(
const
std
::
exception
&
ex
)
{
cerr
<<
"(DBServer::main): "
<<
ex
.
what
()
<<
endl
;
cerr
<<
"(DBServer
_MySQL
::main): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(DBServer::main): catch ..."
<<
endl
;
cerr
<<
"(DBServer
_MySQL
::main): catch ..."
<<
endl
;
}
return
0
;
return
1
;
}
extensions/DBServer-SQLite/DBServer_SQLite.cc
View file @
d5ff6808
...
...
@@ -33,15 +33,13 @@
#include "Debug.h"
#include "UniXML.h"
// --------------------------------------------------------------------------
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) (*(ulog().get()))[DBLogInfoLevel]
using
namespace
UniSetTypes
;
using
namespace
std
;
// --------------------------------------------------------------------------
const
Debug
::
type
DBLEVEL
=
Debug
::
LEVEL1
;
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) ulog()->debug(DBLogInfoLevel)
// --------------------------------------------------------------------------
DBServer_SQLite
::
DBServer_SQLite
(
ObjectId
id
)
:
DBServer_SQLite
::
DBServer_SQLite
(
ObjectId
id
,
const
std
::
string
&
prefix
)
:
DBServer
(
id
),
db
(
new
SQLiteInterface
()),
PingTime
(
300000
),
ReconnectTime
(
180000
),
connect_ok
(
false
),
...
...
@@ -49,6 +47,8 @@ DBServer_SQLite::DBServer_SQLite( ObjectId id ):
qbufSize
(
200
),
lastRemove
(
false
)
{
db
=
make_shared
<
SQLiteInterface
>
();
if
(
getId
()
==
DefaultObjectId
)
{
ostringstream
msg
;
...
...
@@ -59,7 +59,6 @@ DBServer_SQLite::DBServer_SQLite( ObjectId id ):
DBServer_SQLite
::
DBServer_SQLite
()
:
DBServer
(
uniset_conf
()
->
getDBServer
()),
db
(
new
SQLiteInterface
()),
PingTime
(
300000
),
ReconnectTime
(
180000
),
connect_ok
(
false
),
...
...
@@ -67,6 +66,7 @@ DBServer_SQLite::DBServer_SQLite():
qbufSize
(
200
),
lastRemove
(
false
)
{
db
=
make_shared
<
SQLiteInterface
>
();
// init();
if
(
getId
()
==
DefaultObjectId
)
{
...
...
@@ -78,12 +78,8 @@ DBServer_SQLite::DBServer_SQLite():
//--------------------------------------------------------------------------------------------
DBServer_SQLite
::~
DBServer_SQLite
()
{
if
(
db
!=
NULL
)
{
if
(
db
)
db
->
close
();
delete
db
;
db
=
0
;
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_SQLite
::
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
...
...
@@ -308,7 +304,7 @@ void DBServer_SQLite::init_dbserver()
}
}
//--------------------------------------------------------------------------------------------
void
DBServer_SQLite
::
createTables
(
SQLiteInterface
*
db
)
void
DBServer_SQLite
::
createTables
(
std
::
shared_ptr
<
SQLiteInterface
>&
db
)
{
auto
conf
=
uniset_conf
();
UniXML
::
iterator
it
(
conf
->
getNode
(
"Tables"
)
);
...
...
@@ -377,3 +373,34 @@ void DBServer_SQLite::timerInfo( const UniSetTypes::TimerMessage* tm )
}
}
//--------------------------------------------------------------------------------------------
std
::
shared_ptr
<
DBServer_SQLite
>
DBServer_SQLite
::
init_dbserver
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
prefix
)
{
auto
conf
=
uniset_conf
();
ObjectId
ID
=
conf
->
getDBServer
();
string
name
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-name"
,
""
);
if
(
!
name
.
empty
()
)
{
ObjectId
ID
=
conf
->
getObjectID
(
name
);
if
(
ID
==
UniSetTypes
::
DefaultObjectId
)
{
ucrit
<<
"(DBServer_SQLite): Unknown ObjectID for '"
<<
name
<<
endl
;
return
0
;
}
}
uinfo
<<
"(DBServer_SQLite): name = "
<<
name
<<
"("
<<
ID
<<
")"
<<
endl
;
return
make_shared
<
DBServer_SQLite
>
(
ID
,
prefix
);
}
// -----------------------------------------------------------------------------
void
DBServer_SQLite
::
help_print
(
int
argc
,
const
char
*
const
*
argv
)
{
auto
conf
=
uniset_conf
();
cout
<<
"Default: prefix='sqlite'"
<<
endl
;
cout
<<
"--prefix-name objectID - ObjectID. Default: 'conf->getDBServer()'"
<<
endl
;
}
// -----------------------------------------------------------------------------
extensions/DBServer-SQLite/DBServer_SQLite.h
View file @
d5ff6808
...
...
@@ -135,16 +135,22 @@ class DBServer_SQLite:
public
DBServer
{
public
:
DBServer_SQLite
(
UniSetTypes
::
ObjectId
id
);
DBServer_SQLite
(
UniSetTypes
::
ObjectId
id
,
const
std
::
string
&
prefix
);
DBServer_SQLite
();
~
DBServer_SQLite
();
static
const
Debug
::
type
DBLogInfoLevel
=
Debug
::
LEVEL9
;
/*! глобальная функция для инициализации объекта */
static
std
::
shared_ptr
<
DBServer_SQLite
>
init_dbserver
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
prefix
=
"sqlite"
);
/*! глобальная функция для вывода help-а */
static
void
help_print
(
int
argc
,
const
char
*
const
*
argv
);
protected
:
typedef
std
::
map
<
int
,
std
::
string
>
DBTableMap
;
virtual
void
initDB
(
SQLiteInterface
*
db
){};
virtual
void
initDB
(
std
::
shared_ptr
<
SQLiteInterface
>&
db
){};
virtual
void
initDBTableMap
(
DBTableMap
&
tblMap
){};
virtual
void
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
;
...
...
@@ -154,7 +160,7 @@ class DBServer_SQLite:
bool
writeToBase
(
const
string
&
query
);
virtual
void
init_dbserver
();
void
createTables
(
SQLiteInterface
*
db
);
void
createTables
(
std
::
shared_ptr
<
SQLiteInterface
>&
db
);
inline
const
char
*
tblName
(
int
key
)
{
...
...
@@ -169,7 +175,7 @@ class DBServer_SQLite:
};
SQLiteInterface
*
db
;
std
::
shared_ptr
<
SQLiteInterface
>
db
;
int
PingTime
;
int
ReconnectTime
;
bool
connect_ok
;
/*! признак наличия соеднинения с сервером БД */
...
...
extensions/DBServer-SQLite/main.cc
View file @
d5ff6808
...
...
@@ -6,11 +6,6 @@
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
)
{
std
::
ios
::
sync_with_stdio
(
false
);
...
...
@@ -18,54 +13,27 @@ int main(int argc, char** argv)
{
if
(
argc
>
1
&&
!
strcmp
(
argv
[
1
],
"--help"
)
)
{
short_usage
(
);
DBServer_SQLite
::
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
)
{
uwarn
<<
"(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_SQLite
dbs
(
ID
);
auto
dbs
=
DBServer_SQLite
::
init_dbserver
(
argc
,
argv
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
dbs
.
get_ptr
());
act
->
add
(
dbs
);
act
->
run
(
false
);
return
0
;
}
catch
(
const
std
::
exception
&
ex
)
{
cerr
<<
"(DBServer::main): "
<<
ex
.
what
()
<<
endl
;
cerr
<<
"(DBServer
_SQLite
::main): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(DBServer::main): catch ..."
<<
endl
;
cerr
<<
"(DBServer
_SQLite
::main): catch ..."
<<
endl
;
}
return
0
;
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment