forked from chobie/momonga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.go
88 lines (59 loc) · 1.4 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2014, Shuhei Tanuma. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
package common
import (
"github.com/PYW1/momonga/encoding/mqtt"
"github.com/PYW1/momonga/util"
)
type State int32
// ConnectionState: Idle, Send, Receive and Handshake?
const (
STATE_INIT State = iota
STATE_CONNECTING
STATE_CONNECTED
STATE_ACCEPTED
STATE_IDLE
STATE_DETACHED
STATE_SEND
STATE_RECEIVE
STATE_SHUTDOWN
STATE_CLOSED
)
type ConnectionError struct {
s string
}
func (e *ConnectionError) Error() string {
return e.s
}
type ConnectionResetError struct {
s string
}
func (e *ConnectionResetError) Error() string {
return e.s
}
// TODO: あんまり実情にあってないのでみなおそう
type Connection interface {
//WriteMessage(request mqtt.Message) error
WriteMessageQueue(request mqtt.Message)
Close() error
SetState(State)
GetState() State
ResetState()
ReadMessage() (mqtt.Message, error)
IsAlived() bool
SetWillMessage(mqtt.WillMessage)
GetWillMessage() *mqtt.WillMessage
HasWillMessage() bool
GetOutGoingTable() *util.MessageTable
GetSubscribedTopics() map[string]*SubscribeSet
AppendSubscribedTopic(string, *SubscribeSet)
RemoveSubscribedTopic(string)
SetKeepaliveInterval(int)
GetId() string
GetRealId() string
SetId(string)
DisableCleanSession()
ShouldCleanSession() bool
IsBridge() bool
}