gilix

package module
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 2 Imported by: 2

README

gilix

Go Reference

介绍

基于 go 开发的「Service of Things」平台

  • 通过 Acceptor 模式与外部交互,支持 tcp/http/ws 等协议
  • 以 plugin 形式嵌入 Things 功能,包括语义解析、Things action 等

用途

  • 适用于 WOSA/XFS/LFS/PISA/... 及其它自定义协议的 Service Provider 开发
  • 基于 Go 的交叉编译特性,适用于 Windows/Linux/MacOs ,适用于 x86/x64/arm/mips 等多种 CPU 架构
  • 由于 WOSA/XFS/LFS/PISA... 是基于 C 语言 的 API ,因此需要 spi 库来与 gilix 服务通讯,通讯协议由 spi 决定
  • 也可以从 WEB 浏览器通过 JS 以 ws 协议的方式,直接与 gilix 服务通讯

语义

  • 语义解析(通过 tcp/http/ws 收到的数据解析)不包含在 gilix 中
  • 例如 XFS/LFS/PISA 的语义解析,属于业务开发的范畴,可使用 json(推荐)、xml、其它协议等

其它

  • 关于 XFS/LFS/PISA 等语义解析的已有实现及其它问题可私信
  • 相关 WOSA/XFS/LFS/PISA/... 业务实现过程中,会涉及其它组件,例如 Form 解析、配置处理、test 平台(GTP)等,欢迎咨询交流

软件架构

gilix

  • AP 层可使用任何语言直接与 gilix 交互,只要在所支持的传输协议(tcp/http/ws/...)范围内;当然,需要针对 AP 需求来完成相匹配的 plugin 开发
  • AP 若使用 C/C++ 开发,则可使用所提供的 cilix_spi_ap 库来简化访问逻辑
  • 由于 Things 不可避免的需要接入 C/C++ 的 lib 库,因此提供了 RDC 封装,与 cilix-rdc 平台远程交互
  • cilix_spi_ap 和 cilix-rdc 都通过 C 编写,合并在 cilix-rdc 库中
  • 原则:两个一切
    1. 尽一切可能 的将复杂度放在 gilix (Go)
    2. 尽一切可能 的让 cilix-rdc (C) 简化
  • 另外,gilix-util 中提供了一些实用功能,包括:
    • 同步器 syncer
    • 打点工作器 ticker
    • 基于 zap 包装的日志库 zapt
    • ...

How to Use

SOT
  1. import "github.com/lindorof/gilix"

  2. implement interfaces of cbs.go , such as Msg , Dev , Xcbs ...

  3. import _ "github.com/lindorof/gilix/sot" to Initialize func NewCPS automatically

  4. create Xcps

    cps := gilix.NewCPS()
    
  5. start the sot loop

    cps.SotLoopSync()
    
  6. create acceptor as needed

    // ws
    import "github.com/lindorof/gilix/acp/ws"
    acceptor := ws.CreateServer(para)
    
    // tcp
    import "github.com/lindorof/gilix/acp/tcp"
    acceptor := tcp.CreateServer(para)
    
    // http
    import "github.com/lindorof/gilix/acp/http"
    acceptor := http.CreateServer(para)
    
  7. submit acceptors to sot

    cps.SubmitAcp(acceptor)
    
  8. stop the sot loop on exit

    cps.SotLoopBreak()
    
  9. for simplicity, recommend to use syncer

    import "github.com/lindorof/gilix/util"
    
    // create syncer
    syncer := util.CreateSyncer(context.Background())
    
    // sync mode, returned when ctx cancelled
    syncer.Sync(
    	cps.SotLoopSync(),
    	cps.SotLoopBreak())
    
    // async mode, returned immediately
    syncer.Async(
    	cps.SotLoopSync(),
    	cps.SotLoopBreak())
    
    // for async mode, need to cancel and wait on exit
    syncer.WaitRelease(util.SyncerWaitModeCancel)
    // or just wait
    syncer.WaitRelease(util.SyncerWaitModeIdle)
    
RDC

example for using of rdc

import "github.com/lindorof/gilix/rdc/tcp"

type para struct {
    Name string
    Data int
}

