int main(int argc, char* argv[]) { try { terrama2::core::TerraMA2Init terramaRaii("example", 0); terrama2::core::registerFactories(); { QCoreApplication app(argc, argv); auto& serviceManager = terrama2::core::ServiceManager::getInstance(); te::core::URI uri("pgsql://"+TERRAMA2_DATABASE_USERNAME+":"+TERRAMA2_DATABASE_PASSWORD+"@"+TERRAMA2_DATABASE_HOST+":"+TERRAMA2_DATABASE_PORT+"/"+TERRAMA2_DATABASE_DBNAME); serviceManager.setLogConnectionInfo(uri); serviceManager.setInstanceId(1); auto dataManager = std::make_shared<terrama2::services::collector::core::DataManager>(); addInput(dataManager); addOutput(dataManager); addGridSeries(dataManager); terrama2::services::collector::core::Service service(dataManager); auto logger = std::make_shared<terrama2::services::collector::core::CollectorLogger>(); logger->setConnectionInfo(uri); service.setLogger(logger); service.start(); terrama2::services::collector::core::Collector* collector(new terrama2::services::collector::core::Collector()); terrama2::services::collector::core::CollectorPtr collectorPtr(collector); collector->id = 1; collector->projectId = 1; collector->serviceInstanceId = 1; collector->inputDataSeries = 1; collector->outputDataSeries = 2; collector->inputOutputMap.emplace(1, 2); terrama2::services::collector::core::Intersection* intersection(new terrama2::services::collector::core::Intersection()); terrama2::services::collector::core::IntersectionPtr intersectionPtr(intersection); // Adds the attribute "SIGLA" to the collected occurrences. intersection->collectorId = collector->id; std::vector<std::string> attrVec{"2"}; intersection->attributeMap[3] = attrVec; collector->intersection = intersectionPtr; dataManager->add(collectorPtr); service.addToQueue(collectorPtr->id, terrama2::core::TimeUtils::nowUTC()); QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); timer.start(10000); app.exec(); service.stopService(); } } catch(...) { std::cout << "\n\nException...\n" << std::endl; } return 0; }
int main(int argc, char* argv[]) { try { terrama2::core::initializeTerraMA(); terrama2::core::registerFactories(); { QCoreApplication app(argc, argv); auto& serviceManager = terrama2::core::ServiceManager::getInstance(); std::map<std::string, std::string> connInfo { {"PG_HOST", TERRAMA2_DATABASE_HOST}, {"PG_PORT", TERRAMA2_DATABASE_PORT}, {"PG_USER", TERRAMA2_DATABASE_USERNAME}, {"PG_PASSWORD", TERRAMA2_DATABASE_PASSWORD}, {"PG_DB_NAME", TERRAMA2_DATABASE_DBNAME}, {"PG_CONNECT_TIMEOUT", "4"}, {"PG_CLIENT_ENCODING", "UTF-8"} }; serviceManager.setLogConnectionInfo(connInfo); serviceManager.setInstanceId(1); auto dataManager = std::make_shared<terrama2::services::collector::core::DataManager>(); addInput(dataManager); addOutput(dataManager); addStaticDataSeries(dataManager); terrama2::services::collector::core::Service service(dataManager); service.start(); terrama2::services::collector::core::Collector* collector(new terrama2::services::collector::core::Collector()); terrama2::services::collector::core::CollectorPtr collectorPtr(collector); collector->id = 1; collector->projectId = 1; collector->serviceInstanceId = 1; collector->inputDataSeries = 1; collector->outputDataSeries = 2; collector->inputOutputMap.emplace(1, 2); terrama2::services::collector::core::Intersection* intersection(new terrama2::services::collector::core::Intersection()); terrama2::services::collector::core::IntersectionPtr intersectionPtr(intersection); // Adds the attribute "SIGLA" to the collected occurrences. intersection->collectorId = collector->id; std::vector<std::string> attrVec; attrVec.push_back("sigla"); intersection->attributeMap[3] = attrVec; collector->intersection = intersectionPtr; dataManager->add(collectorPtr); QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); timer.start(300000); app.exec(); service.stopService(); } terrama2::core::finalizeTerraMA(); } catch(...) { // TODO: o que fazer com uncaught exception std::cout << "\n\nException...\n" << std::endl; } return 0; }