blob: 0b7b54dda34477bb2c216bf47abaa8ea7b4d5cae [file] [log] [blame]
[email protected]b580f422014-05-22 22:21:231// 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]fd0ca112014-07-17 06:10:205#include "remoting/signaling/server_log_entry.h"
[email protected]b580f422014-05-22 22:21:236
7#include "base/logging.h"
dcheng0765c492016-04-06 22:41:538#include "base/memory/ptr_util.h"
[email protected]b580f422014-05-22 22:21:239#include "base/sys_info.h"
10#include "remoting/base/constants.h"
kjellanderf0e410b2017-01-04 14:45:0111#include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
[email protected]b580f422014-05-22 22:21:2312
13using base::SysInfo;
14using buzz::QName;
15using buzz::XmlElement;
16
17namespace remoting {
18
19namespace {
20
21const char kLogCommand[] = "log";
22const char kLogEntry[] = "entry";
23
24const char kKeyEventName[] = "event-name";
25
26const char kKeyRole[] = "role";
27
28const char kKeyMode[] = "mode";
29const char kValueModeIt2Me[] = "it2me";
30const char kValueModeMe2Me[] = "me2me";
31
32const char kKeyCpu[] = "cpu";
33
34} // namespace
35
36ServerLogEntry::ServerLogEntry() {
37}
38
vmpstr83a7f262016-02-26 21:46:5439ServerLogEntry::ServerLogEntry(const ServerLogEntry& other) = default;
40
[email protected]b580f422014-05-22 22:21:2341ServerLogEntry::~ServerLogEntry() {
42}
43
44void ServerLogEntry::Set(const std::string& key, const std::string& value) {
45 values_map_[key] = value;
46}
47
48void ServerLogEntry::AddCpuField() {
49 Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
50}
51
52void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
sergeyuc5f104b2015-01-09 19:33:2453 const char* mode_value = nullptr;
[email protected]b580f422014-05-22 22:21:2354 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
67void ServerLogEntry::AddRoleField(const char* role) {
68 Set(kKeyRole, role);
69}
70
71void ServerLogEntry::AddEventNameField(const char* name) {
72 Set(kKeyEventName, name);
73}
74
75// static
dcheng0765c492016-04-06 22:41:5376std::unique_ptr<XmlElement> ServerLogEntry::MakeStanza() {
ricea68860bd2016-08-22 02:48:5677 return base::MakeUnique<XmlElement>(
78 QName(kChromotingXmlNamespace, kLogCommand));
[email protected]b580f422014-05-22 22:21:2379}
80
dcheng0765c492016-04-06 22:41:5381std::unique_ptr<XmlElement> ServerLogEntry::ToStanza() const {
82 std::unique_ptr<XmlElement> stanza(
83 new XmlElement(QName(kChromotingXmlNamespace, kLogEntry)));
[email protected]b580f422014-05-22 22:21:2384 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 }
sergeyu42ad7c02015-12-24 00:20:5188 return stanza;
[email protected]b580f422014-05-22 22:21:2389}
90
91} // namespace remoting