void PaintedWidget::mouseMoveEvent(QMouseEvent *event) { QPoint delta=event->pos(); delta-=lastPos; for(int i=0;i<8;i++) { for(int j=0;j<3;j++)node[i][j]=oldNode[i][j]; rtt(node[i],delta.x(),delta.y()); } }
void Transmitter::handleACK(Message &msg) { qDebug() << "in" << __FUNCTION__; quint16 ackedFullType = msg.getAckedFullType(); // FIXME: validate acked CRC // Stop and delete resend timer if (resendTimers[ackedFullType]) { resendTimers[ackedFullType]->stop(); resendSignalMapper->removeMappings(resendTimers[ackedFullType]); delete resendTimers[ackedFullType]; resendTimers[ackedFullType] = NULL; } else { qWarning() << "No Resend timer running for type" << ackedFullType; } // Send RTT signal and delete RT timer if (rtTimers[ackedFullType]) { int rttMs = rtTimers[ackedFullType]->elapsed(); emit(rtt(rttMs)); // Adjust resend timeout but keep it always > 20ms. // If the doubled round trip time is less than current timeout, decrease resendTimeoutMs by 10%. // if the doubled round trip time is greater that current resendTimeoutMs, increase resendTimeoutMs to 2x rtt if (2 * rttMs < resendTimeoutMs) { resendTimeoutMs -= (int)(0.1 * resendTimeoutMs); } else { resendTimeoutMs = 2 * rttMs; } if (resendTimeoutMs < 20) { resendTimeoutMs = 20; } emit(resendTimeout(resendTimeoutMs)); qDebug() << "New resend timeout:" << resendTimeoutMs; delete rtTimers[ackedFullType]; rtTimers[ackedFullType] = NULL; } else { qWarning() << "No RT timer running for type" << ackedFullType; } // Delete the message waiting for resend if (resendMessages[ackedFullType]) { delete resendMessages[ackedFullType]; resendMessages[ackedFullType] = NULL; } }
PaintedWidget::PaintedWidget(QMainWindow*& _qmw):img(1920,1080,QImage::Format_RGB32) { img.fill(Qt::white); for(int i=0;i<8;i++) { rtt(node[i],100,-100); } }
/* * Function: parse_echo_response4 * Purpose: parses an echo response and prints out what we got back * Comments: we pass the host entry with the packet and associated data * rather than all the */ static int parse_echo_response4(struct host_entry *host_entry, char *packet, int len) { int records, i; struct ipmp *ipmp; struct ipmp_trailer *ipmp_trailer; struct ipmp_pathrecord *pr; char ctime_buf[26]; char addr_buf[17]; char fs_buf[25]; struct ipmp_pathrecord *out = NULL, *there = NULL, *back = NULL; int temp, max; struct dns_entry *dns; struct ipmptime t, t2; long base_sec = tv_sec() & 0xffff0000; time_t tt; char *name; char c; struct in_addr *in; /* get the offsets into the packet received */ ipmp = (struct ipmp *)(packet); pr = (struct ipmp_pathrecord *)(packet + sizeof(struct ipmp)); /* convert the echo module into host byte ordering */ ipmp_trailer = (struct ipmp_trailer *)(packet + len - 4); ipmp_trailer->path_pointer = ntohs(ipmp_trailer->path_pointer); /* get the number of path records */ records = (ipmp_trailer->path_pointer - sizeof(struct ipmp)) / sizeof(struct ipmp_pathrecord); /* get a pointer to the first timestamp so we can do a rtt calculation */ if(is_localaddress4(&pr->ip)) out = pr; /* find out how many chars it is to represent the longest address */ if(!(options & OPT_NLANR)) { max = 0; for(i=0; i<records; i++) { if(options & OPT_RESOLV && (dns=dnsentry_lookup4(&pr->ip)) != NULL) { temp = strlen(dns->name); } else { inet_ntop(AF_INET, &pr->ip, addr_buf, sizeof(addr_buf)); temp = strlen(addr_buf); } if(temp > max) max = temp; pr++; } pr--; temp = ipv4_ttl - pr->ttl; if(temp < 9) i = 1; else if(temp < 99) i = 2; else i = 3; snprintf(fs_buf, sizeof(fs_buf), "%%c %%%dd %%%ds %%s %%9u %%x\n", i, max); pr = (struct ipmp_pathrecord *)(packet + sizeof(struct ipmp)); in = &((struct sockaddr_in *)host_entry->addr)->sin_addr; /* print the path records out */ for(i=0; i<records; i++) { t.sec = base_sec + ntohs(pr->sec); t.nsec = ntohl(pr->nsec); /* format the timestamp and remove the \n char from the end */ tt = (time_t)t.sec; strncpy(ctime_buf, ctime(&tt), 24); ctime_buf[24] = '\0'; /* sort out the name we are going to show to the user */ if(options & OPT_RESOLV && (dns=dnsentry_lookup4(&pr->ip)) != NULL) { name = dns->name; } else { inet_ntop(AF_INET, &pr->ip, addr_buf, sizeof(addr_buf)); name = addr_buf; } /* * check to see if the address in this path record is either a * local address or a target address. if it is, we want to show * the user */ if(is_localaddress4(&pr->ip)) { c = '*'; } else if(pr->ip.s_addr == in->s_addr) { c = '*'; there = pr; } else c = ' '; /* actually print the path record now */ printf(fs_buf, c, ipv4_ttl - pr->ttl, name, ctime_buf+4, t.nsec, pr->flowc & 0xf); pr++; } /* * get the corresponding last timestamp so we can work out the * timestamp this will only work, of course, if we are on freebsd which * timestamps the IPMP packets leaving and coming up the stack */ pr--; if(is_localaddress4(&pr->ip)) back = pr; /* if we have been asked to calculate hops there and back, do it */ if(options & OPT_HOPS && there != NULL) { printf("forward path = "); if(out != NULL) printf("%d", out->ttl - there->ttl); else printf("?"); printf(" hops, reverse path = "); if(back != NULL) printf("%d", there->ttl - back->ttl); else printf("%d", there->ttl - host_entry->ttl); printf(" hops\n"); } /* calculate the RTT if we have been asked to */ if((options & OPT_RTT) && out != NULL && back != NULL) { t.sec = ntohs(out->sec); t.nsec = ntohl(out->nsec); t2.sec = ntohs(back->sec); t2.nsec = ntohl(back->nsec); if(t.sec > t2.sec) t2.sec += 0xffff; printf("rtt: %sms\n", rtt(&t, &t2)); } /* beep the pc speaker if we have been asked to */ if(options & OPT_AUDIBLE) printf("\a"); } else { /* * this output is the only stuff that the NLANR side (should) output to * stdio, thus making the perl scripts that much simpler to write */ for(i=0; i<records-1; i++) { pr++; } if(is_localaddress4(&pr->ip)) { back = pr; t.sec = out->sec; t.nsec = out->nsec; t2.sec = back->sec; t2.nsec = back->nsec; if(t.sec > t2.sec) t2.sec += 0xffff; if(options & OPT_TONY) { printf("%s %s %d\n",host_entry->name, rtt(&t, &t2), ipmp->seq); } else { printf("%s %s\n", host_entry->name, rtt(&t, &t2)); } } } fflush(stdout); return 1; }
static int parse_echo_response6(struct host_entry *host_entry, char *packet, int len) { int records, i; struct ipmp *ipmp; struct ipmp_trailer *ipmp_trailer; struct ipmp_pathrecord6 *pr; char ctime_buf[26]; char addr_buf[INET6_ADDRSTRLEN]; char fs_buf[25]; struct ipmp_pathrecord6 *out = NULL, *there = NULL, *back = NULL; int temp, max; struct dns_entry *dns; struct ipmptime t, t2; long base_sec = tv_sec() & 0xffff0000; time_t tt; char *name; char c; struct in6_addr *in6; /* get the offsets into the packet received */ ipmp = (struct ipmp *)packet; pr = (struct ipmp_pathrecord6 *)(packet + sizeof(struct ipmp)); ipmp_trailer = (struct ipmp_trailer *)(packet + len - 4); ipmp_trailer->path_pointer = ntohs(ipmp_trailer->path_pointer); /* get the number of path records */ records = (ipmp_trailer->path_pointer - sizeof(struct ipmp)) / sizeof(struct ipmp_pathrecord6); /* get a pointer to the first timestamp so we can do a rtt calculation */ if(is_localaddress6(&pr->ip)) out = pr; /* find out how many chars it is to represent the longest address */ if(!(options & OPT_NLANR)) { if(records <= 0) return 1; max = 0; for(i=0; i<records; i++) { if(options & OPT_RESOLV && (dns=dnsentry_lookup6(&pr->ip)) != NULL) { temp = strlen(dns->name); } else { inet_ntop(AF_INET6, &pr->ip, addr_buf, sizeof(addr_buf)); temp = strlen(addr_buf); } if(temp > max) max = temp; pr++; } pr--; temp = ipv6_hlim - pr->hlim; if(temp < 9) i = 1; else if(temp < 99) i = 2; else i = 3; snprintf(fs_buf, sizeof(fs_buf), "%%c %%%dd %%%ds %%s %%9u\n", i, max); pr = (struct ipmp_pathrecord6 *)(packet + sizeof(struct ipmp)); in6 = &((struct sockaddr_in6 *)host_entry->addr)->sin6_addr; /* print the path records out */ for(i=0; i<records; i++) { t.sec = base_sec + ntohs(pr->sec); t.nsec = ntohl(pr->nsec); /* format the timestamp and remove the \n char from the end */ tt = (time_t)t.sec; strncpy(ctime_buf, ctime(&tt), 24); ctime_buf[24] = '\0'; /* sort out the name we are going to show to the user */ if(options & OPT_RESOLV && (dns=dnsentry_lookup6(&pr->ip)) != NULL) { name = dns->name; } else { inet_ntop(AF_INET6, &pr->ip, addr_buf, sizeof(addr_buf)); name = addr_buf; } /* * check to see if the address in this path record is either a * local address or a target address. if it is, we want to show * the user */ if(is_localaddress6(&pr->ip)) { c = '*'; } else if(in6addr_cmp(&pr->ip, in6) == 0) { c = '*'; there = pr; } else c = ' '; printf(fs_buf, c, ipv6_hlim - pr->hlim, name, ctime_buf+4, t.nsec); pr++; } pr--; if(is_localaddress6(&pr->ip)) back = pr; if(options & OPT_HOPS && there != NULL) { printf("forward path = "); if(out != NULL) printf("%d", out->hlim - there->hlim); else printf("?"); printf(" hops, reverse path = "); if(back != NULL) printf("%d", there->hlim - back->hlim); else printf("%d", there->hlim - host_entry->ttl); printf(" hops\n"); } /* calculate the RTT if we have been asked to */ if((options & OPT_RTT) && out != NULL && back != NULL) { t.sec = ntohs(out->sec); t.nsec = ntohl(out->nsec); t2.sec = ntohs(back->sec); t2.nsec = ntohl(back->nsec); if(t.sec > t2.sec) t2.sec += 0xffff; printf("rtt: %sms\n", rtt(&t, &t2)); } /* beep the pc speaker if we have been asked to */ if(options & OPT_AUDIBLE) printf("\a"); } else { /* * this output is the only stuff that the NLANR side (should) output to * stdio, thus making the perl scripts that much simpler to write */ for(i=0; i<records-1; i++) { pr++; } if(is_localaddress6(&pr->ip)) { back = pr; t.sec = out->sec; t.nsec = out->nsec; t2.sec = back->sec; t2.nsec = back->nsec; if(t.sec > t2.sec) t2.sec += 0xffff; printf("%s %s\n", host_entry->name, rtt(&t, &t2)); } } fflush(stdout); return 1; }
int main( int argc, char** argv ) { namespace bpo = boost::program_options; try { std::string configFile ; std::string omsEclSettings; try { // only command-line options bpo::options_description genericOptions("Generic options"); genericOptions.add_options() ("version,v", "print version string") ("help,h", "produce help message") ("config,c", bpo::value<std::string>(&configFile)->default_value("utrade.conf"), "configuration file.") ; // both on command line and config file options bpo::options_description configFileOptions( "Configuration" ) ; configFileOptions.add_options() ("OMS.ecl_settings", bpo::value<std::string>(&omsEclSettings) ->default_value("oms-ecl-settings"), "OMS-ECL QuickFIX settings file") ; bpo::options_description cmdLineOptions; cmdLineOptions.add(genericOptions).add(configFileOptions); bpo::variables_map vm; store(bpo::command_line_parser(argc, argv). options(cmdLineOptions).run(), vm); notify(vm); std::ifstream ifs(configFile.c_str()); if (ifs) { store(parse_config_file(ifs, configFileOptions, true), vm); notify(vm); } else { std::cout << "Unable to open file: " << configFile << "\n" << std::endl ; return 1 ; } if (vm.count("help")) { std::cout << cmdLineOptions << "\n"; return 0; } if (vm.count("version")) { std::cout << "uTrade OMS version " VERSION_STRING "\n"; return 0; } bool validationSuccessful = true ; const std::vector< boost::shared_ptr<bpo::option_description> >& myoptions = configFileOptions.options() ; for( int i = myoptions.size() - 1; i >= 0 ; i-- ) { if( vm.count( myoptions[ i ]->long_name() ) == 0 ) { ERROR_3( CONFIG_ERROR_KEY_MISSING, configFile, "ECL_TEST", myoptions[ i ]->long_name() ) ; validationSuccessful = false ; } } if( !validationSuccessful ) { std::cout << "\n\nPress any key to exit ... " << std::endl ; std::cin.get() ; return 1 ; } } catch(boost::program_options::error &e) { std::cout << "Bad Options: " << e.what() << std::endl; return 1; } catch(std::exception& e) { std::cout << "Error when configuring : " << e.what() << std::endl ; return 1; } std::string command( "" ) ; while ( command != "0" ) { std::cout << "\nOptions are : \n" << " 1. Place Orders\n" << " 2. Round Trip Time \n" << " 0. Exit " << std::endl; getline( std::cin, command ) ; if( command == "1" ) { UT::ECL::TESTS::PlaceOrder p( omsEclSettings ) ; } else if( command == "2" ) { UT::ECL::TESTS::RoundTripTime rtt( omsEclSettings ) ; } } } catch( std::exception &e ) { std::cout << "Error : " << e.what() << std::endl ; return 1; } return 0; }
XBOOL XToolBar::OnPaint(XGraphics &g) { //return XTRUE; if(m_pBack==XNULL) return XTRUE; //XRect rect=m_clip; //int mx,my; //g.GetOrigin(mx,my); //g.SetOrigin(mx+rect.left,my+rect.top); // rect-=rect.TopLeft(); int x,w=m_pBack->Width(); XRect rect(0,0,w,m_pBack->Height()); //rect.right=m_pBack->Width(); for(x=0;x<m_clip.right;x+=w) { if(x+w<m_clip.left) continue; XPoint dt(x,0); if(rect.right+x>m_clip.right) rect.right=m_clip.right-x; //rect.right=m_nWidth-x; g.DrawImage(*m_pBack,dt,rect); } int dw=m_nItemWidth,ddh=m_pBack->Height(); int il=0,ir=1,im=0,llx=m_nItemLeft*dw,rrx=m_rect.Width()-m_nItemRight*dw; for(int i=0;i<m_nItemCount;i++) { //int ix=CommandToPos(iCommand); XRect irect; XPoint dt(0,0); XImage*pImage=&m_normal; switch(m_items[i].iStatus) { case XTS_NORMAL: pImage=&m_normal;break; case XTS_DISABLE: if(!m_gray.IsEmpty()) pImage=&m_gray; break; //case XTS_CHECKED: // pImage=&m_check;break; case XTS_ACTIVE: if(!m_active.IsEmpty()) pImage=&m_active;break; } if(m_items[i].iImage==TICON_SLIDER) { im+=SLIDER_WIDTH; XImage*pImageBut=pImage; if(m_items[i].iPos<=0&&!m_gray.IsEmpty()) pImageBut=&m_gray; else if(m_items[i].iStatus==XTS_ACTIVE1&&!m_active.IsEmpty()) pImageBut=&m_active; if(pImageBut&&!pImageBut->IsEmpty()) { int dh=pImage->Height(); dt.y=(ddh-dh+1)>>1; dt.x=(im-SLIDER_WIDTH+1)*dw+dt.y+12; irect.left=TICON_ZOOMIN*dh; irect.right=irect.left+dh; irect.top=0; irect.bottom=dh; XRect rtt(dt.x,dt.y,dt.x+irect.Width(),dt.y+irect.Height()); dt.x+=(m_nItemWidth-ddh)>>1; rtt&=m_clip; if(!rtt.IsRectEmpty()) g.DrawImage(*pImageBut,dt,irect); } pImageBut=pImage; if(m_items[i].iPos>=100&&!m_gray.IsEmpty()) pImageBut=&m_gray; else if(m_items[i].iStatus==XTS_ACTIVE2&&!m_active.IsEmpty()) pImageBut=&m_active; if(pImageBut&&!pImageBut->IsEmpty()) { int dh=pImage->Height(); dt.x=(im)*dw+dt.y; irect.left=TICON_ZOOMOUT*dh; irect.right=irect.left+dh; irect.top=0; irect.bottom=dh; XRect rtt(dt.x,dt.y,dt.x+irect.Width(),dt.y+irect.Height()); dt.x+=(m_nItemWidth-ddh)>>1; rtt&=m_clip; if(!rtt.IsRectEmpty()) g.DrawImage(*pImageBut,dt,irect); }