std::string FailoverWithExptimeRoute::keyWithFailoverTag( folly::StringPiece fullKey, const AccessPoint& ap) { const size_t tagLength = kFailoverTagStart.size() + ap.getHost().size() + 6; // 1 for kFailoverHostPortSeparator + 5 for port. std::string failoverTag; failoverTag.reserve(tagLength); failoverTag = kFailoverTagStart; failoverTag += ap.getHost().str(); if (ap.getPort() != 0) { failoverTag += kFailoverHostPortSeparator; failoverTag += folly::to<std::string>(ap.getPort()); } // Safety check: scrub the host and port for ':' to avoid appending // more than one field to the key. // Note: we start after the ':failover=' part of the string, // since we need the initial ':' and we know the remainder is safe. for (size_t i = kFailoverTagStart.size(); i < failoverTag.size(); i++) { if (failoverTag[i] == ':') { failoverTag[i] = '$'; } } return fullKey.str() + failoverTag; }
std::string ProxyDestinationMap::genProxyDestinationKey( const AccessPoint& ap, std::chrono::milliseconds timeout) const { if (ap.getProtocol() == mc_ascii_protocol) { // we cannot send requests with different timeouts for ASCII, since // it will break in-order nature of the protocol return folly::sformat("{}-{}", ap.toString(), timeout.count()); } else { return ap.toString(); } }
void WifiTile::WifiDetailAdapter::UpdateItems() { if (mItems == NULL) return; AutoPtr<IArrayList> items; if (mAccessPoints != NULL) { Boolean tmp = FALSE; CArrayList::New(mAccessPoints->GetLength(), (IArrayList**)&items); for (Int32 i = 0; i < mAccessPoints->GetLength(); i++) { AccessPoint* ap = (AccessPoint*)(*mAccessPoints)[i]; AutoPtr<CQSDetailItems::Item> item = new CQSDetailItems::Item(); item->mTag = ap->Probe(EIID_IInterface); ap->GetIconId(&item->mIcon); ap->GetSsid(&item->mLine1); if (ap->IsConnected(&tmp), tmp) { mHost->mContext->GetString(R::string::quick_settings_connected, &item->mLine2); } items->Add(i, item->Probe(EIID_IInterface)); } } mItems->SetItems(items); }
bool operator()(AccessPoint& object) { return object.getAccessPointSerial() == _attribute; }
int main(int argc, char const* argv[]) { if (argc < 3) { std::cout << "Usage: " << "/dev/ttyACM0 cmd" << std::endl << "cmd\t" << "description" << std::endl << "---\t" << "-----------" << std::endl << "td\t" << "Get Date and Time from the watch" << std::endl << "st\t" << "Set Time at 4:42:42 on the watch" << std::endl << "a\t" << "Get Alarm from the watch" << std::endl << "ta\t" << "Get Temperature and Altitude from the watch" << std::endl << "us\t" << "Get UnitSystem from the watch" << std::endl << "sus\t" << "Set UnitSystem to American on the watch" << std::endl << "sm\t" << "Set UnitSystem to Metric on the watch" << std::endl << "ssdt\t" << "Set System Date And Time on the watch" << std::endl; return -1; } AccessPoint ap; try { ap.open(argv[1]); } catch (...) { } if (!ap.isOpen()) { std::cout << "not open !" << std::endl; return -1; } if (ap.getRadioState() == AccessPoint::STOPPED) { std::cout << "Starting radio..." << std::endl; ap.startRadio(); } Watch watch(ap.getService()); if (argc > 2) { std::string arg = argv[2]; if (arg == "exit") { std::cout << "Exiting sync mode on the watch..." << std::endl; watch.exitWatchSyncMode(); } else if (arg == "td") { std::cout << "Date: " << watch.getDate() << std::endl; std::cout << "Time: " << watch.getTime() << std::endl; } else if (arg == "st") { Time t; t.hour = 4; t.minute = 42; t.second = 42; std::cout << "Setting time: " << t << std::endl; watch.setTime(t); std::cout << "Time: " << watch.getTime() << std::endl; } else if (arg == "a") { std::cout << "Alarm: " << watch.getAlarm() << std::endl; } else if (arg == "ta") { std::cout << "Temp: " << watch.getTemperature() << std::endl; std::cout << "Alt: " << watch.getAltitude() << std::endl; } else if (arg == "sa") { Time t; t.hour = 4; t.minute = 42; t.second = 0; std::cout << "Setting AlarmTime: " << t << std::endl; watch.setAlarm(t); std::cout << "Alarm: " << watch.getAlarm() << std::endl; } else if (arg == "ta") { std::cout << "Temp: " << watch.getTemperature() << std::endl; std::cout << "Alt: " << watch.getAltitude() << std::endl; } else if (arg == "us") { std::cout << "UnitSystem: " << watch.getUnitSystem() << std::endl; } else if (arg == "sus") { std::cout << "Set American unit" << std::endl; watch.setUnitSystem(Watch::AMERICAN); std::cout << "UnitSystem: " << std::boolalpha << watch.getUnitSystem() << std::endl; } else if (arg == "sm") { std::cout << "Set Metric unit" << std::endl; watch.setUnitSystem(Watch::METRIC); std::cout << "UnitSystem: " << std::boolalpha << watch.getUnitSystem() << std::endl; } else if (arg == "ssdt") { watch.setSystemDateAndTime(); std::cout << "Date: " << watch.getDate() << std::endl; std::cout << "Time: " << watch.getTime() << std::endl; } } std::cout << "bye..." << std::endl; return 0; }
/** Adds an asynchronous request to the event log. */ void asynclog_delete(proxy_t* proxy, const AccessPoint& ap, folly::StringPiece key, folly::StringPiece poolName) { dynamic json = {}; const auto& host = ap.getHost(); const auto& port = proxy->router().opts().asynclog_port_override == 0 ? ap.getPort() : proxy->router().opts().asynclog_port_override; if (proxy->router().opts().use_asynclog_version2) { json = dynamic::object; json["f"] = proxy->router().opts().flavor_name; json["h"] = folly::sformat("[{}]:{}", host, port); json["p"] = poolName.str(); json["k"] = key.str(); } else { /* ["host", port, escaped_command] */ json.push_back(host); json.push_back(port); json.push_back(folly::sformat("delete {}\r\n", key)); } auto fd = asynclog_open(proxy); if (!fd) { MC_LOG_FAILURE(proxy->router().opts(), memcache::failure::Category::kSystemError, "asynclog_open() failed (key {}, pool {})", key, poolName); return; } // ["AS1.0", 1289416829.836, "C", ["10.0.0.1", 11302, "delete foo\r\n"]] // OR ["AS2.0", 1289416829.836, "C", {"f":"flavor","h":"[10.0.0.1]:11302", // "p":"pool_name","k":"foo\r\n"}] dynamic jsonOut = {}; if (proxy->router().opts().use_asynclog_version2) { jsonOut.push_back(ASYNCLOG_MAGIC2); } else { jsonOut.push_back(ASYNCLOG_MAGIC); } struct timeval timestamp; CHECK(gettimeofday(×tamp, nullptr) == 0); auto timestamp_ms = facebook::memcache::to<std::chrono::milliseconds>(timestamp).count(); jsonOut.push_back(1e-3 * timestamp_ms); jsonOut.push_back(std::string("C")); jsonOut.push_back(json); auto jstr = folly::toJson(jsonOut) + "\n"; ssize_t size = folly::writeFull(fd->fd(), jstr.data(), jstr.size()); if (size == -1 || size_t(size) < jstr.size()) { MC_LOG_FAILURE(proxy->router().opts(), memcache::failure::Category::kSystemError, "Error fully writing asynclog request (key {}, pool {})", key, poolName); } }