The set_presence() function
This function is used by setup_Jabber() to send
the script’s (and therefore the coffee’s) initial presence. It’s also used
within the main sensor poll/presence push loop to send further presence
packets if the coffee’s state changes.
sub set_presence {
my ($connection, $s) = @_;
my $presence = Net::Jabber::Presence->new();
my ($show, $status) = split("/", $status[$s], 2);
$presence->SetPresence( show => $show,
status => $status );
print $status, "\n";
$connection->Send($presence);
}
On receipt of the Jabber connection object and the coffee status, which will
be 0 (NOCOFFEE) or 1 (COFFEE),
set_presence() constructs a new
Net::Jabber::Presence object. This object represents a
<presence/> element, upon which we can
make method calls to hone the element as we wish.
SetPresence() is one of these methods, with which
we can set values for each of the <show/>
and <status/> tags. We retrieve the values
for each of these tags by pulling the strings from the appropriate
member of the @status array, as described earlier in
Section 9.2.3.1.
We print the coffee’s status (remember, this function is called only
when the status changes, not every time the
sensor is polled) and send the newly built
<presence/>
element down the XML stream to the Jabber server. This is accomplished by passing the
presence object as an argument to the Send()
method of the connection object in $connection. This
works in the same way as the send() function in
Jabberpy and the send() function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access