本文整理汇总了C++中HostInfo类的典型用法代码示例。如果您正苦于以下问题:C++ HostInfo类的具体用法?C++ HostInfo怎么用?C++ HostInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HostInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
QString HostInfoManager::nameForHost(unsigned int id) const
{
HostInfo* hostInfo = find(id);
if (hostInfo)
return hostInfo->name();
return tr("<unknown>");
}
示例2: getHostInfo
//host information mode
int getHostInfo(int argc, const char* arg, HostInfo& h)
{
hostent* remoteHost;
unsigned int addr;
#ifdef WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
char* hostname = (char*) malloc(40);
strcpy(hostname, arg);
if(isalpha(hostname[0]) != 0)
{
//name -> ipaddr
hostname[strlen(hostname)] = '\0';
remoteHost = gethostbyname(hostname);
if(!remoteHost)
{
cout << "Cannot resolve host information: " << WSAGetLastError() << endl;
}
else
{
h.setName(string(remoteHost->h_name));
struct in_addr rawaddr;
if(remoteHost -> h_addrtype == AF_INET)
{
for(int i=0; remoteHost->h_addr_list[i] != 0; i++)
{
rawaddr.s_addr = *(u_long*) remoteHost->h_addr_list[i];
h.addAddr(string(inet_ntoa(rawaddr)));
}
}
}
}
else
{
//num
addr = inet_addr(hostname);
remoteHost = gethostbyaddr((char*) &addr, 4, AF_INET);
if(!remoteHost)
{
cout << "Cannot resolve host information: " << WSAGetLastError() << endl;
}
else
{
cout << remoteHost->h_name << endl;
h.setName(string(remoteHost->h_name));
h.addAddr(hostname);
}
}
WSACleanup();
#else
cout << "Windows only function" << endl;
#endif
return 0;
}
示例3: to_thrift
void MatrixMasterThriftRpc::to_thrift(const HostInfo& info,
const std::string& host_ip,
const std::string& host_name,
ThriftHostInfo& t_info)
{
t_info.hostIp = host_ip;
t_info.hostName = host_name;
t_info.hostState = static_cast<ThriftHostState::type>(info.get_host_state());
to_thrift(info.get_total_resource(), t_info.totalResource);
}
示例4: beginInsertRows
void SensorBrowserModel::addHost(KSGRD::SensorAgent *sensorAgent, const QString &hostName)
{
beginInsertRows( QModelIndex() , mHostInfoMap.size(), mHostInfoMap.size() );
HostInfo* hostInfo = new HostInfo( mIdCount, sensorAgent, hostName);
mHostInfoMap.insert(mIdCount, hostInfo);
mTreeMap.insert(mIdCount, QList<int>());
mHostSensorsMap.insert(mIdCount, QHash<QString, bool>());
mIdCount++;
endInsertRows();
hostInfo->sensorAgent()->sendRequest( "monitors", this, mIdCount-1 );
}
示例5: switch
QVariant SensorBrowserModel::data( const QModelIndex & index, int role) const { //virtual
if(!index.isValid()) return QVariant();
switch(role) {
case Qt::DisplayRole: {
if(index.column()==0) {
uint id = index.internalId();
if(mSensorInfoMap.contains(id)) {
Q_ASSERT(mSensorInfoMap.value(id));
SensorInfo *sensorInfo = mSensorInfoMap.value(id);
return QString(sensorInfo->description() + " (" + KSGRD::SensorMgr->translateSensorType(sensorInfo->type()) + ')' );
}
if(mTreeNodeNames.contains(id)) return mTreeNodeNames.value(id);
if(mHostInfoMap.contains(id)) {
Q_ASSERT(mHostInfoMap.value(id));
return mHostInfoMap.value(id)->hostName();
}
}
return QString();
}
case Qt::DecorationRole: {
if(index.column() == 0) {
HostInfo *host = getHostInfo(index.internalId());
KSGRD::SensorAgent *agent;
if(host != NULL && (agent = host->sensorAgent())) {
if(agent->daemonOnLine())
return KIcon("computer");
else
return KIcon("dialog-warning");
} else
return QIcon();
} else
return QIcon();
break;
}
case Qt::ToolTipRole: {
if(index.column() == 0) {
HostInfo *host = getHostInfo(index.internalId());
KSGRD::SensorAgent *agent;
if(host != NULL && (agent = host->sensorAgent())) {
if(agent->daemonOnLine())
return agent->hostName();
else
return agent->reasonForOffline();
}
}
break;
}
} //switch
return QVariant();
}
示例6: HostInfo
HostInfo* HostInfoManager::checkNode(unsigned int hostid, const HostInfo::StatsMap& stats)
{
HostMap::ConstIterator it = m_hostMap.constFind(hostid);
HostInfo* hostInfo;
if (it == m_hostMap.constEnd()) {
hostInfo = new HostInfo(hostid);
m_hostMap.insert(hostid, hostInfo);
} else {
hostInfo = *it;
}
hostInfo->updateFromStatsMap(stats);
return hostInfo;
}
示例7: findHostInfoByHostName
void SensorBrowserModel::hostRemoved(const QString &hostName) {
HostInfo* toRemove = findHostInfoByHostName(hostName);
if (toRemove != NULL) {
beginResetModel();
int hostId = toRemove->id();
removeAllSensorUnderBranch(toRemove,hostId);
removeEmptyParentTreeBranches(hostId,hostId,hostId);
delete mHostInfoMap.take(hostId);
mTreeMap.take(hostId);
mHostSensorsMap.take(hostId);
endResetModel();
}
update();
}
示例8: p
bool StarView::event (QEvent* e)
{
if (e->type() != QEvent::ToolTip)
return QWidget::event(e);
QPoint p (static_cast<QHelpEvent*>(e)->pos());
HostItem *item = 0;
QGraphicsItem* graphicsItem = m_canvasView->itemAt(p);
if (graphicsItem)
item = dynamic_cast<HostItem*>(graphicsItem->parentItem());
if (item) {
HostInfo *hostInfo = item->hostInfo();
const QPoint gp(static_cast<QHelpEvent*>(e)->globalPos());
const QRect itemRect = m_canvasView->mapFromScene(graphicsItem->sceneBoundingRect()).boundingRect();
if (hostInfo) {
QToolTip::showText(gp+QPoint(10,10),
"<p><table><tr><td>"
"<img align=\"right\" source=\":/computer.png\"><br><b>" + item->hostName() +
"</b><br>" +
"<table>" +
"<tr><td>" + tr("IP:") + "</td><td>" + hostInfo->ip()
+ "</td></tr>" +
"<tr><td>" + tr("Platform:") + "</td><td>" +
hostInfo->platform() + "</td></tr>" +
"<tr><td>" + tr("Id:") + "</td><td>" +
QString::number(hostInfo->id()) + "</td></tr>" +
"<tr><td>" + tr("Speed:") + "</td><td>" +
QString::number(hostInfo->serverSpeed()) + "</td></tr>" +
"</table>"
"</td></tr></table></p>", this, itemRect);
} else {
QToolTip::showText(gp+QPoint(10,10),
"<p><table><tr><td>"
"<img align=\"right\" source=\":/computer.png\"><br><b>" + tr("Scheduler") + "</b><br/>"
"<table>" +
"<tr><td>" + tr("Host: %1").arg(hostInfoManager()->schedulerName()) + "</td></tr>" +
"<tr><td>" + tr("Network name: %1").arg(hostInfoManager()->networkName()) + "</td></tr>" +
"</table>"
"</td></tr></table></p>", this, itemRect);
}
} else {
QToolTip::hideText();
}
return QWidget::event(e);
}
示例9: hostResolved
void Tracker::hostResolved(HostInfo info) {
if (info.error()) {
logError(
boost::format("[%s] Host lookup failed: %s")
% info.getName() % info.errorMsg()
);
Utils::timedCallback(this, &Tracker::hostLookup, 60000);
} else {
m_addrs = info.getAddresses();
for (uint32_t i = 0; i < m_addrs.size(); ++i) {
m_addrs[i].setPort(m_port);
}
m_curAddr = m_addrs.begin();
connect(*m_curAddr);
}
}
示例10: start_server
int
start_server()
{
MSG("Starting OriSync");
rc = OriSyncConf();
announcer = new Announcer();
listener = new Listener();
repoMonitor = new RepoMonitor();
syncer = new Syncer();
myInfo = HostInfo(rc.getUUID(), rc.getCluster());
// XXX: Update addresses periodically
myInfo.setHost(OriStr_Join(OriNet_GetAddrs(), ','));
announcer->start();
listener->start();
repoMonitor->start();
syncer->start();
struct event_base *base = event_base_new();
struct evhttp *httpd = evhttp_new(base);
evhttp_bind_socket(httpd, "0.0.0.0", 8051);
evhttp_set_cb(httpd, "/", Httpd_getRoot, NULL);
// Event loop
event_base_dispatch(base);
evhttp_free(httpd);
event_base_free(base);
// XXX: Wait for worker threads
return 0;
}
示例11: main
int main(int argc, char* argv[]) {
vector<HostInfo> hostinfo_vector;
HostInfo hostinfo;
ifstream input(argv[1]);
string ip;
while (std::getline(input, ip)) {
int port_start = ip.find(':');
hostinfo.hostname = ip.substr(0, port_start);
hostinfo.port = std::stoi(ip.substr(port_start + 1));
hostinfo_vector.push_back(hostinfo);
}
auto num_hosts = hostinfo.size();
auto num_direct_hosts = num_hosts;
int vp_index = -1;
uint16_t vp_hosts_bits = 0;
vector<int> others_indices;
for (int i = 0; i < num_direct_hosts; ++i) {
others_hosts.push_back(i);
}
if (argc == 3 && argv[2][0] == 'v' && argv[2][1]) {
num_direct_hosts = num_hosts / 2;
vp_index = 1;
for (int i = num_direct_hosts; i < num_hosts; ++i) {
uint16_t mask = 1 << i;
vp_hosts_bits |= mask;
}
}
int data = 0;
AppendEntriesPacket packet(1, 0, 1, 0, 0, vp_index, uint16_t vp_hosts_bits) : header(term, previous_log_index,
previous_log_term, commit_index, president_index, vp_index, vp_hosts_bits)
while (true) {
sleep_for(milliseconds(300));
Network::SendPackets(packet.ToNetworkOrder().ToBytes(), LARGE_PACKET_SIZE, others_hosts);
}
return 0;
}
示例12: hostInfoManager
HostItem *StarView::createHostItem(unsigned int hostid)
{
HostInfo *i = hostInfoManager()->find(hostid);
if (!i || i->isOffline() || i->name().isEmpty())
return 0;
HostItem *hostItem = new HostItem(i, m_canvas, hostInfoManager());
hostItem->setHostColor(hostColor(hostid));
m_hostItems.insert(hostid, hostItem);
hostItem->show();
arrangeHostItems();
if (m_hostItems.count() > 25)
m_configDialog->setMaxNodes(m_hostItems.count());
return hostItem;
}
示例13: pullRepo
void pullRepo(HostInfo &localHost,
HostInfo &remoteHost,
const std::string &uuid)
{
RepoInfo local = localHost.getRepo(uuid);
RepoInfo remote = remoteHost.getRepo(uuid);
RepoControl repo = RepoControl(local.getPath());
DLOG("Local and Remote heads mismatch on repo %s", uuid.c_str());
repo.open();
if (!repo.hasCommit(remote.getHead())) {
LOG("Pulling from %s:%s",
remoteHost.getPreferredIp().c_str(),
remote.getPath().c_str());
repo.pull(remoteHost.getPreferredIp(), remote.getPath());
}
repo.close();
}
示例14: run
void run() {
while (!interruptionRequested()) {
HostInfo infoSnapshot;
list<string> repos;
list<string>::iterator it;
infoSnapshot = myInfo;
repos = infoSnapshot.listRepos();
for (it = repos.begin(); it != repos.end(); it++) {
LOG("Syncer checking %s", (*it).c_str());
checkRepo(infoSnapshot, *it);
}
sleep(ORISYNC_SYNCINTERVAL);
}
DLOG("Syncer exited!");
}
示例15: ConnectToHost
bool TcpSocket::ConnectToHost(const string& hostName,
const string& port,
IBamIODevice::OpenMode mode)
{
// create new address object with requested host name
HostAddress hostAddress;
hostAddress.SetAddress(hostName);
HostInfo info;
// if host name was IP address ("x.x.x.x" or IPv6 format)
// otherwise host name was 'plain-text' ("www.foo.bar")
// we need to look up IP address(es)
if ( hostAddress.HasIPAddress() )
info.SetAddresses( vector<HostAddress>(1, hostAddress) );
else
info = HostInfo::Lookup(hostName, port);
// attempt connection on requested port
return ConnectImpl(info, port, mode);
}