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

Revision 1154, 12.0 kB (checked in by ppalmers, 14 years ago)

add expat based parsing of the device cache. add compile-time selection between libxml++ and expat. will allow to get rid of the libxml++ dependency on the long run. scons SERIALIZE_USE_EXPAT=0Only compile testedscons SERIALIZE_USE_EXPAT=0

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 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 <string>
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( std::string basePath, Util::IOSerialize& ser ) const;
158     static Plug* deserialize( std::string basePath,
159                               Util::IODeserialize& deser,
160                               Unit& avDevice,
161                               PlugManager& plugManager );
162     bool deserializeConnections( std::string basePath,
163                                  Util::IODeserialize& deser );
164     bool deserializeUpdateSubunit();
165
166  public:
167     struct ChannelInfo {
168         stream_position_t          m_streamPosition;
169         stream_position_location_t m_location;
170         std::string              m_name;
171     };
172     typedef std::vector<ChannelInfo> ChannelInfoVector;
173
174     struct ClusterInfo {
175         int                 m_index;
176         port_type_t         m_portType;
177         std::string         m_name;
178
179         nr_of_channels_t    m_nrOfChannels;
180         ChannelInfoVector   m_channelInfos;
181         stream_format_t     m_streamFormat;
182     };
183     typedef std::vector<ClusterInfo> ClusterInfoVector;
184
185     ClusterInfoVector& getClusterInfos()
186         { return m_clusterInfos; }
187
188     virtual void setVerboseLevel( int i );
189
190 // the discovery interface
191 // everything can be overloaded, or
192 // can be left as is
193 public:
194     virtual bool discover();
195     virtual bool discoverConnections();
196     virtual bool propagateFromConnectedPlug( );
197
198 protected:
199     virtual bool discoverPlugType();
200     virtual bool discoverName();
201     virtual bool discoverNoOfChannels();
202     virtual bool discoverChannelPosition();
203     virtual bool discoverChannelName();
204     virtual bool discoverClusterInfo();
205     virtual bool discoverStreamFormat();
206     virtual bool discoverSupportedStreamFormats();
207     virtual bool discoverConnectionsInput();
208     virtual bool discoverConnectionsOutput();
209     virtual bool initFromDescriptor();
210
211     bool propagateFromPlug( Plug *p );
212
213     ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd(
214             ExtendedStreamFormatCmd::ESubFunction subFunction);
215
216 protected:
217     Plug();
218
219     SignalSourceCmd setSrcPlugAddrToSignalCmd();
220
221     void setDestPlugAddrToSignalCmd(
222             SignalSourceCmd& signalSourceCmd, Plug& plug );
223
224     void debugOutputClusterInfos( int debugLevel );
225
226     bool addPlugConnection( PlugVector& connections, Plug& plug );
227
228     bool discoverConnectionsFromSpecificData(
229         EPlugDirection discoverDirection,
230         PlugAddressSpecificData* plugAddress,
231         PlugVector& connections );
232
233     Plug* getPlugDefinedBySpecificData(
234         UnitPlugSpecificDataPlugAddress* pUnitPlugAddress,
235         SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress,
236         FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress );
237
238     EPlugDirection toggleDirection( EPlugDirection direction ) const;
239
240     const ClusterInfo* getClusterInfoByIndex( int index ) const;
241
242     bool serializeChannelInfos( std::string basePath,
243                                 Util::IOSerialize& ser,
244                                 const ClusterInfo& clusterInfo ) const;
245     bool deserializeChannelInfos( std::string basePath,
246                                   Util::IODeserialize& deser,
247                                   ClusterInfo& clusterInfo );
248
249     bool serializeClusterInfos( std::string basePath,
250                                 Util::IOSerialize& ser ) const;
251     bool deserializeClusterInfos( std::string basePath,
252                                   Util::IODeserialize& deser );
253
254     bool serializeFormatInfos( std::string basePath,
255                                Util::IOSerialize& ser ) const;
256     bool deserializeFormatInfos( std::string basePath,
257                                  Util::IODeserialize& deser );
258
259 protected:
260     // Supported stream formats
261     struct FormatInfo {
262         FormatInfo()
263             : m_samplingFrequency( eSF_DontCare )
264             , m_isSyncStream( false )
265             , m_audioChannels( 0 )
266             , m_midiChannels( 0 )
267             , m_index( 0xff )
268             {}
269         sampling_frequency_t  m_samplingFrequency;
270         bool                       m_isSyncStream;
271         number_of_channels_t  m_audioChannels;
272         number_of_channels_t  m_midiChannels;
273         byte_t                     m_index;
274     };
275     typedef std::vector<FormatInfo> FormatInfoVector;
276
277
278     Unit*                       m_unit;
279     Subunit*                    m_subunit;
280     ESubunitType                m_subunitType;
281     subunit_t                   m_subunitId;
282     function_block_type_t       m_functionBlockType;
283     function_block_id_t         m_functionBlockId;
284     EPlugAddressType            m_addressType;
285     EPlugDirection              m_direction;
286     plug_id_t                   m_id;
287     EPlugType                   m_infoPlugType;
288     nr_of_channels_t            m_nrOfChannels;
289     std::string                 m_name;
290     ClusterInfoVector           m_clusterInfos;
291     sampling_frequency_t        m_samplingFrequency;
292     FormatInfoVector            m_formatInfos;
293     PlugVector                  m_inputConnections;
294     PlugVector                  m_outputConnections;
295     int                         m_globalId;
296     static int                  m_globalIdCounter;
297
298     DECLARE_DEBUG_MODULE;
299 };
300
301 const char* avPlugAddressTypeToString( Plug::EPlugAddressType addressType );
302 const char* avPlugTypeToString( Plug::EPlugType type );
303 const char* avPlugDirectionToString( Plug::EPlugDirection direction );
304
305 class PlugManager
306 {
307 public:
308     PlugManager( );
309     PlugManager( const PlugManager& rhs );
310     ~PlugManager();
311
312     bool addPlug( Plug& plug );
313     bool remPlug( Plug& plug );
314
315     void showPlugs() const;
316
317     int getPlugCount()
318         { return m_plugs.size(); };
319
320     Plug* getPlug( ESubunitType subunitType,
321                    subunit_id_t subunitId,
322                    function_block_type_t functionBlockType,
323                    function_block_id_t functionBlockId,
324                    Plug::EPlugAddressType plugAddressType,
325                    Plug::EPlugDirection plugDirection,
326                    plug_id_t plugId ) const;
327     Plug* getPlug( int iGlobalId ) const;
328     PlugVector getPlugsByType( ESubunitType subunitType,
329                                subunit_id_t subunitId,
330                                function_block_type_t functionBlockType,
331                                function_block_id_t functionBlockId,
332                                Plug::EPlugAddressType plugAddressType,
333                                Plug::EPlugDirection plugDirection,
334                                Plug::EPlugType type) const;
335
336     bool serialize( std::string basePath, Util::IOSerialize& ser ) const;
337     static  PlugManager* deserialize( std::string basePath,
338                                       Util::IODeserialize& deser,
339                                       Unit& avDevice );
340     void setVerboseLevel( int i );
341     PlugVector& getPlugs()
342         { return m_plugs; }
343     bool tidyPlugConnections(PlugConnectionVector&);
344
345     bool deserializeUpdate( std::string basePath, 
346                             Util::IODeserialize& deser );
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( std::string basePath, Util::IOSerialize& ser ) const;
365     static PlugConnection* deserialize( std::string 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( std::string basePath,
380                           Util::IOSerialize& ser,
381                           const PlugVector& vec);
382
383 bool deserializePlugVector( std::string 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.