8000 MF-1090 - Use named Interfaces args by manuio · Pull Request #1097 · absmach/supermq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MF-1090 - Use named Interfaces args #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions bootstrap/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,48 +61,48 @@ var _ Service = (*bootstrapService)(nil)
// implementation, and all of its decorators (e.g. logging & metrics).
type Service interface {
// Add adds new Thing Config to the user identified by the provided key.
Add(string, Config) (Config, error)
Add(key string, cfg Config) (Config, error)

// View returns Thing Config with given ID belonging to the user identified by the given key.
View(string, string) (Config, error)
View(key, id string) (Config, error)

// Update updates editable fields of the provided Config.
Update(string, Config) error
Update(key string, cfg Config) error

// UpdateCert updates an existing Config certificate and key.
// A non-nil error is returned to indicate operation failure.
UpdateCert(string, string, string, string, string) error
UpdateCert(key, thingID, clientCert, clientKey, caCert string) error

// UpdateConnections updates list of Channels related to given Config.
UpdateConnections(string, string, []string) error
UpdateConnections(key, id string, connections []string) error

// List returns subset of Configs with given search params that belong to the
// user identified by the given key.
List(string, Filter, uint64, uint64) (ConfigsPage, error)
List(key string, filter Filter, offset, limit uint64) (ConfigsPage, error)

// Remove removes Config with specified key that belongs to the user identified by the given key.
Remove(string, string) error
Remove(key, id string) error

// Bootstrap returns Config to the Thing with provided external ID using external key.
Bootstrap(string, string, bool) (Config, error)
Bootstrap(externalKey, externalID string, secure bool) (Config, error)

// ChangeState changes state of the Thing with given ID and owner.
ChangeState(string, string, State) error
ChangeState(key, id string, state State) error

// Methods RemoveConfig, UpdateChannel, and RemoveChannel are used as
// handlers for events. That's why these methods surpass ownership check.

// RemoveConfigHandler removes Configuration with id received from an event.
RemoveConfigHandler(string) error

// UpdateChannelHandler updates Channel with data received from an event.
UpdateChannelHandler(Channel) error
UpdateChannelHandler(channel Channel) error

// RemoveConfigHandler removes Configuration with id received from an event.
RemoveConfigHandler(id string) error

// RemoveChannelHandler removes Channel with id received from an event.
RemoveChannelHandler(string) error
RemoveChannelHandler(id string) error

// DisconnectHandler changes state of the Config when connect/disconnect event occurs.
DisconnectThingHandler(string, string) error
DisconnectThingHandler(channelID, thingID string) error
}

