server_log_entry.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "remoting/signaling/server_log_entry.h"
  5. #include "base/notreached.h"
  6. #include "base/system/sys_info.h"
  7. #include "remoting/base/constants.h"
  8. #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
  9. using base::SysInfo;
  10. using jingle_xmpp::QName;
  11. using jingle_xmpp::XmlElement;
  12. namespace remoting {
  13. namespace {
  14. const char kLogCommand[] = "log";
  15. const char kLogEntry[] = "entry";
  16. const char kKeyEventName[] = "event-name";
  17. const char kKeyRole[] = "role";
  18. const char kKeyMode[] = "mode";
  19. const char kValueModeIt2Me[] = "it2me";
  20. const char kValueModeMe2Me[] = "me2me";
  21. const char kKeyCpu[] = "cpu";
  22. } // namespace
  23. ServerLogEntry::ServerLogEntry() = default;
  24. ServerLogEntry::ServerLogEntry(const ServerLogEntry& other) = default;
  25. ServerLogEntry::~ServerLogEntry() = default;
  26. void ServerLogEntry::Set(const std::string& key, const std::string& value) {
  27. values_map_[key] = value;
  28. }
  29. void ServerLogEntry::AddCpuField() {
  30. Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
  31. }
  32. void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
  33. const char* mode_value = nullptr;
  34. switch (mode) {
  35. case IT2ME:
  36. mode_value = kValueModeIt2Me;
  37. break;
  38. case ME2ME:
  39. mode_value = kValueModeMe2Me;
  40. break;
  41. default:
  42. NOTREACHED();
  43. }
  44. Set(kKeyMode, mode_value);
  45. }
  46. void ServerLogEntry::AddRoleField(const char* role) {
  47. Set(kKeyRole, role);
  48. }
  49. void ServerLogEntry::AddEventNameField(const char* name) {
  50. Set(kKeyEventName, name);
  51. }
  52. // static
  53. std::unique_ptr<XmlElement> ServerLogEntry::MakeStanza() {
  54. return std::make_unique<XmlElement>(
  55. QName(kChromotingXmlNamespace, kLogCommand));
  56. }
  57. std::unique_ptr<XmlElement> ServerLogEntry::ToStanza() const {
  58. std::unique_ptr<XmlElement> stanza(
  59. new XmlElement(QName(kChromotingXmlNamespace, kLogEntry)));
  60. ValuesMap::const_iterator iter;
  61. for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
  62. stanza->AddAttr(QName(std::string(), iter->first), iter->second);
  63. }
  64. return stanza;
  65. }
  66. apis::v1::GenericLogEntry ServerLogEntry::ToGenericLogEntry() const {
  67. apis::v1::GenericLogEntry log_entry;
  68. for (auto pair : values_map_) {
  69. auto* field = log_entry.add_field();
  70. field->set_key(pair.first);
  71. field->set_value(pair.second);
  72. }
  73. return log_entry;
  74. }
  75. } // namespace remoting