remote update plugins through server_designer

more code clean
This commit is contained in:
2023-12-24 22:28:29 +03:00
parent 2f6f63380c
commit 6dc28f05de
18 changed files with 190 additions and 39 deletions

View File

@@ -51,6 +51,7 @@ SHDesigner::SHDesigner(QWidget * parent): EMainWindow(parent), Ui::SHDesigner(),
});
connect(&SHCORE->plugins_api, &SHDesignerAPI::prepareBlockRequest, this, [](BlockItem * block){
SHCORE->getStorage(block).prepareBlock(block);
SHCORE->sprocess.checkForErrors();
});
draw_tools = new DrawTools(blockView);

View File

@@ -41,7 +41,6 @@ const char qt_new_form[] =
FormWidget::FormWidget(QWidget * parent): QWidget(parent), Ui::FormWidget() {
qRegisterMetaType<QMetaMethod>("QMetaMethod");
setupUi(this);
form = tform = 0;
connect(CORE, SIGNAL(stopTest()), this, SLOT(stopTest()));
double new_font_pt = 12, old_font_pt = font().pointSizeF();
setStyleSheet(QString("font: %1pt \"DejaVu Sans\";").arg(qRound(new_font_pt)));
@@ -157,15 +156,13 @@ void FormWidget::loadFile(const QString & path) {
void FormWidget::stopTest() {
if (!tform) return;
tform->deleteLater();
tform = 0;
tform = nullptr;
}
void FormWidget::reset() {
RUNTIME->widget_list.clear();
if (form)
delete form;
form = 0;
piDeleteSafety(form);
}

View File

@@ -30,7 +30,7 @@ private:
QMenu * widgetPopupMenu(QWidget * w);
void invokeSignalPopup(QWidget * w, QPoint global_pos);
QWidget * form, * tform;
QWidget * form = nullptr, * tform = nullptr;
QString signal_src;
SHSUiLoader ui_loader;

View File

@@ -94,6 +94,7 @@ bool ServerManager::askPassword(PIString server_name) {
void ServerManager::connected() {
if (treeServers->isRequesting()) return;
treePlugins->clear();
sendIdentification();
treeServers->stopBroadcast();
}
@@ -171,6 +172,16 @@ void ServerManager::receiveEvent(PIByteArray data) {
case SHNetworkTypes::AdminRestartQueued:
waitForReconnect(tr("Restarting, wait for server ..."));
break;
case SHNetworkTypes::AdminLoadedPlugins: {
PIVector<PacketServerPlugin> plugins;
data >> plugins;
treePlugins->clear();
for (auto p: plugins)
treePlugins->addTopLevelItem(new QTreeWidgetItem({p.name, p.version}));
} break;
case SHNetworkTypes::AdminStartUpdatePlugins:
waitForReconnect(tr("Update plugins on server, wait for it ..."));
break;
default: break;
}
}
@@ -219,6 +230,20 @@ void ServerManager::on_buttonWaitCancel_clicked() {
}
void ServerManager::on_buttonPluginsUpdate_clicked() {
QStringList names;
for (int i = 0; i < treePlugins->topLevelItemCount(); ++i) {
auto * ti = treePlugins->topLevelItem(i);
if (!ti->isSelected()) continue;
names << ti->text(0);
}
if (names.isEmpty()) return;
PIByteArray ba = SHNetworkTypes::makeHeader(SHNetworkTypes::AdminUpdatePlugins);
ba << names;
channel.dataSend(ba);
}
void ServerManager::on_treeServers_serverSelected(PacketServerInfo info) {
if (!passwords.contains(info.name)) {
if (!askPassword(info.name))

View File

@@ -43,6 +43,7 @@ private slots:
void on_buttonRestart_clicked();
void on_buttonParametersApply_clicked();
void on_buttonWaitCancel_clicked();
void on_buttonPluginsUpdate_clicked();
void on_treeServers_serverSelected(PacketServerInfo info);
signals:

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>421</height>
<width>739</width>
<height>473</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -26,7 +26,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<widget class="QWidget" name="pageServerList">
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -54,7 +54,7 @@
<item>
<widget class="QTabWidget" name="tabWidgetServer">
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="icon">
@@ -138,6 +138,71 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="icon">
<iconset resource="../device_watcher/device_watcher.qrc">
<normaloff>:/icons/plugin.png</normaloff>:/icons/plugin.png</iconset>
</attribute>
<attribute name="title">
<string>Plugins</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QTreeWidget" name="treePlugins">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<attribute name="headerDefaultSectionSize">
<number>250</number>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Version</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="buttonPluginsUpdate">
<property name="text">
<string>Update selected</string>
</property>
<property name="icon">
<iconset resource="../SH_designer/SH_designer.qrc">
<normaloff>:/icons/go-down.png</normaloff>:/icons/go-down.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@@ -384,7 +449,9 @@
</customwidgets>
<resources>
<include location="../device_designer/device_designer.qrc"/>
<include location="../device_watcher/device_watcher.qrc"/>
<include location="serverdesigner.qrc"/>
<include location="../SH_designer/SH_designer.qrc"/>
<include location="../../libs/designer_tools/designer_tools.qrc"/>
</resources>
<connections>

View File

@@ -93,5 +93,6 @@
<file>../../icons/view-process-users.png</file>
<file>../../icons/packet-io.png</file>
<file>../../icons/user-group-properties.png</file>
<file>../../icons/go-down.png</file>
</qresource>
</RCC>

View File

@@ -46,10 +46,10 @@ public:
void disable(const QStringList & names);
bool loadMandatory(const QStringList & names);
void updateAll();
void updateInfo();
private:
static QString pluginsStat(const PIVector<SHPluginsLoader::PluginInfo> & list);
void updateInfo();
SHPluginsWeb web;
SHPluginsLoader loader;

View File

@@ -75,9 +75,9 @@ bool SHPluginsWeb::downloadPlugin(const SHPluginManifest & manifest, QString dir
error = true;
}
);
qDebug() << "wait ...";
//qDebug() << "wait ...";
while (!done) {piMinSleep(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);}
qDebug() << "wait done";
//qDebug() << "wait done";
return !error;
//qDebug() << mpath << lpath << manifest.libraryDownloadPath();
}

View File

@@ -566,10 +566,8 @@ void SHSScriptEngine::remove() {
}
db.stop();
RUNTIME->cache.clear();
RUNTIME->engine_ = 0;
if (engine_)
delete engine_;
engine_ = 0;
RUNTIME->engine_ = nullptr;
piDeleteSafety(engine_);
}

View File

@@ -77,6 +77,9 @@ public:
AdminSetParameter,
AdminScriptError,
AdminRestartQueued,
AdminLoadedPlugins,
AdminUpdatePlugins,
AdminStartUpdatePlugins,
RemotePultPackageNameRequest = 200,
RemotePultPackageName,
@@ -241,6 +244,11 @@ struct PacketScriptError {
ID(14) QString project;
};
struct PacketServerPlugin {
ID(1) QString name;
ID(2) QString version;
};
#undef ID

View File

@@ -1,13 +1,6 @@
#include "SH_runtime.h"
ScriptCache::ScriptCache() {
root_ = 0;
cmd_id_ = 0;
obj_id_ = 0;
}
void ScriptCache::build(SHS::Object & o, const QString & root) {
QMutableMapIterator<QString, SHS::Object> oit(o.objects);
while (oit.hasNext()) {
@@ -26,7 +19,7 @@ void ScriptCache::clear() {
command_by_id.clear();
object_by_id.clear();
commands_in.clear();
root_ = 0;
root_ = nullptr;
cmd_id_ = 0;
obj_id_ = 0;
}

View File

@@ -10,7 +10,6 @@
class ScriptCache {
public:
ScriptCache();
void build(SHS::Object & o, const QString & root = QString());
void clear();
QMap<uint, SHS::Command*> command_by_id;
@@ -18,8 +17,8 @@ public:
QHash<QString, QVector<SHS::Command*> > commands_in;
private:
void buildInternal(SHS::Object & o, QStringList path);
SHS::Object * root_;
uint cmd_id_, obj_id_;
SHS::Object * root_ = nullptr;
uint cmd_id_ = 0, obj_id_ = 0;
};
@@ -36,11 +35,9 @@ public:
object = o;
}
~Block() {
if (object)
delete object;
object = 0;
piDeleteSafety(object);
}
QObject * object;
QObject * object = nullptr;
QHash<QString, QStringList> packet_vars_aliases; // [source_var] = aliases
};

View File

@@ -32,8 +32,8 @@ void ServerClient::init(PIIODevice * e) {
void ServerClient::close() {
//if (device)
// device->stopAndWait();
if (device)
device->stop();
closing = true;
}
@@ -361,6 +361,11 @@ void ServerClient::packetRec(PIByteArray data) {
postGraphicsRequest(vars);
//QMetaObject::invokeMethod(this, "recGraphicsRequest", Qt::QueuedConnection, Q_ARG(QStringList, PI2QStringList(vars)));
} break;
case SHNetworkTypes::AdminUpdatePlugins: {
QStringList names;
data >> names;
server->updatePlugins(names, this);
} break;
default: break;
}
}

