00001
00008 #include <iostream>
00009
00010
00011 #include "SctApi.h"
00012 #include "SctApiDebug.h"
00013 #include "SctApiException.h"
00014
00015 using namespace SctApi;
00016
00017 Debug *Debug::instance = 0;
00018
00019 void Debug::setDebugOption(std::string opt) {
00020 if(find(debugList.begin(), debugList.end(), opt) == debugList.end()) {
00021
00022 if(find(debugOptionList.begin(), debugOptionList.end(), opt) != debugOptionList.end()) {
00023 debugList.push_back(opt);
00024 std::cout << "Option: " << opt << " set\n";
00025 } else {
00026 std::cout << "Option: " << opt << " not known\n";
00027 }
00028 }
00029 }
00030
00031 void Debug::unsetDebugOption(std::string opt) {
00032 if(find(debugList.begin(), debugList.end(), opt) != debugList.end()) {
00033 debugList.erase(find(debugList.begin(), debugList.end(), opt));
00034 }
00035 }
00036
00037 std::list<std::string> Debug::listEnabledDebugOptions() const{
00038 return debugList;
00039 }
00040
00041 std::vector<std::string> Debug::listDebugOptions() const{
00042 return debugOptionList;
00043 }
00044
00045 bool Debug::checkDebugOption(std::string opt) const{
00046 if(find(debugList.begin(), debugList.end(), opt) != debugList.end()) {
00047 return true;
00048 } else {
00049 return false;
00050 }
00051 }
00052
00053 bool Debug::checkDebugOption(DebugOptions intOpt) const{
00054 std::string opt = debugOptionList[intOpt];
00055
00056 return checkDebugOption(opt);
00057 }
00058
00059 void Debug::setupDebugOptions() {
00060 debugOptionList.resize(DEBUG_END_OPTIONS);
00061
00062 for(int i=0; i<DEBUG_END_OPTIONS; i++) {
00063 std::string name;
00064 switch(i) {
00065 case DEBUG_DIAG:
00066 name = "diag";
00067 break;
00068 case DEBUG_DIAG2:
00069 name = "diag2";
00070 break;
00071 case DEBUG_DUMP_PRIM_BINARY:
00072 name = "dump_prim_binary";
00073 break;
00074 case DEBUG_SAVE_PRIM:
00075 name = "save_prim";
00076 break;
00077 case DEBUG_VERBOSE_PROBE:
00078 name = "verbose_probe";
00079 break;
00080 case DEBUG_PRINT_IN_PRIM:
00081 name = "print_in_prim";
00082 break;
00083 case DEBUG_PRINT_OUT_PRIM:
00084 name = "print_out_prim";
00085 break;
00086 case DEBUG_DIAG_RESPONSE:
00087 name = "diag_response";
00088 break;
00089 case DEBUG_MODULE_CONFIG:
00090 name = "module_config";
00091 break;
00092 case DEBUG_PRINT_CALIB:
00093 name = "print_calib";
00094 break;
00095 case DEBUG_PRINT_RAW:
00096 name = "print_raw";
00097 break;
00098 case DEBUG_LOG_PRINT_PRIM:
00099 name = "log_print_prim";
00100 break;
00101 case DEBUG_EXTRA_DUMPS:
00102 name = "extra_dumps";
00103 break;
00104 case DEBUG_PRINT_UNKNOWN:
00105 name = "print_unknown";
00106 break;
00107 case DEBUG_BOC_SETUP:
00108 name = "boc_setup";
00109 break;
00110 case DEBUG_DUMP_RAW_EVENT:
00111 name = "dump_raw_event";
00112 break;
00113 case DEBUG_SAVE_HISTOGRAM:
00114 name = "save_histogram";
00115 break;
00116 case DEBUG_SAVE_RAW_CAPTURE:
00117 name = "save_raw_capture";
00118 break;
00119 case DEBUG_USE_RAW_PRIMITIVE:
00120 name = "use_raw_primitive";
00121 break;
00122 case DEBUG_SCAN_ERROR_TRAP:
00123 name = "scan_error_trap";
00124 break;
00125 case DEBUG_SCAN_ERROR_TRAP_ALL:
00126 name = "scan_error_trap_all";
00127 break;
00128 case DEBUG_SCAN_AUTO_STALL:
00129 name = "scan_auto_stall";
00130 break;
00131 case DEBUG_SCAN_STEP_MODE:
00132 name = "scan_step_mode";
00133 break;
00134 case DEBUG_SCAN_PAUSE_PULSE:
00135 name = "scan_pause_pulse";
00136 break;
00137 case DEBUG_SCAN_ROD_MODE_BITS:
00138 name = "scan_rod_mode_bits";
00139 break;
00140 case DEBUG_SCAN_USE_CCODE:
00141 name = "scan_use_ccode";
00142 break;
00143 case DEBUG_TIM_SCAN_STATUS:
00144 name = "tim_scan_status";
00145 break;
00146 case DEBUG_API_CONFIG_CACHE_CHECK:
00147 name = "api_config_cache_check";
00148 break;
00149 case DEBUG_API_CONFIG_CACHE_SEND:
00150 name = "api_config_cache_send";
00151 break;
00152 case DEBUG_API_CONFIG_NO_COPY:
00153 name = "api_config_no_copy";
00154 break;
00155 case DEBUG_CALIB_NO_SLINK:
00156 name = "calib_no_slink";
00157 break;
00158 case DEBUG_CALIB_RTR_STOP_OUTPUT:
00159 name = "calib_rtr_stop_output";
00160 break;
00161 default:
00162 std::cout << "Unexpected debug option (" << i << ") source code out of sync with itself\n";
00163 throw SctApiException("************ Failed to setup debug options (**************");
00164 }
00165
00166 debugOptionList[i] = name;
00167 }
00168 }
00169
00170 Debug *Debug::getInstance() {
00171 if(!instance) {
00172 instance = new Debug();
00173 }
00174
00175 return instance;
00176 }
00177
00178 Debug::Debug() {
00179 setupDebugOptions();
00180 }
00181