Skip to content

Commit

Permalink
feat: support load custom resource or device
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Sep 4, 2022
1 parent eefd31a commit caf07c0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
14 changes: 13 additions & 1 deletion engine/load_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,21 @@ func (e *RuleEngine) RemoveDevice(uuid string) {
}
}

/*
* 从0.4.0开始, 可支持用户加载设备
* 加载用户设备, 第一个参数为Worker, 第二个参数为设备原始信息,实际上就是元数据
*
*/
func (e *RuleEngine) LoadUserDevice(abstractDevice typex.XDevice, deviceInfo *typex.Device) error {
return startDevices(abstractDevice, deviceInfo, e)
}

//
// 加载设备
// 加载内置设备
//
func (e *RuleEngine) LoadBuiltinDevice(deviceInfo *typex.Device) error {
return e.LoadDevice(deviceInfo)
}
func (e *RuleEngine) LoadDevice(deviceInfo *typex.Device) error {
if deviceInfo.Type == typex.TSS200V02 {
return startDevices(device.NewTS200Sensor(e), deviceInfo, e)
Expand Down
18 changes: 18 additions & 0 deletions engine/load_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ import (
"github.com/i4de/rulex/typex"
)

/*
*
* 加载用户资源
*
*/
func (e *RuleEngine) LoadUserInEnd(source typex.XSource, in *typex.InEnd) error {
return startSources(source, in, e)
}

/*
*
* 内建资源
*
*/
func (e *RuleEngine) LoadBuiltInEnd(in *typex.InEnd) error {
return e.LoadInEnd(in)
}

/*
*
* TODO: 0.3.0重构此处,换成 SourceRegistry 形式
Expand Down
21 changes: 18 additions & 3 deletions engine/load_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@ import (
"github.com/i4de/rulex/typex"
)

//
// LoadOutEnd
//
/*
*
* 加载用户自定义输出资源
*
*/
func (e *RuleEngine) LoadUserOutEnd(target typex.XTarget, out *typex.OutEnd) error {
return startTarget(target, out, e)
}

/*
*
* 加载内建输出资源
*
*/

func (e *RuleEngine) LoadBuiltinOutEnd(out *typex.OutEnd) error {
return e.LoadOutEnd(out)
}
func (e *RuleEngine) LoadOutEnd(out *typex.OutEnd) error {
if out.Type == typex.MONGO_SINGLE {
return startTarget(target.NewMongoTarget(e), out, e)
Expand Down

0 comments on commit caf07c0

Please sign in to comment.