2018-08-26 13:15:48 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018
|
|
|
|
// Mainflux
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
package things
|
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 {
|
|
|
|
// Save persists the channel. Successful operation is indicated by unique
|
|
|
|
// identifier accompanied by nil error response. A non-nil error is
|
|
|
|
// returned to indicate operation failure.
|
2018-12-05 13:09:25 +01:00
|
|
|
Save(Channel) (string, 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.
|
|
|
|
Update(Channel) error
|
|
|
|
|
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.
|
2018-12-05 13:09:25 +01:00
|
|
|
RetrieveByID(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-05-10 18:55:13 +02:00
|
|
|
RetrieveAll(string, uint64, uint64) (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-05-10 18:55:13 +02:00
|
|
|
RetrieveByThing(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.
|
2018-12-05 13:09:25 +01:00
|
|
|
Remove(string, string) error
|
2017-09-23 01:03:27 +02:00
|
|
|
|
2018-05-15 17:13:09 +02:00
|
|
|
// Connect adds thing to the channel's list of connected things.
|
2018-12-05 13:09:25 +01:00
|
|
|
Connect(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.
|
2018-12-05 13:09:25 +01:00
|
|
|
Disconnect(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.
|
2018-12-05 13:09:25 +01:00
|
|
|
HasThing(string, 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.
|
2018-12-05 13:09:25 +01:00
|
|
|
Connect(string, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// HasThing checks if thing is connected to channel.
|
2018-12-05 13:09:25 +01:00
|
|
|
HasThing(string, string) bool
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// Disconnects thing from channel.
|
2018-12-05 13:09:25 +01:00
|
|
|
Disconnect(string, string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
|
|
|
|
// Removes channel from cache.
|
2018-12-05 13:09:25 +01:00
|
|
|
Remove(string) error
|
2018-09-04 22:19:43 +02:00
|
|
|
}
|