Beispiel #1
0
bool IPCSetType::GetMethod(LSOBJECTDATA &ObjectData, PLSTYPEMETHOD pMethod, int argc, char *argv[])
{
/*******************************************
 * Parameters
 *
 * [in] LSOBJECTDATA ObjectData: ObjectData is a 32-bit value that can be accessed in any number of different ways
 *        by way of union.  Most commonly, ObjectData.Ptr, ObjectData.DWord, or ObjectData.CharPtr are useful.  This
 *        value is the representation of some object of this object type.  "ipcfoo" works on IPCFoo*
 *        so ObjectData is a IPCFoo*
 *
 * [in] PLSTYPEMETHOD pMethod: pMethod is a pointer to the information on the method to be retrieved, including its
 *        Name and ID.  We use the ID in a switch statement in order to quickly process the method, since the Name
 *        has already been resolved by the LavishScript engine.
 *
 * [in] int argc, char *argv[]: argc and argv are *nearly* standard C console program parameters.  The difference here
 *        is that the name of the method is NOT given as the first argument (in contrast to LavishScript commands).
 *        Therefore, argc is 0 unless arguments are specifically given to the method retrieval.
 */

/*******************************************
 * Return Value
 *
 * The return value for this function is very simple.  If the method execution fails for any reason, OR the object
 * is destroyed during execution, return false.  Otherwise, return true (indicating the object still exists AND
 * the method execution succeeded).
 *
 */
	/* Validate the pointer */
	if (!pSet)
		return false;

	/* Perform the given member retrieval */
	switch(pMethod->ID)
	{
	case Add:
		if(argc)
		{
			pSet->Set->AddItem(argv[0]);
			SetRelay(pSet->IPCName, "Add", argc, argv);
			return true;
		}
		return false;
	case Remove:
		if(argc)
		{
			pSet->Set->RemoveItem(argv[0]);
			SetRelay(pSet->IPCName, "Remove", argc, argv);
			return true;
		}
		return false;
	case Set:
	case SetIPCName:
		if(argc)
		{
			LSSet *newSet;
			strncpy(pSet->IPCName, argv[0], sizeof(pSet->IPCName));
			if((newSet=FindSet(pSet->IPCName))==0)
			{
				newSet = new LSSet();
				AddSet(pSet->IPCName, newSet);
			}
			pSet->Set = newSet;
			return true;
		}
		return false;
	case GetIterator:
		LSOBJECT iteratorobject;
		if(argc)
		{
			//printf("%s %s %d", argv[0], pSet->IPCName, pSet->Set->GetContainerUsed());
			if(pLSInterface->DataParse(argv[0], iteratorobject))
			{
				return InitializeIterator(pSet->Set, 0, iteratorobject);
			}
		}
		return false;
	}
	return false;
}
/**
 * Set the relay state.
 *
 * Valid values depend on which directions of the relay are controlled by the object.
 *
 * When set to kBothDirections, the relay can only be one of the three reasonable
 *    values, 0v-0v, 0v-12v, or 12v-0v.
 *
 * When set to kForwardOnly or kReverseOnly, you can specify the constant for the
 *    direction or you can simply specify kOff and kOn.  Using only kOff and kOn is
 *    recommended.
 *
 * @param channel The relay channel number for this object
 * @param value The state to set the relay.
 */
void SetRelay(UINT32 channel, RelayValue value)
{
	SetRelay(SensorBase::GetDefaultDigitalModule(), channel, value);
}