int main(int n, char **ppc){ pa_explain ("-i","the first sub-argument defines the marker type (one of bch, icl1 and art). The 2nd sub-argument " "defines which marker to create (this is the marker ID in case of type bch and icl1 and " "in case of makrer type art, an image filename is expected") ("-b","border width, which is only relevant for bch markers (the detectors default value is 2)") ("-r","border ratio, which is only relevant for art markers (the detectors default is value is 0.4)") ("-o","optionally given output filename. If this is not given, the marker image is shown instead") ("-s","output size of the marker image"); pa_init(n,ppc,"-id|-i(type,int) -border-size|-b(int=2) " "-border-ratio|-r(float=0.4) -output|-o(filename) " "-size|-s(size=300x300) " "-show-valid-icl1-codes"); if(pa("-show-valid-icl1-codes")){ std::vector<MarkerCodeICL1> cs = MarkerCodeICL1::generate(); std::sort(cs.begin(),cs.end()); std::cout << "icl1 marker codes with minimal hamming distance > 1" << std::endl; for(size_t i=0;i<cs.size();++i){ if(i<10) std::cout << " "; std::cout << i << ": " << cs[i] << std::endl; } return 0; }else{ if(!pa("-i")){ pa_show_usage("please define marker type and ID using '-i type id'"); return -1; } } FiducialDetector d(*pa("-i")); ParamList params; if(*pa("-i") == "art"){ params = ParamList("border ratio",*pa("-r")); }else if(*pa("-i") == "bch"){ params = ParamList("border width",*pa("-b")); } Img8u image = d.createMarker(*pa("-i",1), pa("-s"), params); if(pa("-o")){ save(image,*pa("-o")); }else{ show(image); } }
void Discover::processFinished(int exitCode, QProcess::ExitStatus exitStatus) { QProcess *process = static_cast<QProcess*>(sender()); // If the process was killed because guhd is shutting down...we dont't care any more about the result if (m_aboutToQuit) return; // Discovery if (process == m_discoveryProcess) { qCDebug(dcWallbe()) << "Discovery process finished"; process->deleteLater(); m_discoveryProcess = 0; QList<DeviceDescriptor> deviceDescriptors; if (exitCode != 0 || exitStatus != QProcess::NormalExit) { qCWarning(dcWallbe()) << "Network scan error:" << process->readAllStandardError(); emit devicesDiscovered(deviceDescriptors); return; } QByteArray outputData = process->readAllStandardOutput(); foreach (const Host &host, parseProcessOutput(outputData)) { DeviceDescriptor descriptor(wallbeEcoDeviceClassId, host.hostName(), host.address()); descriptor.setParams( ParamList() << Param(wallbeEcoIpParamTypeId, host.address())); deviceDescriptors.append(descriptor); }
status_t GlRealtimeParamList::Add( gl_node_id nid, const GlParamType* pt, const BString16* label, int32 control, int32 midi) { if (!pt) return B_ERROR; GlRealtimeEntryList* list = 0; if (midi >= 0 && midi < GL_MIDI_SIZE) list = MidiListAt(midi, true); else list = ParamList(true); if (!list) return B_NO_MEMORY; if (pt->Type() == GL_FLOAT_TYPE) { float min = ((const GlFloatParamType*)pt)->Min(), max = ((const GlFloatParamType*)pt)->Max(); /* FIX: I'm passing in a 0 where index is -- param types have * no index so how best to deal with this? Should there be * an index value that means 'all indexes'? */ return list->Add(new GlRealtimeFloat(nid, pt->Key(), 0, min, max)); } return B_ERROR; }
status_t GlRealtimeParamList::Add( gl_node_id nid, const GlParam* param, int32 index, const BString16* label, int32 control, int32 midi) { if (!param) return B_ERROR; const GlParamType* pt = param->ParamType(); if (!pt) return B_ERROR; GlRealtimeEntryList* list = 0; if (midi >= 0 && midi < GL_MIDI_SIZE) list = MidiListAt(midi, true); else list = ParamList(true); if (!list) return B_NO_MEMORY; if (pt->Type() == GL_FLOAT_TYPE) { float min, max; if (((GlFloatParam*)param)->GetRange(&min, &max) != B_OK) { min = ((const GlFloatParamType*)pt)->Min(); max = ((const GlFloatParamType*)pt)->Max(); } return list->Add(new GlRealtimeFloat(nid, pt->Key(), index, min, max)); } return B_ERROR; }
Array<Parser::Decl> Parser::Declaration(bool l0, bool more) { Array<Decl> r; Decla d; const char *p = lex.Pos(); if(Key(tk_typedef)) { r = Declaration(); r.Top().type_def = true; r.Top().natural = String(p, lex.Pos()); return r; } if(Key(tk_friend)) d.isfriend = true; // if(Key(tk_template)) { // d.istemplate = true; // d.template_params = TemplateParams(d.tnames); // } for(;;) { if(Key(tk_static)) d.s_static = true; else if(Key(tk_extern)) d.s_extern = true; else if(Key(tk_auto)) d.s_auto = true; else if(Key(tk_register)) d.s_register = true; else if(Key(tk_mutable)) d.s_mutable = true; else if(Key(tk_explicit)) d.s_explicit = true; else if(Key(tk_virtual)) d.s_virtual = true; else if(!Key(tk_inline)) break; } Qualifier(); bool isdestructor = Key('~'); if(l0 && context.typenames.Find(lex) >= 0 && lex[1] == '(') { Decl& a = r.Add(); a.name = lex.GetId(); a.isdestructor = isdestructor; a.function = true; a.istructor = true; a.header = String(p, lex.Pos()); ++lex; ParamList(a); const char *p1 = lex.Pos(); Qualifier(); a.ender = String(p1, lex.Pos()); a.natural = String(p, lex.Pos()); EatInitializers(); return r; } if(lex == tk_operator) { Decl& a = r.Add(); (Decla&)a = d; a.name = ReadOper(); a.header = String(p, lex.Pos()); Key('('); ParamList(a); const char *p1 = lex.Pos(); Qualifier(); a.ender = String(p1, lex.Pos()); a.function = true; a.natural = String(p, lex.Pos()); return r; } String st = SimpleType(); if(!st.IsEmpty()) { Decl& a = r.Add(); a.name = st; a.isdestructor = st.Find('~') > 0; a.function = true; a.istructor = true; a.header = String(p, lex.Pos()); if(Key('(')) ParamList(a); const char *p1 = lex.Pos(); Qualifier(); a.ender = String(p1, lex.Pos()); a.natural = String(p, lex.Pos()); EatInitializers(); return r; } String natural1 = String(p, lex.Pos()); do { const char *p1 = lex.Pos(); Decl& a = r.Add(); (Decla&)a = d; Declarator(a, p); a.natural = natural1 + String(p1, lex.Pos()); p = lex.Pos(); } while(more && Key(',')); return r; }
void Parser::Declarator(Decl& d, const char *p) { int n = RPtr(); if(n) { while(n--) lex.Get(); Declarator(d, p); d.isptr = true; return; } if(Key('&')) { Declarator(d, p); return; } if(Key(tk_const)) { Declarator(d, p); return; } if(Key('(')) { Declarator(d, p); if(d.isptr) d.nofn = true; CheckKey(')'); } if(lex == tk_operator) d.name = ReadOper(); else if(lex.IsId() || lex == t_dblcolon) { d.name = Name(); if(Key(':')) if(!Key(t_integer)) Name(); } if(Key('(')) { if((lex < 256 || lex == tk_true || lex == tk_false) && lex != ')') { int level = 0; for(;;) { if(lex == t_eof) break; if(Key('(')) level++; else if(Key(')')) { if(--level < 0) break; } else ++lex; } return; } else { d.header = String(p, lex.Pos() - 1); d.function = !d.nofn; ParamList(d); p = lex.Pos(); Qualifier(); d.ender = String(p, lex.Pos()); } } EatInitializers(); while(Key('[')) { const char *p = lex.Pos(); int level = 1; while(level && lex != t_eof) { if(Key('[')) level++; else if(Key(']')) level--; else ++lex; } } if(Key('=')) { Constant(); } }
void CParser::Factor() { switch (mLookahead) { case '-': Match('-'); Factor(); AddToken(opNegate); break; case NUMBER: { double d = mNum; Match(NUMBER); if (mLookahead == '%') { Match('%'); AddToken(valPerc, &d); } else AddToken(valNum, &d); break; } case '(': Match('('); RelExpr(); Match(')'); AddToken(opParen); break; case CELL: { range r; r.TopLeft() = mCell; Match(CELL); mIsFormula = true; if (mLookahead == RANGE) { Match(RANGE); r.BotRight() = mCell; Match(CELL); AddToken(valRange, &r); } else AddToken(valCell, &r.TopLeft()); break; } case IDENT: { char name[256]; strcpy(name, mToken); int s = mTokenStart - mExprStart; FuncCallData fcd; fcd.funcNr = GetFunctionNr(name); int expectedArgs = gFuncArrayByNr[fcd.funcNr].argCnt; Match(IDENT); if (mLookahead == '(') { Match('('); ParamList(); Match(')'); if (fcd.funcNr < 0) throw CParseErr(s, strlen(name), errUnknownFunction, name); if (expectedArgs == -1 || expectedArgs == mArgCnt || (expectedArgs < 0 || expectedArgs <= -fcd.funcNr)) { fcd.argCnt = mArgCnt; } else if (expectedArgs < 0) throw CParseErr(s, strlen(name), errIncorrectNrOfArgs2, expectedArgs, mArgCnt); else throw CParseErr(s, strlen(name), errIncorrectNrOfArgs, expectedArgs, mArgCnt); AddToken(opFunc, &fcd); } else { if (fcd.funcNr >= 0) { if (expectedArgs != -1 && expectedArgs != 0) throw CParseErr(s, strlen(name), errIncorrectNrOfArgs, expectedArgs, 0); fcd.argCnt = 0; AddToken(opFunc, &fcd); } else if (mContainer && mContainer->GetOwner() && mContainer->GetOwner()->IsNamedRange(name)) { AddToken(valName, name); } else throw CParseErr(s, strlen(name), errUnknownIdentifier, name); } break; } case TEXT: AddToken(valStr, mToken); Match(TEXT); break; case TIME: AddToken(valTime, &mTime); Match(TIME); break; case BOOL: AddToken(valBool, &mBool); Match(BOOL); break; default: Match(NUMBER); } } // CParser::Factor
//Capture process bool __fastcall CaptureModule(const pcap_if *pDrive, const bool IsCaptureList) { std::string CaptureDevice; //Devices name, address and type check if (pDrive->name == nullptr || pDrive->addresses == nullptr || pDrive->flags == PCAP_IF_LOOPBACK) goto DevicesSkip; //Pcap devices blacklist check if (pDrive->description != nullptr) { CaptureDevice.append(pDrive->description); CaseConvert(false, CaptureDevice); for (auto CaptureIter:*Parameter.PcapDevicesBlacklist) { if (CaptureIter.find(CaptureDevice) != std::string::npos) goto DevicesSkip; } } CaptureDevice.clear(); CaptureDevice.append(pDrive->name); CaseConvert(false, CaptureDevice); for (auto CaptureIter:*Parameter.PcapDevicesBlacklist) { if (CaptureIter.find(CaptureDevice) != std::string::npos) goto DevicesSkip; } //Skip this devices. goto DevicesNotSkip; DevicesSkip: if (IsCaptureList && pDrive->next != nullptr) { std::thread CaptureThread(CaptureModule, pDrive->next, true); CaptureThread.detach(); } return true; DevicesNotSkip: //Initialization(Part 1) pcap_t *DeviceHandle = nullptr; std::shared_ptr<char> Buffer(new char[ORIGINAL_PACKET_MAXSIZE + sizeof(uint16_t)]()); //Reserved 2 bytes for TCP header length. memset(Buffer.get(), 0, ORIGINAL_PACKET_MAXSIZE + sizeof(uint16_t)); CaptureDevice.clear(); CaptureDevice.append(pDrive->name); CaptureDevice.shrink_to_fit(); //Open device #if defined(PLATFORM_WIN) if ((DeviceHandle = pcap_open(pDrive->name, ORIGINAL_PACKET_MAXSIZE, PCAP_OPENFLAG_NOCAPTURE_LOCAL, (int)Parameter.PcapReadingTimeout, nullptr, Buffer.get())) == nullptr) #elif (defined(PLATFORM_LINUX) || defined(PLATFORM_MACX)) if ((DeviceHandle = pcap_open_live(pDrive->name, ORIGINAL_PACKET_MAXSIZE, 0, (int)Parameter.PcapReadingTimeout, Buffer.get())) == nullptr) #endif { std::wstring ErrBuffer; if (MBSToWCSString(ErrBuffer, Buffer.get())) PrintError(LOG_ERROR_PCAP, ErrBuffer.c_str(), 0, nullptr, 0); return false; } //Check device type. uint16_t DeviceType = 0; if (pcap_datalink(DeviceHandle) == DLT_EN10MB || pcap_datalink(DeviceHandle) == DLT_PPP_ETHER || pcap_datalink(DeviceHandle) == DLT_EN3MB) //Ethernet II(Including PPPoE) DeviceType = DLT_EN10MB; else if (pcap_datalink(DeviceHandle) == DLT_APPLE_IP_OVER_IEEE1394) //Apple IEEE 1394 DeviceType = DLT_APPLE_IP_OVER_IEEE1394; if (DeviceType == 0) { pcap_close(DeviceHandle); return false; } //Compile the string into a filter program. std::shared_ptr<bpf_program> BPF_Code(new bpf_program()); memset(BPF_Code.get(), 0, sizeof(bpf_program)); #if defined(PLATFORM_WIN) if (pcap_compile(DeviceHandle, BPF_Code.get(), PcapFilterRules.c_str(), PCAP_COMPILE_OPTIMIZE, (bpf_u_int32)pDrive->addresses->netmask) == PCAP_ERROR) #elif (defined(PLATFORM_LINUX) || defined(PLATFORM_MACX)) if (pcap_compile(DeviceHandle, BPF_Code.get(), PcapFilterRules.c_str(), PCAP_COMPILE_OPTIMIZE, 0) == PCAP_ERROR) #endif { std::wstring ErrBuffer; if (MBSToWCSString(ErrBuffer, pcap_geterr(DeviceHandle))) PrintError(LOG_ERROR_PCAP, ErrBuffer.c_str(), 0, nullptr, 0); pcap_close(DeviceHandle); return false; } //Specify a filter program. if (pcap_setfilter(DeviceHandle, BPF_Code.get()) == PCAP_ERROR) { std::wstring ErrBuffer; if (MBSToWCSString(ErrBuffer, pcap_geterr(DeviceHandle))) PrintError(LOG_ERROR_PCAP, ErrBuffer.c_str(), 0, nullptr, 0); pcap_freecode(BPF_Code.get()); pcap_close(DeviceHandle); return false; } //Start captures with other devices. PcapRunningList.push_back(CaptureDevice); if (IsCaptureList && pDrive->next != nullptr) { std::thread CaptureThread(CaptureModule, pDrive->next, IsCaptureList); CaptureThread.detach(); } //Initialization(Part 2) std::shared_ptr<CAPTURE_HANDLER_PARAM> ParamList(new CAPTURE_HANDLER_PARAM()); memset(ParamList.get(), 0, sizeof(CAPTURE_HANDLER_PARAM)); ParamList->Buffer = Buffer.get(); ParamList->DeviceType = DeviceType; SSIZE_T Result = 0; std::unique_lock<std::mutex> CaptureMutex(CaptureLock); CaptureMutex.unlock(); //Start monitor. for (;;) { Result = pcap_loop(DeviceHandle, PCAP_LOOP_INFINITY, CaptureHandler, (PUCHAR)ParamList.get()); // if (Result == PCAP_ERROR || Result == PCAP_ERROR_BREAK || Result == PCAP_ERROR_NO_SUCH_DEVICE || Result == PCAP_ERROR_RFMON_NOTSUP || Result == PCAP_ERROR_NOT_RFMON) if (Result < EXIT_SUCCESS) { //Delete this capture from devices list. CaptureMutex.lock(); for (auto CaptureIter = PcapRunningList.begin();CaptureIter != PcapRunningList.end();) { if (*CaptureIter == CaptureDevice) { CaptureIter = PcapRunningList.erase(CaptureIter); if (CaptureIter == PcapRunningList.end()) break; } else { ++CaptureIter; } } PcapRunningList.shrink_to_fit(); CaptureMutex.unlock(); //Exit this capture thread. pcap_freecode(BPF_Code.get()); pcap_close(DeviceHandle); return false; } else { Sleep(MONITOR_LOOP_INTERVAL_TIME); continue; } } //Monitor terminated pcap_freecode(BPF_Code.get()); pcap_close(DeviceHandle); PrintError(LOG_ERROR_SYSTEM, L"Capture module Monitor terminated", 0, nullptr, 0); return true; }