示例#1
0
func (config *ProductConfig) ValidateStatus(label string, params []interface{}) (*ProductObject, []interface{}, error) {
	// search for status name
	var paramInfo []StatusParam
	var status *ProductObject
	found := false
	for _, obj := range config.Objects {
		if obj.Label == label {
			paramInfo = obj.Status
			status = &obj
			found = true
			break
		}
	}
	if found == false {
		return nil, []interface{}{}, errors.New("object not found.")
	}
	if len(paramInfo) != len(params) {
		return nil, []interface{}{}, errors.New("wrong status parameters.")
	}
	realParams := make([]interface{}, len(params))
	for idx, para := range paramInfo {
		realParams[idx] = tlv.CastTLV(params[idx], para.ValueType)
	}
	return status, realParams, nil
}
示例#2
0
func (config *ProductConfig) ValidateCommandOrEvent(name string, params []interface{}, typ string) (*ProductCommandOrEvent, []interface{}, error) {
	var target []ProductCommandOrEvent
	if typ == "command" {
		target = config.Commands
	} else if typ == "event" {
		target = config.Events
	} else {
		return nil, []interface{}{}, errors.New("wrong target type.")
	}

	// search for name
	var paramInfo []CommandOrEventParam
	var coe *ProductCommandOrEvent
	found := false
	for _, one := range target {
		if one.Name == name {
			paramInfo = one.Params
			coe = &one
			found = true
			break
		}
	}
	if found == false {
		return nil, []interface{}{}, errors.New("command or event not found.")
	}
	if len(paramInfo) != len(params) {
		return nil, []interface{}{}, errors.New("wrong parameters.")
	}
	realParams := make([]interface{}, len(params))
	for idx, para := range paramInfo {
		realParams[idx] = tlv.CastTLV(params[idx], para.ValueType)
	}
	return coe, realParams, nil
}