From 5b297d5c1f49f36141c8031ad6de51a31dd4c597 Mon Sep 17 00:00:00 2001 From: lorsan Date: Sat, 16 May 2026 18:33:36 +0300 Subject: [PATCH] feat: create agent connection store --- .../connection_manager/store/manager.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 hub/internal/service/connection_manager/store/manager.go diff --git a/hub/internal/service/connection_manager/store/manager.go b/hub/internal/service/connection_manager/store/manager.go new file mode 100644 index 0000000..b690f36 --- /dev/null +++ b/hub/internal/service/connection_manager/store/manager.go @@ -0,0 +1,42 @@ +package store + +import ( + "sync" + + "github.com/lorsanstand/HomeOps-Hub/hub/internal/service/connection_manager" +) + +type AgentConnStore struct { + mutex sync.RWMutex + store map[string]*connection_manager.AgentConnection +} + +func NewAgentConnStore() *AgentConnStore { + return &AgentConnStore{store: make(map[string]*connection_manager.AgentConnection)} +} + +func (a *AgentConnStore) Get(agentID string) *connection_manager.AgentConnection { + a.mutex.RLock() + defer a.mutex.RUnlock() + return a.store[agentID] +} + +func (a *AgentConnStore) Add(agentConn *connection_manager.AgentConnection) { + a.mutex.Lock() + defer a.mutex.Unlock() + a.store[agentConn.AgentID] = agentConn +} + +func (a *AgentConnStore) Delete(agentID string) { + a.mutex.Lock() + defer a.mutex.Unlock() + delete(a.store, agentID) +} + +func (a *AgentConnStore) Pop(agentID string) *connection_manager.AgentConnection { + a.mutex.Lock() + defer a.mutex.Unlock() + agent := a.store[agentID] + delete(a.store, agentID) + return agent +}