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

Side by Side Diff: media/midi/midi_manager_alsa.cc

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Fix Mac compile. Created 5 years, 6 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
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 value->SetString(path, in_value); 142 value->SetString(path, in_value);
143 } 143 }
144 144
145 } // namespace 145 } // namespace
146 146
147 MidiManagerAlsa::MidiManagerAlsa() 147 MidiManagerAlsa::MidiManagerAlsa()
148 : in_client_(NULL), 148 : in_client_(NULL),
149 out_client_(NULL), 149 out_client_(NULL),
150 out_client_id_(-1), 150 out_client_id_(-1),
151 in_port_id_(-1), 151 in_port_id_(-1),
152 alsa_cards_deleter_(&alsa_cards_),
153 alsa_card_midi_count_(0), 152 alsa_card_midi_count_(0),
154 decoder_(NULL), 153 decoder_(NULL),
155 udev_(device::udev_new()), 154 udev_(device::udev_new()),
156 send_thread_("MidiSendThread"), 155 send_thread_("MidiSendThread"),
157 event_thread_("MidiEventThread"), 156 event_thread_("MidiEventThread"),
158 event_thread_shutdown_(false) { 157 event_thread_shutdown_(false) {
159 // Initialize decoder. 158 // Initialize decoder.
160 snd_midi_event_new(0, &decoder_); 159 snd_midi_event_new(0, &decoder_);
161 snd_midi_event_no_status(decoder_, 1); 160 snd_midi_event_no_status(decoder_, 1);
162 } 161 }
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 break; 588 break;
590 case MidiPort::Type::kOutput: 589 case MidiPort::Type::kOutput:
591 web_port_index = num_output_ports_++; 590 web_port_index = num_output_ports_++;
592 break; 591 break;
593 } 592 }
594 port->set_web_port_index(web_port_index); 593 port->set_web_port_index(web_port_index);
595 ports()->push_back(port.Pass()); 594 ports()->push_back(port.Pass());
596 return web_port_index; 595 return web_port_index;
597 } 596 }
598 597
599 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() 598 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() : card_client_count_(0) {
600 : clients_deleter_(&clients_), card_client_count_(0) {
601 } 599 }
602 600
603 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default; 601 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default;
604 602
605 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id, 603 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id,
606 const std::string& client_name, 604 const std::string& client_name,
607 snd_seq_client_type_t type) { 605 snd_seq_client_type_t type) {
608 ClientExit(client_id); 606 ClientExit(client_id);
609 clients_[client_id] = new Client(client_name, type); 607 clients_.insert(client_id, make_scoped_ptr(new Client(client_name, type)));
610 if (IsCardClient(type, client_id)) 608 if (IsCardClient(type, client_id))
611 ++card_client_count_; 609 ++card_client_count_;
612 } 610 }
613 611
614 bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) { 612 bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) {
615 return clients_.find(client_id) != clients_.end(); 613 return clients_.find(client_id) != clients_.end();
616 } 614 }
617 615
618 void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) { 616 void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) {
619 auto it = clients_.find(client_id); 617 auto it = clients_.find(client_id);
620 if (it != clients_.end()) { 618 if (it != clients_.end()) {
621 if (IsCardClient(it->second->type(), client_id)) 619 if (IsCardClient(it->second->type(), client_id))
622 --card_client_count_; 620 --card_client_count_;
623 delete it->second;
624 clients_.erase(it); 621 clients_.erase(it);
625 } 622 }
626 } 623 }
627 624
628 void MidiManagerAlsa::AlsaSeqState::PortStart( 625 void MidiManagerAlsa::AlsaSeqState::PortStart(
629 int client_id, 626 int client_id,
630 int port_id, 627 int port_id,
631 const std::string& port_name, 628 const std::string& port_name,
632 MidiManagerAlsa::AlsaSeqState::PortDirection direction, 629 MidiManagerAlsa::AlsaSeqState::PortDirection direction,
633 bool midi) { 630 bool midi) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 const std::string& name, 727 const std::string& name,
731 MidiManagerAlsa::AlsaSeqState::PortDirection direction, 728 MidiManagerAlsa::AlsaSeqState::PortDirection direction,
732 bool midi) 729 bool midi)
733 : name_(name), direction_(direction), midi_(midi) { 730 : name_(name), direction_(direction), midi_(midi) {
734 } 731 }
735 732
736 MidiManagerAlsa::AlsaSeqState::Port::~Port() = default; 733 MidiManagerAlsa::AlsaSeqState::Port::~Port() = default;
737 734
738 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name, 735 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name,
739 snd_seq_client_type_t type) 736 snd_seq_client_type_t type)
740 : name_(name), type_(type), ports_deleter_(&ports_) { 737 : name_(name), type_(type) {
741 } 738 }
742 739
743 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default; 740 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default;
744 741
745 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr, 742 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr,
746 scoped_ptr<Port> port) { 743 scoped_ptr<Port> port) {
747 RemovePort(addr); 744 ports_.set(addr, port.Pass());
748 ports_[addr] = port.release();
749 } 745 }
750 746
751 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) { 747 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) {
752 auto it = ports_.find(addr); 748 ports_.erase(addr);
753 if (it != ports_.end()) {
754 delete it->second;
755 ports_.erase(it);
756 }
757 } 749 }
758 750
759 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator 751 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator
760 MidiManagerAlsa::AlsaSeqState::Client::begin() const { 752 MidiManagerAlsa::AlsaSeqState::Client::begin() const {
761 return ports_.begin(); 753 return ports_.begin();
762 } 754 }
763 755
764 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator 756 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator
765 MidiManagerAlsa::AlsaSeqState::Client::end() const { 757 MidiManagerAlsa::AlsaSeqState::Client::end() const {
766 return ports_.end(); 758 return ports_.end();
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 VLOG(1) << "snd_ctl_hwdep_info fails: " << snd_strerror(err); 1121 VLOG(1) << "snd_ctl_hwdep_info fails: " << snd_strerror(err);
1130 continue; 1122 continue;
1131 } 1123 }
1132 snd_hwdep_iface_t iface = snd_hwdep_info_get_iface(hwdep); 1124 snd_hwdep_iface_t iface = snd_hwdep_info_get_iface(hwdep);
1133 if (iface == SND_HWDEP_IFACE_OPL2 || iface == SND_HWDEP_IFACE_OPL3 || 1125 if (iface == SND_HWDEP_IFACE_OPL2 || iface == SND_HWDEP_IFACE_OPL3 ||
1134 iface == SND_HWDEP_IFACE_OPL4) 1126 iface == SND_HWDEP_IFACE_OPL4)
1135 ++midi_count; 1127 ++midi_count;
1136 } 1128 }
1137 snd_ctl_close(handle); 1129 snd_ctl_close(handle);
1138 1130
1139 if (midi_count > 0) 1131 if (midi_count > 0) {
1140 alsa_cards_[number] = new AlsaCard(dev, name, longname, driver, midi_count); 1132 scoped_ptr<AlsaCard> card(
1141 alsa_card_midi_count_ += midi_count; 1133 new AlsaCard(dev, name, longname, driver, midi_count));
1134 alsa_cards_.insert(number, card.Pass());
1135 alsa_card_midi_count_ += midi_count;
1136 }
1142 } 1137 }
1143 1138
1144 void MidiManagerAlsa::RemoveCard(int number) { 1139 void MidiManagerAlsa::RemoveCard(int number) {
1145 auto it = alsa_cards_.find(number); 1140 auto it = alsa_cards_.find(number);
1146 if (it == alsa_cards_.end()) 1141 if (it == alsa_cards_.end())
1147 return; 1142 return;
1148 1143
1149 alsa_card_midi_count_ -= it->second->midi_device_count(); 1144 alsa_card_midi_count_ -= it->second->midi_device_count();
1150 delete it->second;
1151 alsa_cards_.erase(it); 1145 alsa_cards_.erase(it);
1152 } 1146 }
1153 1147
1154 void MidiManagerAlsa::UpdatePortStateAndGenerateEvents() { 1148 void MidiManagerAlsa::UpdatePortStateAndGenerateEvents() {
1155 // Verify that our information from ALSA and udev are in sync. If 1149 // Verify that our information from ALSA and udev are in sync. If
1156 // not, we cannot generate events right now. 1150 // not, we cannot generate events right now.
1157 if (alsa_card_midi_count_ != alsa_seq_state_.card_client_count()) 1151 if (alsa_card_midi_count_ != alsa_seq_state_.card_client_count())
1158 return; 1152 return;
1159 1153
1160 // Generate new port state. 1154 // Generate new port state.
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 source_map_[AddrToInt(client_id, port_id)] = port_index; 1354 source_map_[AddrToInt(client_id, port_id)] = port_index;
1361 return true; 1355 return true;
1362 } 1356 }
1363 1357
1364 MidiManager* MidiManager::Create() { 1358 MidiManager* MidiManager::Create() {
1365 return new MidiManagerAlsa(); 1359 return new MidiManagerAlsa();
1366 } 1360 }
1367 1361
1368 } // namespace midi 1362 } // namespace midi
1369 } // namespace media 1363 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698