当前位置: 首页>>代码示例>>C++>>正文


C++ OperationEnvironment::SetProgressRange方法代码示例

本文整理汇总了C++中OperationEnvironment::SetProgressRange方法的典型用法代码示例。如果您正苦于以下问题:C++ OperationEnvironment::SetProgressRange方法的具体用法?C++ OperationEnvironment::SetProgressRange怎么用?C++ OperationEnvironment::SetProgressRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OperationEnvironment的用法示例。


在下文中一共展示了OperationEnvironment::SetProgressRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: request

int
Net::DownloadToBuffer(Session &session, const char *url,
                      void *_buffer, size_t max_length,
                      OperationEnvironment &env)
{
  Request request(session, url, 10000);
  if (!request.Send(10000))
    return -1;

  int64_t total = request.GetLength();
  if (total >= 0)
    env.SetProgressRange(total);
  total = 0;

  uint8_t *buffer = (uint8_t *)_buffer, *p = buffer, *end = buffer + max_length;
  while (p != end) {
    if (env.IsCancelled())
      return -1;

    ssize_t nbytes = request.Read(p, end - p, 5000);
    if (nbytes < 0)
      return -1;
    if (nbytes == 0)
      break;

    p += nbytes;

    total += nbytes;
    env.SetProgressPosition(total);
  }

  return p - buffer;
}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:33,代码来源:ToBuffer.cpp

示例2: sizeof

static bool
ReadFlightListInner(Port &port,
                    RecordedFlightList &flight_list,
                    OperationEnvironment &env)
{
  env.SetProgressRange(10);
  if (!Volkslogger::ConnectAndFlush(port, env, 20000))
    return false;
  env.SetProgressPosition(3);

  uint8_t dirbuffer[VLAPI_LOG_MEMSIZE];
  int data_length = Volkslogger::ReadFlightList(port, env,
                                                dirbuffer, sizeof(dirbuffer));
  if (data_length <= 0)
    return data_length == 0;

  std::vector<DIRENTRY> directory;
  if (!conv_dir(directory, dirbuffer, data_length))
    return false;

  if (directory.empty())
    return true;

  env.SetProgressPosition(8);
  if (!ConvertDirectoryToRecordedFlightList(directory, flight_list))
    return false;
  env.SetProgressPosition(10);

  return true;
}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:30,代码来源:Logger.cpp

示例3: while

/**
 * Parses the data provided by the airfield details file handle
 */
static void
ParseAirfieldDetails(Waypoints &way_points, TLineReader &reader,
                     OperationEnvironment &operation)
{
  tstring details;
  std::vector<tstring> files_external, files_embed;
  TCHAR name[201];
  const TCHAR *filename;

  name[0] = 0;

  bool in_details = false;
  int i;

  const long filesize = std::max(reader.GetSize(), 1l);
  operation.SetProgressRange(100);

  TCHAR *line;
  while ((line = reader.ReadLine()) != NULL) {
    if (line[0] == _T('[')) { // Look for start
      if (in_details)
        SetAirfieldDetails(way_points, name, details, files_external,
                           files_embed);

      details.clear();
      files_external.clear();
      files_embed.clear();

      // extract name
      for (i = 1; i < 201; i++) {
        if (line[i] == _T(']'))
          break;

        name[i - 1] = line[i];
      }
      name[i - 1] = 0;

      in_details = true;

      operation.SetProgressPosition(reader.Tell() * 100 / filesize);
    } else if ((filename =
                StringAfterPrefixCI(line, _T("image="))) != NULL) {
      files_embed.emplace_back(filename);
    } else if ((filename =
                StringAfterPrefixCI(line, _T("file="))) != NULL) {
#ifdef ANDROID
      files_external.emplace_back(filename);
#endif
    } else {
      // append text to details string
      if (!StringIsEmpty(line)) {
        details += line;
        details += _T('\n');
      }
    }
  }

  if (in_details)
    SetAirfieldDetails(way_points, name, details, files_external, files_embed);
}
开发者ID:Adrien81,项目名称:XCSoar,代码行数:63,代码来源:WaypointDetailsReader.cpp

示例4: while

