Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: remoting/protocol/server_log_entry.cc

Issue 282063005: Pull out common code from client and host versions of ServerLogEntry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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/protocol/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
12 using base::SysInfo;
13 using buzz::QName;
14 using buzz::XmlElement;
15
16 namespace remoting {
17 namespace protocol {
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
39 ServerLogEntry::~ServerLogEntry() {
40 }
41
42 void ServerLogEntry::Set(const std::string& key, const std::string& value) {
43 values_map_[key] = value;
44 }
45
46 void ServerLogEntry::AddCpuField() {
47 Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
48 }
49
50 void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) {
51 const char* mode_value = NULL;
52 switch (mode) {
53 case IT2ME:
54 mode_value = kValueModeIt2Me;
55 break;
56 case ME2ME:
57 mode_value = kValueModeMe2Me;
58 break;
59 default:
60 NOTREACHED();
61 }
62 Set(kKeyMode, mode_value);
63 }
64
65 void ServerLogEntry::AddRoleField(const char* role) {
66 Set(kKeyRole, role);
67 }
68
69 void ServerLogEntry::AddEventNameField(const char* name) {
70 Set(kKeyEventName, name);
71 }
72
73 // static
74 scoped_ptr<XmlElement> ServerLogEntry::MakeStanza() {
75 return scoped_ptr<XmlElement>(
76 new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
77 }
78
79 scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const {
80 scoped_ptr<XmlElement> stanza(new XmlElement(QName(
81 kChromotingXmlNamespace, kLogEntry)));
82 ValuesMap::const_iterator iter;
83 for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) {
84 stanza->AddAttr(QName(std::string(), iter->first), iter->second);
85 }
86 return stanza.Pass();
87 }
88
89 } // namespace protocol
90 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698