Example #1
0
bool
TCPClientPort::Connect(const char *host, unsigned port)
{
  NarrowString<32> service;
  service.UnsafeFormat("%u", port);

  StaticSocketAddress address;
  if (!address.Lookup(host, service, AF_INET))
    return false;

  SocketDescriptor s;
  if (!s.CreateTCP())
    return false;

#ifdef HAVE_POSIX
  s.SetNonBlocking();
#endif

  if (s.Connect(address)) {
    Set(std::move(s));
    return true;
  }

#ifdef HAVE_POSIX
  if (errno == EINPROGRESS) {
    connecting = std::move(s);
    io_thread->LockAdd(connecting.ToFileDescriptor(), Poll::WRITE, *this);
    StateChanged();
    return true;
  }
#endif

  return false;
}
Example #2
0
void
Profile::SetGeoPoint(const char *key, const GeoPoint &value)
{
  NarrowString<128> buffer;
  buffer.UnsafeFormat("%f %f",
                      (double)value.longitude.Degrees(),
                      (double)value.latitude.Degrees());
  Set(key, buffer);
}
Example #3
0
bool
V7ConfigWidget::Save(bool &_changed, bool &require_restart)
{
  PopupOperationEnvironment env;
  bool changed = false;
  NarrowString<32> buffer;

  if (SaveValue(BRGPS, brgps)) {
    buffer.UnsafeFormat("%u", brgps);
    device.SendV7Setting("BRGPS", buffer, env);
    changed = true;
  }

  if (SaveValue(BRPDA, brpda)) {
    buffer.UnsafeFormat("%u", brpda);
    device.SendV7Setting("BRPDA", buffer, env);
    changed = true;
  }

  _changed |= changed;
  return true;
}
Example #4
0
bool
NanoConfigWidget::SaveSetting(const char *name, unsigned idx,
                              OperationEnvironment &env)
{
  const std::string old_value = device.GetNanoSetting(name);
  unsigned value = strtoul(old_value.c_str(), NULL, 10);
  if (!SaveValue(idx, value))
    return false;

  NarrowString<32> buffer;
  buffer.UnsafeFormat("%u", value);
  return device.SendNanoSetting(name, buffer, env);
}
Example #5
0
bool
TCPClientPort::Connect(const char *host, unsigned port)
{
  NarrowString<32> service;
  service.UnsafeFormat("%u", port);

  resolver.async_resolve({host, service.c_str()},
                         std::bind(&TCPClientPort::OnResolved, this,
                                   std::placeholders::_1,
                                   std::placeholders::_2));

  return true;
}
bool
LX16xxConfigWidget::SaveUnsignedSetting(LX1600::Setting key, unsigned idx,
                                        LX1600::SettingsMap &settings)
{
  const std::string old_value = device.GetLX16xxSetting(key);
  unsigned value = ParseUnsigned(old_value.c_str());
  if (!SaveValue(idx, value))
    return false;

  NarrowString<32> buffer;
  buffer.UnsafeFormat("%u", value);
  settings[key] = std::string(buffer.c_str(), buffer.end());
  return true;
}
Example #7
0
bool
FLARMConfigWidget::Save(bool &_changed)
{
  PopupOperationEnvironment env;
  bool changed = false;
  NarrowString<32> buffer;

  if (SaveValue(Baud, baud)) {
    buffer.UnsafeFormat("%u", baud);
    device.SendSetting("BAUD", buffer, env);
    changed = true;
  }

  if (SaveValue(Priv, priv)) {
    buffer.UnsafeFormat("%u", priv);
    device.SendSetting("PRIV", buffer, env);
    changed = true;
  }

  if (SaveValue(Thre, thre)) {
    buffer.UnsafeFormat("%u", thre);
    device.SendSetting("THRE", buffer, env);
    changed = true;
  }

  if (SaveValue(Range, range)) {
    buffer.UnsafeFormat("%u", range);
    device.SendSetting("RANGE", buffer, env);
    changed = true;
  }

  if (SaveValue(Acft, acft)) {
    buffer.UnsafeFormat("%u", acft);
    device.SendSetting("ACFT", buffer, env);
    changed = true;
  }

  if (SaveValue(LogInt, log_int)) {
    buffer.UnsafeFormat("%u", log_int);
    device.SendSetting("LOGINT", buffer, env);
    changed = true;
  }

  if (SaveValue(NoTrack, notrack)) {
    buffer.UnsafeFormat("%u", notrack);
    device.SendSetting("NOTRACK", buffer, env);
    changed = true;
  }

  _changed |= changed;
  return true;
}
bool
LX16xxConfigWidget::SaveFixedEnumSetting(LX1600::Setting key, unsigned idx,
                                         LX1600::SettingsMap &settings,
                                         unsigned factor)
{
  const std::string old_value = device.GetLX16xxSetting(key);
  unsigned value = unsigned(ParseDouble(old_value.c_str()) * factor);
  if (!SaveValue(idx, value))
    return false;

  NarrowString<32> buffer;
  buffer.UnsafeFormat("%.2f", (double)value / factor);
  settings[key] = std::string(buffer.c_str(), buffer.end());
  return true;
}