// in/out para
in := &para{"Track1", 9}
out := &para{}

// create caller
caller := tcp.CreateCaller(":8808", 5*time.Second)
// several invocations
ret, err := caller.Invoke("ReadTrack", in, out)
// destroy caller
caller.Fini()

Documentation

Index

Constants

View Source
const (
	HS_NIL = 0
	ID_NIL = 0

	TYPE_OPEN    = 1
	TYPE_CLOSE   = 2
	TYPE_REG     = 3
	TYPE_DEREG   = 4
	TYPE_INF     = 5
	TYPE_CMD     = 6
	TYPE_LOCK    = 7
	TYPE_UNLOCK  = 8
	TYPE_CANCEL  = 50
	TYPE_EVT_USR = 101
	TYPE_EVT_SRV = 102
	TYPE_EVT_EXE = 103
	TYPE_EVT_SYS = 104

	RET_SUCCESS         = 0
	RET_TIMEOUT         = 1
	RET_CANCELLED       = 2
	RET_LOCKED          = 3
	RET_ALREADY_LOCKED  = 4
	RET_NOT_LOCKED_YET  = 5
	RET_UNSUPP_CATEGORY = 6
	RET_UNSUPP_COMMAND  = 7

	QUEUET_AUTO = 0
	QUEUET_RT   = 1
	QUEUET_DF   = 2

	ERCV_CURRENT = 1
	ERCV_LOCKER  = 2
	ERCV_ALL     = 3

	EHSU_CURRENT = 1
	EHSU_LOCKER  = 2
	EHSU_ALL     = 3
)

Variables

View Source
var NewCPS func() Xcps = nil

CPS Getter

Functions

This section is empty.

Types

type CODE

type CODE int

type Callee

type Callee func(context.Context, PARA) Rsp /* for Inf/Cmd only */

type Dev

type Dev interface {
	PollInterval() int
	PollFuncs() []Callee

	OnReq(Msg, Usr) (qut QUEUET, cee Callee, pci int, chk bool, chg bool) /* ret used for Inf/Cmd only */
	OnEvt(cur PollCache, e Evt) (ERCV, EHSU)
	OnLockTry()
	PollChange(old PollCache, new PollCache)
	EvtFilter(u Usr, e Evt) bool

	OnCmdStart(*PollCache)
	OnCmdEnd(*PollCache)
}

type DevCp

type DevCp interface {
	PostEvt(Evt)
	PollSwitch(bool)
}

type EHSU

type EHSU int

type ERCV

type ERCV int

type Evt

type Evt interface {
	TypeCode
	ParaX
}

type HS

type HS int

type HsId

type HsId interface {
	Hs() HS
	Id() ID
}

type ID

type ID int

type Msg

type Msg interface {
	HsId
	TypeCode
	ParaX
	Timeout() TIMEOUT
	Ret() RET
	Phyname() string
}

type PARA

type PARA interface{}

type ParaX

type ParaX interface {
	Aux() PARA
	Para() PARA
}

type PollCache

type PollCache []Rsp

type QUEUET

type QUEUET int

type RET

type RET int

type Rsp

type Rsp interface {
	Para() PARA
	Ret() RET
}

type TIMEOUT

type TIMEOUT int

type TYPE

type TYPE int

type TypeCode

type TypeCode interface {
	Type() TYPE
	Code() CODE
}

type Usr

type Usr interface{}

type Xcbs

type Xcbs interface {
	UsrSnap(Msg) Usr

	MsgEncode(Msg) []byte
	MsgDecode([]byte) Msg
	MsgByRsp(Msg, RET, Rsp) Msg
	MsgByEvt(HsId, Usr, Evt) []Msg

	DevInit(phy string, dc DevCp) Dev
	DevFini(Dev)

	ZaptCfg(category int) (path string, categoryName string, mode string, purge int, lelvel string)
}
var CBS Xcbs = nil

CBS Setter

type Xcps

type Xcps interface {
	SotLoopSync()
	SotLoopBreak()
	SubmitAcp(acp acp.Acceptor)
}

Directories

Path Synopsis
acp
tcp
ws
rdc
tcp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL