msgIdsToName *map[uint16]string
msgIdSeq uint16
binApiTypes map[string]reflect.Type
- //TODO lock
+ access sync.RWMutex
}
// replyHeader represents a common header of each VPP request message.
}
func (a *VppAdapter) GetMsgNameByID(msgId uint16) (string, bool) {
- a.initMaps()
-
switch msgId {
case 100:
return "control_ping", true
return "sw_interface_details", true
}
+ a.access.Lock()
+ defer a.access.Unlock()
+ a.initMaps()
msgName, found := (*a.msgIdsToName)[msgId]
return msgName, found
}
func (a *VppAdapter) RegisterBinApiTypes(binApiTypes map[string]reflect.Type) {
+ a.access.Lock()
+ defer a.access.Unlock()
a.initMaps()
for _, v := range binApiTypes {
if msg, ok := reflect.New(v).Interface().(api.Message); ok {
return 201, nil
}
+ a.access.Lock()
+ defer a.access.Unlock()
a.initMaps()
if msgId, found := (*a.msgNameToIds)[msgName]; found {
func (a *VppAdapter) SendMsg(clientID uint32, data []byte) error {
switch mode {
case useReplyHandlers:
+ a.initMaps()
for i := len(replyHandlers) - 1; i >= 0; i-- {
replyHandler := replyHandlers[i]
reqHeader := requestHeader{}
struc.Unpack(buf, &reqHeader)
- a.initMaps()
+ a.access.Lock()
reqMsgName, _ := (*a.msgIdsToName)[reqHeader.VlMsgID]
+ a.access.Unlock()
reply, msgID, finished := replyHandler(MessageDTO{reqHeader.VlMsgID, reqMsgName,
clientID, data})