libGizmod/AlsaSoundCard.hpp

Go to the documentation of this file.
00001 
00012 /*
00013   
00014   Copyright (c) 2007, Tim Burrell
00015   Licensed under the Apache License, Version 2.0 (the "License");
00016   you may not use this file except in compliance with the License.
00017   You may obtain a copy of the License at 
00018 
00019         http://www.apache.org/licenses/LICENSE-2.0
00020 
00021   Unless required by applicable law or agreed to in writing, software
00022   distributed under the License is distributed on an "AS IS" BASIS,
00023   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00024   See the License for the specific language governing permissions and 
00025   limitations under the License. 
00026   
00027 */
00028 
00029 #ifndef __AlsaSoundCard_h
00030 #define __AlsaSoundCard_h
00031 
00032 #if HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif
00035 
00036 #include "AlsaInterface.hpp"
00037 #include "AlsaSoundCardInterface.hpp"
00038 #include "AlsaMixer.hpp"
00039 #include <string>
00040 #include <map>
00041 #include <boost/shared_ptr.hpp>
00042 #include <alsa/asoundlib.h>
00043 
00045 // Namespace
00047 
00048 namespace Gizmod {
00049 
00051 // AlsaSoundCard Class Definition
00053 
00058 class AlsaSoundCard : public AlsaSoundCardInterface {
00059 public: 
00060         // public member variables
00061         
00062         // public functions
00063         std::string                     getCardHardwareID() const;      
00064         int                             getCardID() const;              
00065         std::string                     getCardName() const;            
00066         std::string                     getCardNameLong() const;        
00067         AlsaMixer const *               getMixer(std::string Name);     
00068         size_t                          getNumMixers();                 
00069         void                            setAllPlaybackSwitches(bool Enabled); 
00070         void                            shutdown();                     
00071 
00072         // construction / deconstruction
00073         AlsaSoundCard(AlsaInterface * piAlsa, int CardID);
00074         virtual ~AlsaSoundCard();
00075         
00076         // public static functions
00077         static int                      MixerCallback(snd_mixer_t * Mixer, unsigned int EventMask, snd_mixer_elem_t * MixerElement); 
00078         
00079 private:
00080         // private functions
00081         void                            init();                         
00082         int                             mixerCallback(snd_mixer_t * Mixer, unsigned int EventMask, snd_mixer_elem_t * MixerElement); 
00083         void                            threadProc();                   
00084                 
00085         // private member variables
00086         int                             mCardID;                        
00087         std::string                     mCardHWID;                      
00088         std::string                     mCardName;                      
00089         std::string                     mCardNameLong;                  
00090         snd_ctl_t *                     mCTLHandle;                     
00091         snd_ctl_card_info_t *           mHWInfo;                        
00092         snd_mixer_t *                   mMixerHandle;                   
00093         std::map< std::string, boost::shared_ptr<AlsaMixer> > mMixers;  
00094         bool                            mShutdown;                      
00095         bool                            mWatching;                      
00096 
00100         struct AlsaSoundCardThreadProc {
00101                 AlsaSoundCardThreadProc(AlsaSoundCard * pAlsaSoundCard) : mpAlsaSoundCard(pAlsaSoundCard) {
00102                         mpAlsaSoundCard->mThreading = false;
00103                 };
00104                 
00106                 void operator()() {
00107                         mpAlsaSoundCard->mThreading = true;
00108                         mpAlsaSoundCard->threadProc();
00109                         mpAlsaSoundCard->mThreading = false;
00110                 }
00111                 
00112                 AlsaSoundCard *         mpAlsaSoundCard;                
00113         };              
00114         bool                            mThreading;                     
00115         AlsaSoundCardThreadProc         mThreadProc;                    
00116         
00117 private: 
00118         // serialization
00119         friend class boost::serialization::access;
00120         template<class Archive>
00121         void serialize(Archive & ar, const unsigned int version) {
00122                 ar & mCardID;
00123                 ar & mCardHWID;
00124                 ar & mCardName;
00125                 ar & mCardNameLong;
00126         }                               
00127 };
00128 
00130 
00131 } // Gizmod namespace
00132 
00133 #endif // __AlsaSoundCard_h

Generated on Wed Nov 7 10:04:16 2007 for gizmod by  doxygen 1.5.3