root/trunk/libffado/src/fireworks/fireworks_device.h

Revision 2691, 4.7 kB (checked in by jwoithe, 4 years ago)

Initial attempt to address deprecation of auto_ptr.

C++11 deprecates auto_ptr, and gcc6 (and later versions) print compile time
warnings to this effect whenever it is encountered in the source. The
replacement type is either shared_ptr or unique_ptr depending on the usage.
For almost all usages within FFADO it seems unique_ptr could be the
appropriate choice, but the symantics are a little different to auto_ptr.
Shared_ptr on the other hand can be a drop-in replacement, although it comes
with considerable overheads which unique_ptr avoids. In the context of the
current usage, the extra overhead incurred is not critical.

The code-base cannot at this time change unconditionally to shared_ptr and
unique_ptr because these are not available in gcc4 unless "--std=c++11" is
given. When gcc4 is used certain older versions of dependent libraries must
be used and these in turn will cause compile failures in their header files
if "--std=c++11" is used (libxml++ being an example). At present there are
sufficient users of FFADO still on gcc4 to justify maintaining compatibility
with that gcc version.

The approach adopted at present is to define ffado_smartptr to be either
auto_ptr (if c++11 is not in use) or shared_ptr if it is. All auto_ptr
instances are then changed to ffado_smartptr. This should allow FFADO to be
compiled without errors or warnings on systems using gcc4 and above. Gcc6
defaults to the c++14 standard, so ffado_smartptr will be shared_ptr in that
case; thus the warnings will be avoided.

In time, once gcc4 drops out of common use, the ffado_smartptr instances can
be progressively migrated to unique_ptr or shared_ptr as is appropriate. It
has been pointed out in the ffado-devel mailing list by Jano Svitok (2 May
2017, subject "smart pointers Was: [FFADO-devel] Liquid Saffire 56") that
bebob_dl_mgr.cpp could use unique_ptr. shared_ptr should be ok in other
auto_ptr sites, but futher analysis may show that at least some of them can
use unique_ptr.

The addressing of the auto_ptr issue was prompted by Xavier Forestier's
patch set submitted to ffado-devel in November 2016.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef FIREWORKS_DEVICE_H
26 #define FIREWORKS_DEVICE_H
27
28 #include "debugmodule/debugmodule.h"
29
30 #include "genericavc/avc_avdevice.h"
31
32 #include "efc/efc_cmd.h"
33 #include "efc/efc_cmds_hardware.h"
34 #include "efc/efc_cmds_hardware_ctrl.h"
35 #include "fireworks_session_block.h"
36
37 #include <pthread.h>
38 #include "libutil/Mutex.h"
39
40 class ConfigRom;
41 class Ieee1394Service;
42
43 namespace FireWorks {
44
45 class Device : public GenericAVC::Device {
46     friend class MonitorControl;
47     friend class SimpleControl;
48     friend class BinaryControl;
49     friend class IOConfigControl;
50    
51 public:
52     Device( DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ) );
53     virtual ~Device();
54    
55     static bool probe( Util::Configuration&, ConfigRom& configRom, bool generic = false );
56     static FFADODevice * createDevice( DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ));
57     virtual bool discover();
58
59     virtual void showDevice();
60    
61     virtual bool buildMixer();
62     virtual bool destroyMixer();
63
64     virtual std::vector<int> getSupportedSamplingFrequencies();
65
66     virtual ClockSourceVector getSupportedClockSources();
67     virtual bool setActiveClockSource(ClockSource);
68     virtual ClockSource getActiveClockSource();
69     virtual int getSamplingFrequency();
70     virtual bool setSamplingFrequency( int );
71
72     const EfcHardwareInfoCmd getHwInfo()
73         {return m_HwInfo;};
74
75 // protected: //?
76     bool doEfcOverAVC(EfcCmd& c);
77    
78     /**
79      * @brief Read flash
80      * @param start start address
81      * @param len length in quadlets (4 bytes)
82      * @param buffer target buffer (should be 'len*4' bytes long)
83      * @return true if successful
84      */
85     bool readFlash(uint32_t start, uint32_t len, uint32_t* buffer);
86
87     /**
88      * @brief Write flash
89      * @param start start address
90      * @param len length in quadlets (4 bytes)
91      * @param buffer target buffer (should be 'len*4' bytes long)
92      * @return true if successful
93      */
94     bool writeFlash(uint32_t start, uint32_t len, uint32_t* buffer);
95
96     /**
97      * @brief (un)lock the flash
98      * @param lock true=locked, false=unlocked
99      * @return true if successful
100      */
101     bool lockFlash(bool lock);
102     /**
103      * @brief erase flash block
104      * @param addr address of block to erase
105      * @return true if successful
106      */
107     bool eraseFlash(uint32_t addr);
108     bool eraseFlashBlocks(uint32_t start_address, unsigned int nb_quads);
109
110     /**
111      * @brief wait until the device indicates the flash memory is ready
112      * @param msecs time to wait before timeout
113      * @return true if the flash is ready, false if timeout
114      */
115     bool waitForFlash(unsigned int msecs);
116
117     /**
118      * @brief get the flash address of the session block
119      * @return session block base address
120      */
121     uint32_t getSessionBase();
122
123     /**
124      * load the session block from the device
125      * @return true if successful
126      */
127     bool loadSession();
128     /**
129      * save the session block to the device
130      * @return true if successful
131      */
132     bool saveSession();
133
134 // Echo specific stuff
135 private:
136    
137     bool discoverUsingEFC();
138
139     FFADODevice::ClockSource clockIdToClockSource(uint32_t clockflag);
140     bool isClockValid(uint32_t id);
141
142     bool getClock(EfcGetClockCmd &gccmd);
143     uint32_t getClockSrc();
144
145     bool setClock(EfcSetClockCmd sccmd);
146     bool setClockSrc(uint32_t clock);
147  
148     /*
149      * Audiofire12 often return wrong data for clock source.
150      * This member is used to cache the latest clock source change.
151      */
152     int m_current_clock;
153
154     EfcHardwareInfoCmd  m_HwInfo;
155
156     bool updatePolledValues();
157     Util::Mutex*        m_poll_lock;
158     EfcPolledValuesCmd  m_Polled;
159
160     bool                m_efc_discovery_done;
161
162 protected:
163     Session             m_session;
164 private:
165     Control::Container *m_MixerContainer;
166     Control::Container *m_HwInfoContainer;
167
168 };
169
170
171 } // namespace FireWorks
172
173 #endif
Note: See TracBrowser for help on using the browser.