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

Revision 637, 11.8 kB (checked in by wagi, 15 years ago)

- some code cleanup (whitespace, unnecessary ';' removed, code indention, ...)
- loadFromCache: problem identified why it doesn't work. The PCPLugs and ExternaPlugs? in
AVC::Unit are not deserialized.

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
166  public:
167     struct ChannelInfo {
168         stream_position_t          m_streamPosition;
169         stream_position_location_t m_location;
170         Glib::ustring              m_name;
171     };
172     typedef std::vector<ChannelInfo> ChannelInfoVector;
173
174     struct ClusterInfo {
175         int                 m_index;
176         port_type_t         m_portType;
177         Glib::ustring       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( Glib::ustring basePath,
243                                 Util::IOSerialize& ser,
244                                 const ClusterInfo& clusterInfo ) const;
245     bool deserializeChannelInfos( Glib::ustring basePath,
246                                   Util::IODeserialize& deser,
247                                   ClusterInfo& clusterInfo );
248
249     bool serializeClusterInfos( Glib::ustring basePath,
250                                 Util::IOSerialize& ser ) const;
251     bool deserializeClusterInfos( Glib::ustring basePath,
252                                   Util::IODeserialize& deser );
253
254     bool serializeFormatInfos( Glib::ustring basePath,
255                                Util::IOSerialize& ser ) const;
256     bool deserializeFormatInfos( Glib::ustring basePath,
257                                  Util::IODeserialize& deser );
258
259     bool serializePlugVector( Glib::ustring basePath,
260                               Util::IOSerialize& ser,
261                               const PlugVector& vec) const;
262     bool deserializePlugVector( Glib::ustring basePath,
263                                 Util::IODeserialize& deser,
264                                 PlugVector& vec );
265
266 protected:
267     // Supported stream formats
268     struct FormatInfo {
269         FormatInfo()
270             : m_samplingFrequency( eSF_DontCare )
271             , m_isSyncStream( false )
272             , m_audioChannels( 0 )
273             , m_midiChannels( 0 )
274             , m_index( 0xff )
275             {}
276         sampling_frequency_t  m_samplingFrequency;
277         bool                       m_isSyncStream;
278         number_of_channels_t  m_audioChannels;
279         number_of_channels_t  m_midiChannels;
280         byte_t                     m_index;
281     };
282     typedef std::vector<FormatInfo> FormatInfoVector;
283
284
285     Unit*                       m_unit;
286     Subunit*                    m_subunit;
287     function_block_type_t       m_functionBlockType;
288     function_block_id_t         m_functionBlockId;
289     EPlugAddressType            m_addressType;
290     EPlugDirection              m_direction;
291     plug_id_t                   m_id;
292     EPlugType                   m_infoPlugType;
293     nr_of_channels_t            m_nrOfChannels;
294     Glib::ustring               m_name;
295     ClusterInfoVector           m_clusterInfos;
296     sampling_frequency_t        m_samplingFrequency;
297     FormatInfoVector            m_formatInfos;
298     PlugVector                  m_inputConnections;
299     PlugVector                  m_outputConnections;
300     int                         m_globalId;
301     static int                  m_globalIdCounter;
302
303     DECLARE_DEBUG_MODULE;
304 };
305
306 const char* avPlugAddressTypeToString( Plug::EPlugAddressType addressType );
307 const char* avPlugTypeToString( Plug::EPlugType type );
308 const char* avPlugDirectionToString( Plug::EPlugDirection direction );
309
310 class PlugManager
311 {
312 public:
313     PlugManager( );
314     PlugManager( const PlugManager& rhs );
315     ~PlugManager();
316
317     bool addPlug( Plug& plug );
318     bool remPlug( Plug& plug );
319
320     void showPlugs() const;
321
322     int getPlugCount()
323         { return m_plugs.size(); };
324
325     Plug* getPlug( ESubunitType subunitType,
326                    subunit_id_t subunitId,
327                    function_block_type_t functionBlockType,
328                    function_block_id_t functionBlockId,
329                    Plug::EPlugAddressType plugAddressType,
330                    Plug::EPlugDirection plugDirection,
331                    plug_id_t plugId ) const;
332     Plug* getPlug( int iGlobalId ) const;
333     PlugVector getPlugsByType( ESubunitType subunitType,
334                                subunit_id_t subunitId,
335                                function_block_type_t functionBlockType,
336                                function_block_id_t functionBlockId,
337                                Plug::EPlugAddressType plugAddressType,
338                                Plug::EPlugDirection plugDirection,
339                                Plug::EPlugType type) const;
340
341     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
342     static  PlugManager* deserialize( Glib::ustring basePath,
343                                       Util::IODeserialize& deser,
344                                       Unit& avDevice );
345     void setVerboseLevel( int i )
346         { setDebugLevel(i); }
347     PlugVector& getPlugs()
348         { return m_plugs; }
349     bool tidyPlugConnections(PlugConnectionVector&);
350
351 private:
352
353     PlugVector   m_plugs;
354
355     DECLARE_DEBUG_MODULE;
356 };
357
358 class PlugConnection {
359 public:
360     PlugConnection( Plug& srcPlug, Plug& destPlug );
361
362     Plug& getSrcPlug() const
363         { return *m_srcPlug; }
364     Plug& getDestPlug() const
365         { return *m_destPlug; }
366
367     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
368     static PlugConnection* deserialize( Glib::ustring basePath,
369                                         Util::IODeserialize& deser,
370                                         Unit& avDevice );
371 private:
372     PlugConnection();
373
374 private:
375     Plug* m_srcPlug;
376     Plug* m_destPlug;
377 };
378
379 typedef std::vector<PlugConnection> PlugConnectionOwnerVector;
380
381 }
382
383 #endif // AVC_PLUG
Note: See TracBrowser for help on using the browser.