MCPcopy
hub / github.com/canopy-network/canopy / handleStateReadRequest

Method handleStateReadRequest

lib/plugin.go:313–353  ·  view source on GitHub ↗

HandleStateReadRequest() handles an inbound state read request from a specific FSM context

(msg *PluginToFSM)

Source from the content-addressed store, hash-verified

311
312// HandleStateReadRequest() handles an inbound state read request from a specific FSM context
313func (p *Plugin) handleStateReadRequest(msg *PluginToFSM) ErrorI {
314 // debug log state read request start
315 p.log.Debugf("handleStateReadRequest() processing message ID %d", msg.Id)
316 // get the FSM context for this request ID
317 p.l.Lock()
318 fsm := p.requestFSMs[msg.Id]
319 // debug log FSM lookup
320 p.log.Debugf("handleStateReadRequest() FSM lookup for ID %d: found=%t, total_fsms=%d", msg.Id, fsm != nil, len(p.requestFSMs))
321 p.l.Unlock()
322 // debug log request details
323 request := msg.GetStateRead()
324 p.log.Debugf("handleStateReadRequest() state read request: %+v", request)
325 // check if FSM context exists
326 if fsm == nil {
327 p.log.Debugf("handleStateReadRequest() no FSM context found for request ID %d", msg.Id)
328 return ErrInvalidPluginRespId()
329 }
330 // forward request to the appropriate FSM
331 p.log.Debug("handleStateReadRequest() forwarding request to FSM")
332 response, err := fsm.StateRead(request)
333 if err != nil {
334 p.log.Debugf("handleStateReadRequest() FSM StateRead error: %v", err)
335 response.Error = NewPluginError(err)
336 } else {
337 p.log.Debugf("handleStateReadRequest() FSM StateRead success: %+v", response)
338 }
339 // send response back to FSM
340 p.log.Debugf("handleStateReadRequest() sending response back for message ID %d", msg.Id)
341 sendErr := p.sendProtoMsg(&FSMToPlugin{
342 Id: msg.Id,
343 Payload: &FSMToPlugin_StateRead{
344 StateRead: &response,
345 },
346 })
347 if sendErr != nil {
348 p.log.Debugf("handleStateReadRequest() error sending response: %v", sendErr)
349 } else {
350 p.log.Debug("handleStateReadRequest() response sent successfully")
351 }
352 return sendErr
353}
354
355// HandleStateWriteRequest() handles an inbound state write request from a specific FSM context
356func (p *Plugin) handleStateWriteRequest(msg *PluginToFSM) ErrorI {

Callers 1

ListenForInboundMethod · 0.95

Calls 9

sendProtoMsgMethod · 0.95
NewPluginErrorFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
ErrInvalidPluginRespIdFunction · 0.70
DebugfMethod · 0.65
DebugMethod · 0.65
StateReadMethod · 0.65
GetStateReadMethod · 0.45

Tested by

no test coverage detected