// ############################################################################################################## void jevois::Gadget::streamOff() { JEVOIS_TRACE(2); // Note: we allow for several streamOff() without complaining, this happens, e.g., when destroying a Gadget that is // not currently streaming. LDEBUG("Turning off gadget stream"); // Abort stream in case it was not already done, which will introduce some sleeping in our run() thread, thereby // helping us acquire our needed double lock: abortStream(); JEVOIS_TIMED_LOCK(itsMtx); // Stop streaming over the USB link: int type = V4L2_BUF_TYPE_VIDEO_OUTPUT; try { XIOCTL_QUIET(itsFd, VIDIOC_STREAMOFF, &type); } catch (...) { } // Nuke all our buffers: if (itsBuffers) { delete itsBuffers; itsBuffers = nullptr; } itsImageQueue.clear(); itsDoneImgs.clear(); LDEBUG("Gadget stream is off"); }
int w_check_rtcp_ipport(msg_t *msg) { int i = 0; miprtcp_t *mp = NULL; char ipptmp[256]; char callid[256]; snprintf(callid, sizeof(callid), "%.*s", msg->sip.callId.len, msg->sip.callId.s); for (i = 0; i < msg->sip.mrp_size; i++) { mp = &msg->sip.mrp[i]; if (mp->rtcp_ip.len > 0 && mp->rtcp_ip.s) { snprintf(ipptmp, sizeof(ipptmp), "%.*s:%d", mp->rtcp_ip.len, mp->rtcp_ip.s, mp->rtcp_port); LDEBUG("RTCP CALLID: %.*s", msg->sip.callId.len, msg->sip.callId.s); LDEBUG("RTCP IP PORT: %s", ipptmp); /* one pair = one timer */ if(!find_and_update(ipptmp, callid)) { add_timer(ipptmp); add_ipport(ipptmp, callid); } } } return 1; }
// ############################################################################################################## void jevois::Gadget::processEvents() { JEVOIS_TRACE(3); // Get the event from the driver: struct v4l2_event v4l2ev = { }; XIOCTL_QUIET(itsFd, VIDIOC_DQEVENT, &v4l2ev); struct uvc_event * uvcev = reinterpret_cast<struct uvc_event *>(&v4l2ev.u.data); // Prepare our response, if any will be sent: struct uvc_request_data resp = { }; resp.length = -EL2HLT; // Act according to the event type: try { switch (v4l2ev.type) { case UVC_EVENT_CONNECT: return; case UVC_EVENT_DISCONNECT: LDEBUG("EVENT DISCONNECT"); itsEngine->streamOff(); return; case UVC_EVENT_SETUP: LDEBUG("EVENT SETUP"); processEventSetup(uvcev->req, resp); return; case UVC_EVENT_DATA: LDEBUG("EVENT DATA"); processEventData(uvcev->data); return; case UVC_EVENT_STREAMON: LDEBUG("EVENT STREAMON"); itsEngine->streamOn(); return; case UVC_EVENT_STREAMOFF: LDEBUG("EVENT STREAMOFF"); itsEngine->streamOff(); return; } } catch (...) { } }
void VolumeSeriesSource::openSeries() { if(volumeHandle_) delete volumeHandle_; volumeHandle_ = 0; try { TextFileReader reader(filename_.get()); if (!reader) throw tgt::FileNotFoundException("Reading sdat file failed", filename_.get()); std::string type; std::istringstream args; std::string format, model; tgt::ivec3 resolution(0); tgt::vec3 sliceThickness(1.f); spreadMin_ = 0.f; spreadMax_ = 0.f; files_.clear(); std::string blockfile; while (reader.getNextLine(type, args, false)) { if (type == "ObjectFileName:") { std::string s; args >> s; LDEBUG(type << " " << s); files_.push_back(tgt::FileSystem::dirName(filename_.get()) + "/" + s); } else if (type == "Resolution:") { args >> resolution[0]; args >> resolution[1]; args >> resolution[2]; LDEBUG(type << " " << resolution[0] << " x " << resolution[1] << " x " << resolution[2]); } else if (type == "SliceThickness:") {
static uint8_t *extract_from_m2pa(msg_t *msg, size_t *len) { uint8_t *data; uint32_t data_len; if (msg->len < 8) { LERR("M2PA hdr too short %u", msg->len); return NULL; } data = msg->data; /* check the header */ if (data[0] != 0x01) { LERR("M2PA unknown version number %d", data[0]); return NULL; } if (data[1] != 0x00) { LERR("M2PA unknown reserved fields %d", data[1]); return NULL; } if (data[2] != M2PA_CLASS) { LDEBUG("M2PA unhandled message class %d", data[2]); return NULL; } if (data[3] != M2PA_DATA) { LDEBUG("M2PA not data msg but %d", data[3]); return NULL; } /* check the length */ memcpy(&data_len, &data[4], sizeof(data_len)); data_len = ntohl(data_len); if (msg->len < data_len) { LERR("M2PA data can't fit %u vs. %u", msg->len, data_len); return NULL; } /* skip the header */ data += 8; data_len -= 8; /* BSN, FSN and then priority */ if (data_len < 8) { LERR("M2PA no space for BSN/FSN %u\n", data_len); return NULL; } data += 8; data_len -= 8; if (data_len == 0) return NULL; else if (data_len < 1) { LERR("M2PA no space for prio %u\n", data_len); return NULL; } data += 1; data_len -= 1; *len = data_len; return data; }
void instantiatePatternsHash ( Data& d ) { d.hpinstances.clear(); LINFO ( "maxspan_=" << maxspan_ << ",gapmaxspan=" << gapmaxspan_ ); std::vector<std::string> ss; boost::algorithm::split ( ss, d.sentence, boost::algorithm::is_any_of ( " " ) ); const std::unordered_set<std::string>& patterns = d.grammar->patterns; for ( std::unordered_set<std::string>::const_iterator itx = patterns.begin(); itx != patterns.end(); ++itx ) { /// for each grammar-specific pattern. LDEBUG ( "pattern:" << *itx ); std::vector<std::string> spattern; boost::algorithm::split ( spattern, *itx, boost::algorithm::is_any_of ( "_" ) ); for ( unsigned j = 0; j < ss.size(); ++j ) { // for each word in the sentence std::vector< std::vector<std::string> > pinstances; LDEBUG ( "starting word:" << ss[j] ); //Map each pattern into words. //If there are gaps, then expand them from 1 to given threshold gapmaxspan if ( spattern.size() <= maxspan_ && j + spattern.size() - 1 < ss.size() ) { std::vector<std::string> empty; pinstances.push_back ( empty ); //add empty one. //Create all instances that apply to this particular pattern. buildNextElementFromPattern ( spattern, ss, pinstances, j, 0 ); } for ( unsigned k = 0; k < pinstances.size(); ++k ) { LDEBUG ( "pattern:" << *itx << ":" << "Inserting in " << boost::algorithm::join ( pinstances[k], "_" ) << "values=(" << j << "," << spattern.size() - 1 ); d.hpinstances[boost::algorithm::join ( pinstances[k], "_" )].push_back ( std::pair<unsigned, unsigned> ( j, spattern.size() - 1 ) ); } } } }
/** * \brief Method inherited from ucam::util::TaskInterface. Loads the language model and stores in lm data structure. * \param &d: data structure in which the null filter is to be stored. * \returns false (does not break the chain of tasks) */ bool run ( Data& d ) { mylmfst_.DeleteStates(); if ( !USER_CHECK ( d.klm.size() , "No language models available" ) ) return true; if ( !USER_CHECK ( d.klm.find ( lmkey_ ) != d.klm.end() , "No language models available (key not initialized) " ) ) return true; if ( !USER_CHECK ( d.fsts.find ( latticeloadkey_ ) != d.fsts.end() , " Input fst not available!" ) ) return true; mylmfst_ = * (static_cast<fst::VectorFst<Arc> * > ( d.fsts[latticeloadkey_] ) ); if (deletelmscores_) { LINFO ( "Delete old LM scores first" ); //Deletes LM scores if using lexstdarc. Note -- will copy through on stdarc! fst::MakeWeight2<Arc> mwcopy; fst::Map<Arc> ( &mylmfst_, fst::GenericWeightAutoMapper<Arc, fst::MakeWeight2<Arc> > ( mwcopy ) ); } LINFO ( "Input lattice loaded with key=" << latticeloadkey_ << ", NS=" << mylmfst_.NumStates() ); fst::MakeWeight<Arc> mw; for ( uint k = 0; k < d.klm[lmkey_].size(); ++k ) { if ( !USER_CHECK ( d.klm[lmkey_][k]->model != NULL, "Language model " << k << " not available!" ) ) return true; KenLMModelT& model = *d.klm[lmkey_][k]->model; #ifndef USE_GOOGLE_SPARSE_HASH unordered_set<Label> epsilons; #else google::dense_hash_set<Label> epsilons; epsilons.set_empty_key ( numeric_limits<Label>::max() ); #endif ///We want the language model to ignore these guys: epsilons.insert ( DR ); epsilons.insert ( OOV ); epsilons.insert ( EPSILON ); epsilons.insert ( SEP ); LINFO ( "Applying language model " << k << " with lmkey=" << lmkey_ << ", using lmscale=" << d.klm[lmkey_][k]->lmscale ); LDEBUG ( "lattice NS=" << mylmfst_.NumStates() ); fst::ApplyLanguageModelOnTheFly<Arc, fst::MakeWeight<Arc>, KenLMModelT> *f = new fst::ApplyLanguageModelOnTheFly<Arc, fst::MakeWeight<Arc>, KenLMModelT > ( mylmfst_ , model , epsilons , natlog_ , d.klm[lmkey_][k]->lmscale , d.klm[lmkey_][k]->lmwp , d.klm[lmkey_][k]->idb); f->setMakeWeight ( mw ); d.stats->setTimeStart ( "on-the-fly-composition " + ucam::util::toString ( k ) ); mylmfst_ = * ( ( *f ) () ); delete f; d.stats->setTimeEnd ( "on-the-fly-composition " + ucam::util::toString ( k ) ); LDEBUG ( mylmfst_.NumStates() ); mw.update(); } d.fsts[latticestorekey_] = &mylmfst_; LINFO ( "Done!" ); return false; };
int w_parse_rtcp_to_json(msg_t *_m) { int json_len; char *json_rtcp_buffer; _m->mfree = 0; json_rtcp_buffer = malloc(JSON_BUFFER_LEN); json_rtcp_buffer[0] = '\0'; if((json_len = capt_parse_rtcp((char *)_m->data, _m->len, json_rtcp_buffer, JSON_BUFFER_LEN)) > 0) { _m->rcinfo.proto_type = rtcp_proto_type; _m->data = json_rtcp_buffer; _m->len = json_len; _m->mfree = 1; } else { LDEBUG("GOODBYE or APP MESSAGE. Ignore!\n"); if(json_rtcp_buffer) free(json_rtcp_buffer); if(_m->corrdata) { free(_m->corrdata); _m->corrdata = NULL; } return -1; } LDEBUG("JSON RTCP %s\n", json_rtcp_buffer); return 1; }
int main(int argc, char **argv) { int maxsock,sockfd,sock_auth; unsigned int myport,listnum; fd_set fdsr; struct timeval tv; char *url = "OK OK"; int ret; myport = DEF_LISTEN_PORT; // listnum = 10; listnum = SOMAXCONN; if(argc > 1) { myport = atoi(argv[1]); } if(myport <= 0 ) { printf("%s invalid paramters!\n",argv[0]); return 0; } sockfd = create_server_socket(myport,listnum); if(sockfd == -1) { return 0; } maxsock = sockfd; LDEBUG("%s start to listen\n",argv[0]); while(1) { //init file desc set FD_ZERO(&fdsr); FD_SET(sockfd, &fdsr); // timeout setting tv.tv_sec = 30; tv.tv_usec = 0; ret = select(maxsock + 1, &fdsr, NULL, NULL, &tv); if(ret < 0) { printf("select error"); break; } else if(ret == 0) { LDEBUG("timeout\n"); continue; } if(FD_ISSET(sockfd, &fdsr)) { handleRequest(sockfd,url); } } return 0; }
Json::Value DotNetClient::sendRequest(std::string url) { //TODO remove log lines LDEBUG("Camera") << "sendRequest: " << url << LE; std::string sendUrl = params.query + url; LDEBUG("Camera") << "sendRequest full: " << sendUrl << LE; std::cout << "query " << sendUrl << std::endl; Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, sendUrl); request.setContentType("application/json"); request.set("charsets:", "utf-8"); request.setContentLength(0); //(int) message.length() client->sendRequest(request); Poco::Net::HTTPResponse response; std::istream& rs = client->receiveResponse(response); std::stringstream outstr; Poco::StreamCopier::copyStream(rs, outstr); std::string rawOutput = outstr.str(); std::cout << "response " << rawOutput << std::endl; LDEBUG("Camera") << "resposne raw: " << rawOutput << LE; Json::Value ov; Json::Reader r; r.parse(rawOutput, ov); //LDEBUG("Camera") << "parsed: " << ov << LE; return ov; }
void CacheManager::cleanDirectory(const Directory& dir) const { LDEBUG("Cleaning directory '" << dir << "'"); // First search for all subdirectories and call this function recursively on them std::vector<std::string> contents = dir.readDirectories(); for (const auto& content : contents) { if (FileSys.directoryExists(content)) { cleanDirectory(content); } } // We get to this point in the recursion if either all subdirectories have been // deleted or there exists a file somewhere in the directory tree contents = dir.read(); bool isEmpty = contents.empty(); #ifdef __APPLE__ // Apple stores the .DS_Store directory in the directory which can be removed std::string dsStore = FileSys.pathByAppendingComponent(dir, ".DS_Store"); isEmpty |= ((contents.size() == 1) && contents[0] == dsStore); #endif // If this directory is empty, we can delete it if (isEmpty) { LDEBUG("Deleting directory '" << dir << "'"); FileSys.deleteDirectory(dir); } }
VideoFileInfo getVideoFileInfoFromFilename(const std::string& fname) { VideoFileInfo result; std::string base; std::string ext = nodotExtension(fname, &base); LDEBUG("ext is %s", ext.c_str()); if (ext.compare("gz") == 0) { ext = nodotExtension(base, &base); LDEBUG("new ext is %s", ext.c_str()); result.ctype = COMP_GZIP; } else if (ext.compare("bz2") == 0) { ext = nodotExtension(base, &base); LDEBUG("new ext is %s", ext.c_str()); result.ctype = COMP_BZIP2; } else { result.ctype = COMP_NONE; } const std::string dimsstr = nodotExtension(base); LDEBUG("dimsstr is '%s'", dimsstr.c_str()); if (dimsstr.size() == 0) { LERROR("no <width>x<height> specification found in '%s'; " "assuming default dims of %dx%d instead", fname.c_str(), defaultDims.w(), defaultDims.h()); result.dims = defaultDims; // we didn't get explicit dims, so let's be picky about the // file size matching the defaultDims (--yuv-dims), unless the // user also requests loose matching (--yuv-dims-loose) result.beStrict = strictLength; } else { result.dims = fromStr<Dims>(dimsstr); LDEBUG("parsed dims as %dx%d", result.dims.w(), result.dims.h()); // OK, the user gave us some explicit dims, so let's not be // picky about whether the file size matches the // dims+pixformat result.beStrict = false; } result.format = fromStr<VideoFormat>(ext); return result; }
void BioRadar::GoRelBase(const double & speed) { if (speed == 0) { LDEBUG("HAL")<< "BioRadar antena stop" << LE; baseExecution.addTask(baseMotorModule.taskStop()); } else { LDEBUG("HAL")<< "BioRadar antena goRel: " << speed << " by " << maxRelDurationTimeInMs << LE; baseExecution.addTask(baseMotorModule.taskGoRel(speed, maxRelDurationTimeInMs)); } }
static void internalGoRel(TBS::Task::OneActiveTaskExectution & execution, MBot::CameraMotorModule & module, double speed, int maxDuration) { if (speed == 0) { LDEBUG("HAL")<< "Camera motor stop" << LE; execution.addTask(module.taskStop()); } else { LDEBUG("HAL")<< "Camera motor goRel: " << speed << " by " << maxDuration << LE; execution.addTask(module.taskGoRel(speed, maxDuration)); } }
DWORD GpuCapabilitiesWindows::readVRAMSizeFromReg() { DWORD memSize = 0; char* devicesKey = findPrimaryDevicesKey(); if ( devicesKey == 0 ) { LERROR("Failed to determine primary graphics adapter by calling findPrimaryDevicesKey()!"); return 0; } for ( size_t i = 0; i < strlen(devicesKey); i++ ) devicesKey[i] = tolower(devicesKey[i]); char* substr = strstr(devicesKey, "\\registry\\machine\\"); if ( substr != 0 ) substr += strlen("\\registry\\machine\\"); else substr = devicesKey; LDEBUG("registry key: " << substr); HKEY hKey = NULL; LONG stat = RegOpenKeyEx(HKEY_LOCAL_MACHINE, substr, 0, KEY_READ, &hKey); if ( stat == ERROR_SUCCESS ) { DWORD type = 0; DWORD bufferSize = 4; char* data = new char[bufferSize + 1]; memset(data, 0, bufferSize + 1); stat = RegQueryValueEx(hKey, "HardwareInformation.MemorySize", NULL, &type, (BYTE*) data, &bufferSize); if ((stat == ERROR_SUCCESS) && ((type == REG_BINARY) || (getOSVersion() == GpuCapabilities::OS_WIN_VISTA && type == REG_DWORD))) { LDEBUG("read " << bufferSize << " BYTES from key 'HardwareInformation.MemorySize'..."); for ( DWORD i = (bufferSize - 1); ; i-- ) { LDEBUG("data[" << i << "]: " << static_cast<DWORD>(data[i])); memSize |= (data[i] << (i * 8)); // As DWORD is unsigned, the loop would never exit if // it would not be broken... // if ( i == 0 ) break; } LDEBUG("data converted to " << memSize << " (means " << (memSize / (1024 * 1024)) << " MByte)\n"); } RegCloseKey(hKey); hKey = NULL; delete [] data; data = 0; } else LERROR("Error opening key " << substr << ". Reason: " << stat); delete [] devicesKey; devicesKey = 0; return memSize; }
void Parameters::resetParameters(const int argc, char * argv[]) { std::vector<std::string> m_temp; LDEBUG("Parsing parameters..."); LDEBUG("Number of parameters: "<<argc); for (int i(0); i < argc; ++i) { m_temp.emplace_back(argv[i]); LDEBUG("Parameter: " << argv[i]); } _resetParameters(std::move(m_temp)); }
bool loadDictionaryFromString( const std::string& script, ghoul::Dictionary& dictionary, lua_State* state ) { const static std::string _loggerCat = "lua_loadDictionaryFromString"; if (state == nullptr) { if (_state == nullptr) { LDEBUG("Creating Lua state"); _state = luaL_newstate(); if (_state == nullptr) { LFATAL("Error creating new Lua state: Memory allocation error"); return false; } LDEBUG("Open libraries"); luaL_openlibs(_state); } state = _state; } LDEBUG("Loading dictionary script '" << script.substr(0, 12) << "[...]'"); int status = luaL_loadstring(state, script.c_str()); if (status != LUA_OK) { LERROR("Error loading script: '" << lua_tostring(state, -1) << "'"); return false; } LDEBUG("Executing script"); if (lua_pcall(state, 0, LUA_MULTRET, 0)) { LERROR("Error executing script: " << lua_tostring(state, -1)); return false; } if (lua_isnil(state, -1)) { LERROR("Error in script: '" << script.substr(0, 12) << "[...]'. Script did not return anything."); return false; } if (!lua_istable(state, -1)) { LERROR("Error in script: '" << script.substr(0, 12) << "[...]'. Script did not return a table."); return false; } luaDictionaryFromState(state, dictionary); // Clean up after ourselves by cleaning the stack lua_settop(state, 0); return true; }
// ############################################################################################################## void jevois::Gadget::streamOn() { JEVOIS_TRACE(2); LDEBUG("Turning on UVC stream"); JEVOIS_TIMED_LOCK(itsMtx); if (itsStreaming.load() || itsBuffers) { LERROR("Stream is already on -- IGNORED"); return; } // If number of buffers is zero, adjust it depending on frame size: unsigned int nbuf = itsNbufs; if (nbuf == 0) { unsigned int framesize = jevois::v4l2ImageSize(itsFormat.fmt.pix.pixelformat, itsFormat.fmt.pix.width, itsFormat.fmt.pix.height); // Aim for about 4 mbyte when using small images, and no more than 4 buffers in any case: nbuf = (4U * 1024U * 1024U) / framesize; if (nbuf > 4) nbuf = 4; } // Force number of buffers to a sane value: if (nbuf < 3) nbuf = 3; else if (nbuf > 16) nbuf = 16; // Allocate our buffers for the currently selected resolution, format, etc: itsBuffers = new jevois::VideoBuffers("gadget", itsFd, V4L2_BUF_TYPE_VIDEO_OUTPUT, nbuf); LINFO(itsBuffers->size() << " buffers of " << itsBuffers->get(0)->length() << " bytes allocated"); // Fill itsImageQueue with blank frames that can be given off to application code: for (size_t i = 0; i < nbuf; ++i) { jevois::RawImage img; img.width = itsFormat.fmt.pix.width; img.height = itsFormat.fmt.pix.height; img.fmt = itsFormat.fmt.pix.pixelformat; img.fps = itsFps; img.buf = itsBuffers->get(i); img.bufindex = i; // Push the RawImage to outside consumers: itsImageQueue.push_back(img); LDEBUG("Empty image " << img.bufindex << " ready for filling in by application code"); } // Start streaming over the USB link: int type = V4L2_BUF_TYPE_VIDEO_OUTPUT; XIOCTL(itsFd, VIDIOC_STREAMON, &type); LDEBUG("Device stream on"); itsStreaming.store(true); LDEBUG("Stream is on"); }
// ############################################################################################################## jevois::Camera::Camera(std::string const & devname, unsigned int const nbufs) : jevois::VideoInput(devname, nbufs), itsFd(-1), itsBuffers(nullptr), itsFormat(), itsStreaming(false), itsFps(0.0F) { JEVOIS_TRACE(1); JEVOIS_TIMED_LOCK(itsMtx); // Get our run() thread going and wait until it is cranking, it will flip itsRunning to true as it starts: itsRunFuture = std::async(std::launch::async, &jevois::Camera::run, this); while (itsRunning.load() == false) std::this_thread::sleep_for(std::chrono::milliseconds(5)); // Open the device: itsFd = open(devname.c_str(), O_RDWR | O_NONBLOCK, 0); if (itsFd == -1) PLFATAL("Camera device open failed on " << devname); // See what kinds of inputs we have and select the first one that is a camera: int camidx = -1; struct v4l2_input inp = { }; while (true) { try { XIOCTL_QUIET(itsFd, VIDIOC_ENUMINPUT, &inp); } catch (...) { break; } if (inp.type == V4L2_INPUT_TYPE_CAMERA) { if (camidx == -1) camidx = inp.index; LDEBUG("Input " << inp.index << " [" << inp.name << "] is a camera sensor"); } else LDEBUG("Input " << inp.index << " [" << inp.name << "] is a NOT camera sensor"); ++inp.index; } if (camidx == -1) LFATAL("No valid camera input found on device " << devname); // Select the camera input, this seems to be required by VFE for the camera to power on: XIOCTL(itsFd, VIDIOC_S_INPUT, &camidx); // Find out what camera can do: struct v4l2_capability cap = { }; XIOCTL(itsFd, VIDIOC_QUERYCAP, &cap); LINFO('[' << itsFd << "] V4L2 camera " << devname << " card " << cap.card << " bus " << cap.bus_info); if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) LFATAL(devname << " is not a video capture device"); if ((cap.capabilities & V4L2_CAP_STREAMING) == 0) LFATAL(devname << " does not support streaming"); // List the supported formats: struct v4l2_fmtdesc fmtdesc = { }; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; while (true) { try { XIOCTL_QUIET(itsFd, VIDIOC_ENUM_FMT, &fmtdesc); } catch (...) { break; } LDEBUG("Format " << fmtdesc.index << " is [" << fmtdesc.description << "] fcc " << std::showbase << std::hex << fmtdesc.pixelformat << " [" << jevois::fccstr(fmtdesc.pixelformat) << ']'); ++fmtdesc.index; } }
void set_new_offset(unsigned long long size) { unsigned long long offset = 0; FUNC; LDEBUG("oldoffset is %llu : add size %llu", nextoffset, size); offset = round_512(size); nextoffset = nextoffset + offset; LDEBUG("nextoffset is now %llu", nextoffset); EFUNC; return; }
std::future<DownloadManager::MemoryFile> ScreenSpaceImage::downloadImageToMemory( std::string url) { return std::move(OsEng.downloadManager().fetchFile( url, [url](const DownloadManager::MemoryFile& file) { LDEBUG("Download to memory finished for screen space image"); }, [url](const std::string& err) { LDEBUG("Download to memory failer for screen space image: " +err); } )); }
void ModelManager::registerReader(ModelReader* mr) { readerSet_.insert(mr); LDEBUG("ModuleManager: Registering reader: " << mr->getName()); std::string formats = ""; std::vector<std::string> knownEndings = mr->getEndings(); std::vector<std::string>::iterator i; for ( i = knownEndings.begin(); i != knownEndings.end(); ++i ) { readers_[*i] = mr; formats += *i + " "; } LDEBUG("Known formats: " << formats); }
lua_State* createNewLuaState() { const std::string _loggerCat = "createNewLuaState"; lua_State* s; LDEBUG("Creating Lua state"); s = luaL_newstate(); if (s == nullptr) { LFATAL("Error creating new Lua state: Memory allocation error"); return nullptr; } LDEBUG("Open libraries"); luaL_openlibs(s); return s; }
// ############################################################################################################## void jevois::Camera::done(jevois::RawImage & img) { JEVOIS_TRACE(4); if (itsStreaming.load() == false) { LDEBUG("Not streaming"); throw std::runtime_error("Camera done() rejected while not streaming"); } // To avoid blocking for a long time here, we do not try to lock itsMtx and to qbuf() the buffer right now, instead we // just make a note that this buffer is available and it will be requeued by our run() thread: std::lock_guard<std::mutex> _(itsOutputMtx); itsDoneIdx.push_back(img.bufindex); LDEBUG("Image " << img.bufindex << " freed by processing"); }
// ############################################################################################################## void jevois::Camera::get(jevois::RawImage & img) { JEVOIS_TRACE(4); { std::unique_lock<std::mutex> ulck(itsOutputMtx); itsOutputCondVar.wait(ulck, [&]() { return itsOutputImage.valid() || itsStreaming.load() == false; }); if (itsStreaming.load() == false) { LDEBUG("Not streaming"); throw std::runtime_error("Camera not streaming"); } img = itsOutputImage; itsOutputImage.invalidate(); } LDEBUG("Camera image " << img.bufindex << " handed over to processing"); }
void handleRequest(int sockfd, char *url) { int new_fd; unsigned int sin_size; struct sockaddr_in their_addr; char *p; char sock_buf[1024]; char cmd[1024]; int rval=0; int header_len; char headerBuf[MAX_SENDBUF]={0}; //int body_len; //char sendBuf[MAX_SENDBUF]={0}; header_len = snprintf(headerBuf,MAX_SENDBUF,"get request %s",url); LDEBUG("header:%s,%d\n",headerBuf,header_len); bzero(sock_buf, 1024); p = sock_buf; sin_size = sizeof(struct sockaddr_in); if((new_fd = accept(sockfd,(struct sockaddr *)&their_addr,&sin_size)) == -1) { printf("%s accept is error\n",__FUNCTION__); return; } LDEBUG("%s server:got connection from %s\n",__FUNCTION__,inet_ntoa(their_addr.sin_addr)); sprintf(cmd,"echo `date -Iseconds` %s connection push to %s >> %s",inet_ntoa(their_addr.sin_addr),url,LOG_FILE); system(cmd); if ((rval = recv(new_fd, p, 1024, 0)) < 0) { printf("%s recv errror\n",__FUNCTION__); } else { LDEBUG("%s recv %s\n",__FUNCTION__,p); } if(send(new_fd,headerBuf,header_len,0) == -1) { printf("%s send is error\n",__FUNCTION__); } close(new_fd); return; }
Ident Pool::alloc() { ID_TYPE id; _mutex.lock(); if (_last > _max) { id = -1; for (ID_TYPE i=_first; i<_max; i++) { ListOfID::const_iterator it=std::find_if( _ids.begin(), _ids.end(), IDFinder( i ) ); if (it == _ids.end()) { id = i; break; } } if (id == -1) { _mutex.unlock(); throw std::runtime_error("Cannot allocate identifier, no more identifiers available"); } } else { id = _last; _last++; } _ids.push_back( id ); _mutex.unlock(); LDEBUG("id::Pool", "Pool(%s), Alloc id: id=%ld", _name.c_str(), id); return Ident( new IdentType( (Pool *)this, id ) ); }
int main() { concat( print , hello )(); fprintf(stdout, concat_str("hello", "world!\n")); fprintf(stdout, concat_str1(hello, world!\n)); LDEBUG("hello world: %s", "hmeng\n"); return 0; }
void recv_command(struct ev_loop *loop, struct ev_io *io, int rev) { ADEBUG(!(rev & EV_ERROR)); void *sock = SHIFT(io, config_zmqsocket_t, _watch)->_sock; while(TRUE) { Z_SEQ_INIT(msg, sock); Z_RECV_START(msg, break); size_t len; while(TRUE) { len = zmq_msg_size(&msg); REPLY_COMMAND(sock, msg, TRUE); if(!len) break; Z_RECV_NEXT(msg); } Z_RECV(msg); len = zmq_msg_size(&msg); char *data = zmq_msg_data(&msg); LDEBUG("Got command `%.*s`", len, data); if COMMAND(list_commands) { // Keep alphabetically sorted REPLY_SHORT(sock, msg, "list_commands", TRUE); REPLY_SHORT(sock, msg, "pause_websockets", TRUE); REPLY_SHORT(sock, msg, "resume_websockets", TRUE); REPLY_SHORT(sock, msg, "sync_now", TRUE); REPLY_SHORT(sock, msg, "reopen_logs", FALSE); } else if COMMAND(pause_websockets) { LWARN("Pausing websockets because of command"); pause_websockets(TRUE); REPLY_SHORT(sock, msg, "paused", FALSE); } else if COMMAND(resume_websockets) {
// ###################################################################### void ND_Navigation_Algorithm::setMinimumDistances() { for(uint i = 0; i < itsRegions.size(); i++) { float minDist = itsDistances[itsRegions[i].start]; uint minIndex = itsRegions[i].start; for(uint j = itsRegions[i].start +1; j <= itsRegions[i].end; j++) { // ignore invalid -1.0 distances if(itsDistances[j] == -1.0) continue; // ignore regions occupied by the killswitches if(j >= 25 && j <= 36) continue; if(j >= 243 && j <= 253) continue; if(minDist > itsDistances[j]) { minDist = itsDistances[j]; minIndex = j; } } itsRegions[i].minDistance = minDist; itsRegions[i].minIndex = minIndex; LDEBUG("[%4d]{%4d, %4d} minDist: %f", itsRegions[i].minIndex, itsRegions[i].start, itsRegions[i].end, itsRegions[i].minDistance); } }