cto

package
v0.0.0-...-0cb7091 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: BSD-3-Clause-Clear Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEF_CONTROL_RATE = 10  // 控制器更新频率
	DEF_CONTROL_CAPY = 250 // 控制器通道的默认大小
)

------------------------------------------------------------------------------ ====================================常量定义===================================== ------------------------------------------------------------------------------ Common Consts

Variables

View Source
var (
	ErrTimeOut           = errors.New("TimeOut")
	ErrExitNormal        = errors.New("NormalExit")
	ErrBusyTimeOut       = errors.New("BusyTimeOut")
	ErrControlNotRunning = errors.New("ControlNotRunning")
	ErrSettingLoadNil    = errors.New("SettingLoadNil")
)

Common Errors

View Source
var MCGoreDef = Gore{0, DEF_CONTROL_CAPY}

内置 CtrlGore

Functions

func CombStatus

func CombStatus(field, content string, first ...bool) string

-------- 组装状态接口

func Count

func Count() int

控制器数量

func GetMsgName

func GetMsgName(id TMsgId) string

获取消息名

func Init

func Init(conf ...*util.LogConf)

分步启动框架[1/3]:初始化

func NewReportMarkdown

func NewReportMarkdown(msg string, mentioned ...string) ([]byte, error)

func NewReportText

func NewReportText(msg string, mentioned ...string) ([]byte, error)

func Overview

func Overview() string

控制器概览

func Report

func Report(errlogLv util.ELogLevel, send func(msg string))

 => 设置上报

func Run

func Run(exec func(), conf ...*util.LogConf)

一键启动框架

func SetMsgName

func SetMsgName(id TMsgId, name string)

设置消息名

func Uninstall

func Uninstall(id TCtrlId) error

只有未初始化的control才能卸载

func Wait

func Wait(sleep ...util.TDurt)

分步启动框架[3/3]:等待结束

func Work

func Work() error

分步启动框架[2/3]:开始工作

Types

type ControlBase

type ControlBase struct {
	IOControler // 用继承的方式又有嵌入之意

} //

------------------------------------------------------------------------------ =================================默认空控制定义=================================== ------------------------------------------------------------------------------

func (*ControlBase) HandleGore

func (this *ControlBase) HandleGore() *Gore

func (*ControlBase) HandleInit

func (this *ControlBase) HandleInit()

func (*ControlBase) HandleLaun

func (this *ControlBase) HandleLaun()

func (*ControlBase) HandleStat

func (this *ControlBase) HandleStat() string

func (*ControlBase) HandleSusp

func (this *ControlBase) HandleSusp()

func (*ControlBase) HandleTerm

func (this *ControlBase) HandleTerm()

func (*ControlBase) HandleTick

func (this *ControlBase) HandleTick(now time.Time)

func (*ControlBase) HandleWake

func (this *ControlBase) HandleWake()

type EContrlState

type EContrlState int32 //

=> 控制器运行状态

const (
	ECS_Declare EContrlState = iota
	ECS_Initing
	ECS_Suspend // 不影响命令的执行
	ECS_Running
	ECS_Closeup
)

func (EContrlState) String

func (e EContrlState) String() string

type Gore

type Gore struct {
	Rate, Capy int
}

Go线程初始化参数结构

type IControler

type IControler interface {

	// 线程ID[0:没启动loop]
	GoId() int

	// 控制器名称
	Name() string

	// 控制器状态
	State() EContrlState

	// 控制器状况
	Status() string

	// 线程暂停
	ThreadSusp() error

	// 线程唤醒
	ThreadWake() error

	// 投递消息
	PostMsg(msg IMsger) error
	// contains filtered or unexported methods
}

=> Control开放接口

func Contrler

func Contrler(id TCtrlId) IControler

获取控制器

type ICtrlHandler

type ICtrlHandler interface {

	// 控制器参数 - [重载--重写] 控制器初始化参数 [不重写则使用默认值]
	HandleGore() *Gore

	// 控制器准备 - [基类->派生] 当控制器创建后调用 初始数据
	HandleInit()

	// 控制器销毁 - [派生->基类] 当控制器销毁时调用 清理数据
	HandleTerm()

	// 控制器首次 - [基类->派生] 当控制器运行时最先调用且调用一次
	HandleLaun()

	// 控制器更新 - [基类->派生] 当控制器tick时调用 定时更新
	HandleTick(now time.Time)

	// 控制器暂停 - [基类->派生] 当控制器被暂停时调用
	HandleSusp()

	// 控制器恢复 - [基类->派生] 当控制器被恢复时调用
	HandleWake()

	// 运行状况   - [基类->派生] 当调用Status时调用 建议JSON格式
	HandleStat() string
	// contains filtered or unexported methods
}

