Commit 1b2d84a1 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[uwebsocketgate]: supported "work with SM"

parent 5d5beb86
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
......
...@@ -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<UInterface>& ui ) void UWebSocketGate::UWebSocket::doCommand(const std::shared_ptr<SMInterface>& ui )
{ {
if( qcmd.empty() ) if( qcmd.empty() )
return; return;
......
...@@ -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<UInterface>& ui ); void doCommand( const std::shared_ptr<SMInterface>& 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();
......
#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;
......
...@@ -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;
......
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