EventData Communicator::postEvent(const QString &subject, const QString &event, const Security &security, const QDateTime &dt, const EventProperties &props, const QString &journal) { QVariantList params = authParams(); if (params.size() == 0) EventData(); // Modify params by adding the item id. QMap<QString, QVariant> param = params.takeAt(0).toMap(); // Make sure we use utf-8 encoded strings in response. param["ver"] = 1; param["subject"] = subject; param["event"] = event; param["year"] = dt.date().year(); param["mon"] = dt.date().month(); param["day"] = dt.date().day(); param["hour"] = dt.time().hour(); param["min"] = dt.time().minute(); param["usejournal"] = journal; param["props"] = props.data(); param["security"] = security.selectedMajorLJName(); if (security.type() == Security::UseMask) { param["allowmask"] = security.mask(); } params.push_back(param); request("LJ.XMLRPC.postevent", params); std::auto_ptr<QBuffer> buffer(m_responses.take(m_currentRequestId)); QByteArray buf = buffer->buffer(); return EventData(buf); }
void onDataReceived( lua_State *st, Module *module, const std::string &val, int socketID) { EventImpl event; event["class"] = EventData(st, "tcp"); event["type"] = EventData(st, "data"); event["connection"] = EventData(st, boost::lexical_cast<std::string>(socketID)); event["value"] = EventData(st, val); module->dispatchIn( &event ); }
bool pushErrorEvent() { Mutex::ScopedLock lock(sharedData->mutex); if(sharedData->sock) { sharedData->sock->OnError.pushToMainQueue(EventData(sharedData->sock)); return true; } return false; }
void test1() { std::cout << "FrontPanelTest test 1" << std::endl; int frontPanelI2Cport = (SETTINGS.GetInt(HARDWARE_REV) == 0) ? I2C2_PORT : I2C1_PORT; FrontPanel fp(FP_SLAVE_ADDRESS, frontPanelI2Cport); PrinterStatus ps; ps._numLayers = 100; ps._currentLayer = 30;; ps._estimatedSecondsRemaining = 4380; ps._errorCode = NoImageForLayer; ps._change = NoChange; ps._UISubState = NoUISubState; PrintEngineState pes = PrinterOnState; int iter = 1; srand (time(NULL)); // seed the random number generator // do forever for(;;) { ps._state = pes; ps._errno = iter; ((ICallback*)&fp)->Callback(PrinterStatusUpdate, EventData(ps)); // read the front panel buttons while screen is being drawn // wait 10 to 500 ms first int delayMs = rand() % 490 + 10; usleep(delayMs * 1000); unsigned char btns = fp.Read(BTN_STATUS); if (btns == 0xFF) { std::cout << "Error reading buttons when state = " << STATE_NAME(pes) << " delay = " << delayMs << std::endl; } else { btns &= 0xF; if (btns != 0) std::cout << "Buttons pressed: " << (int)btns << std::endl; } pes = (PrintEngineState)(1 + (int) pes); if (pes >= MaxPrintEngineState) { pes = PrinterOnState; ++iter; } } }
EventDataVec GPIO_Interrupt::Read() { char buffer; EventDataVec eventData; lseek(_fd, 0, SEEK_SET); if (read(_fd, &buffer, 1) == 1) eventData.push_back(EventData(buffer)); return eventData; }
MutateAlign::MutateAlign(const mxArray* seqarr, const mxArray* evarr, AlignParams& par) : params(par), sequence(seqarr) { // how many sequences? this->NumEvents = mxGetNumberOfElements(evarr); // initialize all the events and models for (int i=0; i<NumEvents; i++) events.push_back(EventData(evarr,i)); // and create the alignments and stuff for (int i=0; i<NumEvents; i++) alignments.push_back(Alignment(events[i],sequence,params)); }
int handle() { if(GetAddrFromNameAsync_Internal(addr_name.c_str(), address.get())) { // TODO: we use default DNS record expire time of 1 hour, we should include some DNS client to make it in correct way AddToDnsCache(addr_name, NetworkAddr(NetAddrInternal(*address.get()))); } // TODO: handle failures here? there should be, but we only have the valid field // For now, we leave it at false, so the timeout handling will just occur. // push a net event onDnsReady.pushToMainQueue(EventData()); Mutex::ScopedLock l(PendingDnsQueriesMutex); PendingDnsQueries.erase(addr_name); return 0; }
int postEvent( lua_State *st, bool /*isOut*/, int eventPos ) { // Get event module from stack Module *module = Module::get( st ); if (!module) { return luaL_error( st, "[event::ncl] Invalid event module" ); } EventImpl table; lua_pushnil(st); // First key while (lua_next(st, eventPos) != 0) { const char *key=lua_tostring(st,-2); table[key] = EventData(st); } // Dispatch table to user dispatchUser( module, &table ); lua_pushboolean( st, 1 ); return 1; }
// Read one new-line or null delimited message from the named pipe EventDataVec CommandPipe::Read() { char buffer; EventDataVec eventData; std::string command; lseek(_readFd, 0, SEEK_SET); while (read(_readFd, &buffer, 1) == 1) { if (buffer == '\n' || buffer == '\0') break; else command.push_back(buffer); } eventData.push_back(EventData(command)); return eventData; }
OXSXDataSet DataSetIO::LoadDataSet(const std::string& filename_){ // Get Data Set H5::H5File file(filename_, H5F_ACC_RDONLY); H5::DataSet dataSet = file.openDataSet("observations"); // read meta information unsigned nObs = 0; H5::Attribute nameAtt = dataSet.openAttribute("observed_quantities"); H5::Attribute countAtt = dataSet.openAttribute("n_observables"); H5std_string strreadbuf(""); nameAtt.read(nameAtt.getDataType(), strreadbuf); countAtt.read(countAtt.getDataType(), &nObs); // Read data out as 1D array hsize_t nData = 0; dataSet.getSpace().getSimpleExtentDims(&nData, NULL); size_t nEntries = nData/nObs; std::vector<double> flatData(nData, 0); dataSet.read(&flatData.at(0), H5::PredType::NATIVE_DOUBLE); assert(nData%nObs == 0); // logic error in writing file (this class!) if assert fails. // Assemble into an OXSX data set OXSXDataSet oxsxDataSet; // Set the variable names oxsxDataSet.SetObservableNames(UnpackString(strreadbuf, fDelimiter)); // then the data std::vector<double> oneEventObs(nObs, 0); for(size_t i = 0; i < nEntries; i++){ for(size_t j = 0; j < nObs; j++) oneEventObs[j] = flatData.at(i * nObs + j); oxsxDataSet.AddEntry(EventData(oneEventObs)); } return oxsxDataSet; }
void test1() { std::cout << "NetworkIFUT test 1" << std::endl; // delete the named pipe used for Web status, if it exists if (access(STATUS_TO_WEB_PIPE, F_OK) != -1) remove(STATUS_TO_WEB_PIPE); // create the named pipe used for Web status _before_ constructing // the NetworkINterface mkfifo(STATUS_TO_WEB_PIPE, 0666); NetworkInterface net; // open the named pipes used for pushed status _pPushedStatusPipe = fopen(STATUS_TO_WEB_PIPE, "r+"); // open the file used to pull printer status _pPrinterStatusFile = fopen(PRINTER_STATUS_FILE, "w+"); // set some printer status PrinterStatus ps; ps._state = PrintingLayerState; ps._temperature = 3.14159; // send it in an update event to a NetworkInterface ((ICallback*)&net)->Callback(PrinterStatusUpdate, EventData(ps)); // check the automatically pushed status if (!ExpectedStatus(STATE_NAME(PrintingLayerState), "3.14159", _pPushedStatusPipe)) { std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find first expected printer state and temperature" << std::endl; mainReturnValue = EXIT_FAILURE; } // and the pullable status if (!ExpectedStatus(STATE_NAME(PrintingLayerState), "3.14159", _pPrinterStatusFile)) { std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find first expected printer state and temperature again" << std::endl; mainReturnValue = EXIT_FAILURE; } ps._state = HomingState; ps._temperature = 42; // check status again (should not have changed) if (!ExpectedStatus(STATE_NAME(PrintingLayerState), "3.14159", _pPrinterStatusFile)) { std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find unchanged printer state and temperature" << std::endl; mainReturnValue = EXIT_FAILURE; } // send an update event with the new status ((ICallback*)&net)->Callback(PrinterStatusUpdate, EventData(ps)); // check the automatically pushed status if (!ExpectedStatus(STATE_NAME(HomingState), "42", _pPushedStatusPipe)) { std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find new printer state and temperature" << std::endl; mainReturnValue = EXIT_FAILURE; } // and the pullable status if (!ExpectedStatus(STATE_NAME(HomingState), "42", _pPrinterStatusFile)) { std::cout << "%TEST_FAILED% time=0 testname=test1 (NetworkIFUT) message=failed to find new printer state and temperature again" << std::endl; mainReturnValue = EXIT_FAILURE; } }
void Compiler::feed(const char *buf){ if(lana->debugFlags & LDEBUG_SHOW) lana->dprintf("feed: %s",buf); // output src file and line if in debug mode generateDebugInstructions(false); if(lastLine) free(lastLine); lastLine = strdup(buf); try{ tok->reset(buf); cg->saveSnapshot(); // record where we are in case we need to rewind because of a parse error scanStmt(); // terminate and execute if we're not compiling, otherwise we just add to the function. if(!cg->isCompiling()) { // terminate the sequence cg->emit(OP_END); // get the codegen area Growable *g = cg->getCode(); int size = g->getOffset()/sizeof(instruction); instruction *p = (instruction *)g->get(0,sizeof(instruction)); if(lana->debugFlags & LDEBUG_RECREATE){ char *t = lana->recreate(p,ses); printf("RECREATED:\n***\n%s\n***\n",t); free(t); } // notify any listener eventMgr->notify(COMMAND_PARSED, EventData(p)); if(!(lana->opFlags & LOP_NORUN)){ // if we want to run the code... if(lana->debugFlags & LDEBUG_TRACE) printf("EXECUTE and clear\n"); lana->vm->interpret(p,ses); Value *v = lana->vm->popvalnoexception(); if(v){ printf("%s\n",v->getStr()); } } if(lana->debugFlags & LDEBUG_DUMP){ printf("Dump of interpreter block:\n"); lana->dumpCode((instruction *)cg->current->code->get(0,sizeof(instruction)), cg->current->code->getOffset()/sizeof(instruction),ses); } cg->clear(); // all done with the code, clear it ready for more input } } catch(Exception &ex){ // rewind the code generator to before the broken bit cg->restoreSnapshot(); // printf("Error - recovered : %s\n",ex.what()); // rethrow throw; } lineNumber++; }
int postEvent( lua_State * st, bool /*isOut*/, int eventPos ) { Module *module = Module::get( st ); if (!module) { return luaL_error( st, "[event::tcp] Invalid event module" ); } const char *value = lua::getField( st, eventPos, "type" ); if (!value) { return luaL_error( st, "[event::tcp] Invalid type" ); } else if (strcmp(value,"connect") == 0) { const char *host = lua::getField( st, eventPos, "host" ); if (!host) { return luaL_error( st, "[event::tcp] Invalid host" ); } const char *port = lua::getField( st, eventPos, "port" ); if (!port) { return luaL_error( st, "[event::tcp] Invalid port" ); } EventImpl event; event["class"] = EventData(st, "tcp"); event["type"] = EventData(st, "connect"); event["host"] = EventData(st, host); event["port"] = EventData(st, port); util::id::Ident id; value = lua::getField( st, eventPos, "timeout" ); if (value) { id = module->connect( host, boost::lexical_cast<int>(port), boost::lexical_cast<util::DWORD>(value) ); } else { id = module->connect( host, boost::lexical_cast<int>(port) ); } if (util::id::isValid(id)) { event["connection"] = EventData(st, boost::lexical_cast<std::string>(id->getID())); } else { event["error"] = EventData(st, "Connection failed"); } module->dispatchIn( &event ); } else if (strcmp(value,"disconnect") == 0) { value = lua::getField( st, eventPos, "connection" ); if (!value) { return luaL_error( st, "[event::tcp] Invalid connection" ); } bool res = module->disconnect(boost::lexical_cast<util::id::ID_TYPE>(value)); if (!res) { return luaL_error( st, "[event::tcp] Invalid connection" ); } } else if (strcmp(value,"data") == 0) { bool result; // Get connection value = lua::getField( st, eventPos, "connection" ); if (!value) { return luaL_error( st, "[event::tcp] Invalid connection" ); } util::id::ID_TYPE conn=boost::lexical_cast<util::id::ID_TYPE>(value); // Get value value = lua::getField( st, eventPos, "value" ); if (!value) { return luaL_error( st, "[event::tcp] Invalid value" ); } std::string val=value; // Get timeout value = lua::getField( st, eventPos, "timeout" ); if (value) { result = module->send( conn, val, boost::lexical_cast<util::DWORD>(value) ); } else { result = module->send( conn, val ); } if (!result) { return luaL_error( st, "[event::tcp] Error, cannot send data: value=%s", val.c_str() ); } } else { return luaL_error( st, "[event::tcp] Invalid type: type=%s", value ); } return 1; }