bool NavKeyedDataHandler:: handleGetKeyedData( LangTypes::language_t language, NavRequestPacket* pack, NavReplyPacket* reply ) try { if ( !checkExpectations( pack->getParamBlock(), reply ) ) { return false; } MC2String key; uint32 crc; bool sentCRC; getParameters( pack->getParamBlock(), key, crc, sentCRC ); logParameters( key, language, crc, sentCRC); vector<byte> data; getDataForKey( key, language, data ); uint32 newCrc = MC2CRC32::crc32( &data.front(), data.size() ); if ( !sentCRC || crc != newCrc ) { NParamBlock& rparams = reply->getParamBlock(); rparams.addParam( NParam( 6101, newCrc ) ); addDataAsParams( rparams, data ); } return true; } catch ( const MC2Exception& e ) { mc2log << warn << "handleGetKeyedData: " << e.what() << endl; reply->setStatusCode( NavReplyPacket::NAV_STATUS_NOT_OK ); return false; }
int parseKeyboardProperties (KeyboardProperties *properties, const char *string) { enum { KBD_PARM_TYPE, KBD_PARM_VENDOR, KBD_PARM_PRODUCT }; static const char *const names[] = {"type", "vendor", "product", NULL}; char **parameters = getParameters(names, NULL, string); int ok = 1; logParameters(names, parameters, "Keyboard Property"); *properties = anyKeyboard; if (*parameters[KBD_PARM_TYPE]) { static const KeyboardType types[] = {KBD_TYPE_Any, KBD_TYPE_PS2, KBD_TYPE_USB, KBD_TYPE_Bluetooth}; static const char *choices[] = {"any", "ps2", "usb", "bluetooth", NULL}; unsigned int choice; if (validateChoice(&choice, parameters[KBD_PARM_TYPE], choices)) { properties->type = types[choice]; } else { logMessage(LOG_WARNING, "invalid keyboard type: %s", parameters[KBD_PARM_TYPE]); ok = 0; } } if (*parameters[KBD_PARM_VENDOR]) { static const int minimum = 0; static const int maximum = 0XFFFF; int value; if (validateInteger(&value, parameters[KBD_PARM_VENDOR], &minimum, &maximum)) { properties->vendor = value; } else { logMessage(LOG_WARNING, "invalid keyboard vendor code: %s", parameters[KBD_PARM_VENDOR]); ok = 0; } } if (*parameters[KBD_PARM_PRODUCT]) { static const int minimum = 0; static const int maximum = 0XFFFF; int value; if (validateInteger(&value, parameters[KBD_PARM_PRODUCT], &minimum, &maximum)) { properties->product = value; } else { logMessage(LOG_WARNING, "invalid keyboard product code: %s", parameters[KBD_PARM_PRODUCT]); ok = 0; } } deallocateStrings(parameters); return ok; }
int main(int argc, char** argv) { EBOFConfig cfg; if(init(argc, argv, cfg)) return 1; // If help, fnc returns 1 logParameters(cfg); // Buffers auto eventQueue = std::make_shared<QueueT<Event>>(); auto eventSliceQueue = std::make_shared<QueueT<EventSlice::Ptr>>(); auto flowSliceQueue = std::make_shared<QueueT<FlowSlice::Ptr>>(); // Startup EventReader<QueueT<Event>> eventReader; eventReader.setOutputBuffer(eventQueue); eventReader.setURI(cfg.fn_input); Quantizer<QueueT> quantizer(cfg.timeSliceDuration); quantizer.setInputBuffer(eventQueue); quantizer.setOutputBuffer(eventSliceQueue); auto factory = std::make_unique<FilterFactory>(cfg.t0, cfg.tk, cfg.timeResolution, cfg.spatialRange, cfg.spatialRange); auto padder = std::make_unique<FourierPadder>(cfg.dataSize, cfg.filterSize); auto transformer = std::make_unique<FourierTransformerFFTW>(padder->fourierSizeRows_, padder->fourierSizeCols_); FilteringEngineCPU<QueueT, QueueT> engine(std::move(factory), std::move(padder), std::move(transformer)); engine.setInputBuffer(eventSliceQueue); engine.setOutputBuffer(flowSliceQueue); for(auto angle : cfg.filterAngles) { engine.addFilter(angle); } FlowSinkProcessor<QueueT> sink; sink.setInputBuffer(flowSliceQueue); auto ebfloWriter = std::make_unique<TaskWriteFlowSlice<OutputPolicyBinary> >(); ebfloWriter->setFilePath(cfg.fn_path); sink.addTask(std::move(ebfloWriter)); // Start Processing LOG(INFO) << "Initialization completed"; LOG(INFO) << "Processing..."; auto timer = std::make_shared<boost::timer::auto_cpu_timer>(); if(eventReader.startPublishing()) { // TODO handle keyboard interrupts while(eventReader.isPublishing() || !eventQueue->empty()) { quantizer.process(); engine.process(); } } timer.reset();//trigger time printing LOG(INFO) << "Processing finished. Completed " << flowSliceQueue->size() << " FlowSlices!"; if(!cfg.fn_path.empty()) { FlowSinkProcessor<QueueT> sink; sink.setInputBuffer(flowSliceQueue); auto ebfloWriter = std::make_unique<TaskWriteFlowSlice<OutputPolicyBinary> >(); ebfloWriter->setFilePath(cfg.fn_path); sink.addTask(std::move(ebfloWriter)); sink.start(); while(!flowSliceQueue->empty()) { std::this_thread::sleep_for(std::chrono::seconds(1)); } sink.stop(); } eventReader.stopPublishing(); return 0; }