[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 1 | // Copyright 2014 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. |
| 4 | |
[email protected] | fd0ca11 | 2014-07-17 06:10:20 | [diff] [blame] | 5 | #include "remoting/signaling/server_log_entry.h" |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 6 | |
| 7 | #include "base/logging.h" |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 8 | #include "base/memory/ptr_util.h" |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 9 | #include "base/sys_info.h" |
| 10 | #include "remoting/base/constants.h" |
kjellander | f0e410b | 2017-01-04 14:45:01 | [diff] [blame] | 11 | #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 12 | |
| 13 | using base::SysInfo; |
| 14 | using buzz::QName; |
| 15 | using buzz::XmlElement; |
| 16 | |
| 17 | namespace remoting { |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | const char kLogCommand[] = "log"; |
| 22 | const char kLogEntry[] = "entry"; |
| 23 | |
| 24 | const char kKeyEventName[] = "event-name"; |
| 25 | |
| 26 | const char kKeyRole[] = "role"; |
| 27 | |
| 28 | const char kKeyMode[] = "mode"; |
| 29 | const char kValueModeIt2Me[] = "it2me"; |
| 30 | const char kValueModeMe2Me[] = "me2me"; |
| 31 | |
| 32 | const char kKeyCpu[] = "cpu"; |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | ServerLogEntry::ServerLogEntry() { |
| 37 | } |
| 38 | |
vmpstr | 83a7f26 | 2016-02-26 21:46:54 | [diff] [blame] | 39 | ServerLogEntry::ServerLogEntry(const ServerLogEntry& other) = default; |
| 40 | |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 41 | ServerLogEntry::~ServerLogEntry() { |
| 42 | } |
| 43 | |
| 44 | void ServerLogEntry::Set(const std::string& key, const std::string& value) { |
| 45 | values_map_[key] = value; |
| 46 | } |
| 47 | |
| 48 | void ServerLogEntry::AddCpuField() { |
| 49 | Set(kKeyCpu, SysInfo::OperatingSystemArchitecture()); |
| 50 | } |
| 51 | |
| 52 | void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) { |
sergeyu | c5f104b | 2015-01-09 19:33:24 | [diff] [blame] | 53 | const char* mode_value = nullptr; |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 54 | switch (mode) { |
| 55 | case IT2ME: |
| 56 | mode_value = kValueModeIt2Me; |
| 57 | break; |
| 58 | case ME2ME: |
| 59 | mode_value = kValueModeMe2Me; |
| 60 | break; |
| 61 | default: |
| 62 | NOTREACHED(); |
| 63 | } |
| 64 | Set(kKeyMode, mode_value); |
| 65 | } |
| 66 | |
| 67 | void ServerLogEntry::AddRoleField(const char* role) { |
| 68 | Set(kKeyRole, role); |
| 69 | } |
| 70 | |
| 71 | void ServerLogEntry::AddEventNameField(const char* name) { |
| 72 | Set(kKeyEventName, name); |
| 73 | } |
| 74 | |
| 75 | // static |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 76 | std::unique_ptr<XmlElement> ServerLogEntry::MakeStanza() { |
ricea | 68860bd | 2016-08-22 02:48:56 | [diff] [blame] | 77 | return base::MakeUnique<XmlElement>( |
| 78 | QName(kChromotingXmlNamespace, kLogCommand)); |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 79 | } |
| 80 | |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 81 | std::unique_ptr<XmlElement> ServerLogEntry::ToStanza() const { |
| 82 | std::unique_ptr<XmlElement> stanza( |
| 83 | new XmlElement(QName(kChromotingXmlNamespace, kLogEntry))); |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 84 | ValuesMap::const_iterator iter; |
| 85 | for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) { |
| 86 | stanza->AddAttr(QName(std::string(), iter->first), iter->second); |
| 87 | } |
sergeyu | 42ad7c0 | 2015-12-24 00:20:51 | [diff] [blame] | 88 | return stanza; |
[email protected] | b580f42 | 2014-05-22 22:21:23 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | } // namespace remoting |