diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a5b919..d934f5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,23 +6,16 @@ find_package(eCAL CONFIG REQUIRED) add_library(utils INTERFACE) target_include_directories(utils INTERFACE .) -add_library(ecal_go_types) -target_sources(ecal_go_types PRIVATE - ./ecal/types/types.h - ./ecal/types/types.hpp - ./ecal/types/types.cpp -) -target_include_directories(ecal_go_types - PUBLIC ./ecal/types -) -target_link_libraries(ecal_go_types PRIVATE eCAL::core) - add_library(ecal_go_core) target_sources(ecal_go_core PRIVATE ./ecal/core.h ./ecal/core.cpp + ./ecal/types.h + ./ecal/types.hpp + ./ecal/types.cpp ) target_link_libraries(ecal_go_core PRIVATE eCAL::core) +target_include_directories(ecal_go_core PUBLIC ./ecal) add_library(ecal_go_publisher) target_sources(ecal_go_publisher PRIVATE @@ -43,26 +36,25 @@ target_sources(ecal_go_logging PRIVATE ./ecal/logging/logging.h ./ecal/logging/logging.cpp ) -target_link_libraries(ecal_go_logging PRIVATE eCAL::core ecal_go_types) +target_link_libraries(ecal_go_logging PRIVATE eCAL::core ecal_go_core) add_library(ecal_go_registration) target_sources(ecal_go_registration PRIVATE ./ecal/registration/registration.h ./ecal/registration/registration.cpp ) -target_link_libraries(ecal_go_registration PRIVATE eCAL::core ecal_go_types) +target_link_libraries(ecal_go_registration PRIVATE eCAL::core ecal_go_core) add_library(ecal_go_monitoring) target_sources(ecal_go_monitoring PRIVATE ./ecal/monitoring/monitoring.h ./ecal/monitoring/monitoring.cpp ) -target_link_libraries(ecal_go_monitoring PRIVATE eCAL::core ecal_go_types) +target_link_libraries(ecal_go_monitoring PRIVATE eCAL::core ecal_go_core) # Subpackages that use cgo set(subpackages "ecal" - "ecal/types" "ecal/publisher" "ecal/subscriber" "ecal/logging" diff --git a/ecal/logging/logging.go b/ecal/logging/logging.go index 65d8577..f217e45 100644 --- a/ecal/logging/logging.go +++ b/ecal/logging/logging.go @@ -1,6 +1,6 @@ package logging -// #cgo CPPFLAGS: -I${SRCDIR}/../types +// #cgo CPPFLAGS: -I${SRCDIR}/.. // #include // #include "logging.h" // void GoLog(enum eCAL_Logging_eLogLevel level, _GoString_ msg) { diff --git a/ecal/logging/logging_test.go b/ecal/logging/logging_test.go index 22bff17..4997e54 100644 --- a/ecal/logging/logging_test.go +++ b/ecal/logging/logging_test.go @@ -7,7 +7,6 @@ import ( "github.com/DownerCase/ecal-go/ecal" "github.com/DownerCase/ecal-go/ecal/logging" - _ "github.com/DownerCase/ecal-go/ecal/types" "github.com/DownerCase/ecal-go/internal/ecaltest" ) diff --git a/ecal/monitoring/callback.go b/ecal/monitoring/callback.go index 1cb4e01..aba0a3f 100644 --- a/ecal/monitoring/callback.go +++ b/ecal/monitoring/callback.go @@ -7,7 +7,7 @@ import ( "runtime/cgo" "unsafe" - "github.com/DownerCase/ecal-go/ecal/types" + "github.com/DownerCase/ecal-go/ecal" ) func copyToTopicMons(ctopics []C.struct_CTopicMon) []TopicMon { @@ -22,7 +22,7 @@ func copyToTopicMons(ctopics []C.struct_CTopicMon) []TopicMon { TopicSize: int32(pub.topic_size), UnitName: C.GoString(pub.unit_name), Direction: C.GoString(pub.direction), - Datatype: types.DataType{ + Datatype: ecal.DataType{ Name: C.GoString(pub.datatype.name), Encoding: C.GoString(pub.datatype.encoding), }, diff --git a/ecal/monitoring/monitoring.go b/ecal/monitoring/monitoring.go index 3d8d089..7a792c8 100644 --- a/ecal/monitoring/monitoring.go +++ b/ecal/monitoring/monitoring.go @@ -3,14 +3,14 @@ package monitoring //#cgo LDFLAGS: -lecal_core //#include //#include "monitoring.h" -//#cgo CPPFLAGS: -I${SRCDIR}/../types +//#cgo CPPFLAGS: -I${SRCDIR}/.. import "C" import ( "runtime/cgo" "strconv" - "github.com/DownerCase/ecal-go/ecal/types" + "github.com/DownerCase/ecal-go/ecal" ) type MonitorEntity uint @@ -63,7 +63,7 @@ type TopicMon struct { TopicID string TopicName string Direction string - Datatype types.DataType + Datatype ecal.DataType // TODO: transport layer TopicSize int32 // Size of messages (bytes) ConnectionsLocal int32 diff --git a/ecal/publisher/publisher.go b/ecal/publisher/publisher.go index 875a0a7..4ce079f 100644 --- a/ecal/publisher/publisher.go +++ b/ecal/publisher/publisher.go @@ -16,12 +16,12 @@ import ( "runtime/cgo" "unsafe" - "github.com/DownerCase/ecal-go/ecal/types" + "github.com/DownerCase/ecal-go/ecal" ) var ErrFailedNew = errors.New("failed to create new publisher") -type DataType = types.DataType +type DataType = ecal.DataType type Publisher struct { Messages chan []byte diff --git a/ecal/publisher/publisher_test.go b/ecal/publisher/publisher_test.go index dbab5b3..ab983f1 100644 --- a/ecal/publisher/publisher_test.go +++ b/ecal/publisher/publisher_test.go @@ -4,14 +4,14 @@ import ( "fmt" "testing" + "github.com/DownerCase/ecal-go/ecal" "github.com/DownerCase/ecal-go/ecal/publisher" - "github.com/DownerCase/ecal-go/ecal/types" testutilpublisher "github.com/DownerCase/ecal-go/internal/ecaltest/testutil_publisher" ) func TestNewPublishers(t *testing.T) { for i := range 100 { - ptr, err := publisher.New(fmt.Sprintf("testPubTopic-%v", i), types.DataType{}) + ptr, err := publisher.New(fmt.Sprintf("testPubTopic-%v", i), ecal.DataType{}) if err != nil { t.Error(err) } diff --git a/ecal/registration/registration.go b/ecal/registration/registration.go index 7dcc915..0faf6c7 100644 --- a/ecal/registration/registration.go +++ b/ecal/registration/registration.go @@ -3,14 +3,14 @@ package registration // #cgo LDFLAGS: -lecal_core //#include "registration.h" //#include "types.h" -// #cgo CPPFLAGS: -I${SRCDIR}/../types +// #cgo CPPFLAGS: -I${SRCDIR}/.. import "C" import ( "log" "runtime/cgo" - "github.com/DownerCase/ecal-go/ecal/types" + "github.com/DownerCase/ecal-go/ecal" ) type Event uint8 @@ -20,24 +20,12 @@ const ( EntityDeleted Event = 1 ) -type QualityFlags uint8 - -type ( - EntityID = types.EntityID - TopicID = types.TopicID -) - type CallbackToken struct { ecalToken uint goHandle cgo.Handle } -type QualityTopicInfo struct { - Datatype types.DataType - QualityFlags QualityFlags -} - -func AddPublisherEventCallback(callback func(TopicID, Event)) CallbackToken { +func AddPublisherEventCallback(callback func(ecal.TopicID, Event)) CallbackToken { handle := cgo.NewHandle(callback) ecalToken := C.AddPublisherEventCallback(C.uintptr_t(handle)) token := CallbackToken{ @@ -52,7 +40,7 @@ func RemPublisherCallback(token CallbackToken) { token.goHandle.Delete() } -func AddSubscriberEventCallback(callback func(TopicID, Event)) CallbackToken { +func AddSubscriberEventCallback(callback func(ecal.TopicID, Event)) CallbackToken { handle := cgo.NewHandle(callback) ecalToken := C.AddSubscriberEventCallback(C.uintptr_t(handle)) token := CallbackToken{ @@ -67,9 +55,9 @@ func RemSubscriberCallback(token CallbackToken) { token.goHandle.Delete() } -func toTopicID(id *C.struct_CTopicId) TopicID { - return TopicID{ - TopicID: EntityID{ +func toTopicID(id *C.struct_CTopicId) ecal.TopicID { + return ecal.TopicID{ + TopicID: ecal.EntityID{ EntityID: C.GoString(id.topic_id.entity_id), ProcessID: int32(id.topic_id.process_id), HostName: C.GoString(id.topic_id.host_name), @@ -81,7 +69,7 @@ func toTopicID(id *C.struct_CTopicId) TopicID { //export goTopicEventCallback func goTopicEventCallback(handle C.uintptr_t, id C.struct_CTopicId, event C.uint8_t) { h := cgo.Handle(handle) - f, ok := h.Value().(func(TopicID, Event)) + f, ok := h.Value().(func(ecal.TopicID, Event)) if !ok { log.Panic("Invalid handle passed to registration callback") } diff --git a/ecal/subscriber/subscriber.go b/ecal/subscriber/subscriber.go index c2a2ea1..96bcfab 100644 --- a/ecal/subscriber/subscriber.go +++ b/ecal/subscriber/subscriber.go @@ -18,7 +18,7 @@ import ( "time" "unsafe" - "github.com/DownerCase/ecal-go/ecal/types" + "github.com/DownerCase/ecal-go/ecal" ) var ( @@ -34,7 +34,7 @@ type Subscriber struct { Deserialize func(unsafe.Pointer, int) any } -type DataType = types.DataType +type DataType = ecal.DataType func New(topic string, datatype DataType) (*Subscriber, error) { sub := &Subscriber{ diff --git a/ecal/types/types.cpp b/ecal/types.cpp similarity index 100% rename from ecal/types/types.cpp rename to ecal/types.cpp diff --git a/ecal/types/types.go b/ecal/types.go similarity index 89% rename from ecal/types/types.go rename to ecal/types.go index ad335c4..35c3e07 100644 --- a/ecal/types/types.go +++ b/ecal/types.go @@ -1,6 +1,4 @@ -package types - -import "C" +package ecal type EntityID struct { EntityID string diff --git a/ecal/types/types.h b/ecal/types.h similarity index 100% rename from ecal/types/types.h rename to ecal/types.h diff --git a/ecal/types/types.hpp b/ecal/types.hpp similarity index 100% rename from ecal/types/types.hpp rename to ecal/types.hpp diff --git a/internal/ecaltest/regtest/test_registration.go b/internal/ecaltest/regtest/test_registration.go index 4143a5c..c41ec97 100644 --- a/internal/ecaltest/regtest/test_registration.go +++ b/internal/ecaltest/regtest/test_registration.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/DownerCase/ecal-go/ecal" "github.com/DownerCase/ecal-go/ecal/registration" ) @@ -14,11 +15,11 @@ const ( type Callback struct { Event registration.Event - ID registration.TopicID + ID ecal.TopicID } -func EventCallback(topic string, channel chan Callback) func(registration.TopicID, registration.Event) { - return func(id registration.TopicID, event registration.Event) { +func EventCallback(topic string, channel chan Callback) func(ecal.TopicID, registration.Event) { + return func(id ecal.TopicID, event registration.Event) { if id.TopicName == topic { channel <- Callback{event, id} } diff --git a/main.go b/main.go index dfadb80..28216af 100644 --- a/main.go +++ b/main.go @@ -111,6 +111,6 @@ func receiveMessages(s *subscriber.Subscriber) { } } -func registrationLogger(id registration.TopicID, _ registration.Event) { +func registrationLogger(id ecal.TopicID, _ registration.Event) { fmt.Println("Received registration sample:", id) //nolint:forbidigo }