2014-04-26 09:18:56 +00:00
|
|
|
package Log
|
|
|
|
|
2014-10-19 17:19:11 +00:00
|
|
|
import (
|
|
|
|
"github.com/SommerEngineering/Ocean/Log/Device"
|
|
|
|
)
|
2014-04-26 09:18:56 +00:00
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Function to force all buffers to flush the events.
|
2014-04-26 09:18:56 +00:00
|
|
|
func Flush() {
|
2015-06-17 15:44:52 +00:00
|
|
|
|
|
|
|
// Close the entry buffer:
|
2014-04-26 09:18:56 +00:00
|
|
|
mutexChannel.Lock()
|
|
|
|
channelReady = false
|
|
|
|
close(entriesBuffer)
|
|
|
|
mutexChannel.Unlock()
|
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Wait that the scheduler is done:
|
2014-11-07 12:00:55 +00:00
|
|
|
<-schedulerExitSignal
|
2014-04-26 09:18:56 +00:00
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Get all log entries from the device delay buffer:
|
2014-04-26 09:18:56 +00:00
|
|
|
mutexDeviceDelays.Lock()
|
|
|
|
dataArray := logEntryListToArray(deviceDelayBuffer)
|
|
|
|
deviceDelayBuffer.Init()
|
|
|
|
mutexDeviceDelays.Unlock()
|
|
|
|
|
2015-06-17 15:44:52 +00:00
|
|
|
// Deliver all the events to all devices:
|
2014-04-26 09:18:56 +00:00
|
|
|
mutexDevices.RLock()
|
|
|
|
for entry := devices.Front(); entry != nil; entry = entry.Next() {
|
|
|
|
dev := entry.Value.(Device.Device)
|
|
|
|
dev.Log(dataArray) // Want to wait to complete, therefore no new thread here
|
2014-11-07 12:00:55 +00:00
|
|
|
dev.Flush()
|
2014-04-26 09:18:56 +00:00
|
|
|
}
|
|
|
|
mutexDevices.RUnlock()
|
|
|
|
}
|