root/trunk/libffado/src/genericavc/stanton/scs.h

Revision 2691, 4.0 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) 2009 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 GENERICAVC_STANTON_SCS_DEVICE_H
25 #define GENERICAVC_STANTON_SCS_DEVICE_H
26
27 #include "genericavc/avc_avdevice.h"
28 #include "libieee1394/ieee1394service.h"
29
30 namespace Util {
31     class Functor;
32 }
33
34 namespace GenericAVC {
35 namespace Stanton {
36
37 #define HSS1394_BASE_ADDRESS            0x0000c007dedadadaULL
38 #define HSS1394_RESPONSE_ADDRESS        0x0000c007E0000000ULL
39 #define HSS1394_MAX_PACKET_SIZE         63
40 #define HSS1394_INVALID_NETWORK_ID      0xff
41 #define HSS1394_MAX_RETRIES             32
42
43 #define HSS1394_CMD_USER_DATA           0x00
44 #define HSS1394_CMD_DEBUG_DATA          0x01
45 #define HSS1394_CMD_USER_TAG_BASE       0x10
46 #define HSS1394_CMD_USER_TAG_TOP        0xEF
47 #define HSS1394_CMD_RESET               0xF0
48 #define HSS1394_CMD_CHANGE_ADDRESS      0xF1
49 #define HSS1394_CMD_PING                0xF2
50 #define HSS1394_CMD_PING_RESPONSE       0xF3
51 #define HSS1394_CMD_ECHO_AS_USER_DATA   0xF4
52 #define HSS1394_CMD_UNDEFINED           0xFF
53
54 class ScsDevice : public GenericAVC::Device {
55 public:
56     class HSS1394Handler;
57
58     enum eMessageType {
59         eMT_UserData = HSS1394_CMD_USER_DATA,
60         eMT_DebugData = HSS1394_CMD_DEBUG_DATA,
61         eMT_UserTagBase = HSS1394_CMD_USER_TAG_BASE,
62         eMT_UserTagTop = HSS1394_CMD_USER_TAG_TOP,
63         eMT_Reset = HSS1394_CMD_RESET,
64         eMT_ChangeAddress = HSS1394_CMD_CHANGE_ADDRESS,
65         eMT_Ping = HSS1394_CMD_PING,
66         eMT_PingResponse = HSS1394_CMD_PING_RESPONSE,
67         eMT_EchoAsUserData = HSS1394_CMD_ECHO_AS_USER_DATA,
68         eMT_Undefined = HSS1394_CMD_UNDEFINED,
69     };
70
71 public:
72     ScsDevice( DeviceManager& d,
73                ffado_smartptr<ConfigRom>( configRom ));
74     virtual ~ScsDevice();
75
76     virtual void showDevice();
77
78     virtual bool initMessageHandler();
79     bool discover();
80
81     bool writeHSS1394Message(enum eMessageType message_type, byte_t*, size_t);
82
83 // private: // FIXME: should be private!!!
84     HSS1394Handler *m_hss1394handler;
85 private:
86
87     bool writeRegBlock(fb_nodeaddr_t addr, fb_quadlet_t *data, size_t length, size_t blocksize_quads=32);
88     bool readRegBlock(fb_nodeaddr_t addr, fb_quadlet_t *data, size_t length, size_t blocksize_quads=32);
89
90 public:
91     class HSS1394Handler : public Ieee1394Service::ARMHandler
92     {
93     public:
94         class MessageFunctor
95         {
96         public:
97             MessageFunctor() {};
98             virtual ~MessageFunctor() {}
99             virtual void operator() (byte_t *, size_t len) = 0;
100         };
101
102         typedef std::vector<MessageFunctor*> MessageHandlerVector;
103         typedef std::vector<MessageFunctor*>::iterator MessageHandlerVectorIterator;
104
105     public:
106         HSS1394Handler(Device &, nodeaddr_t start);
107         virtual ~HSS1394Handler();
108
109         virtual bool handleRead(struct raw1394_arm_request  *);
110         virtual bool handleWrite(struct raw1394_arm_request  *);
111         virtual bool handleLock(struct raw1394_arm_request  *);
112
113         bool addMessageHandler(enum eMessageType message_type, MessageFunctor* functor);
114         bool removeMessageHandler(enum eMessageType message_type, MessageFunctor* functor);
115     private:
116         Device &m_device;
117         MessageHandlerVector m_userDataMessageHandlers;
118
119     private:
120         enum eMessageType byteToMessageType(byte_t);
121     };
122 };
123
124 }
125 }
126
127 #endif // GENERICAVC_STANTON_SCS_DEVICE_H
Note: See TracBrowser for help on using the browser.