Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/midi/midi_manager_alsa.h" | 5 #include "media/midi/midi_manager_alsa.h" |
| 6 | 6 |
| 7 #include <alsa/asoundlib.h> | 7 #include <alsa/asoundlib.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 | 84 |
| 85 // If no property, look for sysattrs and walk up the parent devices too. | 85 // If no property, look for sysattrs and walk up the parent devices too. |
| 86 while (value.empty() && udev_device) { | 86 while (value.empty() && udev_device) { |
| 87 value = device::UdevDeviceGetSysattrValue(udev_device, sysattr_key); | 87 value = device::UdevDeviceGetSysattrValue(udev_device, sysattr_key); |
| 88 udev_device = device::udev_device_get_parent(udev_device); | 88 udev_device = device::udev_device_get_parent(udev_device); |
| 89 } | 89 } |
| 90 return value; | 90 return value; |
| 91 } | 91 } |
| 92 #endif // defined(USE_UDEV) | 92 #endif // defined(USE_UDEV) |
| 93 | 93 |
| 94 void SetStringIfNonEmpty(base::DictionaryValue* value, | |
| 95 const std::string& path, | |
| 96 const std::string& in_value) { | |
| 97 if (!in_value.empty()) | |
| 98 value->SetString(path, in_value); | |
| 99 } | |
| 100 | |
| 94 } // namespace | 101 } // namespace |
| 95 | 102 |
| 96 MidiManagerAlsa::MidiManagerAlsa() | 103 MidiManagerAlsa::MidiManagerAlsa() |
| 97 : in_client_(NULL), | 104 : in_client_(NULL), |
| 98 out_client_(NULL), | 105 out_client_(NULL), |
| 99 out_client_id_(-1), | 106 out_client_id_(-1), |
| 100 in_port_(-1), | 107 in_port_(-1), |
| 101 decoder_(NULL), | 108 decoder_(NULL), |
| 102 #if defined(USE_UDEV) | 109 #if defined(USE_UDEV) |
| 103 udev_(device::udev_new()), | 110 udev_(device::udev_new()), |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 port_name_(port_name), | 395 port_name_(port_name), |
| 389 card_name_(card_name), | 396 card_name_(card_name), |
| 390 card_longname_(card_longname), | 397 card_longname_(card_longname), |
| 391 type_(type) { | 398 type_(type) { |
| 392 } | 399 } |
| 393 | 400 |
| 394 MidiManagerAlsa::AlsaPortMetadata::~AlsaPortMetadata() { | 401 MidiManagerAlsa::AlsaPortMetadata::~AlsaPortMetadata() { |
| 395 } | 402 } |
| 396 | 403 |
| 397 scoped_ptr<base::Value> MidiManagerAlsa::AlsaPortMetadata::Value() const { | 404 scoped_ptr<base::Value> MidiManagerAlsa::AlsaPortMetadata::Value() const { |
| 398 base::DictionaryValue* value = new base::DictionaryValue(); | 405 base::DictionaryValue* value = new base::DictionaryValue(); |
|
Takashi Toyoshima
2015/03/23 06:17:11
This is not introduced by this CL, but it's better
| |
| 399 value->SetString("path", path_); | 406 SetStringIfNonEmpty(value, "path", path_); |
| 400 value->SetString("bus", bus_); | 407 SetStringIfNonEmpty(value, "bus", bus_); |
| 401 value->SetString("id", id_); | 408 SetStringIfNonEmpty(value, "id", id_); |
| 402 value->SetInteger("clientAddr", client_addr_); | 409 value->SetInteger("clientAddr", client_addr_); |
| 403 value->SetInteger("portAddr", port_addr_); | 410 value->SetInteger("portAddr", port_addr_); |
| 404 value->SetString("clientName", client_name_); | 411 SetStringIfNonEmpty(value, "clientName", client_name_); |
| 405 value->SetString("portName", port_name_); | 412 SetStringIfNonEmpty(value, "portName", port_name_); |
| 406 value->SetString("cardName", card_name_); | 413 SetStringIfNonEmpty(value, "cardName", card_name_); |
| 407 value->SetString("cardLongname", card_longname_); | 414 SetStringIfNonEmpty(value, "cardLongname", card_longname_); |
| 408 std::string type; | 415 std::string type; |
| 409 switch (type_) { | 416 switch (type_) { |
| 410 case Type::kInput: | 417 case Type::kInput: |
| 411 type = "input"; | 418 type = "input"; |
| 412 break; | 419 break; |
| 413 | 420 |
| 414 case Type::kOutput: | 421 case Type::kOutput: |
| 415 type = "output"; | 422 type = "output"; |
| 416 break; | 423 break; |
| 417 } | 424 } |
| 418 value->SetString("type", type); | 425 SetStringIfNonEmpty(value, "type", type); |
| 419 | 426 |
| 420 return scoped_ptr<base::Value>(value).Pass(); | 427 return scoped_ptr<base::Value>(value).Pass(); |
| 421 } | 428 } |
| 422 | 429 |
| 423 std::string MidiManagerAlsa::AlsaPortMetadata::JSONValue() const { | 430 std::string MidiManagerAlsa::AlsaPortMetadata::JSONValue() const { |
| 424 std::string json; | 431 std::string json; |
| 425 JSONStringValueSerializer serializer(&json); | 432 JSONStringValueSerializer serializer(&json); |
| 426 serializer.Serialize(*Value().get()); | 433 serializer.Serialize(*Value().get()); |
| 427 return json; | 434 return json; |
| 428 } | 435 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 } | 730 } |
| 724 } | 731 } |
| 725 } | 732 } |
| 726 } | 733 } |
| 727 | 734 |
| 728 MidiManager* MidiManager::Create() { | 735 MidiManager* MidiManager::Create() { |
| 729 return new MidiManagerAlsa(); | 736 return new MidiManagerAlsa(); |
| 730 } | 737 } |
| 731 | 738 |
| 732 } // namespace media | 739 } // namespace media |
| OLD | NEW |