Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / remoting / host / host_status_sender.h
blobd1e14aecb58a8e2a33916fec12188c15200ecb00
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_STATUS_SENDER_H_
6 #define REMOTING_HOST_STATUS_SENDER_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/base/rsa_key_pair.h"
14 #include "remoting/host/host_exit_codes.h"
15 #include "remoting/signaling/signal_strategy.h"
17 namespace base {
18 class MessageLoopProxy;
19 } // namespace base
21 namespace buzz {
22 class XmlElement;
23 } // namespace buzz
25 namespace remoting {
27 class RsaKeyPair;
28 class IqSender;
30 // HostStatusSender sends the host status to the Chromoting Bot.
31 // Each host status stanza looks as follows:
33 // <cli:iq type="set" to="user@gmail.com/chromoting123123"
34 // id="123" xmlns:cli="jabber:client">
35 // <rem:host-status rem:hostid="0"
36 // rem:status="OFFLINE" rem:exit-code="INVALID_HOST_CONFIGURATION"
37 // xmlns:rem="google:remoting">
38 // <rem:signature rem:time="1372878097">.signature.</rem:signature>
39 // <rem:host-version>30.0.1554.0</rem:host-version>
40 // <rem:log><rem:entry cpu="x86_64" event-name="host-status"
41 // host-version="30.0.1560.0" os-name="Linux" role="host"/>
42 // </rem:log>
43 // </rem:host-status>
44 // </cli:iq>
46 // The signature is a base-64 encoded SHA-1 hash, signed with the host's
47 // private RSA key. The message being signed contains the full Jid (e.g.
48 // "user@gmail.com/chromoting123123"), the timestamp, the host status,
49 // and the exit code.
50 class HostStatusSender : SignalStrategy::Listener {
51 public:
53 enum HostStatus {
54 OFFLINE = 0,
55 ONLINE = 1
58 HostStatusSender(const std::string& host_id,
59 SignalStrategy* signal_strategy,
60 scoped_refptr<RsaKeyPair> key_pair,
61 const std::string& directory_bot_jid);
62 ~HostStatusSender() override;
64 // SignalStrategy::Listener interface.
65 void OnSignalStrategyStateChange(SignalStrategy::State state) override;
66 bool OnSignalStrategyIncomingStanza(const buzz::XmlElement* stanza) override;
68 // APIs for sending host status XMPP messages to the chromoting bot.
69 // status: the reason (exit code) why the host is offline.
70 void SendOnlineStatus();
71 void SendOfflineStatus(HostExitCodes exit_code);
73 inline static const char* HostStatusToString(HostStatus host_status) {
74 return host_status_strings_[host_status];
77 private:
78 // Helper method for sending either an online or an offline status message.
79 void SendHostStatus(HostStatus status, HostExitCodes exit_code);
81 // Helper method to compose host status stanzas.
82 scoped_ptr<buzz::XmlElement> CreateHostStatusMessage(
83 HostStatus status, HostExitCodes exit_code);
85 // Helper method to create the signature blob used in the host status stanza.
86 scoped_ptr<buzz::XmlElement> CreateSignature(
87 HostStatus status, HostExitCodes exit_code);
89 std::string host_id_;
90 SignalStrategy* signal_strategy_;
91 scoped_refptr<RsaKeyPair> key_pair_;
92 std::string directory_bot_jid_;
93 scoped_ptr<IqSender> iq_sender_;
95 // The string representation of the HostStatus values.
96 static const char* const host_status_strings_[2];
98 DISALLOW_COPY_AND_ASSIGN(HostStatusSender);
101 } // namespace remoting
103 #endif // REMOTING_HOST_STATUS_SENDER_H_