xmpp/status.go
author Chris Jones <chris@cjones.org>
Wed, 02 Oct 2013 23:22:27 -0600
changeset 166 8093a2da46db
parent 163 3f891f7fe817
child 167 7ce61108ed86
permissions -rw-r--r--
Moved some code around.
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
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    45
func (s Status) fatal() bool {
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    46
	switch s {
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    47
	default:
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    48
		return false
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    49
	case StatusShutdown, StatusError:
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    50
		return true
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    51
	}
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    52
}
8093a2da46db Moved some code around.
Chris Jones <chris@cjones.org>
parents: 163
diff changeset
    53
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
    54
type statmgr struct {
155
Chris Jones <christian.jones@sri.com>
parents: 153
diff changeset
    55
	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
    56
	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
    57
}
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
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
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
    60
	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
    61
	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
    62
	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
    63
	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
    64
	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
    65
}
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
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
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
    68
	// 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
    69
	// 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
    70
	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
    71
		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
    72
			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
    73
			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
    74
			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
    75
			}
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
			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
    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
	}()
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
	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
    81
	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
    82
	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
    83
		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
    84
		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
    85
			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
    86
				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
    87
			}
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
			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
    89
				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
    90
			}
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
		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
    92
			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
    93
				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
    94
			}
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
			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
    96
			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
    97
			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
    98
		}
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
	}
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
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
   103
	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
   104
		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
   105
		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
   106
		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
   107
			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
   108
		}
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
	}
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
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
   113
	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
   114
}
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
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
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
   117
	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
   118
}
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
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
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
   121
	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
   122
	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
   123
	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
   124
}
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
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
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
   127
	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
   128
}
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
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
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
   131
	// 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
   132
	// 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
   133
	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
   134
	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
   135
		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
   136
			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
   137
		}
163
3f891f7fe817 Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents: 155
diff changeset
   138
		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
   139
			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
   140
		}
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
		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
   142
			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
   143
		}
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
	}
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
	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
   146
}