View File

@@ -613,6 +613,16 @@ void ServerCore::uploadedBAF(const PIByteArray & baf, ServerClient * r) {
}
void ServerCore::updatePlugins(const QStringList & names, ServerClient * r) {
if (r->info.role != SHServer::RoleAdmin) {
piCoutObj << Q2PIString(r->info.hostname) << "is not in Admin role, ignore update plugins!";
return;
}
r->tcp->send(SHNetworkTypes::makeHeader(SHNetworkTypes::AdminStartUpdatePlugins));
emit updatePluginsRequest(names);
}
PacketParameterList ServerCore::adminParameters() const {
PacketParameterList ret;
ret.parameters << PacketParameter(ServerClient::pLogIO, "Log IO", false);
@@ -839,11 +849,7 @@ void ServerCore::receivedIdentification(ServerClient * r, PIByteArray data) {
r->close();
return;
}
ba = SHNetworkTypes::makeHeader(SHNetworkTypes::AdminPasswordAccepted);
r->tcp->send(ba);
ba = SHNetworkTypes::makeHeader(SHNetworkTypes::AdminParameterList);
ba << adminParameters();
r->tcp->send(ba);
sendInitialAdminData(r);
}
//piCoutObj << "my" << ui_hash << rcc_hash;
@@ -922,6 +928,32 @@ void ServerCore::sendToAll(const PIByteArray & data, SHServer::ClientRole role,
}
void ServerCore::sendInitialAdminData(ServerClient * r) {
PIByteArray ba;
ba = SHNetworkTypes::makeHeader(SHNetworkTypes::AdminPasswordAccepted);
r->tcp->send(ba);
ba = SHNetworkTypes::makeHeader(SHNetworkTypes::AdminLoadedPlugins);
PIVector<PacketServerPlugin> plugins;
auto it = RUNTIME->plugins_manager->localInterface().readedLibraries().makeIterator();
while (it.next()) {
if (it.value().isLoaded()) {
PacketServerPlugin plugin;
plugin.name = it.key();
plugin.version = it.value().manifest.fullVersion();
plugins << plugin;
}
}
ba << plugins;
r->tcp->send(ba);
ba = SHNetworkTypes::makeHeader(SHNetworkTypes::AdminParameterList);
ba << adminParameters();
r->tcp->send(ba);
}
void ServerCore::log(const QString & text, SHServer::LogEntryType type) {
LogEntry e;
e.time = QDateTime::currentDateTime();

View File

@@ -11,6 +11,9 @@
#include "SH_ui_loader.h"
#include "SH_ui_sync.h"
class Server;
class ServerClient;
class ServerStarter;
class ServerCore: public QObject, public SHMulticast {
Q_OBJECT
@@ -42,6 +45,7 @@ private:
void receivedSH(PIByteArray data, uint rec_id) override;
void addressesChanged() override;
void sendToAll(const PIByteArray & data, SHServer::ClientRole role, bool no_check = false);
void sendInitialAdminData(ServerClient * r);
void log(const QString & text, SHServer::LogEntryType type = SHServer::LogInfo);
void message(const QString & text, int type = 0);
void receivedIdentification(ServerClient * r, PIByteArray data);
@@ -55,6 +59,7 @@ private:
void saveUIState();
void restoreUIState();
void uploadedBAF(const PIByteArray & baf, ServerClient * r);
void updatePlugins(const QStringList & names, ServerClient * r);
PacketParameterList adminParameters() const;
EVENT_HANDLER1(void, newTCPConnection, PIEthernet * , client);
EVENT_HANDLER1(void, newCloudConnection, PICloudServer::Client * , client);
@@ -122,6 +127,7 @@ signals:
void startedAsMain();
void startedAsReserve();
void zeroFailure();
void updatePluginsRequest(QStringList);
};

View File

@@ -57,6 +57,7 @@ void ServerStarter::init() {
server->core.engine.connection()->setLogIO(log_io);
connect(&(server->core), SIGNAL(zeroFailure()), this, SLOT(zeroFailure()));
connect(&(server->core), SIGNAL(restart(QString)), this, SLOT(restart(QString)), Qt::QueuedConnection);
connect(&(server->core), SIGNAL(updatePluginsRequest(QStringList)), this, SLOT(updatePlugins(QStringList)), Qt::QueuedConnection);
}
@@ -139,6 +140,24 @@ void ServerStarter::zeroFailure() {
}
void ServerStarter::updatePlugins(QStringList names) {
qDebug() << "[ServerStarter::updatePlugins] Get info from server ...";
RUNTIME->plugins_manager->webInterface().requestPluginsList();
if (!RUNTIME->plugins_manager->webInterface().waitPluginsList()) {
qDebug() << "[ServerStarter::updatePlugins] Can`t get info from server";
return;
}
RUNTIME->plugins_manager->updateInfo();
qDebug() << "[ServerStarter::updatePlugins]" << "Got info from server, shutdown server ...";
destroy();
qDebug() << "[ServerStarter::updatePlugins]" << "Update plugins ...";
RUNTIME->plugins_manager->update(names);
qDebug() << "[ServerStarter::updatePlugins]" << "Update done, start server ...";
restart({});
qDebug() << "[ServerStarter::updatePlugins]" << "Restarted";
}
void ServerStarter::restart(QString baf) {
src_baf_path = baf;
if (!baf.isNull()) baf_path = baf;

View File

@@ -22,6 +22,7 @@ public:
public slots:
void restart(QString baf = QString());
void zeroFailure();
void updatePlugins(QStringList names);
private:
void init();