xmpp/status.go
author Chris Jones <chris@cjones.org>
Fri, 18 Oct 2013 18:31:18 -0600
changeset 172 36a42bc073f0
parent 167 7ce61108ed86
permissions -rw-r--r--
Removed uses of Generic from the Stanza types.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
153
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     1
// Track the current status of the connection to the server.
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     2
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     3
package xmpp
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     4
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     5
import (
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     6
	"fmt"
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     7
)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
     8
166
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
     9
// Status of the connection.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    10
type Status int
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    11
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    12
const (
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    13
	statusUnconnected = iota
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    14
	statusConnected
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    15
	statusConnectedTls
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    16
	statusAuthenticated
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    17
	statusBound
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    18
	statusRunning
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    19
	statusShutdown
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    20
	statusError
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    21
)
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    22
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    23
var (
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    24
	// The client has not yet connected, or it has been
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    25
	// disconnected from the server.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    26
	StatusUnconnected Status = statusUnconnected
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    27
	// Initial connection established.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    28
	StatusConnected Status = statusConnected
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    29
	// Like StatusConnected, but with TLS.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    30
	StatusConnectedTls Status = statusConnectedTls
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    31
	// Authentication succeeded.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    32
	StatusAuthenticated Status = statusAuthenticated
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    33
	// Resource binding complete.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    34
	StatusBound Status = statusBound
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    35
	// Session has started and normal message traffic can be sent
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    36
	// and received.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    37
	StatusRunning Status = statusRunning
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    38
	// The session has closed, or is in the process of closing.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    39
	StatusShutdown Status = statusShutdown
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    40
	// The session has encountered an error. Otherwise identical
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    41
	// to StatusShutdown.
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    42
	StatusError Status = statusError
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    43
)
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    44
167
7ce61108ed86 Expose the Status.Fatal function.
Chris Jones <chris@cjones.org>
parents: 166
diff changeset
    45
// Does the status value indicate that the client is or has
7ce61108ed86 Expose the Status.Fatal function.
Chris Jones <chris@cjones.org>
parents: 166
diff changeset
    46
// disconnected?
7ce61108ed86 Expose the Status.Fatal function.
Chris Jones <chris@cjones.org>
parents: 166
diff changeset
    47
func (s Status) Fatal() bool {
166
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    48
	switch s {
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    49
	default:
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    50
		return false
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    51
	case StatusShutdown, StatusError:
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    52
		return true
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    53
	}
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    54
}
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    55
153
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    56
type statmgr struct {
155
Chris Jones <christian.jones@sri.com>
parents: 153
diff changeset
    57
	newStatus   chan Status
153
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    58
	newlistener chan chan Status
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    59
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    60
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    61
func newStatmgr(client chan<- Status) *statmgr {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    62
	s := statmgr{}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    63
	s.newStatus = make(chan Status)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    64
	s.newlistener = make(chan chan Status)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    65
	go s.manager(client)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    66
	return &s
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    67
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    68
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    69
func (s *statmgr) manager(client chan<- Status) {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    70
	// We handle this specially, in case the client doesn't read
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    71
	// our final status message.
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    72
	defer func() {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    73
		if client != nil {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    74
			select {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    75
			case client <- StatusShutdown:
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    76
			default:
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    77
			}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    78
			close(client)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    79
		}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    80
	}()
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    81
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    82
	stat := StatusUnconnected
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    83
	listeners := []chan Status{}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    84
	for {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    85
		select {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    86
		case stat = <-s.newStatus:
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    87
			for _, l := range listeners {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    88
				sendToListener(l, stat)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    89
			}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    90
			if client != nil && stat != StatusShutdown {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    91
				client <- stat
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    92
			}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    93
		case l, ok := <-s.newlistener:
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    94
			if !ok {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    95
				return
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    96
			}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    97
			defer close(l)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    98
			sendToListener(l, stat)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
    99
			listeners = append(listeners, l)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   100
		}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   101
	}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   102
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   103
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   104
func sendToListener(listen chan Status, stat Status) {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   105
	for {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   106
		select {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   107
		case <-listen:
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   108
		case listen <- stat:
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   109
			return
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   110
		}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   111
	}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   112
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   113
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   114
func (cl *Client) setStatus(stat Status) {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   115
	cl.statmgr.setStatus(stat)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   116
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   117
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   118
func (s *statmgr) setStatus(stat Status) {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   119
	s.newStatus <- stat
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   120
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   121
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   122
func (s *statmgr) newListener() <-chan Status {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   123
	l := make(chan Status, 1)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   124
	s.newlistener <- l
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   125
	return l
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   126
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   127
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   128
func (s *statmgr) close() {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   129
	close(s.newlistener)
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   130
}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   131
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   132
func (s *statmgr) awaitStatus(waitFor Status) error {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   133
	// BUG(chris): This routine leaks one channel each time it's
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   134
	// called. Listeners are never removed.
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   135
	l := s.newListener()
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   136
	for current := range l {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   137
		if current == waitFor {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   138
			return nil
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   139
		}
167
7ce61108ed86 Expose the Status.Fatal function.
Chris Jones <chris@cjones.org>
parents: 166
diff changeset
   140
		if current.Fatal() {
153
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   141
			break
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   142
		}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   143
		if current > waitFor {
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   144
			return nil
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   145
		}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   146
	}
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   147
	return fmt.Errorf("shut down waiting for status change")
bbd4166df95d Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
diff changeset
   148
}