|
@@ -1,48 +1,89 @@
|
|
|
#include "DataManagerProxy.h"
|
|
|
#include "RedisClient.h"
|
|
|
+#include <QJsonArray>
|
|
|
+#include <QJsonObject>
|
|
|
DataManagerProxy::DataManagerProxy() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-QList<DataManagerInfo> DataManagerProxy::loadModuleInfos(const char* id, const char* app)
|
|
|
+QList<DataManagerInfo> DataManagerProxy::loadModuleInfos(const Config& config)
|
|
|
{
|
|
|
-
|
|
|
- RedisClient* redis = new RedisClient();
|
|
|
+ RedisClient redis;
|
|
|
QList<DataManagerInfo > listDataManageInfo;
|
|
|
- QString key = QString("%1:%2").arg(app).arg(id);
|
|
|
+ QString key = QString("%1:%2").arg(config.AppName, config.AppId);
|
|
|
DeviceInfo di;
|
|
|
- if( redis != nullptr)
|
|
|
+
|
|
|
+ redis.Setup(config.redisCfg.host, config.redisCfg.port, config.redisCfg.au);
|
|
|
+ // QHash<QString, QString> h = redis->hgetall(key);
|
|
|
+ // for(auto it = h.begin(); it != h.end(); it++)
|
|
|
+ // {
|
|
|
+ // qDebug()<< "key" << it.key();
|
|
|
+ // //qDebug()<< "val" << it.value();
|
|
|
+ // QJsonArray ja = QJsonDocument::fromJson(it.value().toUtf8()).array();
|
|
|
+ // // QJsonObject jo = QJsonDocument::fromJson(it.value().toUtf8()).object();
|
|
|
+ // }
|
|
|
+
|
|
|
+ QStringList lst = redis.hvals(key);
|
|
|
+ foreach (QString str, lst)
|
|
|
{
|
|
|
- QStringList lst = redis->hvals(key);
|
|
|
- foreach (QString str, lst)
|
|
|
+ if( str.isEmpty() )
|
|
|
{
|
|
|
- if( str.isEmpty() )
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ QJsonParseError jsonParseError;
|
|
|
+ QJsonDocument jsonDocument(QJsonDocument::fromJson(str.toUtf8(), &jsonParseError));
|
|
|
+ if(QJsonParseError::NoError != jsonParseError.error)
|
|
|
+ {
|
|
|
+ //LOGERROR("parse json file {} error", fullpath.toStdString().c_str());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!jsonDocument.isArray()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ QJsonArray ja = jsonDocument.array();
|
|
|
+ foreach (auto var, ja) {
|
|
|
+ QJsonObject item = var.toObject();
|
|
|
+ QString topic = item["topic"].toString();
|
|
|
+ QJsonArray clients = item["Client"].toArray();
|
|
|
+ DataManagerInfo dataManageInfo;
|
|
|
ModuleInfo mi;
|
|
|
- mi.Name = "RedisSubscriber";
|
|
|
-
|
|
|
- mi.AssemblyName = "plugins/RedisSubscriber.dll";
|
|
|
- mi.ClassName = "RedisSubscriber";
|
|
|
+ mi.Name = "TDengineSubscriber";
|
|
|
+ mi.AssemblyName = "plugins/TDengineSubscriber.dll";
|
|
|
+ // mi.ClassName = "TDengineSubscriber";
|
|
|
+ mi.Code = topic.toStdString();
|
|
|
+ foreach (auto client, clients) {
|
|
|
+ ConsumerInfo ci;
|
|
|
+ ci.Name = client["Name"].toString().toStdString();
|
|
|
+ ci.AssemblyName = client["AssemblyName"].toString().toStdString();
|
|
|
+ //ci.ClassName = "Alarm";
|
|
|
+ ci.SubscribeName = topic.toStdString();
|
|
|
+ ci.Settings = client["Settings"].toVariant().toString().toStdString();
|
|
|
+ dataManageInfo.consumers.push_back(ci);
|
|
|
+ }
|
|
|
+ dataManageInfo.modules.push_back(mi);
|
|
|
+ listDataManageInfo.push_back(dataManageInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- ConsumerInfo ci;
|
|
|
+#if 0
|
|
|
|
|
|
- ci.name = "TDengine";
|
|
|
+ ModuleInfo mi;
|
|
|
+ mi.Name = "TDengineSubscriber";
|
|
|
+ mi.AssemblyName = "plugins/TDengineSubscriber.dll";
|
|
|
+ mi.ClassName = "TDengineSubscriber";
|
|
|
+ mi.Code = "topic:xxx";
|
|
|
|
|
|
- ci.AssemblyName = "plugins/TDengine.dll";
|
|
|
- ci.ClassName = "TDengine";
|
|
|
- ci.SubscribeName = "RedisSubscriber";
|
|
|
+ ConsumerInfo ci;
|
|
|
+ ci.Name = "Alarm";
|
|
|
+ ci.AssemblyName = "plugins/Alarm.dll";
|
|
|
+ ci.ClassName = "Alarm";
|
|
|
+ ci.SubscribeName = "TDengineSubscriber";
|
|
|
DataManagerInfo dataManageInfo;
|
|
|
dataManageInfo.consumers.push_back(ci);
|
|
|
dataManageInfo.modules.push_back(mi);
|
|
|
listDataManageInfo.push_back(dataManageInfo);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+#endif
|
|
|
//return di;
|
|
|
|
|
|
-
|
|
|
return listDataManageInfo;
|
|
|
}
|