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
441cda1b
Commit
441cda1b
authored
Mar 16, 2021
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[uwebsocketgate]: supported "work with SM"
parent
9f246b4b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
12 deletions
+53
-12
Makefile.am
extensions/UWebSocketGate/Makefile.am
+5
-1
UWebSocketGate.cc
extensions/UWebSocketGate/UWebSocketGate.cc
+18
-6
UWebSocketGate.h
extensions/UWebSocketGate/UWebSocketGate.h
+13
-3
main.cc
extensions/UWebSocketGate/main.cc
+16
-1
tests_with_sm.cc
extensions/UWebSocketGate/tests/tests_with_sm.cc
+1
-1
No files found.
extensions/UWebSocketGate/Makefile.am
View file @
441cda1b
if
ENABLE_REST_API
if
ENABLE_REST_API
bin_PROGRAMS
=
@PACKAGE@-wsgate
bin_PROGRAMS
=
@PACKAGE@-wsgate
@PACKAGE@
_wsgate_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
@PACKAGE@
_wsgate_CXXFLAGS
=
-I
$(top_builddir)
/extensions/include
-I
$(top_builddir)
/extensions/SharedMemory
$(SIGC_CFLAGS)
$(POCO_CFLAGS)
@PACKAGE@
_wsgate_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
\
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(SIGC_LIBS)
$(POCO_LIBS)
@PACKAGE@
_wsgate_SOURCES
=
UWebSocketGate.cc main.cc
@PACKAGE@
_wsgate_SOURCES
=
UWebSocketGate.cc main.cc
include
$(top_builddir)/include.mk
include
$(top_builddir)/include.mk
...
...
extensions/UWebSocketGate/UWebSocketGate.cc
View file @
441cda1b
...
@@ -39,7 +39,11 @@
...
@@ -39,7 +39,11 @@
using
namespace
uniset
;
using
namespace
uniset
;
using
namespace
std
;
using
namespace
std
;
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
UWebSocketGate
::
UWebSocketGate
(
uniset
::
ObjectId
id
,
xmlNode
*
cnode
,
const
string
&
prefix
)
:
UWebSocketGate
::
UWebSocketGate
(
uniset
::
ObjectId
id
,
xmlNode
*
cnode
,
uniset
::
ObjectId
shmID
,
const
std
::
shared_ptr
<
SharedMemory
>&
ic
,
const
string
&
prefix
)
:
UniSetObject
(
id
)
UniSetObject
(
id
)
{
{
offThread
();
// отключаем поток обработки, потому-что будем обрабатывать сами
offThread
();
// отключаем поток обработки, потому-что будем обрабатывать сами
...
@@ -56,6 +60,11 @@ UWebSocketGate::UWebSocketGate( uniset::ObjectId id, xmlNode* cnode, const strin
...
@@ -56,6 +60,11 @@ UWebSocketGate::UWebSocketGate( uniset::ObjectId id, xmlNode* cnode, const strin
UniXML
::
iterator
it
(
cnode
);
UniXML
::
iterator
it
(
cnode
);
int
maxCacheSize
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"max-ui-cache-size"
,
it
.
getProp
(
"msgUIChacheSize"
),
5000
);
ui
->
setCacheMaxSize
(
maxCacheSize
);
shm
=
make_shared
<
SMInterface
>
(
shmID
,
ui
,
getId
(),
ic
);
maxwsocks
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"ws-max"
,
it
.
getProp
(
"wsMax"
),
maxwsocks
);
maxwsocks
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"ws-max"
,
it
.
getProp
(
"wsMax"
),
maxwsocks
);
wscmd
=
make_shared
<
ev
::
async
>
();
wscmd
=
make_shared
<
ev
::
async
>
();
...
@@ -253,7 +262,10 @@ Poco::JSON::Object::Ptr UWebSocketGate::error_to_json( const std::string& err )
...
@@ -253,7 +262,10 @@ Poco::JSON::Object::Ptr UWebSocketGate::error_to_json( const std::string& err )
return
json
;
return
json
;
}
}
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
std
::
shared_ptr
<
UWebSocketGate
>
UWebSocketGate
::
init_wsgate
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
prefix
)
std
::
shared_ptr
<
UWebSocketGate
>
UWebSocketGate
::
init_wsgate
(
int
argc
,
const
char
*
const
*
argv
,
uniset
::
ObjectId
shmID
,
const
std
::
shared_ptr
<
SharedMemory
>&
ic
,
const
std
::
string
&
prefix
)
{
{
string
name
=
uniset
::
getArgParam
(
"--"
+
prefix
+
"name"
,
argc
,
argv
,
"UWebSocketGate"
);
string
name
=
uniset
::
getArgParam
(
"--"
+
prefix
+
"name"
,
argc
,
argv
,
"UWebSocketGate"
);
...
@@ -263,7 +275,7 @@ std::shared_ptr<UWebSocketGate> UWebSocketGate::init_wsgate( int argc, const cha
...
@@ -263,7 +275,7 @@ std::shared_ptr<UWebSocketGate> UWebSocketGate::init_wsgate( int argc, const cha
return
nullptr
;
return
nullptr
;
}
}
return
uniset
::
make_object
<
UWebSocketGate
>
(
name
,
"UWebSocketGate"
,
prefix
);
return
uniset
::
make_object
<
UWebSocketGate
>
(
name
,
"UWebSocketGate"
,
shmID
,
ic
,
prefix
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
UWebSocketGate
::
help_print
()
void
UWebSocketGate
::
help_print
()
...
@@ -341,7 +353,7 @@ void UWebSocketGate::onActivate( ev::async& watcher, int revents )
...
@@ -341,7 +353,7 @@ void UWebSocketGate::onActivate( ev::async& watcher, int revents )
if
(
!
s
->
isActive
()
)
if
(
!
s
->
isActive
()
)
{
{
s
->
set
(
loop
,
wscmd
);
s
->
set
(
loop
,
wscmd
);
s
->
doCommand
(
ui
);
s
->
doCommand
(
shm
);
}
}
}
}
}
}
...
@@ -357,7 +369,7 @@ void UWebSocketGate::onCommand( ev::async& watcher, int revents )
...
@@ -357,7 +369,7 @@ void UWebSocketGate::onCommand( ev::async& watcher, int revents )
uniset_rwmutex_rlock
lk
(
wsocksMutex
);
uniset_rwmutex_rlock
lk
(
wsocksMutex
);
for
(
const
auto
&
s
:
wsocks
)
for
(
const
auto
&
s
:
wsocks
)
s
->
doCommand
(
ui
);
s
->
doCommand
(
shm
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
#ifndef DISABLE_REST_API
...
@@ -914,7 +926,7 @@ void UWebSocketGate::UWebSocket::sensorInfo( const uniset::SensorMessage* sm )
...
@@ -914,7 +926,7 @@ void UWebSocketGate::UWebSocket::sensorInfo( const uniset::SensorMessage* sm )
ioping
.
stop
();
ioping
.
stop
();
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
UWebSocketGate
::
UWebSocket
::
doCommand
(
const
std
::
shared_ptr
<
U
Interface
>&
ui
)
void
UWebSocketGate
::
UWebSocket
::
doCommand
(
const
std
::
shared_ptr
<
SM
Interface
>&
ui
)
{
{
if
(
qcmd
.
empty
()
)
if
(
qcmd
.
empty
()
)
return
;
return
;
...
...
extensions/UWebSocketGate/UWebSocketGate.h
View file @
441cda1b
...
@@ -34,6 +34,8 @@
...
@@ -34,6 +34,8 @@
#include "LogAgregator.h"
#include "LogAgregator.h"
#include "UniSetObject.h"
#include "UniSetObject.h"
#include "DebugStream.h"
#include "DebugStream.h"
#include "SharedMemory.h"
#include "SMInterface.h"
#include "EventLoopServer.h"
#include "EventLoopServer.h"
#include "UTCPStream.h"
#include "UTCPStream.h"
#include "UHttpRequestHandler.h"
#include "UHttpRequestHandler.h"
...
@@ -189,11 +191,18 @@ namespace uniset
...
@@ -189,11 +191,18 @@ namespace uniset
#endif
#endif
{
{
public
:
public
:
UWebSocketGate
(
uniset
::
ObjectId
id
,
xmlNode
*
cnode
,
const
std
::
string
&
prefix
);
UWebSocketGate
(
uniset
::
ObjectId
id
,
xmlNode
*
cnode
,
uniset
::
ObjectId
shmID
,
const
std
::
shared_ptr
<
SharedMemory
>&
ic
=
nullptr
,
const
std
::
string
&
prefix
=
"-ws"
);
virtual
~
UWebSocketGate
();
virtual
~
UWebSocketGate
();
/*! глобальная функция для инициализации объекта */
/*! глобальная функция для инициализации объекта */
static
std
::
shared_ptr
<
UWebSocketGate
>
init_wsgate
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
prefix
=
"logdb-"
);
static
std
::
shared_ptr
<
UWebSocketGate
>
init_wsgate
(
int
argc
,
const
char
*
const
*
argv
,
uniset
::
ObjectId
shmID
,
const
std
::
shared_ptr
<
SharedMemory
>&
ic
=
nullptr
,
const
std
::
string
&
prefix
=
"ws-"
);
/*! глобальная функция для вывода help-а */
/*! глобальная функция для вывода help-а */
static
void
help_print
();
static
void
help_print
();
...
@@ -247,6 +256,7 @@ namespace uniset
...
@@ -247,6 +256,7 @@ namespace uniset
int
maxMessagesProcessing
=
{
100
};
int
maxMessagesProcessing
=
{
100
};
std
::
shared_ptr
<
DebugStream
>
mylog
;
std
::
shared_ptr
<
DebugStream
>
mylog
;
std
::
shared_ptr
<
SMInterface
>
shm
;
#ifndef DISABLE_REST_API
#ifndef DISABLE_REST_API
std
::
shared_ptr
<
Poco
::
Net
::
HTTPServer
>
httpserv
;
std
::
shared_ptr
<
Poco
::
Net
::
HTTPServer
>
httpserv
;
...
@@ -301,7 +311,7 @@ namespace uniset
...
@@ -301,7 +311,7 @@ namespace uniset
void
get
(
uniset
::
ObjectId
id
);
void
get
(
uniset
::
ObjectId
id
);
void
set
(
uniset
::
ObjectId
id
,
long
value
);
void
set
(
uniset
::
ObjectId
id
,
long
value
);
void
sensorInfo
(
const
uniset
::
SensorMessage
*
sm
);
void
sensorInfo
(
const
uniset
::
SensorMessage
*
sm
);
void
doCommand
(
const
std
::
shared_ptr
<
U
Interface
>&
ui
);
void
doCommand
(
const
std
::
shared_ptr
<
SM
Interface
>&
ui
);
static
Poco
::
JSON
::
Object
::
Ptr
to_short_json
(
sinfo
*
si
);
static
Poco
::
JSON
::
Object
::
Ptr
to_short_json
(
sinfo
*
si
);
void
term
();
void
term
();
...
...
extensions/UWebSocketGate/main.cc
View file @
441cda1b
#include "Configuration.h"
#include "Configuration.h"
#include "Extensions.h"
#include "UWebSocketGate.h"
#include "UWebSocketGate.h"
#include "Configuration.h"
#include "Configuration.h"
#include "UniSetActivator.h"
#include "UniSetActivator.h"
...
@@ -21,7 +22,21 @@ int main(int argc, char** argv)
...
@@ -21,7 +22,21 @@ int main(int argc, char** argv)
auto
conf
=
uniset_init
(
argc
,
argv
);
auto
conf
=
uniset_init
(
argc
,
argv
);
auto
ws
=
UWebSocketGate
::
init_wsgate
(
argc
,
argv
,
"ws-"
);
ObjectId
shmID
=
DefaultObjectId
;
string
sID
=
conf
->
getArgParam
(
"--smemory-id"
);
if
(
!
sID
.
empty
()
)
shmID
=
conf
->
getControllerID
(
sID
);
else
shmID
=
uniset
::
extensions
::
getSharedMemoryID
();
if
(
shmID
==
DefaultObjectId
)
{
cerr
<<
sID
<<
"? SharedMemoryID not found in "
<<
conf
->
getControllersSection
()
<<
" section"
<<
endl
;
return
1
;
}
auto
ws
=
UWebSocketGate
::
init_wsgate
(
argc
,
argv
,
shmID
,
nullptr
,
"ws-"
);
if
(
!
ws
)
if
(
!
ws
)
return
1
;
return
1
;
...
...
extensions/UWebSocketGate/tests/tests_with_sm.cc
View file @
441cda1b
...
@@ -42,7 +42,7 @@ int main(int argc, const char* argv[] )
...
@@ -42,7 +42,7 @@ int main(int argc, const char* argv[] )
if
(
!
shm
)
if
(
!
shm
)
return
1
;
return
1
;
auto
ws
=
UWebSocketGate
::
init_wsgate
(
argc
,
argv
,
"ws-"
);
auto
ws
=
UWebSocketGate
::
init_wsgate
(
argc
,
argv
,
shm
->
getId
(),
shm
,
"ws-"
);
if
(
!
ws
)
if
(
!
ws
)
return
1
;
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