Skip to content

Commit

Permalink
Update Go code for new datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
DownerCase committed Jan 13, 2025
1 parent cfc6c83 commit a28605b
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cmd/monitor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func getTopicMonitoring(topicType TopicType) []monitoring.TopicMon {
return nil
}

func getTopicFromID(topicType TopicType, id string) (monitoring.TopicMon, error) {
func getTopicFromID(topicType TopicType, id uint64) (monitoring.TopicMon, error) {
topicList := getTopicMonitoring(topicType)
for _, topic := range topicList {
if topic.TopicID == id {
Expand Down
6 changes: 3 additions & 3 deletions cmd/monitor/page_services_detailed.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type ModelServiceDetailed struct {
table table.Model
ID string
ID uint64
IsServer bool
}

Expand All @@ -24,7 +24,7 @@ func NewDetailedServiceModel() *ModelServiceDetailed {

return &ModelServiceDetailed{
table: NewTable(cols),
ID: "",
ID: 0,
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func getMethodRows(b monitoring.ServiceBase) []table.Row {
for _, method := range b.Methods {
rows = append(rows, table.Row{
method.Name,
fmt.Sprintf("%s -> %s (Called x%v)", method.RequestType.Type, method.ResponseType.Type, method.CallCount),
fmt.Sprintf("%v -> %v (Called x%v)", method.RequestType.Name, method.ResponseType.Name, method.CallCount),
})
}

Expand Down
16 changes: 11 additions & 5 deletions cmd/monitor/page_services_main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"strconv"

"github.com/charmbracelet/bubbles/table"
Expand Down Expand Up @@ -39,13 +40,18 @@ func (m *ModelServicesMain) View() string {
return baseStyle.Render(m.table.View()) + "\n" + m.table.HelpView()
}

func (m *ModelServicesMain) GetSelectedID() (string, bool, error) {
func (m *ModelServicesMain) GetSelectedID() (uint64, bool, error) {
row := m.table.SelectedRow()
if row == nil {
return "", false, errEmptyTable
return 0, false, errEmptyTable
}

return row[0], row[1] == "S", nil
id, err := strconv.ParseUint(row[0], 10, 64)
if err != nil {
err = fmt.Errorf("services - GetSelectedID() %w", err)
}

return id, row[1] == "S", err
}

func (m *ModelServicesMain) updateTable(msg tea.Msg) tea.Cmd {
Expand Down Expand Up @@ -78,14 +84,14 @@ func serviceToRow(service monitoring.ServiceBase) table.Row {

func clientToRow(client monitoring.ClientMon) table.Row {
return append(
[]string{client.ID, "C"},
[]string{strconv.FormatUint(client.ID, 10), "C"},
serviceToRow(client.ServiceBase)...,
)
}

func serverToRow(server monitoring.ServerMon) table.Row {
return append(
[]string{server.ID, "S"},
[]string{strconv.FormatUint(server.ID, 10), "S"},
serviceToRow(server.ServiceBase)...,
)
}
4 changes: 2 additions & 2 deletions cmd/monitor/page_topics_detailed.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type ModelTopicDetailed struct {
table table.Model
id string `exhaustruct:"optional"`
id uint64 `exhaustruct:"optional"`
topicType TopicType `exhaustruct:"optional"`
}

Expand All @@ -25,7 +25,7 @@ func NewDetailedModel() *ModelTopicDetailed {
}
}

func (m *ModelTopicDetailed) ShowTopic(topicID string, topicType TopicType) {
func (m *ModelTopicDetailed) ShowTopic(topicID uint64, topicType TopicType) {
m.id = topicID
m.topicType = topicType
m.updateDetailedTable(nil)
Expand Down
14 changes: 10 additions & 4 deletions cmd/monitor/page_topics_main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -122,10 +123,10 @@ func (m *ModelTopicsMain) View() string {
return baseStyle.Render(m.table.View()) + "\n" + m.help.View(m.keymap)
}

func (m *ModelTopicsMain) GetSelectedID() (string, TopicType, error) {
func (m *ModelTopicsMain) GetSelectedID() (uint64, TopicType, error) {
row := m.table.SelectedRow()
if row == nil {
return "", 0, errEmptyTable
return 0, 0, errEmptyTable
}

var topicType TopicType
Expand All @@ -137,7 +138,12 @@ func (m *ModelTopicsMain) GetSelectedID() (string, TopicType, error) {
topicType = topicTypePublisher
}

return row[0], topicType, nil
id, err := strconv.ParseUint(row[0], 10, 64)
if err != nil {
err = fmt.Errorf("topics - GetSelectedID(): %w", err)
}

return id, topicType, err
}

func (m *ModelTopicsMain) updateTopicsTable(msg tea.Msg) {
Expand Down Expand Up @@ -168,7 +174,7 @@ func (m *ModelTopicsMain) updateTopicsTable(msg tea.Msg) {

func topicToRow(topic monitoring.TopicMon) table.Row {
return []string{
topic.TopicID,
strconv.FormatUint(topic.TopicID, 10),
strings.ToUpper(topic.Direction[0:1]),
topic.TopicName,
topic.Datatype.Name,
Expand Down
4 changes: 2 additions & 2 deletions cmd/monitor/page_topics_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ModelTopicMessages struct {
viewport viewport.Model
mon monitoring.TopicMon
topicType TopicType
topicID string
topicID uint64
subscriber *subscriber.Subscriber
msg []byte
deserializer func([]byte) string
Expand Down Expand Up @@ -76,7 +76,7 @@ func (m *ModelTopicMessages) Refresh() {
m.mon, _ = getTopicFromID(m.topicType, m.topicID)
}

func (m *ModelTopicMessages) ShowTopic(topicID string, topicType TopicType) {
func (m *ModelTopicMessages) ShowTopic(topicID uint64, topicType TopicType) {
if m.topicID != topicID {
m.topicType = topicType
m.topicID = topicID
Expand Down
44 changes: 21 additions & 23 deletions ecal/monitoring/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ import (
"github.com/DownerCase/ecal-go/ecal"
)

func copyToDatatype(datatype C.struct_CDatatype) ecal.DataType {
return ecal.DataType{
Name: C.GoString(datatype.name),
Encoding: C.GoString(datatype.encoding),
}
}

func copyToTopicMons(ctopics []C.struct_CTopicMon) []TopicMon {
topics := make([]TopicMon, len(ctopics))
for idx, pub := range ctopics {
topics[idx] = TopicMon{
TopicID: C.GoString(pub.topic_id),
RegistrationClock: int32(pub.registration_clock),
TopicName: C.GoString(pub.topic_name),
DataClock: int64(pub.data_clock),
DataFreq: int32(pub.data_freq),
TopicSize: int32(pub.topic_size),
UnitName: C.GoString(pub.unit_name),
Direction: C.GoString(pub.direction),
Datatype: ecal.DataType{
Name: C.GoString(pub.datatype.name),
Encoding: C.GoString(pub.datatype.encoding),
},
TopicID: uint64(pub.topic_id),
RegistrationClock: int32(pub.registration_clock),
TopicName: C.GoString(pub.topic_name),
DataClock: int64(pub.data_clock),
DataFreq: int32(pub.data_freq),
TopicSize: int32(pub.topic_size),
UnitName: C.GoString(pub.unit_name),
Direction: C.GoString(pub.direction),
Datatype: copyToDatatype(pub.datatype),
ConnectionsLocal: int32(pub.connections_local),
ConnectionsExternal: int32(pub.connections_external),
MessageDrops: int32(pub.message_drops),
Expand Down Expand Up @@ -59,16 +63,10 @@ func copyToMethodMons(cmethods []C.struct_CMethodMon) []MethodMon {
methods := make([]MethodMon, len(cmethods))
for idx, cmethod := range cmethods {
methods[idx] = MethodMon{
Name: C.GoString(cmethod.name),
RequestType: methodType{
Type: C.GoString(cmethod.request_name),
Descriptor: C.GoString(cmethod.request_desc),
},
ResponseType: methodType{
Type: C.GoString(cmethod.response_name),
Descriptor: C.GoString(cmethod.response_desc),
},
CallCount: int64(cmethod.call_count),
Name: C.GoString(cmethod.name),
RequestType: copyToDatatype(cmethod.req_datatype),
ResponseType: copyToDatatype(cmethod.resp_datatype),
CallCount: int64(cmethod.call_count),
}
}
return methods
Expand All @@ -77,7 +75,7 @@ func copyToMethodMons(cmethods []C.struct_CMethodMon) []MethodMon {
func copyToServiceBase(cbase C.struct_CServiceCommon) ServiceBase {
return ServiceBase{
Name: C.GoString(cbase.name),
ID: C.GoString(cbase.id),
ID: uint64(cbase.id),
RegistrationClock: int32(cbase.registration_clock),
HostName: C.GoString(cbase.host_name),
Process: C.GoString(cbase.process_name),
Expand Down
13 changes: 4 additions & 9 deletions ecal/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type TopicMon struct {
// pid int32
// process_name string
UnitName string
TopicID string
TopicID uint64
TopicName string
Direction string
Datatype ecal.DataType
Expand Down Expand Up @@ -91,21 +91,16 @@ type ProcessMon struct {
RuntimeVersion string // eCAL Version in use
}

type methodType struct {
Type string
Descriptor string
}

type MethodMon struct {
Name string
RequestType methodType
ResponseType methodType
RequestType ecal.DataType
ResponseType ecal.DataType
CallCount int64
}

type ServiceBase struct {
Name string
ID string
ID uint64
Methods []MethodMon
RegistrationClock int32 // registration heart beat
HostName string
Expand Down
2 changes: 1 addition & 1 deletion ecal/registration/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func RemSubscriberCallback(token CallbackToken) {
func toTopicID(id *C.struct_CTopicId) ecal.TopicID {
return ecal.TopicID{
TopicID: ecal.EntityID{
EntityID: C.GoString(id.topic_id.entity_id),
EntityID: uint64(id.topic_id.entity_id),
ProcessID: int32(id.topic_id.process_id),
HostName: C.GoString(id.topic_id.host_name),
},
Expand Down
2 changes: 1 addition & 1 deletion ecal/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ecal

type EntityID struct {
EntityID string
EntityID uint64
ProcessID int32
HostName string
}
Expand Down

0 comments on commit a28605b

Please sign in to comment.