Beispiel #1
0
void TvStateUpdate(char *UDN, int Service, IXML_Document *ChangedVariables,
		   char **State)
{
	IXML_NodeList *properties;
	IXML_NodeList *variables;
	IXML_Element *property;
	IXML_Element *variable;
	long unsigned int length;
	long unsigned int length1;
	long unsigned int i;
	int j;
	char *tmpstate = NULL;

	SampleUtil_Print("Tv State Update (service %d):\n", Service);
	/* Find all of the e:property tags in the document */
	properties = ixmlDocument_getElementsByTagName(ChangedVariables,
		"e:property");
	if (properties) {
		length = ixmlNodeList_length(properties);
		for (i = 0; i < length; i++) {
			/* Loop through each property change found */
			property = (IXML_Element *)ixmlNodeList_item(
				properties, i);
			/* For each variable name in the state table,
			 * check if this is a corresponding property change */
			for (j = 0; j < TvVarCount[Service]; j++) {
				variables = ixmlElement_getElementsByTagName(
					property, TvVarName[Service][j]);
				/* If a match is found, extract 
				 * the value, and update the state table */
				if (variables) {
					length1 = ixmlNodeList_length(variables);
					if (length1) {
						variable = (IXML_Element *)
							ixmlNodeList_item(variables, 0);
						tmpstate =
						    SampleUtil_GetElementValue(variable);
						if (tmpstate) {
							strcpy(State[j], tmpstate);
							SampleUtil_Print(
								" Variable Name: %s New Value:'%s'\n",
								TvVarName[Service][j], State[j]);
						}
						if (tmpstate)
							free(tmpstate);
						tmpstate = NULL;
					}
					ixmlNodeList_free(variables);
					variables = NULL;
				}
			}
		}
		ixmlNodeList_free(properties);
	}
	return;
	UDN = UDN;
}
/********************************************************************************
 * WscStateVarUpdate
 *
 * Description: 
 *       Update a Wsc state table.  Called when an event is received.  
 *
 * Parameters:
 *   devNode -- The Wsc Device which need to update the State Variables.
 *   ChangedStateVars -- DOM document representing the XML received with the event
 *
 * Note: 
 *       This function is NOT thread save.  It must be called from another function 
 *       that has locked the global device list.
 ********************************************************************************/
void WscStateVarUpdate(
	IN struct upnpDeviceNode *devNode,
	IN IXML_Document *stateDoc)
{
	IXML_NodeList *properties, *stateVars;
	IXML_Element *propItem, *varItem;
	int propLen;
	int i, j;
	char *stateVal = NULL;


	/* Find all of the e:property tags in the document */
	properties = ixmlDocument_getElementsByTagName(stateDoc, "e:property");
	if (properties != NULL)
	{
		propLen = ixmlNodeList_length(properties);
		for (i = 0; i < propLen; i++)
		{ 	/* Loop through each property change found */
			propItem = (IXML_Element *)ixmlNodeList_item(properties, i);
			
			/*
				For each stateVar name in the state table, check if this
				is a corresponding property change
			*/
			for (j = 0; j < WSC_STATE_VAR_MAXVARS; j++)
			{
				stateVars = ixmlElement_getElementsByTagName(propItem, WscVarName[j]);
				/* If found matched item, extract the value, and update the stateVar table */
				if (stateVars)
				{
					if (ixmlNodeList_length(stateVars))
					{
						varItem = (IXML_Element *)ixmlNodeList_item(stateVars, 0);
						stateVal = SampleUtil_GetElementValue(varItem);
						if (stateVal)
						{
							if (devNode->device.services.StateVarVal[j] != NULL)
							{
								//DBGPRINTF(RT_DBG_INFO, "Free the OLD statVarVal!\n"); 
								// We didn't need do this, because the libupnp will free it.
								//free(&devNode->device.services.StateVarVal[j]);
							}
							devNode->device.services.StateVarVal[j] = stateVal;
						}
					}

					ixmlNodeList_free(stateVars);
					stateVars = NULL;
				}
			}
		}
		
		ixmlNodeList_free(properties);
		
	}
}