浙江省网站备案流程,房地产市场规模,工程招标平台,哪个网站做初中作业#xff08;接上篇#xff09;
DeviceTwin struct组成剖析
该部分对DeviceTwin struct的组成进行剖析。接着devicetwin struct调用链剖析的实例化DeviceTwin struct#xff08;dt : DeviceTwin{}#xff09;往下剖析#xff0c;进入DeviceTwin struct的定义#xff0c;…接上篇
DeviceTwin struct组成剖析
该部分对DeviceTwin struct的组成进行剖析。接着devicetwin struct调用链剖析的实例化DeviceTwin structdt : DeviceTwin{}往下剖析进入DeviceTwin struct的定义具体如下所示。 KubeEdge/edge/pkg/devicetwin/devicetwin.go //DeviceTwin the module type DeviceTwin struct { context *context.Context dtcontroller *DTController }
DeviceTwin struct的定义由 *context.Context 和 *DTController两部分组成。其中*context.Context可以参考8.3.2,这里不再赘述。下面重点剖析DTController。
DTController的定义具体如下所示。 KubeEdge/edge/pkg/devicetwin/dtcontroller.go //DTController controller for devicetwin type DTController struct { HeartBeatToModule map[string]chan interface{} DTContexts *dtcontext.DTContext DTModules map[string]dtmodule.DTModule Stop chan bool }
在DTController struct定义中发现\*dtcontext.DTContext和dtmodule.DTModule的定义具体如下所示。 KubeEdge/edge/pkg/devicetwin/dtcontext/dtcontext.go //DTContext context for devicetwin type DTContext struct { GroupID string NodeID string CommChan map[string]chan interface{} ConfirmChan chan interface{} ConfirmMap *sync.Map ModulesHealth *sync.Map ModulesContext *context.Context DeviceList *sync.Map DeviceMutex *sync.Map Mutex *sync.RWMutex // DBConn *dtclient.Conn State string }
从DTContext struct的定义可以看出DTContext struct主要用来实现devicetwin的通信和缓存。DTModule.DTModule struct定义如下所示。 KubeEdge/edge/pkg/devicetwin/dtmodule/dtmodule.go //DTModule module for devicetwin type DTModule struct { Name string Worker dtmanager.DTWorker }
在 DTModule struct定义中dtmanager.DTWorker是interface type定义如下所示。 KubeEdge/edge/pkg/devicetwin/dtmanager/dtworker.go //DTWorker worker for devicetwin type DTWorker interface { Start() }
从dtmanager.DTWorker的interface type可以推测DTModule有多种类型而且都实现了DTWorker interface。KubeEdge/edge/pkg/devicetwin/dtmodule/dtmodule.go中的InitWorker()就是用来实例化DTModule的多种类型的具体定义如下所示。 KubeEdge/edge/pkg/devicetwin/dtmodule/dtmodule.go // InitWorker init worker func (dm *DTModule) InitWorker(recv chan interface{}, confirm chan interface{}, heartBeat chan interface{}, dtContext *dtcontext.DTContext) { switch dm.Name { case dtcommon.MemModule: dm.Worker dtmanager.MemWorker{ Group: dtcommon.MemModule, Worker: dtmanager.Worker{ ReceiverChan: recv, ConfirmChan: confirm, HeartBeatChan: heartBeat, DTContexts: dtContext, }, } ... }
从InitWorker()函数的定义中可以梳理出DTModule有MemWorker、TwinWorker、DeviceWorker和CommWorker四种类型。
到此EdgeCore中devicetwin的struct调用链剖析就全部结束了。
「未完待续……」