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
4e043d01
Commit
4e043d01
authored
Nov 12, 2009
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new extensions SMDBServer
parent
52a32cdd
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
402 additions
and
3 deletions
+402
-3
DBServer_MySQL.h
Utilities/DBServer-MySQL/DBServer_MySQL.h
+1
-1
Makefile.am
Utilities/DBServer-MySQL/Makefile.am
+1
-0
configure.ac
configure.ac
+2
-0
Makefile.am
extensions/Makefile.am
+1
-1
libUniSetRTU.pc.in
extensions/RTUExchange/libUniSetRTU.pc.in
+1
-1
Makefile.am
extensions/SMDBServer/Makefile.am
+34
-0
SMDBServer.cc
extensions/SMDBServer/SMDBServer.cc
+204
-0
SMDBServer.h
extensions/SMDBServer/SMDBServer.h
+49
-0
create_links.sh
extensions/SMDBServer/create_links.sh
+7
-0
libUniSetSMDBServer.pc.in
extensions/SMDBServer/libUniSetSMDBServer.pc.in
+11
-0
main.cc
extensions/SMDBServer/main.cc
+85
-0
start_fg.sh
extensions/SMDBServer/start_fg.sh
+6
-0
No files found.
Utilities/DBServer-MySQL/DBServer_MySQL.h
View file @
4e043d01
...
...
@@ -155,7 +155,7 @@ class DBServer_MySQL:
virtual
void
parse
(
UniSetTypes
::
DBMessage
*
dbmsg
);
virtual
void
parse
(
UniSetTypes
::
InfoMessage
*
imsg
);
virtual
void
parse
(
UniSetTypes
::
AlarmMessage
*
amsg
);
virtual
void
parse
(
UniSetTypes
::
ConfirmMessage
*
cmsg
);
virtual
void
parse
(
UniSetTypes
::
ConfirmMessage
*
cmsg
);
bool
writeToBase
(
const
string
&
query
);
...
...
Utilities/DBServer-MySQL/Makefile.am
View file @
4e043d01
...
...
@@ -16,3 +16,4 @@ include $(top_builddir)/conf/setting.mk
# install
devel_include_HEADERS
=
*
.h
devel_includedir
=
$(includedir)
/@PACKAGE@/mysql
configure.ac
View file @
4e043d01
...
...
@@ -205,6 +205,8 @@ AC_CONFIG_FILES([Makefile
extensions/SMViewer/Makefile
extensions/UniNetwork/Makefile
extensions/UniNetwork/libUniSetNetwork.pc
extensions/SMDBServer/Makefile
extensions/SMDBServer/libUniSetSMDBServer.pc
extensions/SharedMemory/Makefile
extensions/SharedMemory/libUniSetSharedMemory.pc
extensions/SharedMemoryPlus/Makefile])
...
...
extensions/Makefile.am
View file @
4e043d01
...
...
@@ -4,7 +4,7 @@
if
HAVE_EXTENTIONS
SUBDIRS
=
lib include SharedMemory IOControl RTUExchange LogicProcessor
\
ModbusSlave MBTCPMaster SMViewer UniNetwork
ModbusSlave MBTCPMaster SMViewer UniNetwork
SMDBServer
#SharedMemoryPlus
#UDPExchange
...
...
extensions/RTUExchange/libUniSetRTU.pc.in
View file @
4e043d01
...
...
@@ -4,7 +4,7 @@ libdir=@libdir@
includedir=@includedir@
Name: libUniSetRTU
Description: Support library for UniSet
IOControl
Description: Support library for UniSet
RTUExchange
Requires: libUniSetExtensions
Version: @VERSION@
Libs: -L${libdir} -lUniSetRTU
...
...
extensions/SMDBServer/Makefile.am
0 → 100644
View file @
4e043d01
bin_PROGRAMS
=
@PACKAGE@-smdbserver
lib_LTLIBRARIES
=
libUniSetSMDBServer.la
libUniSetSMDBServer_la_LIBADD
=
$(top_builddir)
/lib/libUniSet.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSetSharedMemory.la
\
$(top_builddir)
/extensions/lib/libUniSetExtensions.la
\
$(top_builddir)
/Utilities/DBServer-MySQL/libUniSet-mysql.la
\
$(SIGC_LIBS)
libUniSetSMDBServer_la_CXXFLAGS
=
-I
$(top_builddir)
/extensions/include
\
-I
$(top_builddir)
/extensions/SharedMemory
\
-I
$(top_builddir)
/Utilities/DBServer-MySQL
\
$(SIGC_CFLAGS)
libUniSetSMDBServer_la_SOURCES
=
SMDBServer.cc
@PACKAGE@
_smdbserver_SOURCES
=
main.cc
@PACKAGE@
_smdbserver_LDADD
=
libUniSetSMDBServer.la
$(top_builddir)
/lib/libUniSet.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSetSharedMemory.la
\
$(top_builddir)
/extensions/lib/libUniSetExtensions.la
\
$(top_builddir)
/Utilities/DBServer-MySQL/libUniSet-mysql.la
\
$(SIGC_LIBS)
@PACKAGE@
_smdbserver_CXXFLAGS
=
-I
$(top_builddir)
/extensions/include
\
-I
$(top_builddir)
/extensions/SharedMemory
\
-I
$(top_builddir)
/Utilities/DBServer-MySQL
\
$(SIGC_CFLAGS)
# install
devel_include_HEADERS
=
*
.h
devel_includedir
=
$(pkgincludedir)
/extensions
pkgconfigdir
=
$(libdir)
/pkgconfig
pkgconfig_DATA
=
libUniSetSMDBServer.pc
all-local
:
ln
-sf
../SMDBServer/
$(devel_include_HEADERS)
../include
extensions/SMDBServer/SMDBServer.cc
0 → 100644
View file @
4e043d01
// -----------------------------------------------------------------------------
#include <cmath>
#include <sstream>
#include <Exceptions.h>
#include <extensions/Extensions.h>
#include "SMDBServer.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetExtensions
;
// -----------------------------------------------------------------------------
SMDBServer
::
SMDBServer
(
UniSetTypes
::
ObjectId
objId
,
UniSetTypes
::
ObjectId
shmId
,
SharedMemory
*
ic
,
const
string
prefix
)
:
DBServer_MySQL
(
objId
),
prefix
(
prefix
)
{
if
(
objId
==
DefaultObjectId
)
throw
UniSetTypes
::
SystemError
(
"(SMDBServer): objId=-1?!! Use --"
+
prefix
+
"-name"
);
// xmlNode* cnode = conf->getNode(myname);
// if( cnode == NULL )
// throw UniSetTypes::SystemError("(SMDBServer): Not found conf-node for " + myname );
xmlNode
*
cnode
=
conf
->
getNode
(
"LocalDBServer"
);
if
(
!
cnode
)
throw
NameNotFound
(
string
(
myname
+
"(init): <LocalDBServer> not found.."
));
shm
=
new
SMInterface
(
shmId
,
&
ui
,
objId
,
ic
);
UniXML_iterator
it
(
cnode
);
db_locale
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-locale"
,
it
.
getProp
(
"locale"
));
if
(
db_locale
.
empty
()
)
db_locale
=
"koi8-r"
;
// ********** HEARTBEAT *************
string
heart
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-heartbeat-id"
,
it
.
getProp
(
"heartbeat_id"
));
if
(
!
heart
.
empty
()
)
{
sidHeartBeat
=
conf
->
getSensorID
(
heart
);
if
(
sidHeartBeat
==
DefaultObjectId
)
{
ostringstream
err
;
err
<<
myname
<<
": ID not found ('HeartBeat') for "
<<
heart
;
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(init): "
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
}
int
heartbeatTime
=
getHeartBeatTime
();
if
(
heartbeatTime
)
ptHeartBeat
.
setTiming
(
heartbeatTime
);
else
ptHeartBeat
.
setTiming
(
UniSetTimer
::
WaitUpTime
);
maxHeartBeat
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"-heartbeat-max"
,
it
.
getProp
(
"heartbeat_max"
),
10
);
test_id
=
sidHeartBeat
;
}
else
{
test_id
=
conf
->
getSensorID
(
"TestMode_S"
);
if
(
test_id
==
DefaultObjectId
)
{
ostringstream
err
;
err
<<
myname
<<
"(init): test_id unknown. 'TestMode_S' not found..."
;
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(init): "
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
}
}
dlog
[
Debug
::
INFO
]
<<
myname
<<
"(init): test_id="
<<
test_id
<<
endl
;
}
// -----------------------------------------------------------------------------
SMDBServer
::~
SMDBServer
()
{
delete
shm
;
}
// -----------------------------------------------------------------------------
void
SMDBServer
::
waitSMReady
()
{
// waiting for SM is ready...
int
ready_timeout
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-sm-ready-timeout"
,
"15000"
);
if
(
ready_timeout
==
0
)
ready_timeout
=
15000
;
else
if
(
ready_timeout
<
0
)
ready_timeout
=
UniSetTimer
::
WaitUpTime
;
if
(
!
shm
->
waitSMready
(
ready_timeout
,
50
)
)
{
ostringstream
err
;
err
<<
myname
<<
"(waitSMReady): Wait SharedMemory failed. [ "
<<
ready_timeout
<<
" msec ]"
;
dlog
[
Debug
::
CRIT
]
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
}
}
// -----------------------------------------------------------------------------
void
SMDBServer
::
step
()
{
// DBServer_MySQL::step();
if
(
sidHeartBeat
!=
DefaultObjectId
&&
ptHeartBeat
.
checkTime
()
)
{
try
{
shm
->
localSaveValue
(
aitHeartBeat
,
sidHeartBeat
,
maxHeartBeat
,
getId
());
ptHeartBeat
.
reset
();
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(step): (hb) "
<<
ex
<<
std
::
endl
;
}
}
}
//--------------------------------------------------------------------------------
void
SMDBServer
::
initDB
(
DBInterface
*
db
)
{
{
std
::
ostringstream
q
;
q
<<
"SET NAMES "
<<
db_locale
;
db
->
query
(
q
.
str
());
}
{
std
::
ostringstream
q
;
q
<<
"SET CHARACTER SET "
<<
db_locale
;
db
->
query
(
q
.
str
());
}
try
{
xmlNode
*
snode
=
conf
->
getXMLSensorsSection
();
if
(
!
snode
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
": section <sensors> not found.."
<<
endl
;
return
;
}
UniXML_iterator
it
(
snode
);
if
(
!
it
.
goChildren
()
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
": section <sensors> empty?!.."
<<
endl
;
return
;
}
for
(;
it
.
getCurrent
();
it
.
goNext
()
)
{
// ??. DBTABLE ObjectsMap
std
::
ostringstream
data
;
data
<<
" VALUES('"
;
// ???? ???????
data
<<
it
.
getProp
(
"textname"
)
<<
"','"
;
// name
data
<<
it
.
getProp
(
"name"
)
<<
"','"
;
// rep_name
data
<<
it
.
getProp
(
"id"
)
<<
"','"
;
// id (sensorid)
data
<<
it
.
getIntProp
(
"msg"
)
<<
"')"
;
// msg [0:1]
if
(
!
writeToBase
(
"INSERT IGNORE INTO ObjectsMap(name,rep_name,id,msg)"
+
data
.
str
())
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(insert) ObjectsMap msg error: "
<<
db
->
error
()
<<
std
::
endl
;
db
->
freeResult
();
}
}
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(filling ObjectsMap): "
<<
ex
<<
std
::
endl
;
}
catch
(
...
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(filling ObjectsMap): catch ..."
<<
std
::
endl
;
}
}
//--------------------------------------------------------------------------------
void
SMDBServer
::
help_print
(
int
argc
,
const
char
*
const
*
argv
)
{
cout
<<
"--dbserver-name - ID for dbserver. Default: SMDBServer1. "
<<
endl
;
cout
<<
"--dbserver-locale name - DB locale. Default: koi8-r. "
<<
endl
;
cout
<<
"--dbserver-heartbeat-id name - ID for heartbeat sensor."
<<
endl
;
cout
<<
"--dbserver-heartbeat-max val - max value for heartbeat sensor."
<<
endl
;
}
// -----------------------------------------------------------------------------
SMDBServer
*
SMDBServer
::
init_smdbserver
(
int
argc
,
const
char
*
const
*
argv
,
UniSetTypes
::
ObjectId
icID
,
SharedMemory
*
ic
,
const
std
::
string
prefix
)
{
string
name
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-name"
,
"DBServer"
);
if
(
name
.
empty
()
)
{
cerr
<<
"(SMDBServer): Unknown name'"
<<
endl
;
return
0
;
}
ObjectId
ID
=
conf
->
getServiceID
(
name
);
if
(
ID
==
UniSetTypes
::
DefaultObjectId
)
{
cerr
<<
"(SMDBServer): Not found ID for '"
<<
name
<<
" in '"
<<
conf
->
getServicesSection
()
<<
"' section"
<<
endl
;
return
0
;
}
dlog
[
Debug
::
INFO
]
<<
"(SMDBServer): name = "
<<
name
<<
"("
<<
ID
<<
")"
<<
endl
;
return
new
SMDBServer
(
ID
,
icID
,
ic
,
prefix
);
}
// -----------------------------------------------------------------------------
extensions/SMDBServer/SMDBServer.h
0 → 100644
View file @
4e043d01
#ifndef _SMDBServer_H_
#define _SMDBServer_H_
// -----------------------------------------------------------------------------
#include "DBServer_MySQL.h"
#include "SMInterface.h"
#include "SharedMemory.h"
// -----------------------------------------------------------------------------
/*!
*/
class
SMDBServer
:
public
DBServer_MySQL
{
public
:
SMDBServer
(
UniSetTypes
::
ObjectId
objId
,
UniSetTypes
::
ObjectId
shmID
,
SharedMemory
*
ic
=
0
,
const
std
::
string
prefix
=
"dbserver"
);
virtual
~
SMDBServer
();
/*! */
static
SMDBServer
*
init_smdbserver
(
int
argc
,
const
char
*
const
*
argv
,
UniSetTypes
::
ObjectId
shmID
,
SharedMemory
*
ic
=
0
,
const
std
::
string
prefix
=
"dbserver"
);
/*! help- */
static
void
help_print
(
int
argc
,
const
char
*
const
*
argv
);
protected
:
SMDBServer
();
virtual
void
initDB
(
DBInterface
*
db
);
void
waitSMReady
();
void
step
();
SMInterface
*
shm
;
private
:
bool
aiignore
;
PassiveTimer
ptHeartBeat
;
UniSetTypes
::
ObjectId
sidHeartBeat
;
int
maxHeartBeat
;
IOController
::
AIOStateList
::
iterator
aitHeartBeat
;
UniSetTypes
::
ObjectId
test_id
;
std
::
string
db_locale
;
std
::
string
prefix
;
};
// -----------------------------------------------------------------------------
#endif // _SMDBServer_H_
// -----------------------------------------------------------------------------
extensions/SMDBServer/create_links.sh
0 → 100755
View file @
4e043d01
#!/bin/sh
ln
-s
-f
../../Utilities/scripts/uniset-start.sh
ln
-s
-f
../../Utilities/scripts/uniset-stop.sh stop.sh
ln
-s
-f
../../Utilities/scripts/uniset-functions.sh
ln
-s
-f
../../conf/test.xml test.xml
extensions/SMDBServer/libUniSetSMDBServer.pc.in
0 → 100644
View file @
4e043d01
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libUniSetSMDBServer
Description: Support library for UniSetSMDBServer
Requires: libUniSetExtensions
Version: @VERSION@
Libs: -L${libdir} -lUniSetSMDBServer
Cflags: -I${includedir}/uniset
extensions/SMDBServer/main.cc
0 → 100644
View file @
4e043d01
// $Id: rsexchange.cc,v 1.2 2008/06/06 11:03:32 pv Exp $
// -----------------------------------------------------------------------------
#include <sstream>
#include "SMDBServer.h"
#include "Configuration.h"
#include "Debug.h"
#include "ObjectsActivator.h"
#include "Extensions.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetExtensions
;
// -----------------------------------------------------------------------------
int
main
(
int
argc
,
const
char
**
argv
)
{
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
<<
"--smdbserver-logfile filename - logfilename. Default: smdbserver.log"
<<
endl
;
cout
<<
endl
;
SMDBServer
::
help_print
(
argc
,
argv
);
return
0
;
}
try
{
string
confile
=
UniSetTypes
::
getArgParam
(
"--confile"
,
argc
,
argv
,
"configure.xml"
);
conf
=
new
Configuration
(
argc
,
argv
,
confile
);
string
logfilename
(
conf
->
getArgParam
(
"--smdbserver-logfile"
));
if
(
logfilename
.
empty
()
)
logfilename
=
"smdbserver.log"
;
conf
->
initDebug
(
dlog
,
"dlog"
);
std
::
ostringstream
logname
;
string
dir
(
conf
->
getLogDir
());
logname
<<
dir
<<
logfilename
;
unideb
.
logFile
(
logname
.
str
()
);
dlog
.
logFile
(
logname
.
str
()
);
ObjectId
shmID
=
DefaultObjectId
;
string
sID
=
conf
->
getArgParam
(
"--smemory-id"
);
if
(
!
sID
.
empty
()
)
shmID
=
conf
->
getControllerID
(
sID
);
else
shmID
=
getSharedMemoryID
();
if
(
shmID
==
DefaultObjectId
)
{
cerr
<<
sID
<<
"? SharedMemoryID not found in "
<<
conf
->
getControllersSection
()
<<
" section"
<<
endl
;
return
1
;
}
SMDBServer
*
db
=
SMDBServer
::
init_smdbserver
(
argc
,
argv
,
shmID
);
if
(
!
db
)
{
dlog
[
Debug
::
CRIT
]
<<
"(smdbserver): init ۣ..."
<<
endl
;
return
1
;
}
ObjectsActivator
act
;
act
.
addObject
(
static_cast
<
class
UniSetObject
*>
(
db
));
SystemMessage
sm
(
SystemMessage
::
StartUp
);
act
.
broadcast
(
sm
.
transport_msg
()
);
unideb
(
Debug
::
ANY
)
<<
"
\n\n\n
"
;
unideb
[
Debug
::
ANY
]
<<
"(main): -------------- SMDBServer START -------------------------
\n\n
"
;
dlog
(
Debug
::
ANY
)
<<
"
\n\n\n
"
;
dlog
[
Debug
::
ANY
]
<<
"(main): -------------- SMDBServer START -------------------------
\n\n
"
;
act
.
run
(
false
);
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
"(smdbserver): "
<<
ex
<<
std
::
endl
;
}
catch
(...)
{
dlog
[
Debug
::
CRIT
]
<<
"(smdbserver): catch ..."
<<
std
::
endl
;
}
return
0
;
}
extensions/SMDBServer/start_fg.sh
0 → 100755
View file @
4e043d01
#!/bin/sh
uniset-start.sh
-f
./uniset-smdbserver
--confile
test.xml
\
--dbserver-name
DBServer
\
--dlog-add-levels
info,crit,warn
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