bool
Volkslogger::WriteBulk(Port &port, OperationEnvironment &env,
                       const void *buffer, unsigned length)
{
  const unsigned delay = 1;

  env.SetProgressRange(length);

  uint16_t crc16 = 0;
  const uint8_t *p = (const uint8_t *)buffer, *end = p + length;
  while (p < end) {
    unsigned n = end - p;
    if (n > 400)
      n = 400;

    n = port.Write(p, n);
    if (n == 0)
      return false;

    crc16 = UpdateCRC16CCITT(p, n, crc16);
    p += n;

    env.SetProgressPosition(p - (const uint8_t *)buffer);

    /* throttle sending a bit, or the Volkslogger's receive buffer
       will overrun */
    env.Sleep(delay * 100);
  }

  return port.Write(crc16 >> 8) && port.Write(crc16 & 0xff);
}
开发者ID:Adrien81,项目名称:XCSoar,代码行数:31,代码来源:Protocol.cpp

示例5: Run

 virtual void Run(OperationEnvironment &env) {
   env.SetText(_T("Working..."));
   env.SetProgressRange(30);
   for (unsigned i = 0; i < 30 && !env.IsCancelled(); ++i) {
     env.SetProgressPosition(i);
     env.Sleep(500);
   }
 }
开发者ID:davidswelt,项目名称:XCSoar,代码行数:8,代码来源:RunJobDialog.cpp

示例6: DetectFileType

bool
AirspaceParser::Parse(TLineReader &reader, OperationEnvironment &operation)
{
  bool ignore = false;

  // Create and init ProgressDialog
  operation.SetProgressRange(1024);

  const long file_size = reader.GetSize();

  TempAirspaceType temp_area;
  AirspaceFileType filetype = AFT_UNKNOWN;

  TCHAR *line;

  // Iterate through the lines
  for (unsigned line_num = 1; (line = reader.ReadLine()) != NULL; line_num++) {
    // Skip empty line
    if (StringIsEmpty(line))
      continue;

    if (filetype == AFT_UNKNOWN) {
      filetype = DetectFileType(line);
      if (filetype == AFT_UNKNOWN)
        continue;
    }

    // Parse the line
    if (filetype == AFT_OPENAIR)
      if (!ParseLine(airspaces, line, temp_area) &&
          !ShowParseWarning(line_num, line, operation))
        return false;

    if (filetype == AFT_TNP)
      if (!ParseLineTNP(airspaces, line, temp_area, ignore) &&
          !ShowParseWarning(line_num, line, operation))
        return false;

    // Update the ProgressDialog
    if ((line_num & 0xff) == 0)
      operation.SetProgressPosition(reader.Tell() * 1024 / file_size);
  }

  if (filetype == AFT_UNKNOWN) {
    operation.SetErrorMessage(_("Unknown airspace filetype"));
    return false;
  }

  // Process final area (if any)
  if (!temp_area.points.empty())
    temp_area.AddPolygon(airspaces);

  return true;
}
开发者ID:DRIZO,项目名称:xcsoar,代码行数:54,代码来源:AirspaceParser.cpp

示例7: fos

bool
FlarmDevice::DownloadFlight(Path path, OperationEnvironment &env)
{
  FileOutputStream fos(path);
  BufferedOutputStream os(fos);

  if (env.IsCancelled())
    return false;

  env.SetProgressRange(100);
  while (true) {
    // Create header for getting IGC file data
    FLARM::FrameHeader header = PrepareFrameHeader(FLARM::MT_GETIGCDATA);

    // Send request
    if (!SendStartByte() ||
        !SendFrameHeader(header, env, 1000) ||
        env.IsCancelled())
      return false;

    // Wait for an answer and save the payload for further processing
    AllocatedArray<uint8_t> data;
    uint16_t length;
    bool ack = WaitForACKOrNACK(header.GetSequenceNumber(), data,
                                length, env, 10000) == FLARM::MT_ACK;

    // If no ACK was received
    if (!ack || length <= 3 || env.IsCancelled())
      return false;

    length -= 3;

    // Read progress (in percent)
    uint8_t progress = *(data.begin() + 2);
    env.SetProgressPosition(std::min((unsigned)progress, 100u));

    const char *last_char = (const char *)data.end() - 1;
    bool is_last_packet = (*last_char == 0x1A);
    if (is_last_packet)
      length--;

    // Read IGC data
    const char *igc_data = (const char *)data.begin() + 3;
    os.Write(igc_data, length);

    if (is_last_packet)
      break;
  }

  os.Flush();
  fos.Commit();

  return true;
}
开发者ID:staylo,项目名称:XCSoar,代码行数:54,代码来源:Logger.cpp

示例8: sizeof

