int RegistryMuninNodePlugin::GetConfig(char *buffer, int len)
{
	CRegistry reg(m_RootKey, m_SubKey);
	reg.Check(); // reopen if reg is removed then added

	string graphTitle = reg.GetValue("graph_title", "Disk Time");
	string graphCategory = reg.GetValue("graph_category", "system");
	string graphArgs = reg.GetValue("graph_args", "--base 1000 -l 0");
	string graphInfo = reg.GetValue("graph_info", "disk time");
	string graphVlabel = reg.GetValue("graph_vlabel", "Disk Time");

	int printCount;
	printCount = _snprintf(buffer, len, "graph_title %s\n"
		"graph_category %s\n"
		"graph_args %s\n"
		"graph_info %s\n"
		"graph_vlabel %s\n", 
		graphTitle.c_str(), graphCategory.c_str(), 
		graphArgs.c_str(), graphInfo.c_str(), 
		graphVlabel.c_str() );
	len -= printCount;
	buffer += printCount;

	vector<string> keys;
	reg.EnumKeys(keys);

	// for keys, add definition
	for(vector<string>::iterator it=keys.begin(); it!=keys.end(); ++it)
	{
		string subkey(m_SubKey);
		CRegistry sub_reg(m_RootKey, subkey.append("\\").append(*it));
		string label = sub_reg.GetValue("label", "disk time");
		string draw = sub_reg.GetValue("draw", "Disk Time");

		printCount = _snprintf(buffer, len, "%s.label %s\n"
			"%s.draw %s\n", 
			it->c_str(), label.c_str(),
			it->c_str(), draw.c_str() );

		len -= printCount;
		buffer += printCount;
	}
	strncat(buffer, ".\n", len);

	return 0;
}
int RegistryMuninNodePlugin::GetValues(char *buffer, int len)
{
	CRegistry reg(m_RootKey, m_SubKey);
	vector<string> keys;
	reg.EnumKeys(keys);

	// for keys, add definition
	for(vector<string>::iterator it=keys.begin(); it!=keys.end(); ++it)
	{
		int printCount;
		string subkey(m_SubKey);
		CRegistry sub_reg(m_RootKey, subkey.append("\\").append(*it));
		double v = sub_reg.GetValueF("value", 0.0);
		
		printCount = _snprintf(buffer, len, "%s.value %.2f\n", it->c_str(), v);

		len -= printCount;
		buffer += printCount;
	}

	strncat(buffer, ".\n", len);

	return 0;
}
Пример #3
0
static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
		unsigned long *size)
{
	u32 last_addr[MAX_ADDR_CELLS];
	u32 this_addr[MAX_ADDR_CELLS];
	void *parent;
	u64 ret_addr, ret_size;
	u32 naddr, nsize, prev_naddr, prev_nsize;
	int buflen, offset;

	parent = get_parent(node);
	if (!parent)
		return 0;

	dt_get_reg_format(parent, &naddr, &nsize);

	if (nsize > 2)
		return 0;

	offset = (naddr + nsize) * res;

	if (reglen < offset + naddr + nsize ||
	    MAX_PROP_LEN < (offset + naddr + nsize) * 4)
		return 0;

	copy_val(last_addr, prop_buf + offset, naddr);

	ret_size = prop_buf[offset + naddr];
	if (nsize == 2) {
		ret_size <<= 32;
		ret_size |= prop_buf[offset + naddr + 1];
	}

	for (;;) {
		prev_naddr = naddr;
		prev_nsize = nsize;
		node = parent;

		parent = get_parent(node);
		if (!parent)
			break;

		dt_get_reg_format(parent, &naddr, &nsize);

		buflen = getprop(node, "ranges", prop_buf,
				sizeof(prop_buf));
		if (buflen == 0)
			continue;
		if (buflen < 0 || buflen > sizeof(prop_buf))
			return 0;

		offset = find_range(last_addr, prop_buf, prev_naddr,
		                    naddr, prev_nsize, buflen / 4);

		if (offset < 0)
			return 0;

		copy_val(this_addr, prop_buf + offset, prev_naddr);

		if (!sub_reg(last_addr, this_addr))
			return 0;

		copy_val(this_addr, prop_buf + offset + prev_naddr, naddr);

		if (!add_reg(last_addr, this_addr, naddr))
			return 0;
	}

	if (naddr > 2)
		return 0;

	ret_addr = ((u64)last_addr[2] << 32) | last_addr[3];

	if (sizeof(void *) == 4 &&
	    (ret_addr >= 0x100000000ULL || ret_size > 0x100000000ULL ||
	     ret_addr + ret_size > 0x100000000ULL))
		return 0;

	*addr = ret_addr;
	if (size)
		*size = ret_size;

	return 1;
}