//==========================================================================
// Class:			XMLConversionFactors
// Function:		ReadGroupNode
//
// Description:		Reads the specified group node and it's children.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		None
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool XMLConversionFactors::ReadGroupNode(wxXmlNode *node)
{
	FactorGroup newGroup;
	if (!node->GetAttribute(nameAttr, &newGroup.name))
	{
		DoErrorMessage(_T("Cannot read '") + nameAttr + _T("' attribute for '") + groupNodeStr + _T("' node"));
		return false;
	}

	newGroup.display = node->GetAttribute(displayAttr, _T("1")).Cmp(_T("1")) == 0;

	wxXmlNode *child = node->GetChildren();
	while (child)
	{
		if (child->GetName().Cmp(equivNode) == 0)
		{
			Equivalence equiv;
			if (!ReadEquivNode(child, equiv))
				return false;
			newGroup.equiv.push_back(equiv);
		}
		/*else// Don't do this to allow comments
		{
			DoErrorMessage(_T("Unknown node '") + child->GetName() + _T("'"));
			return false;
		}*/

		child = child->GetNext();
	}

	if (newGroup.equiv.size() == 0)
	{
		DoErrorMessage(_T("Group '") + newGroup.name + _T("' has no equivalence definitions"));
		return false;
	}

	groups.push_back(newGroup);
	return true;
}
//==========================================================================
// Class:			XMLConversionFactors
// Function:		ReadEquivNode
//
// Description:		Reads the specified equivalence node.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		None
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool XMLConversionFactors::ReadEquivNode(wxXmlNode *node, Equivalence &equiv)
{
	if (!node->GetAttribute(aUnitAttr, &equiv.aUnit))
	{
		DoErrorMessage(_T("Cannot read '") + aUnitAttr + _T("' property from '") + equivNode + _T("' node"));
		return false;
	}

	if (!node->GetAttribute(bUnitAttr, &equiv.bUnit))
	{
		DoErrorMessage(_T("Cannot read '") + bUnitAttr + _T("' property from '") + equivNode + _T("' node"));
		return false;
	}

	if (!node->GetAttribute(equationAttr, &equiv.equation))
	{
		DoErrorMessage(_T("Cannot read '") + equationAttr + _T("' property from '") + equivNode + _T("' node"));
		return false;
	}
	if (!equiv.equation.Contains(_T("=")) ||
		!equiv.equation.Contains(_T("a")) ||
		!equiv.equation.Contains(_T("b")))
	{
		DoErrorMessage(_T("Relationship between '") + equiv.aUnit + _T("' and '")
			+ equiv.bUnit + _T("' must containt 'a', 'b', and '='"));
		return false;
	}

	if (equiv.aUnit.Cmp(equiv.bUnit) == 0)
	{
		DoErrorMessage(_T("Equivalence definition must have two unique unit strings"));
		return false;
	}

	return true;
}
//==========================================================================
// Class:			XMLConversionFactors
// Function:		DuplicateGroupsExist
//
// Description:		Determines uniqueness of the groups.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		None
//
// Return Value:
//		bool, true if two groups have the same name
//
//==========================================================================
bool XMLConversionFactors::DuplicateGroupsExist() const
{
	unsigned int i, j;
	for (i = 1; i < groups.size(); i++)
	{
		for (j = i + 1; j < groups.size(); j++)
		{
			if (groups[i].name.CmpNoCase(groups[j].name) == 0)
			{
				DoErrorMessage(_T("Duplicate groups '") + groups[i - 1].name + _T("'"));
				return true;
			}
		}
	}

	return false;
}
//==========================================================================
// Class:			XMLConversionFactors
// Function:		Load
//
// Description:		Method for initializing this object.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		None
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool XMLConversionFactors::Load()
{
	ResetForLoad();

	if (!document->Load(fileName, xmlEncoding, wxXMLDOC_KEEP_WHITESPACE_NODES))
		return false;// Error message generated in wx call - don't create additional message

	if (document->GetFileEncoding().Cmp(xmlEncoding) != 0)
	{
		wxMessageBox(_T("The XML declaration in ") + fileName
			+ _T(" contains 'encoding=") + document->GetFileEncoding()
			+ _T("', but Converter expects ") + xmlEncoding + _T("."));
		return false;
	}

	if (document->GetRoot()->GetName().Cmp(rootName) != 0)
	{
		DoErrorMessage(_T("Root node expected to be '") + rootName + _T("'"));
		return false;
	}

	wxXmlNode *child = document->GetRoot()->GetChildren();
	while (child)
	{
		if (child->GetName().Cmp(groupNodeStr) == 0)
		{
			if (!ReadGroupNode(child))
				return false;
		}
		/*else// Don't do this to allow comments
		{
			DoErrorMessage(_T("Unknown node '") + child->GetName() + _T("'"));
			return false;
		}*/

		child = child->GetNext();
	}

	if (DuplicateGroupsExist())
		return false;

	return groups.size() > 0;
}
Beispiel #5
0
void KmxController::Poll() {
  //poll is called every at least every 100 ms but can be alot more often
  if(msPast(&tval_poll_callbacks,200)){
    //debug("polling callbacks");
    mq->PollCallbacks();
  }

  //only perform poll when locked
  //Timeout must be short enough not to be reentering if multiple threads are calling poll
  if(msPast(&tval_status,200)){
    if(km->WaitToken(false,100) == KMOTION_LOCKED){

      if(!simulate){
        // Note only service the console
        // after we have the token so we
        // are sure of no getting blocked
        if(km->ServiceConsole()){
            //TODO not verified that this works.
            DoErrorMessage(">ServiceConsole Failed\n");
        }
        if(readStatus()){
          //return;
        }
      }
      km->ReleaseToken();

      //TODO
      //if(!simulate){
      //ServiceKFLOPCommands();
      //}

    }
    UpdateClient();

  }

}