46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package ICCC
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/SommerEngineering/Ocean/ICCC/SystemMessages"
|
|
"github.com/SommerEngineering/Ocean/Log"
|
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
|
)
|
|
|
|
// The receiver function for the ICCC message, that registers a command.
|
|
func ICCCRegisterCommand(data map[string][]string) (result map[string][]string) {
|
|
|
|
// Recover from errors:
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityUnknown, LM.ImpactUnknown, LM.MessageNamePARSE, fmt.Sprintf("Was not able to execute the ICCC register command message. %s", err))
|
|
result = make(map[string][]string, 0)
|
|
return
|
|
}
|
|
}()
|
|
|
|
// Converts the HTTP form data into an object:
|
|
_, _, obj := Data2Message(SystemMessages.ICCCRegisterListener{}, data)
|
|
|
|
// Was it possible to convert the data?
|
|
if obj != nil {
|
|
// Cast the object to the right type:
|
|
messageData := obj.(SystemMessages.ICCCRegisterListener)
|
|
|
|
// Provide a log entry:
|
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: Should register another command.`, `channel=`+messageData.Channel, `command=`+messageData.Command, `IPAddressPort=`+messageData.IPAddressPort, fmt.Sprintf(`isActive=%v`, messageData.IsActive))
|
|
|
|
// Execute the command:
|
|
registerCommand2Database(messageData.Channel, messageData.Command, messageData.IPAddressPort, messageData.IsActive)
|
|
|
|
// An answer is necessary:
|
|
return Message2Data(``, ``, SystemMessages.AnswerACK)
|
|
} else {
|
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: Was not able to create the message.`)
|
|
}
|
|
|
|
// In any other error case:
|
|
result = make(map[string][]string, 0)
|
|
return
|
|
}
|