static bool
DownloadFlightInner(Port &port, const RecordedFlightInfo &flight,
                    FILE *file, OperationEnvironment &env)
{
  if (!LX::CommandMode(port, env))
    return false;

  port.Flush();

  LX::SeekMemory seek;
  seek.start_address = flight.internal.lx.start_address;
  seek.end_address = flight.internal.lx.end_address;
  if (!LX::SendPacket(port, LX::SEEK_MEMORY, &seek, sizeof(seek), env) ||
      !LX::ExpectACK(port, env))
      return false;

  LX::MemorySection memory_section;
  if (!LX::ReceivePacketRetry(port, LX::READ_MEMORY_SECTION,
                              &memory_section, sizeof(memory_section), env,
                              5000, 2000, 60000, 2))
      return false;

  unsigned lengths[LX::MemorySection::N];
  unsigned total_length = 0;
  for (unsigned i = 0; i < LX::MemorySection::N; ++i) {
    lengths[i] = FromBE16(memory_section.lengths[i]);
    total_length += lengths[i];
  }

  env.SetProgressRange(total_length);

  uint8_t *data = new uint8_t[total_length], *p = data;
  for (unsigned i = 0; i < LX::MemorySection::N && lengths[i] > 0; ++i) {
    if (!LX::ReceivePacketRetry(port, (LX::Command)(LX::READ_LOGGER_DATA + i),
                                p, lengths[i], env,
                                20000, 2000, 300000, 2)) {
      delete [] data;
      return false;
    }

    p += lengths[i];
    env.SetProgressPosition(p - data);
  }

  bool success = LX::ConvertLXNToIGC(data, total_length, file);
  delete [] data;

  return success;
}
开发者ID:Advi42,项目名称:XCSoar,代码行数:49,代码来源:Logger.cpp

示例9:

void
CAI302WaypointUploader::Run(OperationEnvironment &env)
{
  Waypoints waypoints;

  env.SetText(_("Loading Waypoints..."));
  if (!reader.Parse(waypoints, env)) {
    env.SetErrorMessage(_("Failed to load file."));
    return;
  }

  if (waypoints.size() > 9999) {
    env.SetErrorMessage(_("Too many waypoints."));
    return;
  }

  env.SetText(_("Uploading Waypoints"));
  env.SetProgressRange(waypoints.size() + 1);
  env.SetProgressPosition(0);

  if (!device.ClearPoints(env)) {
    if (!env.IsCancelled())
      env.SetErrorMessage(_("Failed to erase waypoints."));
    return;
  }

  if (!device.EnableBulkMode(env)) {
    if (!env.IsCancelled())
      env.SetErrorMessage(_("Failed to switch baud rate."));
    return;
  }

  unsigned id = 1;
  for (auto i = waypoints.begin(), end = waypoints.end();
       i != end; ++i, ++id) {
    if (env.IsCancelled())
      break;

    env.SetProgressPosition(id);

    if (!device.WriteNavpoint(id, *i, env)) {
      if (!env.IsCancelled())
        env.SetErrorMessage(_("Failed to write waypoint."));
      break;
    }
  }

  device.DisableBulkMode(env);
}
开发者ID:aharrison24,项目名称:XCSoar,代码行数:49,代码来源:WaypointUploader.cpp

示例10: reader

static bool
DownloadFlightInner(Port &port, const char *filename, FILE *file,
                    OperationEnvironment &env)
{
  PortNMEAReader reader(port, env);
  unsigned row_count = 0, i = 1;

  while (true) {
    /* read up to 32 lines at a time */
    unsigned nrequest = row_count == 0 ? 1 : 32;
    if (row_count > 0) {
      assert(i <= row_count);
      const unsigned remaining = row_count - i + 1;
      if (nrequest > remaining)
        nrequest = remaining;
    }

    const unsigned start = i;
    const unsigned end = start + nrequest;

    /* send request to Nano */

    reader.Flush();
    if (!RequestFlight(port, filename, start, end, env))
      return false;

    /* read the requested lines and save to file */

    TimeoutClock timeout(2000);
    while (i != end) {
      const char *line = reader.ExpectLine("PLXVC,FLIGHT,A,", timeout);
      if (line == nullptr ||
          !HandleFlightLine(line, file, i, row_count))
        return false;
    }

    if (i > row_count)
      /* finished successfully */
      return true;

    if (start == 1)
      /* configure the range in the first iteration, now that we know
         the length of the file */
      env.SetProgressRange(row_count);

    env.SetProgressPosition(i - 1);
  }
}
开发者ID:MindMil,项目名称:XCSoar,代码行数:48,代码来源:NanoLogger.cpp

