root/trunk/libffado/src/libavc/general/avc_plug.h

Revision 740, 11.9 kB (checked in by ppalmers, 13 years ago)

fix propagation of debug/verbose level

Line 
1 /*
2  * Copyright (C)      2007 by Pieter Palmers
3  * Copyright (C) 2005-2007 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 library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library 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 GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25 #ifndef AVC_PLUG
26 #define AVC_PLUG
27
28 #include "../ccm/avc_signal_source.h"
29 #include "../streamformat/avc_extended_stream_format.h"
30 #include "../avc_definitions.h"
31 #include "avc_generic.h"
32
33 #include "libutil/serialize.h"
34
35 #include "debugmodule/debugmodule.h"
36
37 #include <glibmm/ustring.h>
38
39 class Ieee1394Service;
40 class ConfigRom;
41
42 namespace AVC {
43
44 class Unit;
45 class Subunit;
46 class PlugManager;
47
48 class Plug;
49 typedef std::vector<Plug*> PlugVector;
50
51 class PlugConnection;
52 typedef std::vector<PlugConnection*> PlugConnectionVector;
53
54
55 class Plug {
56 public:
57
58     enum EPlugAddressType {
59         eAPA_PCR,
60         eAPA_ExternalPlug,
61         eAPA_AsynchronousPlug,
62         eAPA_SubunitPlug,
63         eAPA_FunctionBlockPlug,
64         eAPA_Undefined,
65     };
66     std::string plugAddressTypeToString(enum EPlugAddressType t);
67
68     enum EPlugType {
69         eAPT_IsoStream,
70         eAPT_AsyncStream,
71         eAPT_Midi,
72         eAPT_Sync,
73         eAPT_Analog,
74         eAPT_Digital,
75         eAPT_Unknown,
76     };
77     std::string plugTypeToString(enum EPlugType t);
78
79     enum EPlugDirection {
80         eAPD_Input,
81         eAPD_Output,
82         eAPD_Unknown,
83     };
84     std::string plugDirectionToString(enum EPlugDirection t);
85
86     // \todo This constructors sucks. too many parameters. fix it.
87     Plug( Unit* unit,
88           Subunit* subunit,
89           function_block_type_t functionBlockType,
90           function_block_type_t functionBlockId,
91           EPlugAddressType plugAddressType,
92           EPlugDirection plugDirection,
93           plug_id_t plugId );
94     Plug( const Plug& rhs );
95     virtual ~Plug();
96
97     bool inquireConnnection( Plug& plug );
98     bool setConnection( Plug& plug );
99
100     int getSignalSource();
101
102     int getGlobalId() const
103         { return m_globalId; }
104     plug_id_t getPlugId() const
105         { return m_id; }
106     ESubunitType getSubunitType() const;
107     subunit_id_t getSubunitId() const;
108
109     const char* getName() const
110         { return m_name.c_str(); }
111     bool setName(const char *n)
112         { m_name=n; return true; }
113     bool setName(std::string n)
114         { m_name=n; return true; }
115     EPlugDirection getPlugDirection() const
116         { return m_direction; }
117     bool setPlugDirection(EPlugDirection d)
118         { m_direction=d; return true; }
119     sampling_frequency_t getSamplingFrequency() const
120         { return m_samplingFrequency; }
121     int getSampleRate() const; // 22050, 24000, 32000, ...
122     bool setSampleRate( int rate );
123
124     int getNrOfChannels() const;
125     bool setNrOfChannels(int i);
126     int getNrOfStreams() const;
127
128     // FIXME: this is the same as getPlugDirection
129     EPlugDirection getDirection() const
130         { return m_direction; }
131     EPlugAddressType getPlugAddressType() const
132         { return m_addressType; }
133     EPlugType getPlugType() const
134         { return m_infoPlugType; }
135     bool setPlugType(EPlugType t)
136         { m_infoPlugType=t; return true; }
137
138     function_block_type_t getFunctionBlockType() const
139         { return m_functionBlockType; }
140     function_block_id_t getFunctionBlockId() const
141         { return m_functionBlockId; }
142
143 //     const PlugVector& getInputConnections() const
144 //         { return m_inputConnections; }
145 //     const PlugVector& getOutputConnections() const
146 //         { return m_outputConnections; }
147     PlugVector& getInputConnections()
148         { return m_inputConnections; }
149     PlugVector& getOutputConnections()
150         { return m_outputConnections; }
151
152     static PlugAddress::EPlugDirection convertPlugDirection(
153     EPlugDirection direction);
154
155     void showPlug() const;
156
157     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
158     static Plug* deserialize( Glib::ustring basePath,
159                               Util::IODeserialize& deser,
160                               Unit& avDevice,
161                               PlugManager& plugManager );
162
163     bool deserializeUpdate( Glib::ustring basePath,
164                             Util::IODeserialize& deser );
165     bool deserializeUpdateSubunit();
166
167  public:
168     struct ChannelInfo {
169         stream_position_t          m_streamPosition;
170         stream_position_location_t m_location;
171         Glib::ustring              m_name;
172     };
173     typedef std::vector<ChannelInfo> ChannelInfoVector;
174
175     struct ClusterInfo {
176         int                 m_index;
177         port_type_t         m_portType;
178         Glib::ustring       m_name;
179
180         nr_of_channels_t    m_nrOfChannels;
181         ChannelInfoVector   m_channelInfos;
182         stream_format_t     m_streamFormat;
183     };
184     typedef std::vector<ClusterInfo> ClusterInfoVector;
185
186     ClusterInfoVector& getClusterInfos()
187         { return m_clusterInfos; }
188
189     virtual void setVerboseLevel( int i );
190
191 // the discovery interface
192 // everything can be overloaded, or
193 // can be left as is
194 public:
195     virtual bool discover();
196     virtual bool discoverConnections();
197     virtual bool propagateFromConnectedPlug( );
198
199 protected:
200     virtual bool discoverPlugType();
201     virtual bool discoverName();
202     virtual bool discoverNoOfChannels();
203     virtual bool discoverChannelPosition();
204     virtual bool discoverChannelName();
205     virtual bool discoverClusterInfo();
206     virtual bool discoverStreamFormat();
207     virtual bool discoverSupportedStreamFormats();
208     virtual bool discoverConnectionsInput();
209     virtual bool discoverConnectionsOutput();
210     virtual bool initFromDescriptor();
211
212     bool propagateFromPlug( Plug *p );
213
214     ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd(
215             ExtendedStreamFormatCmd::ESubFunction subFunction);
216
217 protected:
218     Plug();
219
220     SignalSourceCmd setSrcPlugAddrToSignalCmd();
221
222     void setDestPlugAddrToSignalCmd(
223             SignalSourceCmd& signalSourceCmd, Plug& plug );
224
225     void debugOutputClusterInfos( int debugLevel );
226
227     bool addPlugConnection( PlugVector& connections, Plug& plug );
228
229     bool discoverConnectionsFromSpecificData(
230         EPlugDirection discoverDirection,
231         PlugAddressSpecificData* plugAddress,
232         PlugVector& connections );
233
234     Plug* getPlugDefinedBySpecificData(
235         UnitPlugSpecificDataPlugAddress* pUnitPlugAddress,
236         SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress,
237         FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress );
238
239     EPlugDirection toggleDirection( EPlugDirection direction ) const;
240
241     const ClusterInfo* getClusterInfoByIndex( int index ) const;
242
243     bool serializeChannelInfos( Glib::ustring basePath,
244                                 Util::IOSerialize& ser,
245                                 const ClusterInfo& clusterInfo ) const;
246     bool deserializeChannelInfos( Glib::ustring basePath,
247                                   Util::IODeserialize& deser,
248                                   ClusterInfo& clusterInfo );
249
250     bool serializeClusterInfos( Glib::ustring basePath,
251                                 Util::IOSerialize& ser ) const;
252     bool deserializeClusterInfos( Glib::ustring basePath,
253                                   Util::IODeserialize& deser );
254
255     bool serializeFormatInfos( Glib::ustring basePath,
256                                Util::IOSerialize& ser ) const;
257     bool deserializeFormatInfos( Glib::ustring basePath,
258                                  Util::IODeserialize& deser );
259
260 protected:
261     // Supported stream formats
262     struct FormatInfo {
263         FormatInfo()
264             : m_samplingFrequency( eSF_DontCare )
265             , m_isSyncStream( false )
266             , m_audioChannels( 0 )
267             , m_midiChannels( 0 )
268             , m_index( 0xff )
269             {}
270         sampling_frequency_t  m_samplingFrequency;
271         bool                       m_isSyncStream;
272         number_of_channels_t  m_audioChannels;
273         number_of_channels_t  m_midiChannels;
274         byte_t                     m_index;
275     };
276     typedef std::vector<FormatInfo> FormatInfoVector;
277
278
279     Unit*                       m_unit;
280     Subunit*                    m_subunit;
281     ESubunitType                m_subunitType;
282     subunit_t                   m_subunitId;
283     function_block_type_t       m_functionBlockType;
284     function_block_id_t         m_functionBlockId;
285     EPlugAddressType            m_addressType;
286     EPlugDirection              m_direction;
287     plug_id_t                   m_id;
288     EPlugType                   m_infoPlugType;
289     nr_of_channels_t            m_nrOfChannels;
290     Glib::ustring               m_name;
291     ClusterInfoVector           m_clusterInfos;
292     sampling_frequency_t        m_samplingFrequency;
293     FormatInfoVector            m_formatInfos;
294     PlugVector                  m_inputConnections;
295     PlugVector                  m_outputConnections;
296     int                         m_globalId;
297     static int                  m_globalIdCounter;
298
299     DECLARE_DEBUG_MODULE;
300 };
301
302 const char* avPlugAddressTypeToString( Plug::EPlugAddressType addressType );
303 const char* avPlugTypeToString( Plug::EPlugType type );
304 const char* avPlugDirectionToString( Plug::EPlugDirection direction );
305
306 class PlugManager
307 {
308 public:
309     PlugManager( );
310     PlugManager( const PlugManager& rhs );
311     ~PlugManager();
312
313     bool addPlug( Plug& plug );
314     bool remPlug( Plug& plug );
315
316     void showPlugs() const;
317
318     int getPlugCount()
319         { return m_plugs.size(); };
320
321     Plug* getPlug( ESubunitType subunitType,
322                    subunit_id_t subunitId,
323                    function_block_type_t functionBlockType,
324                    function_block_id_t functionBlockId,
325                    Plug::EPlugAddressType plugAddressType,
326                    Plug::EPlugDirection plugDirection,
327                    plug_id_t plugId ) const;
328     Plug* getPlug( int iGlobalId ) const;
329     PlugVector getPlugsByType( ESubunitType subunitType,
330                                subunit_id_t subunitId,
331                                function_block_type_t functionBlockType,
332                                function_block_id_t functionBlockId,
333                                Plug::EPlugAddressType plugAddressType,
334                                Plug::EPlugDirection plugDirection,
335                                Plug::EPlugType type) const;
336
337     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
338     static  PlugManager* deserialize( Glib::ustring basePath,
339                                       Util::IODeserialize& deser,
340                                       Unit& avDevice );
341     void setVerboseLevel( int i );
342     PlugVector& getPlugs()
343         { return m_plugs; }
344     bool tidyPlugConnections(PlugConnectionVector&);
345
346     bool deserializeUpdate();
347
348 private:
349
350     PlugVector   m_plugs;
351
352     DECLARE_DEBUG_MODULE;
353 };
354
355 class PlugConnection {
356 public:
357     PlugConnection( Plug& srcPlug, Plug& destPlug );
358
359     Plug& getSrcPlug() const
360         { return *m_srcPlug; }
361     Plug& getDestPlug() const
362         { return *m_destPlug; }
363
364     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
365     static PlugConnection* deserialize( Glib::ustring basePath,
366                                         Util::IODeserialize& deser,
367                                         Unit& avDevice );
368 private:
369     PlugConnection();
370
371 private:
372     Plug* m_srcPlug;
373     Plug* m_destPlug;
374 };
375
376 typedef std::vector<PlugConnection> PlugConnectionOwnerVector;
377
378
379 bool serializePlugVector( Glib::ustring basePath,
380                           Util::IOSerialize& ser,
381                           const PlugVector& vec);
382
383 bool deserializePlugVector( Glib::ustring basePath,
384                             Util::IODeserialize& deser,
385                             const PlugManager& plugManager,
386                             PlugVector& vec );
387
388 }
389
390 #endif // AVC_PLUG
Note: See TracBrowser for help on using the browser.