root/trunk/libffado/src/dice/dice_avdevice.h

Revision 2691, 8.2 kB (checked in by jwoithe, 7 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  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef DICEDEVICE_H
25 #define DICEDEVICE_H
26
27 #include "dice_firmware_loader.h"
28
29 #include "ffadotypes.h"
30 #include "ffadodevice.h"
31
32 #include "debugmodule/debugmodule.h"
33 #include "libavc/avc_definitions.h"
34
35 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
36 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
37 #include "libstreaming/amdtp/AmdtpPort.h"
38
39 #include "libieee1394/ieee1394service.h"
40
41 #include "libcontrol/Element.h"
42 #include "libcontrol/MatrixMixer.h"
43 #include "libcontrol/CrossbarRouter.h"
44
45 #include <string>
46 #include <vector>
47
48 class ConfigRom;
49 class Ieee1394Service;
50
51 namespace Util {
52     class Configuration;
53 }
54
55 namespace Dice {
56
57 class EAP;
58
59
60 /**
61   @brief Devices based on the DICE-platform
62
63   This class is the basic implementation for devices using the DICE-chip.
64   */
65 class Device : public FFADODevice {
66 private:
67     friend class EAP;
68
69 public:
70     /// constructor
71     Device( DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ));
72     /// destructor
73     ~Device();
74
75     static bool probe( Util::Configuration& c, ConfigRom& configRom, bool generic = false );
76     static FFADODevice * createDevice( DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ));
77     virtual bool discover();
78
79     static int getConfigurationId( );
80
81     virtual void showDevice();
82     bool canChangeNickname() { return true; }
83
84     virtual bool deleteImgFL(const char*, bool v = true);
85     virtual bool flashDiceFL(const char*, const char* image = "dice");
86     virtual bool dumpFirmwareFL(const char*);
87     virtual bool showDiceInfoFL();
88     virtual bool showImgInfoFL();
89     virtual bool testDiceFL(int);
90     virtual DICE_FL_INFO_PARAM* showFlashInfoFL(bool v = true);
91     virtual bool showAppInfoFL();
92
93     virtual bool onSamplerateChange( int oldSamplingFrequency );
94     virtual bool setSamplingFrequency( int samplingFrequency );
95     virtual int getSamplingFrequency( );
96     virtual std::vector<int> getSupportedSamplingFrequencies();
97
98     virtual ClockSourceVector getSupportedClockSources();
99     virtual bool setActiveClockSource(ClockSource);
100     virtual ClockSource getActiveClockSource();
101
102     virtual int getStreamCount();
103     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
104     virtual enum FFADODevice::eStreamingState getStreamingState();
105
106     virtual bool prepare();
107
108     virtual bool lock();
109     virtual bool unlock();
110
111     virtual bool startStreamByIndex(int i);
112     virtual bool stopStreamByIndex(int i);
113
114     virtual bool enableStreaming();
115     virtual bool disableStreaming();
116
117     virtual std::string getNickname();
118     virtual bool setNickname(std::string name);
119
120 protected:
121     // streaming stuff
122     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
123     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
124     StreamProcessorVector m_receiveProcessors;
125     StreamProcessorVector m_transmitProcessors;
126
127 private: // streaming & port helpers
128     enum EPortTypes {
129         ePT_Analog,
130         ePT_MIDI,
131     };
132
133     typedef struct {
134         std::string name;
135         enum EPortTypes portType;
136         unsigned int streamPosition;
137         unsigned int streamLocation;
138     } diceChannelInfo;
139
140     bool addChannelToProcessor( diceChannelInfo *,
141                               Streaming::StreamProcessor *,
142                               Streaming::Port::E_Direction direction);
143
144     int allocateIsoChannel(unsigned int packet_size);
145     bool deallocateIsoChannel(int channel);
146
147 private: // active config
148     enum eDiceConfig {
149         eDC_Unknown,
150         eDC_Low,
151         eDC_Mid,
152         eDC_High,
153     };
154
155     enum eDiceConfig getCurrentConfig();
156
157 private: // helper functions
158     bool enableIsoStreaming();
159     bool disableIsoStreaming();
160     bool isIsoStreamingEnabled();
161
162     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
163     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
164
165     stringlist splitNameString(std::string in);
166     stringlist getTxNameString(unsigned int i);
167     stringlist getRxNameString(unsigned int i);
168     stringlist getCptrNameString(unsigned int);
169     stringlist getPbckNameString(unsigned int);
170     stringlist getClockSourceNameString();
171
172     enum eClockSourceType  clockIdToType(unsigned int id);
173     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
174     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
175
176 // EAP stuff
177 private:
178     EAP*         m_eap;
179 protected:
180     virtual EAP* createEAP();
181 public:
182     EAP* getEAP() {return m_eap;};
183
184 private: // register I/O routines
185     bool initIoFunctions();
186     // functions used for RX/TX abstraction
187     bool startstopStreamByIndex(int i, const bool start);
188     bool prepareSP (unsigned int, const Streaming::Port::E_Direction direction_requested);
189     void setRXTXfuncs (const Streaming::Port::E_Direction direction);
190
191     // quadlet read/write routines
192     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
193     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
194     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
195     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
196
197     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
198     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
199     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
200     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
201     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
202
203     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
204     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
205     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
206     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
207     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
208
209     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
210     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
211     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
212     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
213     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
214
215     fb_quadlet_t m_global_reg_offset;
216     fb_quadlet_t m_global_reg_size;
217     fb_quadlet_t m_tx_reg_offset;
218     fb_quadlet_t m_tx_reg_size;
219     fb_quadlet_t m_rx_reg_offset;
220     fb_quadlet_t m_rx_reg_size;
221     fb_quadlet_t m_unused1_reg_offset;
222     fb_quadlet_t m_unused1_reg_size;
223     fb_quadlet_t m_unused2_reg_offset;
224     fb_quadlet_t m_unused2_reg_size;
225
226     fb_quadlet_t m_nb_tx;
227     fb_quadlet_t m_tx_size;
228     fb_quadlet_t m_nb_rx;
229     fb_quadlet_t m_rx_size;
230
231     fb_quadlet_t audio_base_register;
232     fb_quadlet_t midi_base_register;
233     char dir[3];
234
235     // Function pointers to call readTxReg/readRxReg or writeTxReg/writeRxReg respectively
236     bool (Device::*writeFunc) (unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t data);
237     bool (Device::*readFunc) (unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *result);
238
239 // private:
240 public:
241     /**
242      * this class reacts on the DICE device writing to the
243      * hosts notify address
244      */
245     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
246     #define DICE_NOTIFIER_BLOCK_LENGTH 4
247
248     class Notifier : public Ieee1394Service::ARMHandler
249     {
250     public:
251         Notifier(Device &, nodeaddr_t start);
252         virtual ~Notifier();
253
254     private:
255         Device &m_device;
256     };
257
258     // notification
259     Notifier *m_notifier;
260
261
262
263 };
264
265 }
266
267 #endif
Note: See TracBrowser for help on using the browser.