示例11: ParseLine

void
WaypointReaderBase::Parse(Waypoints &way_points, TLineReader &reader,
                          OperationEnvironment &operation)
{
  const long filesize = std::max(reader.GetSize(), 1l);
  operation.SetProgressRange(100);

  // Read through the lines of the file
  TCHAR *line;
  for (unsigned i = 0; (line = reader.ReadLine()) != nullptr; i++) {
    // and parse them
    ParseLine(line, i, way_points);

    if ((i & 0x3f) == 0)
      operation.SetProgressPosition(reader.Tell() * 100 / filesize);
  }
}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:17,代码来源:WaypointReaderBase.cpp

示例12: Copy

static bool
ReadFlightListInner(Port &port, RecordedFlightList &flight_list,
                    OperationEnvironment &env)
{
  env.SetProgressRange(8);

  for (unsigned i = 0; i < 8 && !flight_list.full(); ++i) {
    CAI302::FileList file_list;
    if (!CAI302::UploadFileList(port, i, file_list, env))
      break;

    for (unsigned j = 0; j < 8 && !flight_list.full(); ++j) {
      const CAI302::FileList::FileInfo &file = file_list.files[j];
      if (file.start_utc.month > 0)
        Copy(flight_list.append(), i * 8 + j, file);
    }

    env.SetProgressPosition(i);
  }

  return !flight_list.empty() && !env.IsCancelled();
}
开发者ID:DRIZO,项目名称:xcsoar,代码行数:22,代码来源:Logger.cpp

示例13: item

void
RasterWeatherStore::ScanAll(const GeoPoint &location,
                            OperationEnvironment &operation)
{
    /* not holding the lock here, because this method is only called
       during startup, when the other threads aren't running yet */

    operation.SetText(_("Scanning weather forecast"));

    ZZIP_DIR *dir = OpenArchive();
    if (dir == nullptr)
        return;

    operation.SetProgressRange(MAX_WEATHER_TIMES);

    maps.clear();

    std::set<tstring> names;

    for (const auto &i : WeatherDescriptors) {
        if (i.name == nullptr) {
            /* special case: 0 = terrain */
            assert(maps.empty());

            auto &m = maps.append();
            m.name.clear();
            m.label = i.label;
            m.help = i.help;
        } else {
            if (maps.full())
                break;

            MapItem item(i.name);
            item.label = i.label;
            item.help = i.help;
            if (ScanMapItem(dir, item))
                maps.push_back(item);

            names.insert(i.name);
        }
    }

    ZZIP_DIRENT e;
    while (zzip_dir_read(dir, &e)) {
        if (maps.full())
            break;

        const char *filename = e.d_name;
        if (!StringEndsWith(filename, ".jp2"))
            continue;

        MapItem item(_T(""));

        const char *dot = strchr(filename, '.');
        if (dot == nullptr || dot == filename ||
                size_t(dot - filename) >= item.name.capacity())
            continue;

        item.name.SetASCII(filename, dot);
        item.label = nullptr;
        item.help = nullptr;

        if (!names.insert(item.name.c_str()).second)
            continue;

        if (ScanMapItem(dir, item))
            maps.push_back(item);
    }

    // TODO: scan the rest

    zzip_dir_close(dir);
}
开发者ID:Andy-1954,项目名称:XCSoar,代码行数:73,代码来源:RasterWeatherStore.cpp

示例14: narrow_directory

