Home | History | Annotate | Download | only in jingle_glue
      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/jingle_glue/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 
     18 namespace {
     19 
     20 const char kLogCommand[] = "log";
     21 const char kLogEntry[] = "entry";
     22 
     23 const char kKeyEventName[] = "event-name";
     24 
     25 const char kKeyRole[] = "role";
     26 
     27 const char kKeyMode[] = "mode";
     28 const char kValueModeIt2Me[] = "it2me";
     29 const char kValueModeMe2Me[] = "me2me";
     30 
     31 const char kKeyCpu[] = "cpu";
     32 
     33 }  // namespace
     34 
     35 ServerLogEntry::ServerLogEntry() {
     36 }
     37 
     38 ServerLogEntry::~ServerLogEntry() {
     39 }
     40 
     41 void ServerLogEntry::Set(const std::string& key, const std::string& value) {
     42   values_map_[key] = value;
     43 }
     44 
     45 void ServerLogEntry::AddCpuField() {
     46   Set(kKeyCpu, SysInfo::OperatingSystemArchitecture());
     47 }
     48 
     49 void 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 
     64 void ServerLogEntry::AddRoleField(const char* role) {
     65   Set(kKeyRole, role);
     66 }
     67 
     68 void ServerLogEntry::AddEventNameField(const char* name) {
     69   Set(kKeyEventName, name);
     70 }
     71 
     72 // static
     73 scoped_ptr<XmlElement> ServerLogEntry::MakeStanza() {
     74   return scoped_ptr<XmlElement>(
     75       new XmlElement(QName(kChromotingXmlNamespace, kLogCommand)));
     76 }
     77 
     78 scoped_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