github.com/enbility/spine-go@v0.7.0/api/device.go (about) 1 package api 2 3 import ( 4 shipapi "github.com/enbility/ship-go/api" 5 "github.com/enbility/spine-go/model" 6 ) 7 8 /* Device */ 9 10 // This interface defines the functions being common to local and remote devices 11 // A device corresponds to a SPINE device, see SPINE Introduction Chapter 2.2 12 type DeviceInterface interface { 13 // Get the device address 14 Address() *model.AddressDeviceType 15 // Get the device type 16 DeviceType() *model.DeviceTypeType 17 // Get the device feature set 18 FeatureSet() *model.NetworkManagementFeatureSetType 19 // Get the device destination data 20 DestinationData() model.NodeManagementDestinationDataType 21 } 22 23 // This interface defines all the required functions need to implement a local device 24 type DeviceLocalInterface interface { 25 DeviceInterface 26 // Setup a new remote device with a given SKI and triggers SPINE requesting device details 27 SetupRemoteDevice(ski string, writeI shipapi.ShipConnectionDataWriterInterface) shipapi.ShipConnectionDataReaderInterface 28 // Add a DeviceRemoteInterface implementation (used in SetupRemoteDevice and in tests) 29 AddRemoteDeviceForSki(ski string, rDevice DeviceRemoteInterface) 30 31 // Request NodeManagementDetailedDiscovery Data from a remote device 32 RequestRemoteDetailedDiscoveryData(rDevice DeviceRemoteInterface) (*model.MsgCounterType, *model.ErrorType) 33 34 // Remove a remote device and its connection 35 RemoveRemoteDeviceConnection(ski string) 36 // Remove a remote device (used in RemoveRemoteDeviceConnection and in tests) 37 RemoveRemoteDevice(ski string) 38 39 // Get a list of connected remote devices DeviceRemoteInterface implementations 40 RemoteDevices() []DeviceRemoteInterface 41 // Get a connected remote device DeviceRemoteInterface implementation for a given device address 42 RemoteDeviceForAddress(address model.AddressDeviceType) DeviceRemoteInterface 43 // Get a connected remote device DeviceRemoteInterface implementation for a SKI 44 RemoteDeviceForSki(ski string) DeviceRemoteInterface 45 46 // Add a new entity to the device 47 // It should trigger a notification of all remote devices about this new entity 48 AddEntity(entity EntityLocalInterface) 49 // Remove a entity from the device 50 // It should trigger a notification of all remote devices about this removed entity 51 RemoveEntity(entity EntityLocalInterface) 52 // Get a list of all entities EntityLocalInterface implementations 53 Entities() []EntityLocalInterface 54 // Get an entity EntityLocalInterface implementation for a given entity address 55 Entity(id []model.AddressEntityType) EntityLocalInterface 56 // Get the first entity EntityLocalInterface implementation for a given entity type 57 EntityForType(entityType model.EntityTypeType) EntityLocalInterface 58 59 // Get a FeatureLocalInterface implementation for a given feature address 60 FeatureByAddress(address *model.FeatureAddressType) FeatureLocalInterface 61 62 // Clean all entity specific caches 63 CleanRemoteEntityCaches(remoteAddress *model.EntityAddressType) 64 65 // Process incoming SPINE datagram 66 ProcessCmd(datagram model.DatagramType, remoteDevice DeviceRemoteInterface) error 67 68 // Get the node management 69 NodeManagement() NodeManagementInterface 70 71 // Get the bindings manager 72 BindingManager() BindingManagerInterface 73 74 // Get the subscription manager 75 SubscriptionManager() SubscriptionManagerInterface 76 // Send a notify message to remote device subscribing to a specific feature 77 NotifySubscribers(featureAddress *model.FeatureAddressType, cmd model.CmdType) 78 79 // Get the SPINE data structure for NodeManagementDetailDiscoveryData messages for this device 80 Information() *model.NodeManagementDetailedDiscoveryDeviceInformationType 81 } 82 83 // This interface defines all the required functions need to implement a remote device 84 type DeviceRemoteInterface interface { 85 DeviceInterface 86 // Get the SKI of a remote device 87 Ski() string 88 89 // Add a new entity EntityRemoteInterface implementation 90 AddEntity(entity EntityRemoteInterface) 91 92 // Remove an entity for a given address and return the entity that was removed 93 RemoveEntityByAddress(addr []model.AddressEntityType) EntityRemoteInterface 94 95 // Get an entity EntityRemoteInterface implementation for a given address 96 Entity(id []model.AddressEntityType) EntityRemoteInterface 97 // Get all entities EntityRemoteInterface implementations 98 Entities() []EntityRemoteInterface 99 100 // Get a feature FeatureRemoteInterface implementation for a given address 101 FeatureByAddress(address *model.FeatureAddressType) FeatureRemoteInterface 102 // Get a feature FeatureRemoteInterface implementation from a given entity EntityRemoteInterface implementation by the feature type and feature role 103 FeatureByEntityTypeAndRole(entity EntityRemoteInterface, featureType model.FeatureTypeType, role model.RoleType) FeatureRemoteInterface 104 105 // Process incoming data payload 106 HandleSpineMesssage(message []byte) (*model.MsgCounterType, error) 107 108 // Get the SenderInterface implementation 109 Sender() SenderInterface 110 111 // Get the devices usecase data 112 UseCases() []model.UseCaseInformationDataType 113 114 // Update the devices address, type and featureset based on NetworkManagementDeviceDescriptionData 115 UpdateDevice(description *model.NetworkManagementDeviceDescriptionDataType) 116 117 // Add entities and their features using provided NodeManagementDetailedDiscoveryData 118 AddEntityAndFeatures(initialData bool, data *model.NodeManagementDetailedDiscoveryDataType) ([]EntityRemoteInterface, error) 119 120 // Helper method for checking incoming NodeManagementDetailedDiscoveryEntityInformation data 121 CheckEntityInformation(initialData bool, entity model.NodeManagementDetailedDiscoveryEntityInformationType) error 122 }