//static void Index::writeSchema(DocumentSchemaPtr& pDocSchema, FileSystemPtr& pFileSys) { XMLConfigurator configurator(Configurator::TO_CONF); pDocSchema->configure(configurator); configurator.save(SCHEMA_FILENAME, pFileSys); }
void ConfigureLogger() { #if defined(_WIN32) TCHAR path_buffer[MAX_PATH]; DWORD buffer_size = GetModuleFileName(NULL, path_buffer, MAX_PATH); // if buffer_size == MAX_PATH the buffer was truncated and GetLastError() returns ERROR_INSUFFICIENT_BUFFER // TODO: if buffer_size == 0 check GetLastError() boost::filesystem::path log_path(path_buffer); #elif defined(__APPLE__) char path_buffer[MAXPATHLEN]; std::uint32_t buffer_size = sizeof(path_buffer); int got_path = _NSGetExecutablePath(path_buffer, &buffer_size); // TODO: check if got_path != 0, in which case the call failed. boost::filesystem::path log_path(path_buffer); #else // Assuming linux # if !defined(NDEBUG) // On debug the configuration file is in the same directory as the executable char path_buffer[8192]; std::uint32_t buffer_size = sizeof(path_buffer); ssize_t path_size = readlink("/proc/self/exe", path_buffer, buffer_size); // TODO: if path_size == -1 check errno path_buffer[path_size] = '\0'; boost::filesystem::path log_path(path_buffer); # else // On release mode, it should be in a common directory boost::filesystem::path log_path("/var/log/actor/logging.conf"); # endif #endif log_path.remove_filename(); log_path /= "logging.conf"; // only in version 1.1.1 and beyond // log4cplus::initialize(); if (boost::filesystem::exists(log_path) && boost::filesystem::is_regular_file(log_path)) { log4cplus::PropertyConfigurator configurator(log_path.string()); configurator.configure(); } else { log4cplus::BasicConfigurator configurator; configurator.configure(); // TODO: make this code work /*log4cplus::SharedAppenderPtr appender( new log4cplus::ConsoleAppender(false, false)); appender->setName("RootAppender"); std::auto_ptr<log4cplus::Layout> layout( new log4cplus::PatternLayout("%D{%d.%m.%Y %H:%M:%S.%q} [%8t] %-5p - " "%c{2} - %m%n")); appender->setLayout(layout); auto logger = log4cplus::Logger::getRoot(); logger.addAppender(appender); logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL);*/ } }
void tryParsingAddress(Address_ip4& in_address, std::uint16_t& in_sender_port) { std::uint32_t receiver_ip(0x00); std::uint16_t receiver_port(0x00); std::uint16_t sender_port(0x00); try{ unsigned char address_component = 0x00; for(int comp_idx = 3; comp_idx >= 0; --comp_idx) { switch(comp_idx) { case 0: address_component = (unsigned char) (configurator().getUint("receiver_addr_p3")); break; case 1: address_component = (unsigned char) (configurator().getUint("receiver_addr_p2")); break; case 2: address_component = (unsigned char) (configurator().getUint("receiver_addr_p1")); break; case 3: address_component = (unsigned char) (configurator().getUint("receiver_addr_p0")); break; default: throw; } receiver_ip |= (address_component << ( comp_idx * 8 )); } } catch (...){ std::cout << "Receiver address parsing exception occured. Using 127.0.0.1 instead.\n"; receiver_ip = (127 << 24) | ( 0 << 16) | ( 0 << 8) | ( 1 << 0); } try{ receiver_port = (configurator().getUint("receiver_port")); } catch (...) { std::cout << "Receiver port parsing exception occured. Using 30000 instead.\n"; receiver_port = 30000; } try{ sender_port = (configurator().getUint("sender_port")); } catch (...) { std::cout << "Sender port parsing exception occured. Using 6666 instead.\n"; sender_port = 6666; } in_address.set_address(receiver_ip); in_address.set_port(receiver_port); in_sender_port = sender_port; }
Locator::Locator(unsigned int num_mics) :shutdown_{false} ,recorder_{num_mics, (unsigned)(configurator().getFloat("audio_device_sampling_rate")), configurator().getUint("max_recording_time")} ,collector_{recorder_.bufferBytes() / num_mics, num_mics} ,tdoator_{330.0f, configurator().getVec("microphone1_pos"), configurator().getVec("microphone2_pos"), configurator().getVec("microphone3_pos"), configurator().getVec("microphone4_pos")} ,locator_frame_counter_(cached_positions[0].size()) ,current_signal_chunk_(0) { loadLocatorParameters(); for (auto freq : configurator().getList("known_frequencies")) { cached_positions[freq] = std::vector<std::pair<unsigned, glm::vec2>>(std::size_t{configurator().getUint("num_median_samples")}); } }
int main(int argc, char* argv[]) { try { Configuration& configuration = Configuration::it(); if (argc > 1) configuration.readConfiguration(argv[1]); else configuration.readConfiguration("bbstrassenfest.conf"); log_init(configuration.loggingConfiguration()); tnt::Tntnet app; app.listen(configuration.listenIp(), configuration.listenPort()); tnt::Configurator configurator(app); if (configuration.sessionTimeout()) configurator.setSessionTimeout(configuration.sessionTimeout()); // configure static stuff - lookup files in static resources first app.mapUrl("^/(.*)", "resources") .setPathInfo("resources/$1"); // index page app.mapUrl("^/$", "webmain") .setArg("next", "index"); // controller app.mapUrl("^/(.*)$", "controller/$1"); // view app.mapUrl("^/(.*)$", "webmain") .setArg("next", "view/$1"); app.run(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; } }
int main(int argc, char** argv) { std::string file_name{"default_server_config.conf"}; if(argc > 1) { file_name = argv[1]; } // load the server configurations from the provided file configurator().read(file_name); Address_ip4 parsed_target_address{0x00, 0x00, 0x00, 0x00, 0x00}; std::uint16_t parsed_sender_port = 0x00; tryParsingAddress(parsed_target_address, parsed_sender_port); // create the server and run it's main loop // note, that the server implementation is blocking MobatServer sending_server(parsed_target_address, parsed_sender_port); sending_server.run(); return 0; }
int main() { char starlist[99]; char starlist2[99]; int fe1, fe2; configurator(); /* Get the Fe I list from the user and open it and the corresponding solar list */ fprintf(stderr, "Where is the Fe-I lines list located?\n"); scanf("%s", starlist); FILE *stellar = fopen(starlist, "r"); FILE *solar = fopen(sunlst1, "r"); /* Get the Fe II list from the user and open it and the solar list */ fprintf(stderr, "Where is the Fe-II lines list located?\n"); scanf("%s", starlist2); FILE *stellar2 = fopen(starlist2, "r"); FILE *solar2 = fopen(sunlst2, "r"); fprintf(stderr, "Thank you!\n"); fe1 = sortlists(stellar, solar, 0); fclose(stellar); fclose(solar); fprintf(stderr, "Fe1 Lists are sorted. . . "); fe2 = sortlists(stellar2, solar2, 1); fclose(stellar2); /* fclose(solar2);*/ fprintf(stderr, "Fe2 Lists are sorted. . . Continuing!\n"); fprintf(stderr, "READY FOR PARAMS FUNCTION!\n"); prelim(fe1, fe2); return 0; }
void ConfigureLoggers(const Config& config) { const ConfigProperties* props = config.get_child("logs"); if (!props) { THROW_EXCEPTION("Cannot find logs config section"); } stringstream stream; for (auto i = props->begin(); i != props->end(); ++i) { string key = i->first; string value = i->second.get_value<string>(); if (!starts_with(key, "log4cplus.")) { key = "log4cplus." + key; } stream << key << "=" << value << endl; } log4cplus::PropertyConfigurator configurator(stream); configurator.configure(); }
void Locator:: loadLocatorParameters() { request_vis_vectors_ = configurator().getUint("show_signalvis") > 0; }
void Locator::recordPosition() { bool show_times = configurator().getUint("show_times") > 0; std::chrono::high_resolution_clock::time_point start_loop, start; unsigned elapsed_time; // start recording loop auto recording_thread = std::thread{&Recorder::recordingLoop, &recorder_}; unsigned num_chunks_to_analyze = configurator().getUint("num_analyzed_fourier_chunks"); bool first_signal_available = false; while (!shutdown_) { if(show_times) { start_loop = std::chrono::high_resolution_clock::now(); } for (unsigned frequency_to_analyze : frequencies_to_locate) { signal_analyzer_.startListeningTo(frequency_to_analyze); } bool work_on_old_signal = false; if (!recorder_.newRecording()) { work_on_old_signal = true; } else { first_signal_available = true; } if (!work_on_old_signal) { current_signal_chunk_ = 0; // TODO: make recordedBytes() independent from buffer() call std::size_t buffer_bytes = recorder_.recordedBytes() / collector_.count; collector_.fromInterleaved(recorder_.buffer(), buffer_bytes); // recorder_.requestRecording(); } else { if (!first_signal_available || ++current_signal_chunk_ >= num_chunks_to_analyze) continue; } if (collector_.length == 0) { continue; } // std::cout << "@ chunk: " << current_signal_chunk_+1 << "/" << num_chunks_to_analyze << "\n"; signal_analyzer_.analyze(collector_, current_signal_chunk_); if(show_times) { start = std::chrono::high_resolution_clock::now(); } bool found_positions = false; std::map<unsigned,glm::vec2> currently_located_positions; for (unsigned frequency_to_locate : frequencies_to_locate) { std::array<double, 4> current_frequency_toas = signal_analyzer_.getTOAsFor(frequency_to_locate); double const & (*d_min) (double const &, double const &) = std::min<double>; double const & (*d_max) (double const &, double const &) = std::max<double>; double toa_min = std::accumulate(current_frequency_toas.begin(), current_frequency_toas.end(), std::numeric_limits<double>::max(), d_min); double toa_max = std::accumulate(current_frequency_toas.begin(), current_frequency_toas.end(), 0.0, d_max); if (toa_max != std::numeric_limits<double>::max() && toa_max - toa_min < 100.00 ) { found_positions = true; currently_located_positions[frequency_to_locate] = tdoator_.locate(current_frequency_toas[0], current_frequency_toas[1], current_frequency_toas[2], current_frequency_toas[3]); currently_located_positions[frequency_to_locate].y = currently_located_positions[frequency_to_locate].y; } } //cached_signal_vis_samples = signal_analyzer_.get_signal_samples_for(17000); if(show_times) { unsigned elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::high_resolution_clock::now() - start).count(); std::cout << "Time for TDOAtion: " << elapsed_time << std::endl; start = std::chrono::high_resolution_clock::now(); } if (found_positions) { ++locator_frame_counter_; cached_located_positions.clear(); for (auto const& currently_located_position_entry : currently_located_positions) { glm::vec2 accumulated_position = glm::vec2(0.0, 0.0); //glm::temp_pos = glm::vec2(0.0, 0.0); cached_located_positions[currently_located_position_entry.first] = std::make_pair( locator_frame_counter_ , currently_located_position_entry.second); cached_positions[currently_located_position_entry.first][locator_frame_counter_ % cached_positions[currently_located_position_entry.first].size()] = std::make_pair(locator_frame_counter_,currently_located_position_entry.second); unsigned normalization_counter = 0; std::vector< float > valid_x_pos; std::vector< float > valid_y_pos; for (auto const& glm_vec : cached_positions[currently_located_position_entry.first]) { if (locator_frame_counter_ - glm_vec.first < cached_positions[currently_located_position_entry.first].size()) { valid_x_pos.push_back(glm_vec.second.x); valid_y_pos.push_back(glm_vec.second.y); std::sort(valid_x_pos.begin(), valid_x_pos.end()); std::sort(valid_y_pos.begin(), valid_y_pos.end()); accumulated_position += glm_vec.second ; ++normalization_counter; } //temp_pos = glm_vec * 2.0f; //accumulated_position += temp_pos; } //float median_x = valid_x_pos[valid_x_pos.size()/2.0]; //float median_y = valid_y_pos[valid_y_pos.size()/2.0]; accumulated_position /= normalization_counter; //accumulated_position.x = median_x; //accumulated_position.y = median_y; cached_located_positions[currently_located_position_entry.first] = std::make_pair( locator_frame_counter_ , accumulated_position); } position_mutex.lock(); located_positions = cached_located_positions; position_mutex.unlock(); } if(request_vis_vectors_) { cached_signal_vis_samples = signal_analyzer_.getSignalSamples(); signal_vis_samples_mutex.lock(); signal_vis_samples = cached_signal_vis_samples; signal_vis_samples_mutex.unlock(); cached_recognized_vis_sample_pos = signal_analyzer_.getVisSamplePos(); recognized_vis_sample_pos_mutex.lock(); recognized_vis_sample_pos = cached_recognized_vis_sample_pos; recognized_vis_sample_pos_mutex.unlock(); cached_peak_sample_indices_ = signal_analyzer_.getRawPeakIndices(); peak_sample_indices_mutex.lock(); peak_sample_indices_ = cached_peak_sample_indices_; peak_sample_indices_mutex.unlock(); if(show_times) { elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::high_resolution_clock::now() - start).count(); std::cout << "Time for rest: " << elapsed_time << std::endl; elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::high_resolution_clock::now() - start_loop).count(); std::cout << "Time for Locator: " << elapsed_time << std::endl; } } } signal_analyzer_.shutdown(); // stop recording loop recorder_.shutdown(); recording_thread.join(); }
Soprano::StorageModel* Soprano::Virtuoso::BackendPlugin::createModel( const BackendSettings& settings ) const { // for now we only support connecting to a running virtuoso instance QString host = valueInSettings( settings, BackendOptionHost ).toString(); int port = valueInSettings( settings, BackendOptionPort ).toInt(); QString uid = valueInSettings( settings, BackendOptionUsername ).toString(); QString pwd = valueInSettings( settings, BackendOptionPassword ).toString(); QString path = valueInSettings( settings, BackendOptionStorageDir ).toString(); bool debugMode = valueInSettings( settings, BackendOptionUser, QLatin1String( "debugmode" ) ).toBool(); int queryTimeout = valueInSettings( settings, QLatin1String( "QueryTimeout" ), 0 ).toInt(); bool disableStatementSignals = valueInSettings( settings, QLatin1String( "noStatementSignals" ), false ).toBool(); bool enableFakeBookleans = valueInSettings( settings, QLatin1String( "fakeBooleans" ), true ).toBool(); bool enableEmptyGraphs = valueInSettings( settings, QLatin1String( "emptyGraphs" ), true ).toBool(); VirtuosoController* controller = 0; QString virtuosoVersion = QLatin1String("1.0.0"); // a default low version in case we connect to a running server if ( host.isEmpty() && port == 0 && uid.isEmpty() && pwd.isEmpty() ) { if ( path.isEmpty() ) { setError( "Need a database storage path set to start a local Virtuoso instance." ); return 0; } const QString virtuosoExe = locateVirtuosoBinary(); if ( virtuosoExe.isEmpty() ) { setError( "Unable to find the Virtuoso binary." ); return 0; } virtuosoVersion = determineVirtuosoVersion(virtuosoExe); if ( virtuosoVersion.isEmpty() ) { setError( QString::fromLatin1("Failed to determine version of Virtuoso binary at %1").arg(virtuosoExe) ); return 0; } // start local server controller = new VirtuosoController(); if ( !controller->start( virtuosoExe, settings, debugMode ? VirtuosoController::DebugMode : VirtuosoController::NoFlags ) ) { setError( controller->lastError() ); delete controller; return 0; } host = QLatin1String("localhost"); port = controller->usedPort(); uid = QLatin1String("dba"); pwd = QLatin1String("dba"); } #ifdef Q_OS_WIN const QString odbcDriver = QLatin1String( "{Virtuoso (Open Source)}" ); #else const QString odbcDriver = findVirtuosoDriver(); if ( odbcDriver.isEmpty() ) { setError( "Could not find Virtuoso ODBC driver" ); return 0; } #endif const QString connectString = QString::fromLatin1( "host=%1:%2;uid=%3;pwd=%4;driver=%5" ) .arg( host, QString::number( port ), uid, pwd, odbcDriver ); QStringList connectionSetupCommands; if ( queryTimeout > 1000 ) { connectionSetupCommands << QString::fromLatin1( "set result_timeout=%1" ).arg( queryTimeout ); } ODBC::ConnectionPool* connectionPool = new ODBC::ConnectionPool( connectString, connectionSetupCommands ); // FIXME: should configuration only be allowed on spawned servers? if ( ODBC::Connection* conn = connectionPool->connection() ) { DatabaseConfigurator configurator( conn ); configurator.configureServer( settings ); delete conn; } else { qDebug() << Q_FUNC_INFO << "Failed to connect to" << connectString; delete connectionPool; return 0; } VirtuosoModel* model = new VirtuosoModel( virtuosoVersion, connectionPool, enableFakeBookleans, enableEmptyGraphs, this ); model->d->m_noStatementSignals = disableStatementSignals; // mem mangement the ugly way // FIXME: improve if ( controller ) { controller->setParent( model ); connect(controller, SIGNAL(stopped(Soprano::VirtuosoController::ExitStatus)), model, SLOT(slotVirtuosoStopped(Soprano::VirtuosoController::ExitStatus))); } // HACK: Ideally we need a better way of communicating what parameters have been set emit virtuosoInitParameters( port, virtuosoVersion ); return model; }