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

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: Rebase. 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
« no previous file with comments | « media/midi/midi_manager_alsa.h ('k') | sync/engine/commit.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void SetStringIfNonEmpty(base::DictionaryValue* value, 138 void SetStringIfNonEmpty(base::DictionaryValue* value,
139 const std::string& path, 139 const std::string& path,
140 const std::string& in_value) { 140 const std::string& in_value) {
141 if (!in_value.empty()) 141 if (!in_value.empty())
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 : alsa_cards_deleter_(&alsa_cards_), 148 : udev_(device::udev_new()),
149 udev_(device::udev_new()),
150 send_thread_("MidiSendThread"), 149 send_thread_("MidiSendThread"),
151 event_thread_("MidiEventThread") { 150 event_thread_("MidiEventThread") {
152 // Initialize decoder. 151 // Initialize decoder.
153 snd_midi_event_t* decoder; 152 snd_midi_event_t* decoder;
154 snd_midi_event_new(0, &decoder); 153 snd_midi_event_new(0, &decoder);
155 decoder_.reset(decoder); 154 decoder_.reset(decoder);
156 snd_midi_event_no_status(decoder_.get(), 1); 155 snd_midi_event_no_status(decoder_.get(), 1);
157 } 156 }
158 157
159 MidiManagerAlsa::~MidiManagerAlsa() { 158 MidiManagerAlsa::~MidiManagerAlsa() {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 break; 579 break;
581 case MidiPort::Type::kOutput: 580 case MidiPort::Type::kOutput:
582 web_port_index = num_output_ports_++; 581 web_port_index = num_output_ports_++;
583 break; 582 break;
584 } 583 }
585 port->set_web_port_index(web_port_index); 584 port->set_web_port_index(web_port_index);
586 ports().push_back(port.release()); 585 ports().push_back(port.release());
587 return web_port_index; 586 return web_port_index;
588 } 587 }
589 588
590 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() 589 MidiManagerAlsa::AlsaSeqState::AlsaSeqState() : card_client_count_(0) {
591 : clients_deleter_(&clients_), card_client_count_(0) {
592 } 590 }
593 591
594 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default; 592 MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default;
595 593
596 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id, 594 void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id,
597 const std::string& client_name, 595 const std::string& client_name,
598 snd_seq_client_type_t type) { 596 snd_seq_client_type_t type) {
599 ClientExit(client_id); 597 ClientExit(client_id);
600 clients_[client_id] = new Client(client_name, type); 598 clients_.insert(client_id, make_scoped_ptr(new Client(client_name, type)));
601 if (IsCardClient(type, client_id)) 599 if (IsCardClient(type, client_id))
602 ++card_client_count_; 600 ++card_client_count_;
603 } 601 }
604 602
605 bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) { 603 bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) {
606 return clients_.find(client_id) != clients_.end(); 604 return clients_.find(client_id) != clients_.end();
607 } 605 }
608 606
609 void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) { 607 void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) {
610 auto it = clients_.find(client_id); 608 auto it = clients_.find(client_id);
611 if (it != clients_.end()) { 609 if (it != clients_.end()) {
612 if (IsCardClient(it->second->type(), client_id)) 610 if (IsCardClient(it->second->type(), client_id))
613 --card_client_count_; 611 --card_client_count_;
614 delete it->second;
615 clients_.erase(it); 612 clients_.erase(it);
616 } 613 }
617 } 614 }
618 615
619 void MidiManagerAlsa::AlsaSeqState::PortStart( 616 void MidiManagerAlsa::AlsaSeqState::PortStart(
620 int client_id, 617 int client_id,
621 int port_id, 618 int port_id,
622 const std::string& port_name, 619 const std::string& port_name,
623 MidiManagerAlsa::AlsaSeqState::PortDirection direction, 620 MidiManagerAlsa::AlsaSeqState::PortDirection direction,
624 bool midi) { 621 bool midi) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 const std::string& name, 718 const std::string& name,
722 MidiManagerAlsa::AlsaSeqState::PortDirection direction, 719 MidiManagerAlsa::AlsaSeqState::PortDirection direction,
723 bool midi) 720 bool midi)
724 : name_(name), direction_(direction), midi_(midi) { 721 : name_(name), direction_(direction), midi_(midi) {
725 } 722 }
726 723
727 MidiManagerAlsa::AlsaSeqState::Port::~Port() = default; 724 MidiManagerAlsa::AlsaSeqState::Port::~Port() = default;
728 725
729 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name, 726 MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name,
730 snd_seq_client_type_t type) 727 snd_seq_client_type_t type)
731 : name_(name), type_(type), ports_deleter_(&ports_) { 728 : name_(name), type_(type) {
732 } 729 }
733 730
734 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default; 731 MidiManagerAlsa::AlsaSeqState::Client::~Client() = default;
735 732
736 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr, 733 void MidiManagerAlsa::AlsaSeqState::Client::AddPort(int addr,
737 scoped_ptr<Port> port) { 734 scoped_ptr<Port> port) {
738 RemovePort(addr); 735 ports_.set(addr, port.Pass());
739 ports_[addr] = port.release();
740 } 736 }
741 737
742 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) { 738 void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) {
743 auto it = ports_.find(addr); 739 ports_.erase(addr);
744 if (it != ports_.end()) {
745 delete it->second;
746 ports_.erase(it);
747 }
748 } 740 }
749 741
750 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator 742 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator
751 MidiManagerAlsa::AlsaSeqState::Client::begin() const { 743 MidiManagerAlsa::AlsaSeqState::Client::begin() const {
752 return ports_.begin(); 744 return ports_.begin();
753 } 745 }
754 746
755 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator 747 MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator
756 MidiManagerAlsa::AlsaSeqState::Client::end() const { 748 MidiManagerAlsa::AlsaSeqState::Client::end() const {
757 return ports_.end(); 749 return ports_.end();
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 VLOG(1) << "snd_ctl_hwdep_info fails: " << snd_strerror(err); 1114 VLOG(1) << "snd_ctl_hwdep_info fails: " << snd_strerror(err);
1123 continue; 1115 continue;
1124 } 1116 }
1125 snd_hwdep_iface_t iface = snd_hwdep_info_get_iface(hwdep); 1117 snd_hwdep_iface_t iface = snd_hwdep_info_get_iface(hwdep);
1126 if (iface == SND_HWDEP_IFACE_OPL2 || iface == SND_HWDEP_IFACE_OPL3 || 1118 if (iface == SND_HWDEP_IFACE_OPL2 || iface == SND_HWDEP_IFACE_OPL3 ||
1127 iface == SND_HWDEP_IFACE_OPL4) 1119 iface == SND_HWDEP_IFACE_OPL4)
1128 ++midi_count; 1120 ++midi_count;
1129 } 1121 }
1130 snd_ctl_close(handle); 1122 snd_ctl_close(handle);
1131 1123
1132 if (midi_count > 0) 1124 if (midi_count > 0) {
1133 alsa_cards_[number] = new AlsaCard(dev, name, longname, driver, midi_count); 1125 scoped_ptr<AlsaCard> card(
1134 alsa_card_midi_count_ += midi_count; 1126 new AlsaCard(dev, name, longname, driver, midi_count));
1127 alsa_cards_.insert(number, card.Pass());
1128 alsa_card_midi_count_ += midi_count;
1129 }
1135 } 1130 }
1136 1131
1137 void MidiManagerAlsa::RemoveCard(int number) { 1132 void MidiManagerAlsa::RemoveCard(int number) {
1138 auto it = alsa_cards_.find(number); 1133 auto it = alsa_cards_.find(number);
1139 if (it == alsa_cards_.end()) 1134 if (it == alsa_cards_.end())
1140 return; 1135 return;
1141 1136
1142 alsa_card_midi_count_ -= it->second->midi_device_count(); 1137 alsa_card_midi_count_ -= it->second->midi_device_count();
1143 delete it->second;
1144 alsa_cards_.erase(it); 1138 alsa_cards_.erase(it);
1145 } 1139 }
1146 1140
1147 void MidiManagerAlsa::UpdatePortStateAndGenerateEvents() { 1141 void MidiManagerAlsa::UpdatePortStateAndGenerateEvents() {
1148 // Verify that our information from ALSA and udev are in sync. If 1142 // Verify that our information from ALSA and udev are in sync. If
1149 // not, we cannot generate events right now. 1143 // not, we cannot generate events right now.
1150 if (alsa_card_midi_count_ != alsa_seq_state_.card_client_count()) 1144 if (alsa_card_midi_count_ != alsa_seq_state_.card_client_count())
1151 return; 1145 return;
1152 1146
1153 // Generate new port state. 1147 // Generate new port state.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 source_map_[AddrToInt(client_id, port_id)] = port_index; 1346 source_map_[AddrToInt(client_id, port_id)] = port_index;
1353 return true; 1347 return true;
1354 } 1348 }
1355 1349
1356 MidiManager* MidiManager::Create() { 1350 MidiManager* MidiManager::Create() {
1357 return new MidiManagerAlsa(); 1351 return new MidiManagerAlsa();
1358 } 1352 }
1359 1353
1360 } // namespace midi 1354 } // namespace midi
1361 } // namespace media 1355 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_manager_alsa.h ('k') | sync/engine/commit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698