void HttpInterface::evReset(HttpRequest* req, strings& args) { for (NodesMap::iterator descIt = nodes.begin(); descIt != nodes.end(); ++descIt) { bool ok; nodeId = getNodeId(descIt->second.name, 0, &ok); if (!ok) continue; string nodeName = WStringToUTF8(descIt->second.name); Reset(nodeId).serialize(asebaStream); // reset node asebaStream->flush(); Run(nodeId).serialize(asebaStream); // re-run node asebaStream->flush(); if (nodeName.find("thymio-II") == 0) { strings args; args.push_back("motor.left.target"); args.push_back("0"); sendSetVariable(nodeName, args); args[0] = "motor.right.target"; sendSetVariable(nodeName, args); } size_t eventPos; if (commonDefinitions.events.contains(UTF8ToWString("reset"), &eventPos)) { strings data; data.push_back("reset"); sendEvent(nodeName,data); } finishResponse(req, 200, ""); } }
// Utility: request update of all variables, used for variable caching void HttpInterface::updateVariables(const std::string nodeName) { strings all_variables; for(VariablesMap::iterator it = allVariables[nodeName].begin(); it != allVariables[nodeName].end(); ++it) all_variables.push_back(WStringToUTF8(it->first)); sendGetVariables(nodeName, all_variables); }
int wmain(int argc, wchar_t* argv[]) { if (argc < 2) { std::cout << "Data path argument not set, test run failed\n"; return 1; } g_datapath = WStringToUTF8(argv[1]); std::locale::global(boost::locale::generator().generate("")); return UnitTest::RunAllTests(); }
// Incoming User Messages void HttpInterface::incomingUserMsg(const UserMessage *userMsg) { if (verbose) cerr << "incomingUserMsg msg ("<< userMsg->type <<","<< &userMsg->data <<")" << endl; // skip if event not known (yet, aesl probably not loaded) try { commonDefinitions.events.at(userMsg->type); } catch (const std::out_of_range& oor) { return; } if (commonDefinitions.events[userMsg->type].name.find(L"R_state")==0) { // update variables } if (eventSubscriptions.size() > 0) { // set up SSE message std::stringstream reply; string event_name = WStringToUTF8(commonDefinitions.events[userMsg->type].name); reply << "data: " << event_name; for (size_t i = 0; i < userMsg->data.size(); ++i) reply << " " << userMsg->data[i]; reply << "\r\n\r\n"; // In the HTTP world we set up a stream of Server-Sent Events for this. // Note that event name is in commonDefinitions.events[userMsg->type].name for (StreamEventSubscriptionMap::iterator subscriber = eventSubscriptions.begin(); subscriber != eventSubscriptions.end(); ++subscriber) { if (subscriber->second.count("*") >= 1 || subscriber->second.count(event_name) >= 1) { appendResponse(subscriber->first, 200, true, reply.str().c_str()); } } } }
void Viewer::UpdateImageInformation() { if (m_statusBar == nullptr) { return; } if (ViewportMode() == SM_Fullscreen) { m_statusBar->Show(false); return; } Img::Image::Ptr image(m_viewPort.Image()); m_statusBar->SetStatusText(UII_LoadProgress(image), StatusProgress); m_statusBar->SetStatusText(UII_ImageResolution(image), StatusResolution); SetTitle(wxString::FromUTF8(((image ? IO::GetFile(m_cacher.CurrentImageFilename()) + " - ":"") + WStringToUTF8(AppTitle)).c_str())); if (image == nullptr) { for (int i = 0; i < StatusNumParts; ++i) { m_statusBar->SetStatusText("", 0); } } else { m_statusBar->SetStatusText(IO::GetFile(m_cacher.CurrentImageFilename()), StatusName); m_statusBar->SetStatusText(ToAString(m_cacher.CurrentImageIndex() + 1) + "\\" + ToAString(m_cacher.ImageCount()), StatusPosition); m_statusBar->SetStatusText(UII_MemoryUsage(m_cacher.CurrentImageFileSize()), StatusFileSize); if (image->IsHeaderInformationValid() == false && image->IsFinished()) { m_statusBar->SetStatusText("", StatusZoom); } else { m_statusBar->SetStatusText(ToAString(RoundCast(m_viewPort.ZoomLevel() * 100.0f)) + "%", StatusZoom); m_statusBar->SetStatusText(UII_LastModified(m_cacher.CurrentImageLastModifiedDate()), StatusLastModified); } } }
void HttpInterface::evNodes(HttpRequest* req, strings& args) { bool do_one_node(args.size() > 0); std::stringstream json; json << (do_one_node ? "" : "["); for (NodesMap::iterator descIt = nodes.begin(); descIt != nodes.end(); ++descIt) { const Node& description(descIt->second); string nodeName = WStringToUTF8(description.name); json << "{"; json << "\"name\":\"" << nodeName << "\",\"protocolVersion\":" << description.protocolVersion; if (do_one_node) { json << ",\"bytecodeSize\":" << description.bytecodeSize; json << ",\"variablesSize\":" <<description.variablesSize; json << ",\"stackSize\":" << description.stackSize; // named variables json << ",\"namedVariables\":{"; bool seen_named_variables = false; for (NodeNameVariablesMap::const_iterator n(allVariables.find(nodeName)); n != allVariables.end(); ++n) { VariablesMap vm = n->second; for (VariablesMap::iterator i = vm.begin(); i != vm.end(); ++i) { json << (i == vm.begin() ? "" : ",") << "\"" << WStringToUTF8(i->first) << "\":" << i->second.second; seen_named_variables = true; } } if ( ! seen_named_variables ) { // failsafe: if compiler hasn't found any variables, get them from the node description for (vector<Aseba::TargetDescription::NamedVariable>::const_iterator i(description.namedVariables.begin()); i != description.namedVariables.end(); ++i) json << (i == description.namedVariables.begin() ? "" : ",") << "\"" << WStringToUTF8(i->name) << "\":" << i->size; } json << "}"; // local events variables json << ",\"localEvents\":{"; for (size_t i = 0; i < description.localEvents.size(); ++i) { string ev(WStringToUTF8(description.localEvents[i].name)); json << (i == 0 ? "" : ",") << "\"" << ev << "\":" << "\"" << WStringToUTF8(description.localEvents[i].description) << "\""; } json << "}"; // constants from introspection json << ",\"constants\":{"; for (size_t i = 0; i < commonDefinitions.constants.size(); ++i) json << (i == 0 ? "" : ",") << "\"" << WStringToUTF8(commonDefinitions.constants[i].name) << "\":" << commonDefinitions.constants[i].value; json << "}"; // events from introspection json << ",\"events\":{"; for (size_t i = 0; i < commonDefinitions.events.size(); ++i) json << (i == 0 ? "" : ",") << "\"" << WStringToUTF8(commonDefinitions.events[i].name) << "\":" << commonDefinitions.events[i].value; json << "}"; } json << "}"; } json <<(do_one_node ? "" : "]"); finishResponse(req,200,json.str()); }
bool DropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames) { //SetImageLocation(WStringToUTF8(reinterpret_cast<wchar_t*>(pcds->lpData))); m_viewer->SetImageLocation(WStringToUTF8(filenames[0].c_str().AsWChar())); return true; }
int wmain(int argc, wchar_t* argv[]) { if (argc < 3) { OutputString("Error: Bad params.\nStresser.exe CACHER|FOLDER|FULL PATH"); return EXIT_FAILURE; } g_runner.reset(new ThreadRunner); auto test = boost::locale::to_upper(WStringToUTF8(argv[1])); wchar_t wfullPath[MAX_PATH]; GetFullPathName( argv[2], MAX_PATH, wfullPath, 0); auto fullPath = WStringToUTF8(wfullPath); auto path = IO::GetPath(fullPath + "\\"); OutputString("Setting up ..."); // FIXME: Cacher test didn't like it when these lines were missing copyFiles(path + "a\\", path + "d\\"); copyFiles(path + "b\\", path + "e\\"); auto numThreads = std::max<unsigned int>(2, std::thread::hardware_concurrency()); OutputString("Processor count : " + ToAString(numThreads)); if (test == "CACHER") { OutputString("Cacher-only test"); prepareCacherTest(path); } else if (test == "FOLDER") { OutputString("Folder-only test"); prepareFolderTest(path); } else if (test == "FULL") { OutputString("Full test"); prepareCacherTest(path); prepareFolderTest(path); } OutputString("Starting threads, press Enter to quit ..."); g_runner->Run(); for (;;) { if(_kbhit()) { int c = _getch(); if(c == '\n' || c=='\r') break; } if(!g_run) break; Sleep(100); } g_runner->Terminate(); g_runner.reset(); if(!g_run) { std::cout << "Some sort of error occurred. Press enter to terminate.\n"; std::cin.get(); } return EXIT_SUCCESS; }