int main() {
	unsigned int id;
	printf ("Enter the id of the domain: ");
	scanf ("%du", &id);
	
	getDomainInfo(id);

	return(0);
}
void FieldPropertiesDialog::updateDomainInfo(const wxString& domain)
{
    wxString type, size, scale, charset;
    if (!getDomainInfo(domain, type, size, scale, charset))
        return;
    textctrl_scale->SetValue(scale);
    textctrl_size->SetValue(size);
    choice_datatype->SetSelection(choice_datatype->FindString(type));
    choice_charset->SetSelection(choice_charset->FindString(charset));
}
Beispiel #3
0
int main()
{
    getDomainInfo(0);

    return 0;
}
// UDD = user defined domain
// AGD = auto generated domain (those starting with RDB$)
bool FieldPropertiesDialog::getStatementsToExecute(wxString& statements,
    bool justCheck)
{
    wxString colNameSql(Identifier::userString(textctrl_fieldname->GetValue()));
    Identifier selDomain(choice_domain->GetStringSelection());
    bool newDomain = getIsNewDomainSelected();
    wxString selDatatype = choice_datatype->GetStringSelection();
    wxString dtSize = textctrl_size->GetValue();
    wxString dtScale = textctrl_scale->GetValue();
    bool isNullable = !checkbox_notnull->IsChecked();

    int n = choice_datatype->GetSelection();
    if (n >= 0 && n < datatypescnt)
    {
        if (!datatypes[n].hasSize)
            dtSize.Clear();
        if (!datatypes[n].hasScale)
            dtScale.Clear();
    }

    wxString alterTable = "ALTER TABLE " + tableM->getQuotedName() + " ";
    enum unn { unnNone, unnBefore, unnAfter } update_not_null = unnNone;

    // detect changes to existing field, create appropriate SQL actions
    if (columnM)
    {
        // field name changed ?
        // compare regardless of active quoting rules, so that name
        // will remain unchanged if edit field contents haven't changed
        // OR if the altered name would result in same SQL identifier
        if (textctrl_fieldname->GetValue() == columnM->getName_()
            || colNameSql == columnM->getQuotedName())
        {
            // no changes -> use original name for all other statements
            colNameSql = columnM->getQuotedName();
        }
        else
        {
            statements += alterTable + "ALTER " + columnM->getQuotedName()
                + " TO " + colNameSql + ";\n\n";
        }

        // domain changed ?
        wxString type, size, scale, charset;
        if (!getDomainInfo(columnM->getSource(), type, size, scale, charset))
        {
            ::wxMessageBox(_("Can not get domain info - aborting."),
                _("Error"), wxOK | wxICON_ERROR);
            return false;
        }
        if (columnM->getSource() != selDomain.get() && !newDomain)
        {   // UDD -> other UDD  or  AGD -> UDD
            statements += alterTable + "ALTER " + colNameSql +
                " TYPE " + selDomain.getQuoted() + ";\n\n";
        }
        else if (newDomain
            || type.CmpNoCase(selDatatype) || size != dtSize || scale != dtScale)
        {   // UDD -> AGD  or  AGD -> different AGD
            statements += alterTable + "ALTER " + colNameSql +
                " TYPE ";
            statements += selDatatype;
            if (!dtSize.IsEmpty())
            {
                statements += "(" + dtSize;
                if (!dtScale.IsEmpty())
                    statements += "," + dtScale;
                statements += ")";
            }
            statements += ";\n\n";
        }

        // not null option changed ?
        if (isNullable != columnM->isNullable(CheckDomainNullability))
        {
            if (!isNullable) // change from NULL to NOT NULL
                update_not_null = unnBefore;

            statements += "UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = ";
            if (isNullable)
                statements += "NULL";
            else
                statements += "1";
            // direct change in RDB$RELATION_FIELDS needs unquoted field name
            Identifier id;
            id.setFromSql(colNameSql);
            wxString fnm = id.get();
            fnm.Replace("'", "''");
            wxString tnm = tableM->getName_();
            statements += "\nWHERE RDB$FIELD_NAME = '" + fnm
                + "' AND RDB$RELATION_NAME = '" + tnm
                + "';\n\n";

            if (isNullable) // change from NOT NULL to NULL
            {
                wxString constraintName;
                if (getNotNullConstraintName(fnm, constraintName))
                {
                    statements += alterTable + "DROP CONSTRAINT "
                        + constraintName + ";\n\n";
                }
            }
        }
    }
    else // create new field
    {
        wxString addCollate;
        statements += alterTable + "ADD \n" + colNameSql + " ";
        if (newDomain)
        {
            statements += selDatatype;
            if (!dtSize.IsEmpty())
            {
                statements += "(" + dtSize;
                if (!dtScale.IsEmpty())
                    statements += "," + dtScale;
                statements += ")";
            }
            if (datatypes[n].isChar)
            {
                wxString charset = choice_charset->GetStringSelection();
                wxString collate = choice_collate->GetStringSelection();
                if (!charset.IsEmpty())
                {
                    statements += " CHARACTER SET " + charset;
                    if (!collate.IsEmpty())
                        addCollate = " COLLATE " + collate;
                }
            }
        }
        else
            statements += selDomain.getQuoted();

        if (!isNullable)
        {
            statements += " NOT NULL";
            update_not_null = unnAfter;
        }
        statements += addCollate + ";\n\n";
    }

    if (update_not_null != unnNone && !justCheck)
    {
        wxString s = ::wxGetTextFromUser(
            _("Enter value for existing fields containing NULL"),
            _("Update Existing NULL Values"), "", this);
        if (update_not_null == unnBefore)
        {
            wxString origColumnName = columnM->getQuotedName();
            statements = "UPDATE " + tableM->getQuotedName()
                + " \nSET " + origColumnName + " = '" + s
                + "' \nWHERE " + origColumnName + " IS NULL;\n"
                + statements;
        }
        else
        {
            statements = statements + "COMMIT;\n"
                + "UPDATE " + tableM->getQuotedName()
                + " \nSET " + colNameSql + " = '" + s
                + "' \nWHERE " + colNameSql + " IS NULL;\n";
        }
    }
    statements += textctrl_sql->GetValue();
    return !statements.IsEmpty();
}
Beispiel #5
0
int main()
{
    int idCount;
    int i;
    int id;
    //int ids[MAXID];
	int *ids;
    //timeInfoNode timeInfos[MAXID];

    printf("--------------------------------------------------------\n");
    printf("             XEN Domain Monitor \n");
    printf("--------------------------------------------------------\n");

    /* NULL means connect to local Xen hypervisor */
    conn = virConnectOpenReadOnly(NULL);
    if (conn == NULL)
    {
        fprintf(stderr, "Failed to connect to hypervisor\n");
        closeConn();
        return 0;
    }

	/*char* caps;
	caps = virConnectGetCapabilities(conn);
	printf("Capabilities:\n%s\n",caps);
	free(caps);*/
	char *host;
	host = virConnectGetHostname(conn);
	fprintf(stdout, "Hostname:%s\n",host);
	free(host);
	int vcpus;
	vcpus = virConnectGetMaxVcpus(conn,NULL);
	fprintf(stdout, "Maxmum support vcpus:%d\n",vcpus);
	unsigned long long node_free_memory;
	node_free_memory = virNodeGetFreeMemory(conn);
	fprintf(stdout, "free memory:%lld\n",node_free_memory);
	virNodeInfo nodeinfo;
	virNodeGetInfo(conn,&nodeinfo);
	fprintf(stdout, "Model: %s\n", nodeinfo.model);
    fprintf(stdout, "Memory size: %lukb\n", nodeinfo.memory);
    fprintf(stdout, "Number of CPUs: %u\n", nodeinfo.cpus);
    fprintf(stdout, "MHz of CPUs: %u\n", nodeinfo.mhz);
    fprintf(stdout, "Number of NUMA nodes: %u\n", nodeinfo.nodes);
    fprintf(stdout, "Number of CPU sockets: %u\n", nodeinfo.sockets);
    fprintf(stdout, "Number of CPU cores per socket: %u\n", nodeinfo.cores);
    fprintf(stdout, "Number of CPU threads per core: %u\n", nodeinfo.threads);	
    fprintf(stdout, "Virtualization type: %s\n", virConnectGetType(conn));
	unsigned long ver;
	virConnectGetVersion(conn, &ver);
	fprintf(stdout, "Version: %lu\n", ver);
	/*unsigned long Libver;
	virConnectGetLibVersion(conn, &Libver);
	fprintf(stdout, "Libvirt Version: %lu\n", Libver);*/
	char *uri;
	uri = virConnectGetURI(conn);
	fprintf(stdout, "Canonical URI: %s\n", uri);
	free(uri);
	/* get the count of IDs and save these ID into ids[] */
    idCount = virConnectNumOfDomains(conn);
	ids = malloc(sizeof(int) *idCount);
	idCount = virConnectListDomains(conn,ids,idCount);
	//idCount = virConnectListDomains(conn, &ids[0], MAXID);
    if (idCount < 0)
    {
        fprintf(stderr, "Failed to list the domains\n");
        closeConn();
        return 0;
    }

    timeInfoNode timeInfos[idCount];
	printf("Domain Totals: %d\n", idCount);
    printf("ID\tCPU\tMEM\tMaxMEM\tVCPUs\tState\tNAME\n");

    /* loop get the CPUtime info by IDs */
    for (i = 0; i < idCount; i++)
    {
        id = ids[i];
        getTimeInfo(id, &(timeInfos[i]));
    }

    sleep(1);

    /* loop print the domain info and calculate the usage of cpus*/
    for (i = 0; i < idCount; i++)
    {
        id = ids[i];
        getDomainInfo(id, timeInfos[i]);
    }

    free(ids);
	printf("--------------------------------------------------------\n");
    closeConn();
    return 0;
}