Improved ICCC for external components
This commit is contained in:
1 parent
6abe562642
commit
184f320a2e
12 files changed
+113
-63
No files matched your search
@@ -1,44 +1,44 @@
|
||||
package System
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/SommerEngineering/Ocean/ICCC"
|
||||
"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 a server is up and running.
|
||||
func icccSystemStart(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 server startup message. %s", err))
|
||||
result = make(map[string][]string, 0)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
// Converts the HTTP form data into an object:
|
||||
_, _, obj := ICCC.Data2Message(SystemMessages.ICCCStartUpMessage{}, data)
|
||||
|
||||
// Was it possible to convert the data?
|
||||
if obj != nil {
|
||||
// Cast the object to the right type:
|
||||
messageData := obj.(SystemMessages.ICCCStartUpMessage)
|
||||
|
||||
// Provide a log entry:
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: The server is now up and ready.`, messageData.PublicIPAddressAndPort, messageData.AdminIPAddressAndPort)
|
||||
|
||||
// An answer is necessary:
|
||||
return ICCC.Message2Data("", "", SystemMessages.AnswerACK)
|
||||
} else {
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: Was not able to create the message.`)
|
||||
fmt.Println(`[Error] ICCC message: Was not able to create the message.`)
|
||||
}
|
||||
|
||||
// In any other error case:
|
||||
result = make(map[string][]string, 0)
|
||||
return
|
||||
}
|
||||
package System
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/SommerEngineering/Ocean/ICCC"
|
||||
"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 a external component is up and running.
|
||||
func icccComponentStartUpMessage(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 component startup message. %s", err))
|
||||
result = make(map[string][]string, 0)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
// Converts the HTTP form data into an object:
|
||||
_, _, obj := ICCC.Data2Message(SystemMessages.ICCCComponentStartUpMessage{}, data)
|
||||
|
||||
// Was it possible to convert the data?
|
||||
if obj != nil {
|
||||
// Cast the object to the right type:
|
||||
messageData := obj.(SystemMessages.ICCCComponentStartUpMessage)
|
||||
|
||||
// Provide a log entry:
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: The external component is now up and ready.`, messageData.IPAddressPort)
|
||||
|
||||
// An answer is necessary:
|
||||
return ICCC.Message2Data("", "", SystemMessages.AnswerACK)
|
||||
} else {
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: Was not able to create the message.`)
|
||||
fmt.Println(`[Error] ICCC message: Was not able to create the message.`)
|
||||
}
|
||||
|
||||
// In any other error case:
|
||||
result = make(map[string][]string, 0)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package System
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/SommerEngineering/Ocean/ICCC"
|
||||
"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 an Ocean server is up and running.
|
||||
func icccOceanStartUpMessage(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 Ocean server startup message. %s", err))
|
||||
result = make(map[string][]string, 0)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
// Converts the HTTP form data into an object:
|
||||
_, _, obj := ICCC.Data2Message(SystemMessages.ICCCOceanStartUpMessage{}, data)
|
||||
|
||||
// Was it possible to convert the data?
|
||||
if obj != nil {
|
||||
// Cast the object to the right type:
|
||||
messageData := obj.(SystemMessages.ICCCOceanStartUpMessage)
|
||||
|
||||
// Provide a log entry:
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: The Ocean server is now up and ready.`, messageData.PublicIPAddressPort, messageData.AdminIPAddressPort)
|
||||
|
||||
// An answer is necessary:
|
||||
return ICCC.Message2Data("", "", SystemMessages.AnswerACK)
|
||||
} else {
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `ICCC message: Was not able to create the message.`)
|
||||
fmt.Println(`[Error] ICCC message: Was not able to create the message.`)
|
||||
}
|
||||
|
||||
// In any other error case:
|
||||
result = make(map[string][]string, 0)
|
||||
return
|
||||
}
|
||||
@@ -97,7 +97,8 @@ func initSystem() {
|
||||
// The logging subsystem is not registered here, because it will be automated called at the end
|
||||
|
||||
// Register all system ICCC commands:
|
||||
ICCC.Registrar(ICCC.ChannelSYSTEM, `System::Start`, icccSystemStart)
|
||||
ICCC.Registrar(ICCC.ChannelSYSTEM, `System::OceanStart`, icccOceanStartUpMessage)
|
||||
ICCC.Registrar(ICCC.ChannelSYSTEM, `System::ComponentStart`, icccComponentStartUpMessage)
|
||||
ICCC.Registrar(ICCC.ChannelICCC, `ICCC::RegisterHost`, ICCC.ICCCRegisterHost)
|
||||
ICCC.Registrar(ICCC.ChannelICCC, `ICCC::RegisterCommand`, ICCC.ICCCRegisterCommand)
|
||||
ICCC.Registrar(ICCC.ChannelNUMGEN, `NumGen::Next`, NumGen.ICCCNextNumber)
|
||||
|
||||
Reference in new issue
Block a user