Files
ai-operator/internal/call/session_store.go
T

42 lines
955 B
Go

package call
import "sync"
type SessionStore struct {
mu sync.RWMutex
sessions map[string]*CallSession
}
func NewSessionStore() *SessionStore { return &SessionStore{sessions: make(map[string]*CallSession)} }
func (s *SessionStore) Create(session *CallSession) {
s.mu.Lock()
defer s.mu.Unlock()
s.sessions[session.AsteriskChannelID] = session
}
func (s *SessionStore) Get(channelID string) (*CallSession, bool) {
s.mu.RLock()
defer s.mu.RUnlock()
session, ok := s.sessions[channelID]
return session, ok
}
func (s *SessionStore) Delete(channelID string) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.sessions, channelID)
}
func (s *SessionStore) Count() int {
s.mu.RLock()
defer s.mu.RUnlock()
return len(s.sessions)
}
func (s *SessionStore) List() []*CallSession {
s.mu.RLock()
defer s.mu.RUnlock()
out := make([]*CallSession, 0, len(s.sessions))
for _, session := range s.sessions {
out = append(out, session)
}
return out
}