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
9356415b
Commit
9356415b
authored
May 11, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make style..
parent
8df67095
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
300 additions
and
275 deletions
+300
-275
main.cc
Utilities/SImitator/main.cc
+2
-2
DBServer_PostgreSQL.cc
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
+0
-0
DBServer_PostgreSQL.h
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
+45
-45
PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
+96
-94
PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
+49
-34
main.cc
extensions/DBServer-PostgreSQL/main.cc
+26
-26
test.cc
extensions/DBServer-PostgreSQL/test.cc
+54
-50
PassiveLProcessor.cc
extensions/LogicProcessor/PassiveLProcessor.cc
+2
-1
PassiveLProcessor.h
extensions/LogicProcessor/PassiveLProcessor.h
+1
-1
plogicproc.cc
extensions/LogicProcessor/plogicproc.cc
+1
-1
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+6
-5
test_mbslave.cc
extensions/ModbusSlave/tests/test_mbslave.cc
+2
-2
SharedMemory.cc
extensions/SharedMemory/SharedMemory.cc
+2
-2
test_sm.cc
extensions/SharedMemory/tests/test_sm.cc
+9
-8
TCPCheck.h
include/TCPCheck.h
+2
-2
TCPCheck.cc
src/Communications/TCP/TCPCheck.cc
+2
-1
test_tcpcheck.cc
tests/test_tcpcheck.cc
+1
-1
No files found.
Utilities/SImitator/main.cc
View file @
9356415b
...
...
@@ -60,7 +60,7 @@ int main( int argc, char** argv )
std
::
list
<
ExtInfo
>
l
;
for
(
auto
&&
it
:
lst
)
for
(
auto
&&
it
:
lst
)
{
UniversalIO
::
IOType
t
=
conf
->
getIOType
(
it
.
si
.
id
);
...
...
@@ -129,7 +129,7 @@ int main( int argc, char** argv )
cout
<<
"
\r
"
<<
" i = "
<<
j
<<
" "
<<
flush
;
for
(
const
auto
&
it
:
l
)
for
(
const
auto
&
it
:
l
)
{
try
{
...
...
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
View file @
9356415b
This diff is collapsed.
Click to expand it.
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
View file @
9356415b
...
...
@@ -8,67 +8,67 @@
#include "DBServer.h"
//------------------------------------------------------------------------------------------
class
DBServer_PostgreSQL
:
public
DBServer
public
DBServer
{
public
:
DBServer_PostgreSQL
(
UniSetTypes
::
ObjectId
id
,
const
std
::
string
&
prefix
);
DBServer_PostgreSQL
();
virtual
~
DBServer_PostgreSQL
();
public
:
DBServer_PostgreSQL
(
UniSetTypes
::
ObjectId
id
,
const
std
::
string
&
prefix
);
DBServer_PostgreSQL
();
virtual
~
DBServer_PostgreSQL
();
static
const
Debug
::
type
DBLogInfoLevel
=
Debug
::
LEVEL9
;
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"
);
/*! глобальная функция для инициализации объекта */
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
);
/*! глобальная функция для вывода help-а */
static
void
help_print
(
int
argc
,
const
char
*
const
*
argv
);
protected
:
typedef
std
::
map
<
int
,
std
::
string
>
DBTableMap
;
protected
:
typedef
std
::
map
<
int
,
std
::
string
>
DBTableMap
;
virtual
void
initDB
(
std
::
shared_ptr
<
PostgreSQLInterface
>&
db
)
{};
virtual
void
initDBTableMap
(
DBTableMap
&
tblMap
)
{};
virtual
void
initDB
(
std
::
shared_ptr
<
PostgreSQLInterface
>&
db
)
{};
virtual
void
initDBTableMap
(
DBTableMap
&
tblMap
)
{};
virtual
void
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
;
virtual
void
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
override
;
virtual
void
sensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
)
override
;
virtual
void
confirmInfo
(
const
UniSetTypes
::
ConfirmMessage
*
cmsg
)
override
;
virtual
void
sigterm
(
int
signo
)
override
;
virtual
void
timerInfo
(
const
UniSetTypes
::
TimerMessage
*
tm
)
override
;
virtual
void
sysCommand
(
const
UniSetTypes
::
SystemMessage
*
sm
)
override
;
virtual
void
sensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
)
override
;
virtual
void
confirmInfo
(
const
UniSetTypes
::
ConfirmMessage
*
cmsg
)
override
;
virtual
void
sigterm
(
int
signo
)
override
;
bool
writeToBase
(
const
string
&
query
);
virtual
void
init_dbserver
();
void
createTables
(
std
::
shared_ptr
<
PostgreSQLInterface
>&
db
);
bool
writeToBase
(
const
string
&
query
);
virtual
void
init_dbserver
();
void
createTables
(
std
::
shared_ptr
<
PostgreSQLInterface
>&
db
);
inline
const
char
*
tblName
(
int
key
)
{
return
tblMap
[
key
].
c_str
();
}
inline
const
char
*
tblName
(
int
key
)
{
return
tblMap
[
key
].
c_str
();
}
enum
Timers
{
PingTimer
,
/*!< таймер на переодическую проверку соединения с сервером БД */
ReconnectTimer
,
/*!< таймер на повторную попытку соединения с сервером БД (или восстановления связи) */
lastNumberOfTimer
};
enum
Timers
{
PingTimer
,
/*!< таймер на переодическую проверку соединения с сервером БД */
ReconnectTimer
,
/*!< таймер на повторную попытку соединения с сервером БД (или восстановления связи) */
lastNumberOfTimer
};
std
::
shared_ptr
<
PostgreSQLInterface
>
db
;
int
PingTime
;
int
ReconnectTime
;
bool
connect_ok
;
/*! признак наличия соеднинения с сервером БД */
std
::
shared_ptr
<
PostgreSQLInterface
>
db
;
int
PingTime
;
int
ReconnectTime
;
bool
connect_ok
;
/*! признак наличия соеднинения с сервером БД */
bool
activate
;
bool
activate
;
typedef
std
::
queue
<
std
::
string
>
QueryBuffer
;
typedef
std
::
queue
<
std
::
string
>
QueryBuffer
;
QueryBuffer
qbuf
;
unsigned
int
qbufSize
;
// размер буфера сообщений.
bool
lastRemove
;
QueryBuffer
qbuf
;
unsigned
int
qbufSize
;
// размер буфера сообщений.
bool
lastRemove
;
void
flushBuffer
();
UniSetTypes
::
uniset_mutex
mqbuf
;
void
flushBuffer
();
UniSetTypes
::
uniset_mutex
mqbuf
;
private
:
DBTableMap
tblMap
;
private
:
DBTableMap
tblMap
;
};
//------------------------------------------------------------------------------------------
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
View file @
9356415b
...
...
@@ -10,189 +10,189 @@ using namespace pqxx;
// --------------------------------------------------------------------------
PostgreSQLInterface
::
PostgreSQLInterface
()
:
lastQ
(
""
),
lastE
(
""
),
last_inserted_id
(
0
)
lastQ
(
""
),
lastE
(
""
),
last_inserted_id
(
0
)
{
//db = make_shared<pqxx::connection>();
//db = make_shared<pqxx::connection>();
}
PostgreSQLInterface
::~
PostgreSQLInterface
()
{
close
();
close
();
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
ping
()
{
return
db
&&
db
->
is_open
();
return
db
&&
db
->
is_open
();
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
connect
(
const
string
&
host
,
const
string
&
user
,
const
string
&
pswd
,
const
string
&
dbname
)
{
if
(
db
)
return
true
;
if
(
db
)
return
true
;
std
::
string
conninfo
=
"dbname="
+
dbname
+
" host="
+
host
+
" user="
+
user
+
" password="
+
pswd
;
std
::
string
conninfo
=
"dbname="
+
dbname
+
" host="
+
host
+
" user="
+
user
+
" password="
+
pswd
;
try
{
db
=
make_shared
<
pqxx
::
connection
>
(
conninfo
);
return
db
->
is_open
();
try
{
db
=
make_shared
<
pqxx
::
connection
>
(
conninfo
);
return
db
->
is_open
();
}
catch
(
const
std
::
exception
&
e
)
{
cerr
<<
e
.
what
()
<<
std
::
endl
;
}
}
catch
(
const
std
::
exception
&
e
)
{
cerr
<<
e
.
what
()
<<
std
::
endl
;
}
return
false
;
return
false
;
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
close
()
{
if
(
db
)
{
db
->
disconnect
();
db
.
reset
();
}
if
(
db
)
{
db
->
disconnect
();
db
.
reset
();
}
return
true
;
return
true
;
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
insert
(
const
string
&
q
)
{
if
(
!
db
)
return
false
;
if
(
!
db
)
return
false
;
try
{
work
w
(
*
(
db
.
get
())
);
w
.
exec
(
q
);
w
.
commit
();
return
true
;
}
catch
(
const
std
::
exception
&
e
)
{
//cerr << e.what() << std::endl;
lastE
=
string
(
e
.
what
());
}
try
{
work
w
(
*
(
db
.
get
())
);
w
.
exec
(
q
);
w
.
commit
();
return
true
;
}
catch
(
const
std
::
exception
&
e
)
{
//cerr << e.what() << std::endl;
lastE
=
string
(
e
.
what
());
}
return
false
;
return
false
;
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
insertAndSaveRowid
(
const
string
&
q
)
{
if
(
!
db
)
return
false
;
if
(
!
db
)
return
false
;
std
::
string
qplus
=
q
+
" RETURNING id"
;
std
::
string
qplus
=
q
+
" RETURNING id"
;
try
{
work
w
(
*
(
db
.
get
())
);
pqxx
::
result
res
=
w
.
exec
(
qplus
);
w
.
commit
();
save_inserted_id
(
res
);
return
true
;
}
catch
(
const
std
::
exception
&
e
)
{
//cerr << e.what() << std::endl;
lastE
=
string
(
e
.
what
());
}
try
{
work
w
(
*
(
db
.
get
())
);
pqxx
::
result
res
=
w
.
exec
(
qplus
);
w
.
commit
();
save_inserted_id
(
res
);
return
true
;
}
catch
(
const
std
::
exception
&
e
)
{
//cerr << e.what() << std::endl;
lastE
=
string
(
e
.
what
());
}
return
false
;
return
false
;
}
// -----------------------------------------------------------------------------------------
PostgreSQLResult
PostgreSQLInterface
::
query
(
const
string
&
q
)
{
if
(
!
db
)
return
PostgreSQLResult
();
if
(
!
db
)
return
PostgreSQLResult
();
try
{
nontransaction
n
(
*
(
db
.
get
()));
try
{
nontransaction
n
(
*
(
db
.
get
()));
/* Execute SQL query */
result
res
(
n
.
exec
(
q
)
);
return
PostgreSQLResult
(
res
);
}
catch
(
const
std
::
exception
&
e
)
{
lastE
=
string
(
e
.
what
());
}
/* Execute SQL query */
result
res
(
n
.
exec
(
q
)
);
return
PostgreSQLResult
(
res
);
}
catch
(
const
std
::
exception
&
e
)
{
lastE
=
string
(
e
.
what
());
}
return
PostgreSQLResult
();
return
PostgreSQLResult
();
}
// -----------------------------------------------------------------------------------------
string
PostgreSQLInterface
::
error
()
{
return
lastE
;
return
lastE
;
}
// -----------------------------------------------------------------------------------------
const
string
PostgreSQLInterface
::
lastQuery
()
{
return
lastQ
;
return
lastQ
;
}
// -----------------------------------------------------------------------------------------
double
PostgreSQLInterface
::
insert_id
()
{
return
last_inserted_id
;
return
last_inserted_id
;
}
// -----------------------------------------------------------------------------------------
void
PostgreSQLInterface
::
save_inserted_id
(
const
pqxx
::
result
&
res
)
{
if
(
res
.
size
()
>
0
&&
res
[
0
].
size
()
>
0
)
last_inserted_id
=
res
[
0
][
0
].
as
<
int
>
();
if
(
res
.
size
()
>
0
&&
res
[
0
].
size
()
>
0
)
last_inserted_id
=
res
[
0
][
0
].
as
<
int
>
();
}
// -----------------------------------------------------------------------------------------
bool
PostgreSQLInterface
::
isConnection
()
{
return
(
db
&&
db
->
is_open
());
return
(
db
&&
db
->
is_open
());
}
// -----------------------------------------------------------------------------------------
int
num_cols
(
PostgreSQLResult
::
iterator
&
it
)
{
return
it
->
size
();
return
it
->
size
();
}
// -----------------------------------------------------------------------------------------
int
as_int
(
PostgreSQLResult
::
iterator
&
it
,
int
col
)
{
// if( col<0 || col >it->size() )
// return 0;
return
uni_atoi
(
(
*
it
)[
col
]
);
// if( col<0 || col >it->size() )
// return 0;
return
uni_atoi
(
(
*
it
)[
col
]
);
}
// -----------------------------------------------------------------------------------------
double
as_double
(
PostgreSQLResult
::
iterator
&
it
,
int
col
)
{
return
atof
(
((
*
it
)[
col
]).
c_str
()
);
return
atof
(
((
*
it
)[
col
]).
c_str
()
);
}
// -----------------------------------------------------------------------------------------
string
as_string
(
PostgreSQLResult
::
iterator
&
it
,
int
col
)
{
return
((
*
it
)[
col
]);
return
((
*
it
)[
col
]);
}
// -----------------------------------------------------------------------------------------
int
as_int
(
PostgreSQLResult
::
COL
::
iterator
&
it
)
{
return
uni_atoi
(
(
*
it
)
);
return
uni_atoi
(
(
*
it
)
);
}
// -----------------------------------------------------------------------------------------
double
as_double
(
PostgreSQLResult
::
COL
::
iterator
&
it
)
{
return
atof
(
(
*
it
).
c_str
()
);
return
atof
(
(
*
it
).
c_str
()
);
}
// -----------------------------------------------------------------------------------------
std
::
string
as_string
(
PostgreSQLResult
::
COL
::
iterator
&
it
)
{
return
(
*
it
);
return
(
*
it
);
}
// -----------------------------------------------------------------------------------------
#if 0
PostgreSQLResult::COL get_col( PostgreSQLResult::ROW::iterator& it )
{
return (*it);
return (*it);
}
#endif
// -----------------------------------------------------------------------------------------
...
...
@@ -203,12 +203,14 @@ PostgreSQLResult::~PostgreSQLResult()
// -----------------------------------------------------------------------------------------
PostgreSQLResult
::
PostgreSQLResult
(
const
pqxx
::
result
&
res
)
{
for
(
result
::
const_iterator
c
=
res
.
begin
();
c
!=
res
.
end
();
++
c
)
{
COL
col
;
for
(
int
i
=
0
;
i
<
c
.
size
();
i
++
)
col
.
push_back
(
c
[
i
].
as
<
string
>
()
);
row
.
push_back
(
col
);
}
for
(
result
::
const_iterator
c
=
res
.
begin
();
c
!=
res
.
end
();
++
c
)
{
COL
col
;
for
(
int
i
=
0
;
i
<
c
.
size
();
i
++
)
col
.
push_back
(
c
[
i
].
as
<
string
>
()
);
row
.
push_back
(
col
);
}
}
// -----------------------------------------------------------------------------------------
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
View file @
9356415b
...
...
@@ -13,59 +13,74 @@ class PostgreSQLResult;
// ----------------------------------------------------------------------------
class
PostgreSQLInterface
{
public
:
public
:
PostgreSQLInterface
();
~
PostgreSQLInterface
();
PostgreSQLInterface
();
~
PostgreSQLInterface
();
bool
connect
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
pswd
,
const
std
::
string
&
dbname
);
bool
close
();
bool
isConnection
();
bool
ping
();
// проверка доступности БД
bool
connect
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
pswd
,
const
std
::
string
&
dbname
);
bool
close
();
bool
isConnection
();
bool
ping
();
// проверка доступности БД
PostgreSQLResult
query
(
const
std
::
string
&
q
);
const
std
::
string
lastQuery
();
PostgreSQLResult
query
(
const
std
::
string
&
q
);
const
std
::
string
lastQuery
();
bool
insert
(
const
std
::
string
&
q
);
bool
insertAndSaveRowid
(
const
std
::
string
&
q
);
double
insert_id
();
void
save_inserted_id
(
const
pqxx
::
result
&
res
);
bool
insert
(
const
std
::
string
&
q
);
bool
insertAndSaveRowid
(
const
std
::
string
&
q
);
double
insert_id
();
void
save_inserted_id
(
const
pqxx
::
result
&
res
);
std
::
string
error
();
std
::
string
error
();
protected
:
protected
:
private
:
private
:
std
::
shared_ptr
<
pqxx
::
connection
>
db
;
std
::
string
lastQ
;
std
::
string
lastE
;
double
last_inserted_id
;
std
::
shared_ptr
<
pqxx
::
connection
>
db
;
std
::
string
lastQ
;
std
::
string
lastE
;
double
last_inserted_id
;
};
// ----------------------------------------------------------------------------------
class
PostgreSQLResult
{
public
:
PostgreSQLResult
()
{}
PostgreSQLResult
(
const
pqxx
::
result
&
res
);
~
PostgreSQLResult
();
public
:
PostgreSQLResult
()
{}
PostgreSQLResult
(
const
pqxx
::
result
&
res
);
~
PostgreSQLResult
();
typedef
std
::
vector
<
std
::
string
>
COL
;
typedef
std
::
list
<
COL
>
ROW
;
typedef
std
::
vector
<
std
::
string
>
COL
;
typedef
std
::
list
<
COL
>
ROW
;
typedef
ROW
::
iterator
iterator
;
typedef
ROW
::
iterator
iterator
;
inline
iterator
begin
(){
return
row
.
begin
();
}
inline
iterator
end
(){
return
row
.
end
();
}
inline
iterator
begin
()
{
return
row
.
begin
();
}
inline
iterator
end
()
{
return
row
.
end
();
}
inline
operator
bool
(){
return
!
row
.
empty
();
}
inline
operator
bool
()
{
return
!
row
.
empty
();
}
inline
int
size
(){
return
row
.
size
();
}
inline
bool
empty
(){
return
row
.
empty
();
}
inline
int
size
()
{
return
row
.
size
();
}
inline
bool
empty
()
{
return
row
.
empty
();
}
protected
:
protected
:
ROW
row
;
ROW
row
;
};
// ----------------------------------------------------------------------------
int
num_cols
(
PostgreSQLResult
::
iterator
&
);
...
...
extensions/DBServer-PostgreSQL/main.cc
View file @
9356415b
...
...
@@ -8,33 +8,33 @@ using namespace std;
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
{
try
{
if
(
argc
>
1
&&
!
strcmp
(
argv
[
1
],
"--help"
)
)
{
DBServer_PostgreSQL
::
help_print
(
argc
,
argv
);
return
0
;
}
try
{
if
(
argc
>
1
&&
!
strcmp
(
argv
[
1
],
"--help"
)
)
{
DBServer_PostgreSQL
::
help_print
(
argc
,
argv
);
return
0
;
}
auto
conf
=
uniset_init
(
argc
,
argv
,
"configure.xml"
);
auto
conf
=
uniset_init
(
argc
,
argv
,
"configure.xml"
);
auto
dbs
=
DBServer_PostgreSQL
::
init_dbserver
(
argc
,
argv
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
dbs
);
act
->
run
(
false
);
}
catch
(
const
Exception
&
ex
)
{
cerr
<<
"(DBServer_PosgreSQL::main): "
<<
ex
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
cerr
<<
"(DBServer_PosgreSQL::main): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(DBServer_PosgreSQL::main): catch ..."
<<
endl
;
}
auto
dbs
=
DBServer_PostgreSQL
::
init_dbserver
(
argc
,
argv
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
dbs
);
act
->
run
(
false
);
}
catch
(
const
Exception
&
ex
)
{
cerr
<<
"(DBServer_PosgreSQL::main): "
<<
ex
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
cerr
<<
"(DBServer_PosgreSQL::main): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(DBServer_PosgreSQL::main): catch ..."
<<
endl
;
}
return
0
;
return
0
;
}
extensions/DBServer-PostgreSQL/test.cc
View file @
9356415b
...
...
@@ -8,54 +8,58 @@ using namespace std;
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
{
std
::
string
dbname
(
"test-db"
);
if
(
argc
>
1
)
dbname
=
string
(
argv
[
1
]);
try
{
PostgreSQLInterface
db
;
if
(
!
db
.
connect
(
"localhost"
,
"dbadmin"
,
"dbadmin"
,
dbname
)
)
{
cerr
<<
"db connect error: "
<<
db
.
error
()
<<
endl
;
return
1
;
}
stringstream
q
;
q
<<
"SELECT * from main_history"
;
PostgreSQLResult
r
=
db
.
query
(
q
.
str
());
if
(
!
r
)
{
cerr
<<
"db connect error: "
<<
db
.
error
()
<<
endl
;
return
1
;
}
for
(
PostgreSQLResult
::
iterator
it
=
r
.
begin
();
it
!=
r
.
end
();
it
++
)
{
cout
<<
"ROW: "
;
PostgreSQLResult
::
COL
col
(
*
it
);
for
(
PostgreSQLResult
::
COL
::
iterator
cit
=
it
->
begin
();
cit
!=
it
->
end
();
cit
++
)
cout
<<
as_string
(
cit
)
<<
"("
<<
as_double
(
cit
)
<<
") | "
;
cout
<<
endl
;
}
db
.
close
();
}
catch
(
const
Exception
&
ex
)
{
cerr
<<
"(test): "
<<
ex
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
cerr
<<
"(test): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(test): catch ..."
<<
endl
;
}
return
0
;
std
::
string
dbname
(
"test-db"
);
if
(
argc
>
1
)
dbname
=
string
(
argv
[
1
]);
try
{
PostgreSQLInterface
db
;
if
(
!
db
.
connect
(
"localhost"
,
"dbadmin"
,
"dbadmin"
,
dbname
)
)
{
cerr
<<
"db connect error: "
<<
db
.
error
()
<<
endl
;
return
1
;
}
stringstream
q
;
q
<<
"SELECT * from main_history"
;
PostgreSQLResult
r
=
db
.
query
(
q
.
str
());
if
(
!
r
)
{
cerr
<<
"db connect error: "
<<
db
.
error
()
<<
endl
;
return
1
;
}
for
(
PostgreSQLResult
::
iterator
it
=
r
.
begin
();
it
!=
r
.
end
();
it
++
)
{
cout
<<
"ROW: "
;
PostgreSQLResult
::
COL
col
(
*
it
);
for
(
PostgreSQLResult
::
COL
::
iterator
cit
=
it
->
begin
();
cit
!=
it
->
end
();
cit
++
)
cout
<<
as_string
(
cit
)
<<
"("
<<
as_double
(
cit
)
<<
") | "
;
cout
<<
endl
;
}
db
.
close
();
}
catch
(
const
Exception
&
ex
)
{
cerr
<<
"(test): "
<<
ex
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
cerr
<<
"(test): "
<<
ex
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(test): catch ..."
<<
endl
;
}
return
0
;
}
extensions/LogicProcessor/PassiveLProcessor.cc
View file @
9356415b
...
...
@@ -26,7 +26,8 @@ PassiveLProcessor::PassiveLProcessor( UniSetTypes::ObjectId objId,
UniXML
::
iterator
it
(
confnode
);
confnode
=
conf
->
getNode
(
myname
);
string
lfile
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-schema"
,
it
.
getProp
(
"schema"
));
string
lfile
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-schema"
,
it
.
getProp
(
"schema"
));
if
(
lfile
.
empty
()
)
{
ostringstream
err
;
...
...
extensions/LogicProcessor/PassiveLProcessor.h
View file @
9356415b
...
...
@@ -30,7 +30,7 @@ class PassiveLProcessor:
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
,
UniSetTypes
::
ObjectId
shmID
,
const
std
::
shared_ptr
<
SharedMemory
>
ic
=
nullptr
,
const
std
::
string
&
prefix
=
"plproc"
);
protected
:
...
...
extensions/LogicProcessor/plogicproc.cc
View file @
9356415b
...
...
@@ -60,7 +60,7 @@ int main(int argc, const char** argv)
return
1
;
}
auto
plp
=
PassiveLProcessor
::
init_plproc
(
argc
,
argv
,
shmID
);
auto
plp
=
PassiveLProcessor
::
init_plproc
(
argc
,
argv
,
shmID
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
plp
);
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
9356415b
...
...
@@ -1285,7 +1285,7 @@ ModbusRTU::mbErrCode MBSlave::real_write_it( IOMap::iterator& it, ModbusRTU::Mod
if
(
p
->
bitreg
)
return
real_bitreg_write_it
(
p
->
bitreg
,
dat
[
i
++
]);
return
real_write_prop
(
p
,
dat
,
i
,
count
);
return
real_write_prop
(
p
,
dat
,
i
,
count
);
}
// -------------------------------------------------------------------------
ModbusRTU
::
mbErrCode
MBSlave
::
real_bitreg_write_it
(
std
::
shared_ptr
<
BitRegProperty
>&
bp
,
const
ModbusRTU
::
ModbusData
val
)
...
...
@@ -1302,13 +1302,13 @@ ModbusRTU::mbErrCode MBSlave::real_bitreg_write_it( std::shared_ptr<BitRegProper
if
(
p
->
si
.
id
==
DefaultObjectId
)
continue
;
ModbusRTU
::
ModbusData
dat
[]
=
{
d
[
i
]};
ModbusRTU
::
ModbusData
dat
[]
=
{
d
[
i
]};
dinfo
<<
myname
<<
"(real_bitreg_write_it): set "
<<
ModbusRTU
::
dat2str
(
bp
->
mbreg
)
<<
"("
<<
(
int
)
bp
->
mbreg
<<
")"
<<
" bit["
<<
i
<<
"]="
<<
(
int
)
dat
[
0
]
<<
" sid="
<<
p
->
si
.
id
<<
endl
;
<<
" bit["
<<
i
<<
"]="
<<
(
int
)
dat
[
0
]
<<
" sid="
<<
p
->
si
.
id
<<
endl
;
int
k
=
0
;
real_write_prop
(
p
,
dat
,
k
,
1
);
int
k
=
0
;
real_write_prop
(
p
,
dat
,
k
,
1
);
}
return
ModbusRTU
::
erNoError
;
...
...
@@ -1317,6 +1317,7 @@ ModbusRTU::mbErrCode MBSlave::real_bitreg_write_it( std::shared_ptr<BitRegProper
ModbusRTU
::
mbErrCode
MBSlave
::
real_write_prop
(
IOProperty
*
p
,
ModbusRTU
::
ModbusData
*
dat
,
int
&
i
,
int
count
)
{
ModbusRTU
::
ModbusData
mbval
=
dat
[
i
++
];
try
{
if
(
p
->
amode
==
MBSlave
::
amRO
)
...
...
extensions/ModbusSlave/tests/test_mbslave.cc
View file @
9356415b
...
...
@@ -979,14 +979,14 @@ TEST_CASE("Write(0x06,0x10): nbit", "[modbus][mbslave][mbtcpslave][writenbit]")
SECTION
(
"Test: write06"
)
{
ModbusRTU
::
WriteSingleOutputRetMessage
ret
=
mb
->
write06
(
slaveaddr
,
tREG
,
3
);
ModbusRTU
::
WriteSingleOutputRetMessage
ret
=
mb
->
write06
(
slaveaddr
,
tREG
,
3
);
REQUIRE
(
ret
.
start
==
tREG
);
REQUIRE
(
ret
.
data
==
3
);
REQUIRE
(
ui
->
getValue
(
2020
)
==
1
);
REQUIRE
(
ui
->
getValue
(
2021
)
==
1
);
REQUIRE
(
ui
->
getValue
(
2022
)
==
0
);
ret
=
mb
->
write06
(
slaveaddr
,
tREG
,
0
);
ret
=
mb
->
write06
(
slaveaddr
,
tREG
,
0
);
REQUIRE
(
ret
.
start
==
tREG
);
REQUIRE
(
ret
.
data
==
0
);
REQUIRE
(
ui
->
getValue
(
2020
)
==
0
);
...
...
extensions/SharedMemory/SharedMemory.cc
View file @
9356415b
...
...
@@ -243,7 +243,7 @@ bool SharedMemory::activateObject()
res
=
IONotifyController_LT
::
activateObject
();
// инициализируем указатели
for
(
auto
&&
it
:
hlist
)
for
(
auto
&&
it
:
hlist
)
{
it
.
a_it
=
myioEnd
();
it
.
d_it
=
myioEnd
();
...
...
@@ -253,7 +253,7 @@ bool SharedMemory::activateObject()
for
(
auto
&
it
:
hist
)
{
for
(
auto
&&
hit
:
it
.
hlst
)
for
(
auto
&&
hit
:
it
.
hlst
)
hit
.
ioit
=
myioEnd
();
}
...
...
extensions/SharedMemory/tests/test_sm.cc
View file @
9356415b
...
...
@@ -37,13 +37,13 @@ TEST_CASE("[SM]: get/set", "[sm][getset]")
{
InitTest
();
ui
->
setValue
(
500
,
30
);
ui
->
setValue
(
500
,
30
);
CHECK
(
ui
->
getValue
(
500
)
==
30
);
ui
->
setValue
(
500
,
-
30
);
ui
->
setValue
(
500
,
-
30
);
CHECK
(
ui
->
getValue
(
500
)
==
-
30
);
ui
->
setValue
(
500
,
0
);
ui
->
setValue
(
500
,
0
);
CHECK
(
ui
->
getValue
(
500
)
==
0
);
}
// -----------------------------------------------------------------------------
...
...
@@ -51,19 +51,20 @@ TEST_CASE("[SM]: threshold", "[sm][threshold]")
{
InitTest
();
ui
->
setValue
(
503
,
30
);
ui
->
setValue
(
503
,
30
);
CHECK
(
ui
->
getValue
(
504
)
==
0
);
ui
->
setValue
(
503
,
400
);
ui
->
setValue
(
503
,
400
);
CHECK
(
ui
->
getValue
(
504
)
==
1
);
ui
->
setValue
(
503
,
25
);
ui
->
setValue
(
503
,
25
);
CHECK
(
ui
->
getValue
(
504
)
==
0
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[SM]: pulsar"
,
"[sm][pulsar]"
)
{
InitTest
();
while
(
ui
->
getValue
(
505
)
)
msleep
(
50
);
...
...
@@ -81,13 +82,13 @@ TEST_CASE("[SM]: heartbeat", "[sm][heartbeat]")
InitTest
();
CHECK_FALSE
(
ui
->
getValue
(
507
)
);
ui
->
setValue
(
506
,
2
);
ui
->
setValue
(
506
,
2
);
msleep
(
500
);
CHECK
(
ui
->
getValue
(
507
)
);
msleep
(
2000
);
CHECK_FALSE
(
ui
->
getValue
(
507
)
);
ui
->
setValue
(
506
,
4
);
ui
->
setValue
(
506
,
4
);
msleep
(
2000
);
CHECK
(
ui
->
getValue
(
507
)
);
}
...
...
include/TCPCheck.h
View file @
9356415b
...
...
@@ -35,7 +35,7 @@ class TCPCheck
* \note Вызывается через system()! Это может быть опасно с точки зрения безопасности..
* \todo Возможно стоит написать свою реализацию ping
*/
bool
ping
(
const
std
::
string
&
_ip
,
timeout_t
tout
=
1000
,
timeout_t
sleep_msec
=
200
,
const
std
::
string
&
ping_argc
=
"-c 1 -w 0.1 -q -n"
);
bool
ping
(
const
std
::
string
&
_ip
,
timeout_t
tout
=
1000
,
timeout_t
sleep_msec
=
200
,
const
std
::
string
&
ping_argc
=
"-c 1 -w 0.1 -q -n"
);
protected
:
...
...
@@ -52,7 +52,7 @@ class TCPCheck
int
port
=
{
0
};
int
tout_msec
;
std
::
string
ping_args
=
{
"-c 1 -w 0.1 -q -n"
};
std
::
string
ping_args
=
{
"-c 1 -w 0.1 -q -n"
};
};
// -----------------------------------------------------------------------------
#endif // _TCPCheck_H_
...
...
src/Communications/TCP/TCPCheck.cc
View file @
9356415b
...
...
@@ -54,6 +54,7 @@ bool TCPCheck::check( const std::string& _ip, int _port, timeout_t tout, timeout
void
TCPCheck
::
check_thread
()
{
setResult
(
false
);
try
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
...
...
@@ -98,6 +99,6 @@ void TCPCheck::ping_thread()
int
ret
=
system
(
cmd
.
str
().
c_str
());
int
res
=
WEXITSTATUS
(
ret
);
setResult
((
res
==
0
));
setResult
((
res
==
0
));
}
// -----------------------------------------------------------------------------
tests/test_tcpcheck.cc
View file @
9356415b
...
...
@@ -33,7 +33,7 @@ class TSRunner
TSRunner
()
{
cancel
=
false
;
res
=
std
::
async
(
std
::
launch
::
async
,
run_test_server
);
res
=
std
::
async
(
std
::
launch
::
async
,
run_test_server
);
}
~
TSRunner
()
...
...
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