2019-10-07 08:14:47 -06:00
|
|
|
// Copyright (c) Mainflux
|
2018-08-26 13:15:48 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
package things
|
2017-09-23 01:03:27 +02:00
|
|
|
|
2019-07-18 15:01:09 +02:00
|
|
|
import "context"
|
|
|
|
|
2017-09-23 01:03:27 +02:00
|
|
|
// Channel represents a Mainflux "communication group". This group contains the
|
2018-05-15 17:13:09 +02:00
|
|
|
// things that can exchange messages between eachother.
|
2017-09-23 01:03:27 +02:00
|
|
|
type Channel struct {
|
2018-12-05 13:09:25 +01:00
|
|
|
ID string
|
2018-11-28 15:58:48 +01:00
|
|
|
Owner string
|
|
|
|
Name string
|
2019-04-16 14:58:56 +02:00
|
|
|
Metadata map[string]interface{}
|
2017-09-23 01:03:27 +02:00
|
|
|
}
|
|
|
|
|
2019-01-08 11:53:24 +01:00
|
|
|
// ChannelsPage contains page related metadata as well as list of channels that
|
|
|
|
// belong to this page.
|
|
|
|
type ChannelsPage struct {
|
|
|
|
PageMetadata
|
|
|
|
Channels []Channel
|
|
|
|
}
|
|
|
|
|
2017-09-23 01:03:27 +02:00
|
|
|
// ChannelRepository specifies a channel persistence API.
|
|
|
|
type ChannelRepository interface {
|
2019-11-04 13:14:17 -07:00
|
|
|
// Save persists multiple channels. Channels are saved using a transaction. If one channel
|
|
|
|
// fails then none will be saved. Successful operation is indicated by non-nil
|
2019-10-29 05:59:54 -06:00
|
|
|
// error response.
|
2019-11-04 13:14:17 -07:00
|
|
|
Save(context.Context, ...Channel) ([]Channel, error)
|
2017-09-23 01:03:27 +02:00
|
|
|
|
|
|
|
// Update performs an update to the existing channel. A non-nil error is
|
|
|
|
// returned to indicate operation failure.
|
2019-07-18 15:01:09 +02:00
|
|
|
Update(context.Context, Channel) error
|
2017-09-23 01:03:27 +02:00
|
|
|
|
2018-05-17 20:17:02 +02:00
|
|
|
// RetrieveByID retrieves the channel having the provided identifier, that is owned
|
2017-09-23 01:03:27 +02:00
|
|
|
// by the specified user.
|
2019-07-18 15:01:09 +02:00
|
|
|
RetrieveByID(context.Context, string, string) (Channel, error)
|
2017-09-23 01:03:27 +02:00
|
|
|
|
2018-05-17 20:17:02 +02:00
|
|
|
// RetrieveAll retrieves the subset of channels owned by the specified user.
|
2019-10-01 14:12:52 +02:00
|
|
|
RetrieveAll(context.Context, string, uint64, uint64, string, Metadata) (ChannelsPage, error)
|
2019-01-08 11:53:24 +01:00
|
|
|
|
|
|
|
// RetrieveByThing retrieves the subset of channels owned by the specified
|
|
|
|
// user and have specified thing connected to them.
|
2019-07-18 15:01:09 +02:00
|
|
|
RetrieveByThing(context.Context, string, string, uint64, uint64) (ChannelsPage, error)
|
2017-09-23 01:03:27 +02:00
|
|
|
|
|
|
|
// Remove removes the channel having the provided identifier, that is owned
|
|
|
|
// by the specified user.
|
2019-07-18 15:01:09 +02:00
|
|
|
Remove(context.Context, string, string) error
|
2017-09-23 01:03:27 +02:00
|
|
|
|
2019-11-11 06:22:30 -07:00
|
|
|
// Connect adds things to the channel's list of connected things.
|
|
|
|
Connect(context.Context, string, string, ...string) error
|
2018-03-11 18:06:01 +01:00
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
// Disconnect removes thing from the channel's list of connected
|
|
|
|
// things.
|
2019-07-18 15:01:09 +02:00
|
|
|
Disconnect(context.Context, string, string, string) error
|
2018-03-11 18:06:01 +01:00
|
|
|
|
2018-05-16 14:28:41 +02:00
|
|
|
// HasThing determines whether the thing with the provided access key, is
|
2018-05-21 12:51:46 +02:00
|
|
|
// "connected" to the specified channel. If that's the case, it returns
|
|
|
|
// thing's ID.
|
2019-07-18 15:01:09 +02:00
|
|
|
HasThing(context.Context, string, string) (string, error)
|
2019-07-15 18:28:15 +02:00
|
|
|
|
|
|
|
// HasThingByID determines whether the thing with the provided ID, is
|
|
|
|
// "connected" to the specified channel. If that's the case, then
|
|
|
|
// returned error will be nil.
|
2019-07-18 15:01:09 +02:00
|
|
|
HasThingByID(context.Context, string, string) error
|
2017-09-23 01:03:27 +02:00
|
|
|
}
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// ChannelCache contains channel-thing connection caching interface.
|
|
|
|
type ChannelCache interface {
|
|
|
|
// Connect channel thing connection.
|
2019-07-18 15:01:09 +02:00
|
|
|
Connect(context.Context, string, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// HasThing checks if thing is connected to channel.
|
2019-07-18 15:01:09 +02:00
|
|
|
HasThing(context.Context, string, string) bool
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// Disconnects thing from channel.
|
2019-07-18 15:01:09 +02:00
|
|
|
Disconnect(context.Context, string, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// Removes channel from cache.
|
2019-07-18 15:01:09 +02:00
|
|
|
Remove(context.Context, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
}
|