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
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
include $(top_builddir)/include.mk
......
......@@ -39,7 +39,11 @@
using namespace uniset;
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)
{
offThread(); // отключаем поток обработки, потому-что будем обрабатывать сами
......@@ -56,6 +60,11 @@ UWebSocketGate::UWebSocketGate( uniset::ObjectId id, xmlNode* cnode, const strin
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);
wscmd = make_shared<ev::async>();
......@@ -253,7 +262,10 @@ Poco::JSON::Object::Ptr UWebSocketGate::error_to_json( const std::string& err )
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");
......@@ -263,7 +275,7 @@ std::shared_ptr<UWebSocketGate> UWebSocketGate::init_wsgate( int argc, const cha
return nullptr;
}
return uniset::make_object<UWebSocketGate>(name, "UWebSocketGate", prefix);
return uniset::make_object<UWebSocketGate>(name, "UWebSocketGate", shmID, ic, prefix);
}
// -----------------------------------------------------------------------------
void UWebSocketGate::help_print()
......@@ -341,7 +353,7 @@ void UWebSocketGate::onActivate( ev::async& watcher, int revents )
if( !s->isActive() )
{
s->set(loop, wscmd);
s->doCommand(ui);
s->doCommand(shm);
}
}
}
......@@ -357,7 +369,7 @@ void UWebSocketGate::onCommand( ev::async& watcher, int revents )
uniset_rwmutex_rlock lk(wsocksMutex);
for( const auto& s : wsocks )
s->doCommand(ui);
s->doCommand(shm);
}
// -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API
......@@ -914,7 +926,7 @@ void UWebSocketGate::UWebSocket::sensorInfo( const uniset::SensorMessage* sm )
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() )
return;
......
......@@ -34,6 +34,8 @@
#include "LogAgregator.h"
#include "UniSetObject.h"
#include "DebugStream.h"
#include "SharedMemory.h"
#include "SMInterface.h"
#include "EventLoopServer.h"
#include "UTCPStream.h"
#include "UHttpRequestHandler.h"
......@@ -189,11 +191,18 @@ namespace uniset
#endif
{
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();
/*! глобальная функция для инициализации объекта */
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-а */
static void help_print();
......@@ -247,6 +256,7 @@ namespace uniset
int maxMessagesProcessing = { 100 };
std::shared_ptr<DebugStream> mylog;
std::shared_ptr<SMInterface> shm;
#ifndef DISABLE_REST_API
std::shared_ptr<Poco::Net::HTTPServer> httpserv;
......@@ -301,7 +311,7 @@ namespace uniset
void get( uniset::ObjectId id );
void set( uniset::ObjectId id, long value );
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 );
void term();
......
#include "Configuration.h"
#include "Extensions.h"
#include "UWebSocketGate.h"
#include "Configuration.h"
#include "UniSetActivator.h"
......@@ -21,7 +22,21 @@ int main(int argc, char** 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 )
return 1;
......
......@@ -42,7 +42,7 @@ int main(int argc, const char* argv[] )
if( !shm )
return 1;
auto ws = UWebSocketGate::init_wsgate(argc, argv, "ws-");
auto ws = UWebSocketGate::init_wsgate(argc, argv, shm->getId(), shm, "ws-");
if( !ws )
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