=> Control代理接口

func Install

func Install(id TCtrlId, handler ICtrlHandler) ICtrlHandler

安装一个全局控制器[如果重复安装则后者覆盖前者]

type IMLocker

type IMLocker interface {

	// 主锁
	Lock() interface{}

	UnLock(i interface{})
}

------------------------------------------------------------------------------ =================================Defer Lock 接口================================= ------------------------------------------------------------------------------

type IMRWLocker

type IMRWLocker interface {

	// 写锁
	WLock() interface{}

	WUnLock(i interface{})

	// 读锁
	RLock() interface{}

	RUnLock(i interface{})
}

------------------------------------------------------------------------------ =================================Defer RWLock 接口================================= ------------------------------------------------------------------------------

type IMTimer

type IMTimer interface {

	// 添加定时器[当tickFun返回false时自动删除此TimerHandler]
	TimerHandler(asyn bool, d time.Duration, tickFun TimerHandFunc, right ...bool)

	// 添加每天一次的定时器[同上](after0:每天超过零点多少时间)
	DayerHandler(asyn bool, after0 time.Duration, tickFun TimerHandFunc, right ...bool)

	// 移除定时器
	UnTimHandler(tickFun func() bool)
}

type IModuler

type IModuler interface {

	// 模块名称
	Name() string

	// 模块加载
	Load(timer IMTimer) error

	// 模块运行
	Tick()

	// 模块销毁
	Term()
}

------------------------------------------------------------------------------ ====================================Module接口=================================== ------------------------------------------------------------------------------

type IMsger

type IMsger interface {
	MsgId() TMsgId
}

=> Control消息

type IOControler

type IOControler interface {
	// 继承接口
	util.ILogMe
	// 继承接口
	IMTimer
	// 继承接口
	IMRWLocker
	// 继承接口
	IControler

	// 获取Handler
	Handler() ICtrlHandler

	// 注册消息处理函数
	SetCMHandle(mid TMsgId, handle MCMsgHandFunc)
}

=> Control自主接口

type MCMsgHandFunc

type MCMsgHandFunc func(IMsger)

------------------------------------------------------------------------------ ===================================Control接口================================== ------------------------------------------------------------------------------

type MLock

type MLock struct {
	// contains filtered or unexported fields
}

func (*MLock) Lock

func (this *MLock) Lock() interface{}

func (*MLock) Mutex

func (this *MLock) Mutex() *sync.Mutex

func (*MLock) UnLock

func (this *MLock) UnLock(i interface{})

type MRWLock

type MRWLock struct {
	// contains filtered or unexported fields
}

func (*MRWLock) Mutex

func (this *MRWLock) Mutex() *sync.RWMutex

func (*MRWLock) RLock

func (this *MRWLock) RLock() interface{}

func (*MRWLock) RUnLock

func (this *MRWLock) RUnLock(i interface{})

func (*MRWLock) WLock

func (this *MRWLock) WLock() interface{}

func (*MRWLock) WUnLock

func (this *MRWLock) WUnLock(i interface{})

type MTimer

type MTimer struct {
	// contains filtered or unexported fields
}

func (*MTimer) DayerHandler

func (this *MTimer) DayerHandler(asyn bool, after0 time.Duration, tickFun TimerHandFunc, right ...bool)

func (*MTimer) Init

func (this *MTimer) Init() *MTimer

func (*MTimer) TickTimer

func (this *MTimer) TickTimer()

func (*MTimer) TimerHandler

func (this *MTimer) TimerHandler(asyn bool, d time.Duration, tickFun TimerHandFunc, right ...bool)

func (*MTimer) UnTimHandler

func (this *MTimer) UnTimHandler(tickFun func() bool)

type TCtrlId

type TCtrlId = string // 控制器Id

type TMsgId

type TMsgId int //

=> 控制器消息类型

const (
	CTL_DEFAULT_ID  TMsgId = iota // 默认消息
	MCM_THREAD_SUSP               // 暂停消息
	MCM_THREAD_WAKE               // 恢复消息
	CTL_MSG_ID_END  TMsgId = 100
)

Contrl_Msg

func (TMsgId) MsgId

func (id TMsgId) MsgId() TMsgId

func (TMsgId) String

func (id TMsgId) String() string

type TimerHandFunc

type TimerHandFunc func(now time.Time) (keep bool)

------------------------------------------------------------------------------ =================================MTimer开放接口================================= ------------------------------------------------------------------------------

Jump to

Keyboard shortcuts

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