void
TopographyStore::Load(OperationEnvironment &operation, NLineReader &reader,
                      const TCHAR *directory, struct zzip_dir *zdir)
{
  Reset();

  // Create buffer for the shape filenames
  // (shape_filename will be modified with the shape_filename_end pointer)
  char shape_filename[MAX_PATH];
  if (directory != nullptr) {
    const WideToACPConverter narrow_directory(directory);
    strcpy(shape_filename, narrow_directory);
    strcat(shape_filename, DIR_SEPARATOR_S);
  } else
    shape_filename[0] = 0;

  char *shape_filename_end = shape_filename + strlen(shape_filename);

  // Read file size to have a rough progress estimate for the progress bar
  const long filesize = std::max(reader.GetSize(), 1l);

  // Set progress bar to 100 steps
  operation.SetProgressRange(100);

  // Iterate through shape files in the "topology.tpl" file until
  // end or max. file number reached
  char *line;
  while (!files.full() && (line = reader.ReadLine()) != nullptr) {
    // .tpl Line format: filename,range,icon,field,r,g,b,pen_width,label_range,important_range,alpha

    // Ignore comments (lines starting with *) and empty lines
    if (StringIsEmpty(line) || line[0] == '*')
      continue;

    // Find first comma to extract shape filename
    char *p = strchr(line, ',');
    if (p == nullptr || p == line)
      // If no comma was found -> ignore this line/shapefile
      continue;

    if (HasLittleMemory()) {
      /* hard-coded blacklist for huge files on PPC2000; those
         devices usually have very little memory */

      // Null-terminate the line string after the first comma
      // for strcmp() calls in IsHugeTopographyFile() function
      *p = 0;

      // Skip large topography files
      if (IsHugeTopographyFile(line))
        continue;
    }

    // Extract filename and append it to the shape_filename buffer
    memcpy(shape_filename_end, line, p - line);
    // Append ".shp" file extension to the shape_filename buffer
    strcpy(shape_filename_end + (p - line), ".shp");

    // Parse shape range
    fixed shape_range = fixed(strtod(p + 1, &p)) * 1000;
    if (*p != _T(','))
      continue;

    // Extract shape icon name
    char icon_name[23];
    char *start = p + 1;
    p = strchr(start, ',');
    // Null-terminate the line string at the next comma for strncpy() call
    *p = 0;
    strncpy(icon_name, start, 22);
    ResourceId icon = ResourceId::Null(), big_icon = ResourceId::Null();

    if (strlen(icon_name) > 0) {
      const LOOKUP_ICON *ip = icon_list;
      while (ip->name != nullptr) {
        if (StringIsEqual(ip->name, icon_name)) {
          icon = ip->resource_id;
          big_icon = ip->big_resource_id;
          break;
        }
        ip++;
      }
    }

    // Parse shape field for text display
    long shape_field = strtol(p + 1, &p, 10) - 1;
    if (*p != _T(','))
      continue;

    // Parse red component of line / shading colour
    uint8_t red = (uint8_t)strtol(p + 1, &p, 10);
    if (*p != _T(','))
      continue;

    // Parse green component of line / shading colour
    uint8_t green = (uint8_t)strtol(p + 1, &p, 10);
    if (*p != _T(','))
      continue;

    // Parse blue component of line / shading colour
//.........这里部分代码省略.........
开发者ID:badbadc0ffee,项目名称:XCSoar,代码行数:101,代码来源:TopographyStore.cpp

示例15: writer

bool
FlytecDevice::DownloadFlight(const RecordedFlightInfo &flight,
                             Path path, OperationEnvironment &env)
{
  port.StopRxThread();

  PeriodClock status_clock;
  status_clock.Update();

  // Request flight record
  char buffer[256];
  sprintf(buffer, "$PBRTR,%02d", flight.internal.flytec);
  AppendNMEAChecksum(buffer);
  strcat(buffer, "\r\n");

  port.Write(buffer);
  if (!ExpectXOff(port, env, 1000))
    return false;

  // Open file writer
  FileHandle writer(path, _T("wb"));
  if (!writer.IsOpen())
    return false;

  unsigned start_sec = flight.start_time.GetSecondOfDay();
  unsigned end_sec = flight.end_time.GetSecondOfDay();
  if (end_sec < start_sec)
    end_sec += 24 * 60 * 60;

  unsigned range = end_sec - start_sec;
  env.SetProgressRange(range);

  while (true) {
    // Check if the user cancelled the operation
    if (env.IsCancelled())
      return false;

    // Receive the next line
    if (!ReceiveLine(port, buffer, ARRAY_SIZE(buffer), 1000))
      return false;

    // XON was received
    if (StringIsEmpty(buffer))
      break;

    if (status_clock.CheckUpdate(250) &&
        *buffer == 'B') {
      // Parse the fix time
      BrokenTime time;
      if (IGCParseTime(buffer + 1, time)) {

        unsigned time_sec = time.GetSecondOfDay();
        if (time_sec < start_sec)
          time_sec += 24 * 60 * 60;

        if (time_sec > end_sec + 5 * 60)
          time_sec = start_sec;

        unsigned position = time_sec - start_sec;
        if (position > range)
          position = range;

        env.SetProgressPosition(position);
      }
    }

    // Write line to the file
    writer.Write(buffer);
  }

  return true;
}
开发者ID:Andy-1954,项目名称:XCSoar,代码行数:72,代码来源:Logger.cpp


注:本文中的OperationEnvironment::SetProgressRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。