root/trunk/libffado/src/genericavc/avc_avdevice.h

Revision 2691, 3.8 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 Pieter Palmers
3  * Copyright (C) 2005-2008 by Daniel Wagner
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 GENERICAVC_DEVICE_H
26 #define GENERICAVC_DEVICE_H
27
28 #include "ffadodevice.h"
29 #include "libutil/Configuration.h"
30
31 #include "libavc/avc_definitions.h"
32 #include "libavc/general/avc_unit.h"
33 #include "libavc/general/avc_subunit.h"
34 #include "libavc/general/avc_plug.h"
35
36 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
37 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
38 #include "libstreaming/amdtp/AmdtpPort.h"
39 #include "libstreaming/amdtp/AmdtpPortInfo.h"
40
41 #include "debugmodule/debugmodule.h"
42
43 class ConfigRom;
44 class Ieee1394Service;
45
46 namespace GenericAVC {
47
48 class Device : public FFADODevice, public AVC::Unit {
49 public:
50     Device( DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ));
51     virtual ~Device();
52
53     static bool probe( Util::Configuration&, ConfigRom& configRom, bool generic = false );
54     virtual bool discover();
55     static FFADODevice * createDevice( DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ));
56
57     virtual bool serialize( std::string basePath, Util::IOSerialize& ser ) const;
58     virtual bool deserialize( std::string basePath, Util::IODeserialize& deser );
59
60     virtual void setVerboseLevel(int l);
61     virtual void showDevice();
62
63     virtual bool setSamplingFrequency( int );
64     virtual bool supportsSamplingFrequency( int s );
65     virtual int getSamplingFrequency( );
66     virtual std::vector<int> getSupportedSamplingFrequencies();
67
68     virtual ClockSourceVector getSupportedClockSources();
69     virtual bool setActiveClockSource(ClockSource);
70     virtual ClockSource getActiveClockSource();
71
72     virtual int getStreamCount();
73     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
74
75     virtual enum eStreamingState getStreamingState();
76
77     virtual bool prepare();
78     virtual bool lock();
79     virtual bool unlock();
80
81     virtual bool startStreamByIndex(int i);
82     virtual bool stopStreamByIndex(int i);
83
84     // redefinition to resolve ambiguity
85     virtual Ieee1394Service& get1394Service()
86         { return FFADODevice::get1394Service(); };
87     virtual ConfigRom& getConfigRom() const
88         { return FFADODevice::getConfigRom(); };
89
90 protected:
91     bool discoverGeneric();
92     virtual bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor,
93                              Streaming::AmdtpAudioPort::E_Direction direction);
94 /*    bool setSamplingFrequencyPlug( AVC::Plug& plug,
95                                    AVC::Plug::EPlugDirection direction,
96                                    AVC::ESamplingFrequency samplingFrequency );*/
97
98     // streaming stuff
99     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
100     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
101     StreamProcessorVector m_receiveProcessors;
102     StreamProcessorVector m_transmitProcessors;
103
104     DECLARE_DEBUG_MODULE;
105
106 private:
107     ClockSource syncInfoToClockSource(const SyncInfo& si);
108     std::vector<int> m_supported_frequencies_cache;
109 };
110
111 }
112
113 #endif //GENERICAVC_AVDEVICE_H
Note: See TracBrowser for help on using the browser.