// ConfigReader is used to parse Config into format which will be encoded
Expand Down
10 changes: 5 additions & 5 deletions broker/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
// Nats specifies a NATS message API.
type Nats interface {
// Publish publishes message to the msessage broker.
Publish(context.Context, string, Message) error
Publish(ctx context.Context, token string, msg Message) error

// Subscribe subscribes to a message broker subject.
Subscribe(string, func(msg *nats.Msg)) (*nats.Subscription, error)
Subscribe(subject string, consumer func(msg *nats.Msg)) (*nats.Subscription, error)

// Subscribe subscribes to the message broker for a given channel ID and subtopic.
QueueSubscribe(string, string, func(msg *nats.Msg)) (*nats.Subscription, error)
QueueSubscribe(subject, queue string, f func(msg *nats.Msg)) (*nats.Subscription, error)

// Close closes NATS connection.
Close()
Expand Down Expand Up @@ -75,9 +75,9 @@ func (b broker) Publish(_ context.Context, _ string, msg Message) error {
return nil
}

func (b broker) Subscribe(subject string, f func(msg *nats.Msg)) (*nats.Subscription, error) {
func (b broker) Subscribe(subject string, consumer func(msg *nats.Msg)) (*nats.Subscription, error) {
ps := fmt.Sprintf("%s.%s", prefix, subject)
sub, err := b.conn.Subscribe(ps, f)
sub, err := b.conn.Subscribe(ps, consumer)
if err != nil {
return nil, errors.Wrap(errNatsSub, err)
}
Expand Down
6 changes: 3 additions & 3 deletions coap/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ var (
// Service specifies coap service API.
type Service interface {
// Publish Messssage
Publish(context.Context, string, broker.Message) error
Publish(ctx context.Context, token string, msg broker.Message) error

// Subscribes to channel with specified id, subtopic and adds subscription to
// service map of subscriptions under given ID.
Subscribe(string, string, string, *Observer) error
Subscribe(chanID, subtopic, obsID string, obs *Observer) error

// Unsubscribe method is used to stop observing resource.
Unsubscribe(string)
Unsubscribe(obsID string)
}

var _ Service = (*adapterService)(nil)
Expand Down
2 changes: 1 addition & 1 deletion http/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// Service specifies coap service API.
type Service interface {
// Publish Messssage
Publish(context.Context, string, broker.Message) error
Publish(ctx context.Context, token string, msg broker.Message) error
}

var _ Service = (*adapterService)(nil)
Expand Down
50 changes: 25 additions & 25 deletions lora/service.go
6D40
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ var (
// Service specifies an API that must be fullfiled by the domain service
// implementation, and all of its decorators (e.g. logging & metrics).
type Service interface {
// CreateThing creates thing mfx:lora & lora:mfx route-map
CreateThing(string, string) error
// CreateThing creates thingID:devEUI route-map
CreateThing(thingID string, devEUI string) error

// UpdateThing updates thing mfx:lora & lora:mfx route-map
UpdateThing(string, string) error
// UpdateThing updates thingID:devEUI route-map
UpdateThing(thingID string, devEUI string) error

// RemoveThing removes thing mfx:lora & lora:mfx route-map
RemoveThing(string) error
// RemoveThing removes thingID:devEUI route-map
RemoveThing(thingID string) error

// CreateChannel creates channel mfx:lora & lora:mfx route-map
CreateChannel(string, string) error
// CreateChannel creates channelID:appID route-map
CreateChannel(chanID string, appID string) error

// UpdateChannel updates mfx:lora & lora:mfx route-map
UpdateChannel(string, string) error
// UpdateChannel updates channelID:appID route-map
UpdateChannel(chanID string, appID string) error

// RemoveChannel removes channel mfx:lora & lora:mfx route-map
RemoveChannel(string) error
// RemoveChannel removes channelID:appID route-map
RemoveChannel(chanID string) error

// Publish forwards messages from the LoRa MQTT broker to Mainflux NATS broker
Publish(context.Context, string, Message) error
Publish(ctx context.Context, token string, msg Message) error
}

var _ Service = (*adapterService)(nil)
Expand Down Expand Up @@ -115,26 +115,26 @@ func (as *adapterService) Publish(ctx context.Context, token string, m Message)
return as.broker.Publish(ctx, token, msg)
}

func (as *adapterService) CreateThing(mfxDevID string, loraDevEUI string) error {
return as.thingsRM.Save(mfxDevID, loraDevEUI)
func (as *adapterService) CreateThing(thingID string, devEUI string) error {
return as.thingsRM.Save(thingID, devEUI)
}

func (as *adapterService) UpdateThing(mfxDevID string, loraDevEUI string) error {
return as.thingsRM.Save(mfxDevID, loraDevEUI)
func (as *adapterService) UpdateThing(thingID string, devEUI string) error {
return as.thingsRM.Save(thingID, devEUI)
}

func (as *adapterService) RemoveThing(mfxDevID string) error {
return as.thingsRM.Remove(mfxDevID)
func (as *adapterService) RemoveThing(thingID string) error {
return as.thingsRM.Remove(thingID)
}

func (as *adapterService) CreateChannel(mfxChanID string, loraAppID string) error {
return as.channelsRM.Save(mfxChanID, loraAppID)
func (as *adapterService) CreateChannel(chanID string, appID string) error {
return as.channelsRM.Save(chanID, appID)
}

func (as *adapterService) UpdateChannel(mfxChanID string, loraAppID string) error {
return as.channelsRM.Save(mfxChanID, loraAppID)
func (as *adapterService) UpdateChannel(chanID string, appID string) error {
return as.channelsRM.Save(chanID, appID)
}

func (as *adapterService) RemoveChannel(mfxChanID string) error {
return as.channelsRM.Remove(mfxChanID)
func (as *adapterService) RemoveChannel(chanID string) error {
return as.channelsRM.Remove(chanID)
}
70 changes: 35 additions & 35 deletions opcua/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ var (
// Service specifies an API that must be fullfiled by the domain service
// implementation, and all of its decorators (e.g. logging & metrics).
type Service interface {
// CreateThing creates thing mfx:opc & opc:mfx route-map
CreateThing(string, string) error
// CreateThing creates thingID:OPC-UA-nodeID route-map
CreateThing(thingID, nodeID string) error

// UpdateThing updates thing mfx:opc & opc:mfx route-map
UpdateThing(string, string) error
// UpdateThing updates thingID:OPC-UA-nodeID route-map
UpdateThing(thingID, nodeID string) error

// RemoveThing removes thing mfx:opc & opc:mfx route-map
RemoveThing(string) error
// RemoveThing removes thingID:OPC-UA-nodeID route-map
RemoveThing(thingID string) error

// CreateChannel creates channel route-map
CreateChannel(string, string) error
// CreateChannel creates channelID:OPC-UA-serverURI route-map
CreateChannel(chanID, serverURI string) error

// UpdateChannel updates chroute-map
UpdateChannel(string, string) error
// UpdateChannel updates channelID:OPC-UA-serverURI route-map
UpdateChannel(chanID, serverURI string) error

// RemoveChannel removes channel route-map
RemoveChannel(string) error
// RemoveChannel removes channelID:OPC-UA-serverURI route-map
RemoveChannel(chanID string) error

// ConnectThing creates thing and channel connection route-map
ConnectThing(string, string) error
// ConnectThing creates thingID:channelID route-map
ConnectThing(chanID, thingID string) error

// DisconnectThing removes thing and channel connection route-map
DisconnectThing(string, string) error
// DisconnectThing removes thingID:channelID route-map
DisconnectThing(chanID, thingID string) error

// Browse browses available nodes for a given OPC-UA Server URI and NodeID
Browse(string, string, string) ([]BrowsedNode, error)
Browse(serverURI, namespace, identifier string) ([]BrowsedNode, error)
}

// Config OPC-UA Server
Expand Down Expand Up @@ -85,45 +85,45 @@ func New(sub Subscriber, brow Browser, thingsRM, channelsRM, connectRM RouteMapR
}
}

func (as *adapterService) CreateThing(mfxDevID, opcuaNodeID string) error {
return as.thingsRM.Save(mfxDevID, opcuaNodeID)
func (as *adapterService) CreateThing(thingID, nodeID string) error {
return as.thingsRM.Save(thingID, nodeID)
}

func (as *adapterService) UpdateThing(mfxDevID, opcuaNodeID string) error {
return as.thingsRM.Save(mfxDevID, opcuaNodeID)
func (as *adapterService) UpdateThing(thingID, nodeID string) error {
return as.thingsRM.Save(thingID, nodeID)
}

func (as *adapterService) RemoveThing(mfxDevID string) error {
return as.thingsRM.Remove(mfxDevID)
func (as *adapterService) RemoveThing(thingID string) error {
return as.thingsRM.Remove(thingID)
}

func (as *adapterService) CreateChannel(mfxChanID, opcuaServerURI string) error {
return as.channelsRM.Save(mfxChanID, opcuaServerURI)
func (as *adapterService) CreateChannel(chanID, serverURI string) error {
return as.channelsRM.Save(chanID, serverURI)
}

func (as *adapterService) UpdateChannel(mfxChanID, opcuaServerURI string) error {
return as.channelsRM.Save(mfxChanID, opcuaServerURI)
func (as *adapterService) UpdateChannel(chanID, serverURI string) error {
return as.channelsRM.Save(chanID, serverURI)
}

func (as *adapterService) RemoveChannel(mfxChanID string) error {
return as.channelsRM.Remove(mfxChanID)
func (as *adapterService) RemoveChannel(chanID string) error {
return as.channelsRM.Remove(chanID)
}

func (as *adapterService) ConnectThing(mfxChanID, mfxThingID string) error {
serverURI, err := as.channelsRM.Get(mfxChanID)
func (as *adapterService) ConnectThing(chanID, thingID string) error {
serverURI, err := as.channelsRM.Get(chanID)
if err != nil {
return err
}

nodeID, err := as.thingsRM.Get(mfxThingID)
nodeID, err := as.thingsRM.Get(thingID)
if err != nil {
return err
}

as.cfg.NodeID = nodeID
as.cfg.ServerURI = serverURI

c := fmt.Sprintf("%s:%s", mfxChanID, mfxThingID)
c := fmt.Sprintf("%s:%s", chanID, thingID)
if err := as.connectRM.Save(c, c); err != nil {
return err
}
Expand All @@ -148,7 +148,7 @@ func (as *adapterService) Browse(serverURI, namespace, identifier string) ([]Bro
return nodes, nil
}

func (as *adapterService) DisconnectThing(mfxChanID, mfxThingID string) error {
c := fmt.Sprintf("%s:%s", mfxChanID, mfxThingID)
func (as *adapterService) DisconnectThing(chanID, thingID string) error {
c := fmt.Sprintf("%s:%s", chanID, thingID)
return as.connectRM.Remove(c)
}
2 changes: 1 addition & 1 deletion readers/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrNotFound = errors.New("entity not found")
type MessageRepository interface {
// ReadAll skips given number of messages for given channel and returns next
// limited number of messages.
ReadAll(string, uint64, uint64, map[string]string) (MessagesPage, error)
ReadAll(chanID string, offset, limit uint64, query map[string]string) (MessagesPage, error)
}

// MessagesPage contains page related metadata as well as list of messages that
Expand Down
Loading
0