server_log_entry.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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
5#include "remoting/signaling/server_log_entry.h"
6
7#include "base/logging.h"
8#include "base/sys_info.h"
9#include "remoting/base/constants.h"
10#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
11
12using base::SysInfo;
13using buzz::QName;
14using buzz::XmlElement;
15
16namespace remoting {
17
18namespace {
19
20const char kLogCommand[] = "log";
21const char kLogEntry[] = "entry";
22
23const char kKeyEventName[] = "event-name";
24
25const char kKeyRole[] = "role";
26
27const char kKeyMode[] = "mode";
28const char kValueModeIt2Me[] = "it2me";
29const char kValueModeMe2Me[] = "me2me";
30
31const char kKeyCpu[] = "cpu";
32
33}  // namespace
34
35ServerLogEntry::ServerLogEntry() {
36}
37
38ServerLogEntry::~ServerLogEntry() {
39}
40
41void ServerLogEntry::Set(const std::string& key, const std::string& value) {
42  values_map_[key] = value;
43}
44
45void ServerLogEntry::AddCpuField() {
46  Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
47}
48
49void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
50  const char* mode_value = NULL;
51  switch (mode) {
52    case IT2ME:
53      mode_value = kValueModeIt2Me;
54      break;
55    case ME2ME:
56      mode_value = kValueModeMe2Me;
57      break;
58    default:
59      NOTREACHED();
60  }
61  Set(kKeyMode, mode_value);
62}
63
64void ServerLogEntry::AddRoleField(const char* role) {
65  Set(kKeyRole, role);
66}
67
68void ServerLogEntry::AddEventNameField(const char* name) {
69  Set(kKeyEventName, name);
70}
71
72// static
73scoped_ptr<XmlElement> ServerLogEntry::MakeStanza() {
74  return scoped_ptr<XmlElement>(
75      new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
76}
77
78scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
79  scoped_ptr<XmlElement> stanza(new XmlElement(QName(
80      kChromotingXmlNamespace, kLogEntry)));
81  ValuesMap::const_iterator iter;
82  for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
83    stanza->AddAttr(QName(std::string(), iter->first), iter->second);
84  }
85  return stanza.Pass();
86}
87
88}  // namespace remoting
89