github.com/enbility/spine-go@v0.7.0/spine/feature.go (about)

     1  package spine
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/enbility/spine-go/api"
     7  	"github.com/enbility/spine-go/model"
     8  	"github.com/enbility/spine-go/util"
     9  )
    10  
    11  type Feature struct {
    12  	address     *model.FeatureAddressType
    13  	ftype       model.FeatureTypeType
    14  	description *model.DescriptionType
    15  	role        model.RoleType
    16  	operations  map[model.FunctionType]api.OperationsInterface
    17  }
    18  
    19  var _ api.FeatureInterface = (*Feature)(nil)
    20  
    21  func NewFeature(address *model.FeatureAddressType, ftype model.FeatureTypeType, role model.RoleType) *Feature {
    22  	res := &Feature{
    23  		address: address,
    24  		ftype:   ftype,
    25  		role:    role,
    26  	}
    27  
    28  	return res
    29  }
    30  
    31  func (r *Feature) Address() *model.FeatureAddressType {
    32  	return r.address
    33  }
    34  
    35  func (r *Feature) Type() model.FeatureTypeType {
    36  	return r.ftype
    37  }
    38  
    39  func (r *Feature) Role() model.RoleType {
    40  	return r.role
    41  }
    42  
    43  func (r *Feature) Operations() map[model.FunctionType]api.OperationsInterface {
    44  	return r.operations
    45  }
    46  
    47  func (r *Feature) Description() *model.DescriptionType {
    48  	return r.description
    49  }
    50  
    51  func (r *Feature) SetDescription(d *model.DescriptionType) {
    52  	r.description = d
    53  }
    54  
    55  func (r *Feature) SetDescriptionString(s string) {
    56  	r.description = util.Ptr(model.DescriptionType(s))
    57  }
    58  
    59  func (r *Feature) String() string {
    60  	if r == nil {
    61  		return ""
    62  	}
    63  	return fmt.Sprintf("Id: %d (%s)", *r.Address().Feature, string(r.ftype))
    64  }
    65  
    66  func featureAddressType(id uint, entityAddress *model.EntityAddressType) *model.FeatureAddressType {
    67  	res := model.FeatureAddressType{
    68  		Device:  entityAddress.Device,
    69  		Entity:  entityAddress.Entity,
    70  		Feature: util.Ptr(model.AddressFeatureType(id)),
    71  	}
    72  
    73  	return &res
    74  }