📄 startup.cpp
字号:
/*** *** See the file "L2_RTI_EO1/disclaimers-and-notices-L2.txt" for *** information on usage and redistribution of this file, *** and for a DISCLAIMER OF ALL WARRANTIES. ***/#include "RTITask.hpp"#include "L2Task.hpp"#include "LogTask.hpp"#include "TimerTask.hpp"#include <api/livingstone.h>#include <readers/from_any.h> // to get the file type#include "Logging.hpp"#include "ExceptionAction.hpp"#include <ioLib.h>void startRTI( CONFIG& config ) { RTITask RTITask; RTITask.listenForMonitorEvents();}/** A substitute for L2_parameters::print(). */static void print(const L2_parameters& l2_parameters) { // Where the search parameters should be logged const Logging::logType logStream = Logging::L2_DEBUG; // A buffer to be used several times char message[MAX_MSG_LENGTH]; Logging::log(logStream, "Startup:: Search settings"); sprintf(message, " Search type = %s", l2_parameters.get_search_style_str().c_str()); Logging::log(logStream, message); if (l2_parameters.get_search_style() == Tracker::cbfs) { sprintf(message, " Max candidates returned = %i", l2_parameters.get_cbfs_max_candidates()); Logging::log(logStream, message); sprintf(message, " Max candidates searched = %i", l2_parameters.get_cbfs_search_space()); Logging::log(logStream, message); sprintf(message, " Max candidate classes = %i", l2_parameters.get_cbfs_max_candidate_classes()); Logging::log(logStream, message); sprintf(message, " Max rank = %i", l2_parameters.get_cbfs_max_rank()); Logging::log(logStream, message); } else if (l2_parameters.get_search_style()==Tracker::cover) { sprintf(message, " Max rank = %i", l2_parameters.get_cover_max_rank()); Logging::log(logStream, message); } const unsigned historyLength = l2_parameters.get_history(); if (historyLength > 0) { sprintf(message, " History length = %i", historyLength); } else { strcpy(message, " History length = unlimited"); } Logging::log(logStream, message); Logging::log(logStream, ""); // forces a newline sprintf(message, " Max candidates tracked = %i", l2_parameters.get_max_truncated_candidates()); Logging::log(logStream, message); sprintf(message, " Progress style = %s", l2_parameters.get_progress_style_str().c_str()); Logging::log(logStream, message); sprintf(message, " Find Candidates style = %s", l2_parameters.get_find_candidates_style_str().c_str()); Logging::log(logStream, message); Logging::log(logStream, "------------------------------");}/** A substitute for Livingstone::print_search_parameters(). */static void printSearchParameters(const Livingstone& livingstone) { char message[MAX_MSG_LENGTH]; const char* fileType = livingstone.getReader().getFiletype().c_str(); const char* formatString = (strlen(fileType) == 0) ? "Startup:: Read `%s'%s\n" : "Startup:: Read `%s' (%s format)\n"; sprintf(message, formatString, livingstone.get_filename().c_str(), fileType); Logging::log(Logging::L2_DEBUG, message); print(*(livingstone.get_parameters()));}void initializeLivingstoneEngine(Livingstone& livingstone) { const char* const modelFilePathname = "ramdisk:\\livmdl00.bin"; livingstone.set_filename(modelFilePathname); const MBA_string& modelFile = livingstone.get_filename(); from_any::FileType type = from_any::discover_file_type(modelFile); char rmfMessage[MAX_MSG_LENGTH]; sprintf(rmfMessage, "Startup:: Reading model file(s): %s%s\n", modelFile.c_str(), ((type == from_any::xmpl) ? ".{xmpl,hrn,ini}" : "")); Logging::log(Logging::L2_DEBUG, rmfMessage); if (!livingstone.read_file()) { ExceptionAction::L2FailureToReadModelFile(modelFile.c_str()); ExceptionAction::setModelLoadedIndicator(0); } else { Logging::log(Logging::L2_DEBUG, "Startup:: read_file succeeded\n"); ExceptionAction::setModelLoadedIndicator(1);#ifndef DISABLE_OPTIMIZER // optimize if requested if (livingstone.get_use_optimizer()) { if (!livingstone.verbose_optimizer()) { Logging::log(Loggin::L2_DEBUG, "Startup:: Optimizing model ...\n") } if (!livingstone.optimize()) { ExceptionAction::L2FailureToOptimizeModel(); } }#endif // create the tracker livingstone.create_tracker(); // load the model file if (!livingstone.initialize_tracker()) { ExceptionAction::L2FailureToCreateTracker(); } else { printSearchParameters(livingstone); } }}static int outputFd; // Redirection of Livingstone's stdout and stderr./** A substitute for L2_error_function. */extern "C" void L2_error_function(const char *xcp_name, const char *filename, unsigned linenum) { cerr << xcp_name << " at " << filename << ':' << linenum << endl; ioctl(outputFd, FIOFLUSH, 0); // Force flushing out to file. close(outputFd); outputFd = 0; #if DEBUG_LEVEL==3 char message[MAX_MSG_LENGTH]; sprintf(message, "%s at %s: %u\n", xcp_name, filename, linenum); Logging::log(Logging::L2_ERROR, message); #endif exit(1);}void startLivingstone( CONFIG* configPtr ) { if (outputFd) { // Just incase the Livingstone and the logging task have crashed before // closing the L2int.err file because there are only so many file // descriptors that can be open at onetime. ioctl(outputFd, FIOFLUSH, 0); // Force flushing out to file. close(outputFd); } outputFd = creat("ramdisk:\\L20.int", O_WRONLY); ioTaskStdSet(0, 1, outputFd); // Standard output ioTaskStdSet(0, 2, outputFd); // Standard error reset_memory_flag(); // Initialize memory for Livingstone. Livingstone livingstone; initializeLivingstoneEngine(livingstone); L2Task dispatcher(livingstone); dispatcher.dequeueRealTimeInput(); ioctl(outputFd, FIOFLUSH, 0); // Force flushing out to file. close(outputFd); outputFd = 0;}void startLogging( CONFIG* configPtr ) { LogTask logTask; logTask.processLogEvents();}void startTimer( CONFIG* configPtr ) { TimerTask();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -