(WIP) Move rule initialization into rule package.
This commit is contained in:
parent
727985f91c
commit
9e4062ba30
21 changed files with 366 additions and 489 deletions
|
|
@ -93,6 +93,11 @@ func initVirtualBuffers(config *configparser.Config) (map[string]*evdev.InputDev
|
|||
return vDevicesByName, vBuffersByName, vBuffersByDevice
|
||||
}
|
||||
|
||||
// TODO: At some point it would *very likely* make sense to map each rule to all of the physical devices that can
|
||||
// trigger it, and return that instead. Something like a map[Device][]mappingrule.MappingRule.
|
||||
// This would speed up rule matching by only checking relevant rules for a given input event.
|
||||
// We could take this further and make it a map[<struct of *inputdevice, type, and code>][]rule
|
||||
// For very large rule-bases this may be helpful for staying performant.
|
||||
func loadRules(
|
||||
config *configparser.Config,
|
||||
pDevices map[string]*evdev.InputDevice,
|
||||
|
|
@ -103,8 +108,21 @@ func loadRules(
|
|||
eventChannel := make(chan ChannelEvent, 1000)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
// Setup device mapping for the mappingrules package
|
||||
pDevs := mappingrules.ConvertDeviceMap(pDevices)
|
||||
vDevs := mappingrules.ConvertDeviceMap(vDevices)
|
||||
|
||||
// Initialize rules
|
||||
rules := configparser.InitRules(config.Rules, pDevices, vDevices, modes)
|
||||
rules := make([]mappingrules.MappingRule, 0)
|
||||
for _, ruleConfig := range config.Rules {
|
||||
newRule, err := mappingrules.NewRule(ruleConfig, pDevs, vDevs, modes)
|
||||
if err != nil {
|
||||
logger.LogError(err, "Failed to create rule, skipping")
|
||||
continue
|
||||
}
|
||||
rules = append(rules, newRule)
|
||||
}
|
||||
|
||||
logger.Logf("Created %d mapping rules.", len(rules))
|
||||
|
||||
// start listening for events on devices and timers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue