本文整理汇总了C++中OperationEnvironment::IsCancelled方法的典型用法代码示例。如果您正苦于以下问题:C++ OperationEnvironment::IsCancelled方法的具体用法?C++ OperationEnvironment::IsCancelled怎么用?C++ OperationEnvironment::IsCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationEnvironment
的用法示例。
在下文中一共展示了OperationEnvironment::IsCancelled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2:
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);
}
示例3: SelectFlight
bool
FlarmDevice::DownloadFlight(const RecordedFlightInfo &flight,
Path path, OperationEnvironment &env)
{
if (!BinaryMode(env))
return false;
FLARM::MessageType ack_result = SelectFlight(flight.internal.flarm, env);
// If no ACK was received -> cancel
if (ack_result != FLARM::MT_ACK || env.IsCancelled())
return false;
try {
if (DownloadFlight(path, env))
return true;
} catch (...) {
mode = Mode::UNKNOWN;
throw;
}
mode = Mode::UNKNOWN;
return false;
}
示例4: timeout
bool
Port::ExpectString(const char *token, OperationEnvironment &env,
unsigned timeout_ms)
{
assert(token != NULL);
const char *const token_end = token + strlen(token);
const TimeoutClock timeout(timeout_ms);
char buffer[256];
const char *p = token;
while (true) {
WaitResult wait_result = WaitRead(env, timeout.GetRemainingOrZero());
if (wait_result != WaitResult::READY)
// Operation canceled, Timeout expired or I/O error occurred
return false;
int nbytes = Read(buffer, std::min(sizeof(buffer), size_t(token_end - p)));
if (nbytes < 0 || env.IsCancelled())
return false;
for (const char *q = buffer, *end = buffer + nbytes; q != end; ++q) {
const char ch = *q;
if (ch != *p)
/* retry */
p = token;
else if (++p == token_end)
return true;
}
}
}
示例5: 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;
}
示例6: SelectFlight
bool
FlarmDevice::ReadFlightList(RecordedFlightList &flight_list,
OperationEnvironment &env)
{
if (!BinaryMode(env))
return false;
// Try to receive flight information until the list is full
for (uint8_t i = 0; !flight_list.full(); ++i) {
FLARM::MessageType ack_result = SelectFlight(i, env);
// Last record reached -> bail out and return list
if (ack_result == FLARM::MT_NACK)
break;
// If neither ACK nor NACK was received
if (ack_result != FLARM::MT_ACK || env.IsCancelled()) {
mode = Mode::UNKNOWN;
return false;
}
RecordedFlightInfo flight_info;
flight_info.internal.flarm = i;
if (ReadFlightInfo(flight_info, env))
flight_list.append(flight_info);
}
return true;
}
示例7: 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);
}
}
示例8: GetState
bool
Port::WaitConnected(OperationEnvironment &env)
{
while (GetState() == PortState::LIMBO && !env.IsCancelled())
env.Sleep(200);
return GetState() == PortState::READY;
}
示例9: protect
bool
DeviceDescriptor::OpenOnPort(DumpPort *_port, OperationEnvironment &env)
{
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
assert(_port != nullptr);
#endif
assert(port == nullptr);
assert(device == nullptr);
assert(second_device == nullptr);
assert(driver != nullptr);
assert(!ticker);
assert(!IsBorrowed());
reopen_clock.Update();
device_blackboard->mutex.Lock();
device_blackboard->SetRealState(index).Reset();
device_blackboard->ScheduleMerge();
device_blackboard->mutex.Unlock();
settings_sent.Clear();
settings_received.Clear();
was_alive = false;
port = _port;
parser.Reset();
parser.SetReal(!StringIsEqual(driver->name, _T("Condor")));
if (config.IsDriver(_T("Condor")))
parser.DisableGeoid();
if (driver->CreateOnPort != nullptr) {
Device *new_device = driver->CreateOnPort(config, *port);
const ScopeLock protect(mutex);
device = new_device;
if (driver->HasPassThrough() && config.use_second_device)
second_device = second_driver->CreateOnPort(config, *port);
} else
port->StartRxThread();
EnableNMEA(env);
if (env.IsCancelled()) {
/* the caller is responsible for freeing the port on error */
port = nullptr;
delete device;
device = nullptr;
delete second_device;
second_device = nullptr;
return false;
}
return true;
}
示例10: Connect
bool
IMIDevice::DownloadFlight(const RecordedFlightInfo &flight, const TCHAR *path,
OperationEnvironment &env)
{
bool success = Connect(env) && !env.IsCancelled();
success = success && IMI::FlightDownload(port, flight, path, env);
// disconnect
Disconnect();
return success;
}
示例11: OpenInternalSensors
bool
DeviceDescriptor::DoOpen(OperationEnvironment &env)
{
assert(config.IsAvailable());
if (config.port_type == DeviceConfig::PortType::INTERNAL)
return OpenInternalSensors();
if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2)
return OpenDroidSoarV2();
if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR)
return OpenI2Cbaro();
if (config.port_type == DeviceConfig::PortType::NUNCHUCK)
return OpenNunchuck();
if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE)
return OpenVoltage();
if (config.port_type == DeviceConfig::PortType::ADCAIRSPEED)
return OpenAdcAirspeed();
reopen_clock.Update();
Port *port = OpenPort(config, *this);
if (port == NULL) {
TCHAR name_buffer[64];
const TCHAR *name = config.GetPortName(name_buffer, 64);
StaticString<256> msg;
msg.Format(_T("%s: %s."), _("Unable to open port"), name);
env.SetErrorMessage(msg);
return false;
}
while (port->GetState() == PortState::LIMBO) {
env.Sleep(200);
if (env.IsCancelled() || port->GetState() == PortState::FAILED) {
delete port;
return false;
}
}
if (!Open(*port, env)) {
delete port;
return false;
}
return true;
}
示例12: OpenInternalSensors
bool
DeviceDescriptor::DoOpen(OperationEnvironment &env)
{
assert(config.IsAvailable());
if (config.port_type == DeviceConfig::PortType::INTERNAL)
return OpenInternalSensors();
if (config.port_type == DeviceConfig::PortType::DROIDSOAR_V2)
return OpenDroidSoarV2();
if (config.port_type == DeviceConfig::PortType::I2CPRESSURESENSOR)
return OpenI2Cbaro();
if (config.port_type == DeviceConfig::PortType::NUNCHUCK)
return OpenNunchuck();
if (config.port_type == DeviceConfig::PortType::IOIOVOLTAGE)
return OpenVoltage();
reopen_clock.Update();
Port *port = OpenPort(config, port_listener, *this);
if (port == nullptr) {
TCHAR name_buffer[64];
const TCHAR *name = config.GetPortName(name_buffer, 64);
StaticString<256> msg;
msg.Format(_T("%s: %s."), _("Unable to open port"), name);
env.SetErrorMessage(msg);
return false;
}
DumpPort *dump_port = new DumpPort(port);
dump_port->Disable();
if (!port->WaitConnected(env) || !OpenOnPort(dump_port, env)) {
if (!env.IsCancelled())
++n_failures;
delete dump_port;
return false;
}
ResetFailureCounter();
return true;
}
示例13:
bool
LX::CommandMode(Port &port, OperationEnvironment &env)
{
/* switch to command mode, first attempt */
if (!SendSYN(port) || !port.FullFlush(env, 50, 200))
return false;
/* the port is clean now; try the SYN/ACK procedure up to three
times */
for (unsigned i = 0; i < 100 && !env.IsCancelled(); ++i)
if (Connect(port, env))
/* make sure all remaining ACKs are flushed */
return port.FullFlush(env, 200, 500);
return false;
}
示例14: Wait
const_iterator Wait(const K &key, OperationEnvironment &env,
TimeoutClock timeout) {
while (true) {
auto i = map.find(key);
if (i != map.end() && !i->second.old)
return const_iterator(i);
if (env.IsCancelled())
return end();
int remaining = timeout.GetRemainingSigned();
if (remaining <= 0)
return end();
cond.timed_wait(*this, remaining);
}
}
示例15: Wait
const_iterator Wait(std::unique_lock<Mutex> &lock,
const K &key, OperationEnvironment &env,
TimeoutClock timeout) {
while (true) {
auto i = map.find(key);
if (i != map.end() && !i->second.old)
return const_iterator(i);
if (env.IsCancelled())
return end();
const auto remaining = timeout.GetRemainingSigned();
if (remaining.count() <= 0)
return end();
cond.wait_for(lock, remaining);
}
}