void GraphEditor::load(void) { auto fileName = this->getCurrentFilePath().toStdString(); if (fileName.empty()) { _stateManager->resetToDefault(); handleStateChange(GraphState("document-new", tr("Create new topology"))); _stateManager->saveCurrent(); this->render(); return; } try { poco_information_f1(Poco::Logger::get("PothosGui.GraphEditor.load"), "Loading %s from file", fileName); postStatusMessage(tr("Loading %1").arg(QString::fromStdString(fileName))); std::ifstream inFile(fileName.c_str()); this->loadState(inFile); } catch (const std::exception &ex) { poco_error_f2(Poco::Logger::get("PothosGui.GraphEditor.load"), "Error loading %s: %s", fileName, std::string(ex.what())); } _stateManager->resetToDefault(); handleStateChange(GraphState("document-new", tr("Load topology from file"))); _stateManager->saveCurrent(); this->updateGraphEditorMenus(); this->render(); }
void TagDB::startTagDB() { double sysTime1 = clock(); DBUtils::openHashDB(hashDB, pathHashDB); DBUtils::openGrassDB(grassDB); cout << "Copying TagDB..." << endl; DBUtils::copyDBFromHashDBtoGrassDB(hashDB, grassDB); double sysTime2 = clock(); LASTID = DBUtils::initalizeLastID(grassDB); //cout << "Time to search: " << (double) (sysTime2 - sysTime1) << endl; poco_information_f1(*logger, "startTagDB: Start TagDB in %0.0f milliseconds.", (double) (sysTime2 - sysTime1)); return; }
bool TagDB::editTag(string tagID, string tagName) { if (grassDB.check(tagID) == -1) { return false; } Tag tag; tag.tagID = tagID; tag.tagName = tagName; tag.viewCounts = 0; tag.dateAdd = Utils::getTimeNow(); string jsonString = convertTagToJson(tag); try { grassDB.replace(tagID, jsonString); addQueue(UPDATE, tagID, jsonString); return true; } catch (char* str) { //cout << "Edit error!" << endl; poco_information_f1(*logger, "editTag: Error editTag %s", str); return false; } }
/** * Start ItemDB. */ void ItemDB::startItemDB() { Timestamp sysTime1 = Timestamp().utcTime(); DBUtils::openHashDB(hashDB, pathHashDB); DBUtils::openGrassDB(grassDB); cout << "Copying ItemDB..." << endl; DBUtils::copyDBFromHashDBtoGrassDB(hashDB, grassDB); Timestamp sysTime2 = Timestamp().utcTime(); cout << "Start ItemDB in " << sysTime2 - sysTime1 << " milliseconds." << endl; poco_information_f1(*logger, "startItemDB: Start ItemDB in %s milliseconds.", Utils::convertIntToString((sysTime2 - sysTime1))); int n = 300; cout << "Getting ListTopItemID" << endl; // Mac dinh lTopItemID chi co 300 itemID. lTopItemID = getListTopItemID(n); Timestamp sysTime3 = Timestamp().utcTime(); cout << "Get List Top ItemID in " << sysTime3 - sysTime2 << " milliseconds." << endl; Timestamp sysTime4 = Timestamp().utcTime(); LASTID = DBUtils::initalizeLastID(grassDB); cout << "Initalize LastID=" << LASTID << " in " << sysTime4 - sysTime3 << " milliseconds." << endl; return; }
Template::Ptr TemplateCache::getTemplate(const Path& path) { if ( _logger ) { poco_trace_f1(*_logger, "Trying to load %s", path.toString()); } Path templatePath = resolvePath(path); std::string templatePathname = templatePath.toString(); if ( _logger ) { poco_trace_f1(*_logger, "Path resolved to %s", templatePathname); } File templateFile(templatePathname); Template::Ptr tpl; std::map<std::string, Template::Ptr>::iterator it = _cache.find(templatePathname); if ( it == _cache.end() ) { if ( templateFile.exists() ) { if ( _logger ) { poco_information_f1(*_logger, "Loading template %s", templatePath.toString()); } tpl = new Template(templatePath); try { tpl->parse(); _cache[templatePathname] = tpl; } catch(JSONTemplateException& jte) { if ( _logger ) { poco_error_f2(*_logger, "Template %s contains an error: %s", templatePath.toString(), jte.message()); } } } else { if ( _logger ) { poco_error_f1(*_logger, "Template file %s doesn't exist", templatePath.toString()); } throw FileNotFoundException(templatePathname); } } else { tpl = it->second; if ( tpl->parseTime() < templateFile.getLastModified() ) { if ( _logger ) { poco_information_f1(*_logger, "Reloading template %s", templatePath.toString()); } tpl = new Template(templatePath); try { tpl->parse(); _cache[templatePathname] = tpl; } catch(JSONTemplateException& jte) { if ( _logger ) { poco_error_f2(*_logger, "Template %s contains an error: %s", templatePath.toString(), jte.message()); } } } } return tpl; }
void GraphEditor::exportToJSONTopology(const QString &fileName) { poco_information_f1(_logger, "Exporting %s", fileName.toStdString()); Poco::JSON::Object topObj; //all graph objects excluding widgets which are not exported //we will have to filter out graphical blocks as well const auto graphObjects = this->getGraphObjects(~GRAPH_WIDGET); //global variables Poco::JSON::Array globals; for (const auto &name : this->listGlobals()) { const auto &value = this->getGlobalExpression(name); Poco::JSON::Object globalObj; globalObj.set("name", name.toStdString()); globalObj.set("value", value.toStdString()); globals.add(globalObj); } if (globals.size() > 0) topObj.set("globals", globals); //thread pools (filled in by blocks loop) Poco::JSON::Object threadPools; auto affinityZones = AffinityZonesDock::global(); //blocks Poco::JSON::Array blocks; std::map<size_t, const GraphBlock*> uidToBlock; for (const auto *obj : graphObjects) { const auto block = dynamic_cast<const GraphBlock *>(obj); if (block == nullptr) continue; if (block->isGraphWidget()) continue; uidToBlock[block->uid()] = block; //copy in the the id and path Poco::JSON::Object blockObj; blockObj.set("id", block->getId().toStdString()); blockObj.set("path", block->getBlockDescPath()); //setup the thread pool when specified const auto affinityZone = block->getAffinityZone(); if (not affinityZone.isEmpty() and affinityZone != "gui") { const auto config = affinityZones->zoneToConfig(affinityZone); threadPools.set(affinityZone.toStdString(), config); blockObj.set("threadPool", affinityZone.toStdString()); } //block description args are in the same format const auto desc = block->getBlockDesc(); if (desc->has("args")) blockObj.set("args", desc->get("args")); //copy in the named calls in array format Poco::JSON::Array calls; if (desc->isArray("calls")) for (const auto &elem : *desc->getArray("calls")) { const auto callObj = elem.extract<Poco::JSON::Object::Ptr>(); Poco::JSON::Array call; call.add(callObj->get("name")); for (const auto &arg : *callObj->getArray("args")) call.add(arg); calls.add(call); } blockObj.set("calls", calls); //copy in the parameters as local variables Poco::JSON::Array locals; for (const auto &name : block->getProperties()) { Poco::JSON::Object local; local.set("name", name.toStdString()); local.set("value", block->getPropertyValue(name).toStdString()); locals.add(local); } blockObj.set("locals", locals); blocks.add(blockObj); } topObj.set("blocks", blocks); if (threadPools.size() > 0) topObj.set("threadPools", threadPools); //connections Poco::JSON::Array connections; for (const auto &connInfo : TopologyEval::getConnectionInfo(graphObjects)) { //the block may have been filtered out //check that its found in the mapping auto srcIt = uidToBlock.find(connInfo.srcBlockUID); if (srcIt == uidToBlock.end()) continue; auto dstIt = uidToBlock.find(connInfo.dstBlockUID); if (dstIt == uidToBlock.end()) continue; //create the connection information in order Poco::JSON::Array connArr; connArr.add(srcIt->second->getId().toStdString()); connArr.add(connInfo.srcPort); connArr.add(dstIt->second->getId().toStdString()); connArr.add(connInfo.dstPort); connections.add(connArr); } topObj.set("connections", connections); //write to file try { std::ofstream outFile(fileName.toStdString().c_str()); topObj.stringify(outFile, 4/*indent*/); } catch (const std::exception &ex) { poco_error_f2(_logger, "Error exporting %s: %s", fileName, std::string(ex.what())); } }