void CalculationsCore::run() { while ( true ) { if ( this->maxCalculations != 0 && this->maxCalculations <= this->calculations ) { break; } if ( this->cancel == true ) { break; } this->sync.lock(); if ( this->pause == true ) { pauseCond.wait ( &this->sync ); } this->sync.unlock(); this->calculations++; std::vector<int> input = getRandomIp(); std::vector< std::vector<int> > volume = getIpVolume ( input ); std::vector< std::vector<double> > r_input = writeIp ( input, volume ); double ip[3] = { r_input[0][0], r_input[1][0], r_input[2][0] }; if ( searchIp ( ip ) == true ) { this->coincidences++; Data::CalculationResult result; result.r_input = r_input; result.ipVolume = volume; result.calculations = this->calculations; result.coincidences = this->coincidences; emit ipFound ( this->coincidences ); this->wr->saveResult ( result ); if ( this->maxCoincidences != 0 && this->maxCoincidences <= this->coincidences ) { break; } } } this->wr->writeEndingToFile(); }
bool Configurator::writeSubnet (std::ostream &stream, const IpSubnet &subnet) { return writeIp(stream, subnet.address()) && writeInt(stream, subnet.cidr()); }
bool Configurator::writeConfiguration (const char *filename) { std::ofstream file(filename == 0 ? Configurator::filename : filename, std::ios_base::out | std::ios_base::trunc); if (!file.good()) return false; if (!writeInt(file, 3)) return false; std::vector<VrrpService *> services = Configurator::services(); if (!writeInt(file, services.size())) return false; for (std::vector<VrrpService *>::const_iterator it = services.begin(); it != services.end(); ++it) { const VrrpService *service = *it; char ifname[IFNAMSIZ]; if_indextoname(service->interface(), ifname); int flags = 0; if (!service->hasAutoPrimaryIpAddress()) flags |= FLAG_HAS_PRIMARY_IP_ADDRESS; if ( !writeString(file, ifname) || !writeInt(file, service->virtualRouterId()) || !writeInt(file, service->family()) || !writeInt(file, service->priority()) || !writeInt(file, service->advertisementInterval() * 10) || !writeBoolean(file, service->acceptMode()) || !writeBoolean(file, service->preemptMode()) || !writeBoolean(file, service->enabled()) || !writeInt(file, flags)) return false; if (flags & FLAG_HAS_PRIMARY_IP_ADDRESS) { if (!writeIp(file, service->primaryIpAddress())) return false; } if ( !writeString(file, service->masterCommand()) || !writeString(file, service->backupCommand()) || !writeInt(file, service->vlanId())) { return false; } const IpSubnetSet &subnets = service->subnets(); if (!writeInt(file, subnets.size())) return false; for (IpSubnetSet::const_iterator subnet = subnets.begin(); subnet != subnets.end(); ++subnet) { if (!writeSubnet(file, *subnet)) return false; } } return true; }