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 <poll.h> | 7 #include <poll.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 client_id_(client_id), | 315 client_id_(client_id), |
316 port_id_(port_id), | 316 port_id_(port_id), |
317 client_name_(client_name), | 317 client_name_(client_name), |
318 port_name_(port_name), | 318 port_name_(port_name), |
319 manufacturer_(manufacturer), | 319 manufacturer_(manufacturer), |
320 version_(version), | 320 version_(version), |
321 web_port_index_(0), | 321 web_port_index_(0), |
322 connected_(true) { | 322 connected_(true) { |
323 } | 323 } |
324 | 324 |
325 MidiManagerAlsa::MidiPort::~MidiPort() { | 325 MidiManagerAlsa::MidiPort::~MidiPort() = default; |
326 } | |
327 | 326 |
328 // Note: keep synchronized with the MidiPort::Match* methods. | 327 // Note: keep synchronized with the MidiPort::Match* methods. |
329 scoped_ptr<base::Value> MidiManagerAlsa::MidiPort::Value() const { | 328 scoped_ptr<base::Value> MidiManagerAlsa::MidiPort::Value() const { |
330 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 329 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
331 | 330 |
332 std::string type; | 331 std::string type; |
333 switch (type_) { | 332 switch (type_) { |
334 case Type::kInput: | 333 case Type::kInput: |
335 type = "input"; | 334 type = "input"; |
336 break; | 335 break; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 // port_name | 432 // port_name |
434 // midi_device == -1, for both this and query | 433 // midi_device == -1, for both this and query |
435 return !connected() && (type() == query.type()) && path().empty() && | 434 return !connected() && (type() == query.type()) && path().empty() && |
436 query.path().empty() && id().empty() && query.id().empty() && | 435 query.path().empty() && id().empty() && query.id().empty() && |
437 (port_id() == query.port_id()) && | 436 (port_id() == query.port_id()) && |
438 (client_name() == query.client_name()) && | 437 (client_name() == query.client_name()) && |
439 (port_name() == query.port_name()) && (midi_device() == -1) && | 438 (port_name() == query.port_name()) && (midi_device() == -1) && |
440 (query.midi_device() == -1); | 439 (query.midi_device() == -1); |
441 } | 440 } |
442 | 441 |
443 MidiManagerAlsa::MidiPortStateBase::~MidiPortStateBase() { | 442 MidiManagerAlsa::MidiPortStateBase::~MidiPortStateBase() = default; |
444 } | |
445 | |
446 ScopedVector<MidiManagerAlsa::MidiPort>* | |
447 MidiManagerAlsa::MidiPortStateBase::ports() { | |
448 return &ports_; | |
449 } | |
450 | 443 |
451 MidiManagerAlsa::MidiPortStateBase::iterator | 444 MidiManagerAlsa::MidiPortStateBase::iterator |
452 MidiManagerAlsa::MidiPortStateBase::Find( | 445 MidiManagerAlsa::MidiPortStateBase::Find( |
453 const MidiManagerAlsa::MidiPort& port) { | 446 const MidiManagerAlsa::MidiPort& port) { |
454 auto result = FindConnected(port); | 447 auto result = FindConnected(port); |
455 if (result == end()) | 448 if (result == end()) |
456 result = FindDisconnected(port); | 449 result = FindDisconnected(port); |
457 return result; | 450 return result; |
458 } | 451 } |
459 | 452 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 return p->MatchNoCardPass2(port); | 514 return p->MatchNoCardPass2(port); |
522 }); | 515 }); |
523 if (it != ports_.end()) | 516 if (it != ports_.end()) |
524 return it; | 517 return it; |
525 } | 518 } |
526 | 519 |
527 // No match. | 520 // No match. |
528 return ports_.end(); | 521 return ports_.end(); |
529 } | 522 } |
530 | 523 |
531 MidiManagerAlsa::MidiPortStateBase::MidiPortStateBase() { | 524 MidiManagerAlsa::MidiPortStateBase::MidiPortStateBase() = default; |
532 } | |
533 | 525 |
534 void MidiManagerAlsa::TemporaryMidiPortState::Insert( | 526 void MidiManagerAlsa::TemporaryMidiPortState::Insert( |
535 scoped_ptr<MidiPort> port) { | 527 scoped_ptr<MidiPort> port) { |
536 ports()->push_back(port.Pass()); | 528 ports()->push_back(port.Pass()); |
537 } | 529 } |
538 | 530 |
539 MidiManagerAlsa::MidiPortState::MidiPortState() | 531 MidiManagerAlsa::MidiPortState::MidiPortState() |
540 : num_input_ports_(0), num_output_ports_(0) { | 532 : num_input_ports_(0), num_output_ports_(0) { |
541 } | 533 } |
542 | 534 |
(...skipping 10 matching lines...) Expand all Loading... |
553 } | 545 } |
554 port->set_web_port_index(web_port_index); | 546 port->set_web_port_index(web_port_index); |
555 ports()->push_back(port.Pass()); | 547 ports()->push_back(port.Pass()); |
556 return web_port_index; | 548 return web_port_index; |
557 } | 549 } |
558 | 550 |
559 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() | 551 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() |
560 : clients_deleter_(&clients_), card_client_count_(0) { | 552 : clients_deleter_(&clients_), card_client_count_(0) { |
561 } | 553 } |
562 | 554 |
563 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() { | 555 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default; |
564 } | |
565 | 556 |
566 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id, | 557 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id, |
567 const std::string& client_name, | 558 const std::string& client_name, |
568 snd_seq_client_type_t type) { | 559 snd_seq_client_type_t type) { |
569 ClientExit(client_id); | 560 ClientExit(client_id); |
570 clients_[client_id] = new Client(client_name, type); | 561 clients_[client_id] = new Client(client_name, type); |
571 if (IsCardClient(type, client_id)) | 562 if (IsCardClient(type, client_id)) |
572 ++card_client_count_; | 563 ++card_client_count_; |
573 } | 564 } |
574 | 565 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 return midi_ports.Pass(); | 674 return midi_ports.Pass(); |
684 } | 675 } |
685 | 676 |
686 MidiManagerAlsa::AlsaSeqState::Port::Port( | 677 MidiManagerAlsa::AlsaSeqState::Port::Port( |
687 const std::string& name, | 678 const std::string& name, |
688 MidiManagerAlsa::AlsaSeqState::PortDirection direction, | 679 MidiManagerAlsa::AlsaSeqState::PortDirection direction, |
689 bool midi) | 680 bool midi) |
690 : name_(name), direction_(direction), midi_(midi) { | 681 : name_(name), direction_(direction), midi_(midi) { |
691 } | 682 } |
692 | 683 |
693 MidiManagerAlsa::AlsaSeqState::Port::~Port() { | 684 MidiManagerAlsa::AlsaSeqState::Port::~Port() = default; |
694 } | |
695 | |
696 std::string MidiManagerAlsa::AlsaSeqState::Port::name() const { | |
697 return name_; | |
698 } | |
699 | |
700 MidiManagerAlsa::AlsaSeqState::PortDirection | |
701 MidiManagerAlsa::AlsaSeqState::Port::direction() const { | |
702 return direction_; | |
703 } | |
704 | |
705 bool MidiManagerAlsa::AlsaSeqState::Port::midi() const { | |
706 return midi_; | |
707 } | |
708 | 685 |
709 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name, | 686 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name, |
710 snd_seq_client_type_t type) | 687 snd_seq_client_type_t type) |
711 : name_(name), type_(type), ports_deleter_(&ports_) { | 688 : name_(name), type_(type), ports_deleter_(&ports_) { |
712 } | 689 } |
713 | 690 |
714 MidiManagerAlsa::AlsaSeqState::Client::~Client() { | 691 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default; |
715 } | |
716 | |
717 std::string MidiManagerAlsa::AlsaSeqState::Client::name() const { | |
718 return name_; | |
719 } | |
720 | |
721 snd_seq_client_type_t MidiManagerAlsa::AlsaSeqState::Client::type() const { | |
722 return type_; | |
723 } | |
724 | 692 |
725 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr, | 693 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr, |
726 scoped_ptr<Port> port) { | 694 scoped_ptr<Port> port) { |
727 RemovePort(addr); | 695 RemovePort(addr); |
728 ports_[addr] = port.release(); | 696 ports_[addr] = port.release(); |
729 } | 697 } |
730 | 698 |
731 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) { | 699 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) { |
732 auto it = ports_.find(addr); | 700 auto it = ports_.find(addr); |
733 if (it != ports_.end()) { | 701 if (it != ports_.end()) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 // Get the model id, by either property or sysattr. | 749 // Get the model id, by either property or sysattr. |
782 model_id_ = | 750 model_id_ = |
783 UdevDeviceGetPropertyOrSysattr(dev, kUdevIdModelId, kSysattrModel); | 751 UdevDeviceGetPropertyOrSysattr(dev, kUdevIdModelId, kSysattrModel); |
784 // Get the usb interface number. | 752 // Get the usb interface number. |
785 usb_interface_num_ = | 753 usb_interface_num_ = |
786 device::UdevDeviceGetPropertyValue(dev, kUdevIdUsbInterfaceNum); | 754 device::UdevDeviceGetPropertyValue(dev, kUdevIdUsbInterfaceNum); |
787 manufacturer_ = ExtractManufacturerString( | 755 manufacturer_ = ExtractManufacturerString( |
788 vendor, vendor_id_, vendor_from_database, alsa_name, alsa_longname); | 756 vendor, vendor_id_, vendor_from_database, alsa_name, alsa_longname); |
789 } | 757 } |
790 | 758 |
791 MidiManagerAlsa::AlsaCard::~AlsaCard() { | 759 MidiManagerAlsa::AlsaCard::~AlsaCard() = default; |
792 } | |
793 | 760 |
794 // static | 761 // static |
795 std::string MidiManagerAlsa::AlsaCard::ExtractManufacturerString( | 762 std::string MidiManagerAlsa::AlsaCard::ExtractManufacturerString( |
796 const std::string& udev_id_vendor, | 763 const std::string& udev_id_vendor, |
797 const std::string& udev_id_vendor_id, | 764 const std::string& udev_id_vendor_id, |
798 const std::string& udev_id_vendor_from_database, | 765 const std::string& udev_id_vendor_from_database, |
799 const std::string& alsa_name, | 766 const std::string& alsa_name, |
800 const std::string& alsa_longname) { | 767 const std::string& alsa_longname) { |
801 // Let's try to determine the manufacturer. Here is the ordered preference | 768 // Let's try to determine the manufacturer. Here is the ordered preference |
802 // in extraction: | 769 // in extraction: |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 source_map_[AddrToInt(client_id, port_id)] = port_index; | 1321 source_map_[AddrToInt(client_id, port_id)] = port_index; |
1355 return true; | 1322 return true; |
1356 } | 1323 } |
1357 | 1324 |
1358 MidiManager* MidiManager::Create() { | 1325 MidiManager* MidiManager::Create() { |
1359 return new MidiManagerAlsa(); | 1326 return new MidiManagerAlsa(); |
1360 } | 1327 } |
1361 | 1328 |
1362 } // namespace midi | 1329 } // namespace midi |
1363 } // namespace media | 1330 } // namespace media |
OLD | NEW |