| @@ -4,8 +4,8 @@ import ( | |||
| "github.com/AFASystems/presence/internal/pkg/model" | |||
| ) | |||
| // Manager provides centralized access to application state | |||
| type Manager struct { | |||
| // AppState provides centralized access to application state | |||
| type AppState struct { | |||
| beacons model.BeaconsList | |||
| settings model.Settings | |||
| beaconEvents model.BeaconEventList | |||
| @@ -13,9 +13,9 @@ type Manager struct { | |||
| latestList model.LatestBeaconsList | |||
| } | |||
| // NewManager creates a new application context manager with default values | |||
| func NewManager() *Manager { | |||
| return &Manager{ | |||
| // NewAppState creates a new application context AppState with default values | |||
| func NewAppState() *AppState { | |||
| return &AppState{ | |||
| beacons: model.BeaconsList{ | |||
| Beacons: make(map[string]model.Beacon), | |||
| }, | |||
| @@ -41,48 +41,48 @@ func NewManager() *Manager { | |||
| } | |||
| // GetBeacons returns thread-safe access to beacons list | |||
| func (m *Manager) GetBeacons() *model.BeaconsList { | |||
| func (m *AppState) GetBeacons() *model.BeaconsList { | |||
| return &m.beacons | |||
| } | |||
| // GetSettings returns thread-safe access to settings | |||
| func (m *Manager) GetSettings() *model.Settings { | |||
| func (m *AppState) GetSettings() *model.Settings { | |||
| return &m.settings | |||
| } | |||
| // GetBeaconEvents returns thread-safe access to beacon events | |||
| func (m *Manager) GetBeaconEvents() *model.BeaconEventList { | |||
| func (m *AppState) GetBeaconEvents() *model.BeaconEventList { | |||
| return &m.beaconEvents | |||
| } | |||
| // GetBeaconsLookup returns thread-safe access to beacon lookup map | |||
| func (m *Manager) GetBeaconsLookup() map[string]struct{} { | |||
| func (m *AppState) GetBeaconsLookup() map[string]struct{} { | |||
| return m.beaconsLookup | |||
| } | |||
| // GetLatestList returns thread-safe access to latest beacons list | |||
| func (m *Manager) GetLatestList() *model.LatestBeaconsList { | |||
| func (m *AppState) GetLatestList() *model.LatestBeaconsList { | |||
| return &m.latestList | |||
| } | |||
| // AddBeaconToLookup adds a beacon ID to the lookup map | |||
| func (m *Manager) AddBeaconToLookup(id string) { | |||
| func (m *AppState) AddBeaconToLookup(id string) { | |||
| m.beaconsLookup[id] = struct{}{} | |||
| } | |||
| // RemoveBeaconFromLookup removes a beacon ID from the lookup map | |||
| func (m *Manager) RemoveBeaconFromLookup(id string) { | |||
| func (m *AppState) RemoveBeaconFromLookup(id string) { | |||
| delete(m.beaconsLookup, id) | |||
| } | |||
| // BeaconExists checks if a beacon exists in the lookup | |||
| func (m *Manager) BeaconExists(id string) bool { | |||
| func (m *AppState) BeaconExists(id string) bool { | |||
| _, exists := m.beaconsLookup[id] | |||
| return exists | |||
| } | |||
| // GetBeacon returns a beacon by ID (thread-safe) | |||
| func (m *Manager) GetBeacon(id string) (model.Beacon, bool) { | |||
| func (m *AppState) GetBeacon(id string) (model.Beacon, bool) { | |||
| m.beacons.Lock.RLock() | |||
| defer m.beacons.Lock.RUnlock() | |||
| @@ -91,7 +91,7 @@ func (m *Manager) GetBeacon(id string) (model.Beacon, bool) { | |||
| } | |||
| // UpdateBeacon updates a beacon in the list (thread-safe) | |||
| func (m *Manager) UpdateBeacon(id string, beacon model.Beacon) { | |||
| func (m *AppState) UpdateBeacon(id string, beacon model.Beacon) { | |||
| m.beacons.Lock.Lock() | |||
| defer m.beacons.Lock.Unlock() | |||
| @@ -99,7 +99,7 @@ func (m *Manager) UpdateBeacon(id string, beacon model.Beacon) { | |||
| } | |||
| // GetBeaconEvent returns a beacon event by ID (thread-safe) | |||
| func (m *Manager) GetBeaconEvent(id string) (model.BeaconEvent, bool) { | |||
| func (m *AppState) GetBeaconEvent(id string) (model.BeaconEvent, bool) { | |||
| m.beaconEvents.Lock.RLock() | |||
| defer m.beaconEvents.Lock.RUnlock() | |||
| @@ -108,7 +108,7 @@ func (m *Manager) GetBeaconEvent(id string) (model.BeaconEvent, bool) { | |||
| } | |||
| // UpdateBeaconEvent updates a beacon event in the list (thread-safe) | |||
| func (m *Manager) UpdateBeaconEvent(id string, event model.BeaconEvent) { | |||
| func (m *AppState) UpdateBeaconEvent(id string, event model.BeaconEvent) { | |||
| m.beaconEvents.Lock.Lock() | |||
| defer m.beaconEvents.Lock.Unlock() | |||
| @@ -116,7 +116,7 @@ func (m *Manager) UpdateBeaconEvent(id string, event model.BeaconEvent) { | |||
| } | |||
| // GetLatestBeacon returns the latest beacon by ID (thread-safe) | |||
| func (m *Manager) GetLatestBeacon(id string) (model.Beacon, bool) { | |||
| func (m *AppState) GetLatestBeacon(id string) (model.Beacon, bool) { | |||
| m.latestList.Lock.RLock() | |||
| defer m.latestList.Lock.RUnlock() | |||
| @@ -125,7 +125,7 @@ func (m *Manager) GetLatestBeacon(id string) (model.Beacon, bool) { | |||
| } | |||
| // UpdateLatestBeacon updates the latest beacon in the list (thread-safe) | |||
| func (m *Manager) UpdateLatestBeacon(id string, beacon model.Beacon) { | |||
| func (m *AppState) UpdateLatestBeacon(id string, beacon model.Beacon) { | |||
| m.latestList.Lock.Lock() | |||
| defer m.latestList.Lock.Unlock() | |||
| @@ -133,7 +133,7 @@ func (m *Manager) UpdateLatestBeacon(id string, beacon model.Beacon) { | |||
| } | |||
| // GetAllBeacons returns a copy of all beacons | |||
| func (m *Manager) GetAllBeacons() map[string]model.Beacon { | |||
| func (m *AppState) GetAllBeacons() map[string]model.Beacon { | |||
| m.beacons.Lock.RLock() | |||
| defer m.beacons.Lock.RUnlock() | |||
| @@ -145,7 +145,7 @@ func (m *Manager) GetAllBeacons() map[string]model.Beacon { | |||
| } | |||
| // GetAllLatestBeacons returns a copy of all latest beacons | |||
| func (m *Manager) GetAllLatestBeacons() map[string]model.Beacon { | |||
| func (m *AppState) GetAllLatestBeacons() map[string]model.Beacon { | |||
| m.latestList.Lock.RLock() | |||
| defer m.latestList.Lock.RUnlock() | |||
| @@ -157,7 +157,7 @@ func (m *Manager) GetAllLatestBeacons() map[string]model.Beacon { | |||
| } | |||
| // GetBeaconCount returns the number of tracked beacons | |||
| func (m *Manager) GetBeaconCount() int { | |||
| func (m *AppState) GetBeaconCount() int { | |||
| m.beacons.Lock.RLock() | |||
| defer m.beacons.Lock.RUnlock() | |||
| @@ -165,7 +165,7 @@ func (m *Manager) GetBeaconCount() int { | |||
| } | |||
| // GetSettingsValue returns current settings as a value | |||
| func (m *Manager) GetSettingsValue() model.SettingsVal { | |||
| func (m *AppState) GetSettingsValue() model.SettingsVal { | |||
| m.settings.Lock.RLock() | |||
| defer m.settings.Lock.RUnlock() | |||
| @@ -173,7 +173,7 @@ func (m *Manager) GetSettingsValue() model.SettingsVal { | |||
| } | |||
| // UpdateSettings updates the system settings (thread-safe) | |||
| func (m *Manager) UpdateSettings(newSettings model.SettingsVal) { | |||
| func (m *AppState) UpdateSettings(newSettings model.SettingsVal) { | |||
| m.settings.Lock.Lock() | |||
| defer m.settings.Lock.Unlock() | |||