root/trunk/libffado/src/libavc/general/avc_extended_plug_info.cpp

Revision 742, 23.5 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
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 3 of the License, or
12  * (at your option) any later version.
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 #include "avc_extended_plug_info.h"
25 #include "libutil/cmd_serialize.h"
26 #include "libieee1394/ieee1394service.h"
27
28 #include <netinet/in.h>
29 #include <iostream>
30
31 using namespace std;
32
33 namespace AVC {
34
35 /////////////////////////////////////////
36 /////////////////////////////////////////
37
38 ExtendedPlugInfoPlugTypeSpecificData::ExtendedPlugInfoPlugTypeSpecificData( EExtendedPlugInfoPlugType ePlugType )
39     : IBusData()
40     , m_plugType( ePlugType )
41 {
42 }
43
44 ExtendedPlugInfoPlugTypeSpecificData::~ExtendedPlugInfoPlugTypeSpecificData()
45 {
46 }
47
48 bool
49 ExtendedPlugInfoPlugTypeSpecificData::serialize( Util::IOSSerialize& se )
50 {
51     se.write( m_plugType, "ExtendedPlugInfoPlugTypeSpecificData plugType" );
52     return true;
53 }
54
55
56 bool
57 ExtendedPlugInfoPlugTypeSpecificData::deserialize( Util::IISDeserialize& de )
58 {
59     de.read( &m_plugType );
60     return true;
61 }
62
63 ExtendedPlugInfoPlugTypeSpecificData* ExtendedPlugInfoPlugTypeSpecificData::clone() const
64 {
65     return new ExtendedPlugInfoPlugTypeSpecificData( *this );
66 }
67
68 const char* extendedPlugInfoPlugTypeStrings[] =
69 {
70     "IsoStream",
71     "AsyncStream",
72     "Midi",
73     "Sync",
74     "Analog",
75     "Digital",
76     "Unknown",
77 };
78
79 const char* extendedPlugInfoPlugTypeToString( plug_type_t plugType )
80 {
81     if ( plugType > sizeof( extendedPlugInfoPlugTypeStrings ) ) {
82         return "Unknown";
83     } else {
84         return extendedPlugInfoPlugTypeStrings[plugType];
85     }
86 }
87
88 /////////////////////////////////////////
89 /////////////////////////////////////////
90
91 ExtendedPlugInfoPlugNameSpecificData::ExtendedPlugInfoPlugNameSpecificData()
92     : IBusData()
93 {
94 }
95
96 ExtendedPlugInfoPlugNameSpecificData::~ExtendedPlugInfoPlugNameSpecificData()
97 {
98 }
99
100 bool
101 ExtendedPlugInfoPlugNameSpecificData::serialize( Util::IOSSerialize& se )
102 {
103     byte_t length = strlen( m_name.c_str() );
104     se.write( length,
105               "ExtendedPlugInfoPlugNameSpecificData: string length" );
106     for ( unsigned int i = 0; i < length; ++i ) {
107         se.write( static_cast<byte_t>( m_name[i] ),
108                   "ExtendedPlugInfoPlugNameSpecificData: char" );
109     }
110
111     return true;
112 }
113
114 bool
115 ExtendedPlugInfoPlugNameSpecificData::deserialize( Util::IISDeserialize& de )
116 {
117     byte_t length;
118     de.read( &length );
119     m_name.clear();
120     char* name;
121     // note that the pointer returned by de.read is not valid outside this function
122     // but since we assign it to m_name it's not a problem since the contents are copied
123     de.read( &name, length );
124     m_name = name;
125
126     return true;
127 }
128
129 ExtendedPlugInfoPlugNameSpecificData::ExtendedPlugInfoPlugNameSpecificData*
130 ExtendedPlugInfoPlugNameSpecificData::clone() const
131 {
132     return new ExtendedPlugInfoPlugNameSpecificData( *this );
133 }
134
135
136 /////////////////////////////////////////
137 /////////////////////////////////////////
138
139 ExtendedPlugInfoPlugNumberOfChannelsSpecificData::ExtendedPlugInfoPlugNumberOfChannelsSpecificData()
140     : IBusData()
141     , m_nrOfChannels( 0 )
142 {
143 }
144
145 ExtendedPlugInfoPlugNumberOfChannelsSpecificData::~ExtendedPlugInfoPlugNumberOfChannelsSpecificData()
146 {
147 }
148
149 bool
150 ExtendedPlugInfoPlugNumberOfChannelsSpecificData::serialize( Util::IOSSerialize& se )
151 {
152     se.write( m_nrOfChannels,
153               "ExtendedPlugInfoPlugNumberOfChannelsSpecificData: "
154               "number of channels" );
155     return true;
156 }
157
158 bool
159 ExtendedPlugInfoPlugNumberOfChannelsSpecificData::deserialize( Util::IISDeserialize& de )
160 {
161     de.read( &m_nrOfChannels );
162     return true;
163 }
164
165 ExtendedPlugInfoPlugNumberOfChannelsSpecificData::ExtendedPlugInfoPlugNumberOfChannelsSpecificData*
166 ExtendedPlugInfoPlugNumberOfChannelsSpecificData::clone() const
167 {
168     return new ExtendedPlugInfoPlugNumberOfChannelsSpecificData( *this );
169 }
170
171 /////////////////////////////////////////
172 /////////////////////////////////////////
173
174 ExtendedPlugInfoPlugChannelPositionSpecificData::ExtendedPlugInfoPlugChannelPositionSpecificData()
175     : IBusData()
176     , m_nrOfClusters( 0 )
177 {
178 }
179
180 ExtendedPlugInfoPlugChannelPositionSpecificData::~ExtendedPlugInfoPlugChannelPositionSpecificData()
181 {
182 }
183
184 bool
185 ExtendedPlugInfoPlugChannelPositionSpecificData::serialize( Util::IOSSerialize& se )
186 {
187     se.write( m_nrOfClusters,
188               "ExtendedPlugInfoPlugChannelPositionSpecificData: "
189               "number of clusters" );
190
191     for ( ClusterInfoVector::const_iterator it = m_clusterInfos.begin();
192           it != m_clusterInfos.end();
193           ++it )
194     {
195         const ClusterInfo* clusterInfo = &( *it );
196
197         se.write( clusterInfo->m_nrOfChannels,
198                   "ExtendedPlugInfoPlugChannelPositionSpecificData: "
199                   "number of channels" );
200         for ( ChannelInfoVector::const_iterator cit
201                   = clusterInfo->m_channelInfos.begin();
202               cit != clusterInfo->m_channelInfos.end();
203               ++cit )
204         {
205             const ChannelInfo* channelInfo = &( *cit );
206             se.write( channelInfo->m_streamPosition,
207                       "ExtendedPlugInfoPlugChannelPositionSpecificData: "
208                       "stream position" );
209             se.write( channelInfo->m_location,
210                       "ExtendedPlugInfoPlugChannelPositionSpecificData: "
211                       "location" );
212         }
213     }
214
215     return true;
216 }
217
218 bool
219 ExtendedPlugInfoPlugChannelPositionSpecificData::deserialize( Util::IISDeserialize& de )
220 {
221     m_clusterInfos.clear();
222
223     de.read( &m_nrOfClusters );
224     for ( int i = 0; i < m_nrOfClusters; ++i ) {
225         ClusterInfo clusterInfo;
226         de.read ( &clusterInfo.m_nrOfChannels );
227         for ( int j = 0; j < clusterInfo.m_nrOfChannels; ++j ) {
228             ChannelInfo channelInfo;
229             de.read( &channelInfo.m_streamPosition );
230             de.read( &channelInfo.m_location );
231             clusterInfo.m_channelInfos.push_back( channelInfo );
232         }
233         m_clusterInfos.push_back( clusterInfo );
234     }
235     return true;
236 }
237
238 ExtendedPlugInfoPlugChannelPositionSpecificData::ExtendedPlugInfoPlugChannelPositionSpecificData*
239 ExtendedPlugInfoPlugChannelPositionSpecificData::clone() const
240 {
241     return new ExtendedPlugInfoPlugChannelPositionSpecificData( *this );
242 }
243
244 /////////////////////////////////////////
245 /////////////////////////////////////////
246
247 ExtendedPlugInfoPlugChannelNameSpecificData::ExtendedPlugInfoPlugChannelNameSpecificData()
248     : IBusData()
249     , m_streamPosition( 0 )
250     , m_stringLength( 0xff )
251 {
252 }
253
254 ExtendedPlugInfoPlugChannelNameSpecificData::~ExtendedPlugInfoPlugChannelNameSpecificData()
255 {
256 }
257
258 bool
259 ExtendedPlugInfoPlugChannelNameSpecificData::serialize( Util::IOSSerialize& se )
260 {
261     se.write( m_streamPosition,
262               "ExtendedPlugInfoPlugChannelNameSpecificData: stream position" );
263     se.write( m_stringLength,
264               "ExtendedPlugInfoPlugChannelNameSpecificData: string length" );
265     for ( unsigned int i = 0; i < m_plugChannelName.size(); ++i ) {
266         se.write( static_cast<byte_t>( m_plugChannelName[i] ),
267                   "ExtendedPlugInfoPlugChannelNameSpecificData: char" );
268     }
269
270     return true;
271 }
272
273 bool
274 ExtendedPlugInfoPlugChannelNameSpecificData::deserialize( Util::IISDeserialize& de )
275 {
276     de.read( &m_streamPosition );
277     de.read( &m_stringLength );
278
279     char* name = new char[m_stringLength+1];
280     for ( int i = 0; i < m_stringLength; ++i ) {
281         byte_t c;
282         de.read( &c );
283         // \todo do correct encoding
284         if ( c == '&' ) {
285             c = '+';
286         }
287         name[i] = c;
288     }
289     name[m_stringLength] = '\0';
290     m_plugChannelName = name;
291     delete[] name;
292
293     return true;
294 }
295
296 ExtendedPlugInfoPlugChannelNameSpecificData::ExtendedPlugInfoPlugChannelNameSpecificData*
297 ExtendedPlugInfoPlugChannelNameSpecificData::clone() const
298 {
299     return new ExtendedPlugInfoPlugChannelNameSpecificData( *this );
300 }
301
302 /////////////////////////////////////////
303 /////////////////////////////////////////
304 ExtendedPlugInfoPlugInputSpecificData::ExtendedPlugInfoPlugInputSpecificData()
305     : IBusData()
306 {
307     UnitPlugSpecificDataPlugAddress
308         unitPlug( UnitPlugSpecificDataPlugAddress::ePT_PCR,  0x00 );
309     m_plugAddress
310         = new PlugAddressSpecificData( PlugAddressSpecificData::ePD_Output,
311                                        PlugAddressSpecificData::ePAM_Unit,
312                                        unitPlug );
313 }
314
315 ExtendedPlugInfoPlugInputSpecificData::ExtendedPlugInfoPlugInputSpecificData(const ExtendedPlugInfoPlugInputSpecificData& rhs )
316 {
317     m_plugAddress = rhs.m_plugAddress->clone();
318 }
319
320
321 ExtendedPlugInfoPlugInputSpecificData::~ExtendedPlugInfoPlugInputSpecificData()
322 {
323     delete m_plugAddress;
324     m_plugAddress = 0;
325 }
326
327 bool
328 ExtendedPlugInfoPlugInputSpecificData::serialize( Util::IOSSerialize& se )
329 {
330     if ( m_plugAddress ) {
331         return m_plugAddress->serialize( se );
332     } else {
333         return false;
334     }
335 }
336
337 bool
338 ExtendedPlugInfoPlugInputSpecificData::deserialize( Util::IISDeserialize& de )
339 {
340     return m_plugAddress->deserialize( de );
341 }
342
343 ExtendedPlugInfoPlugInputSpecificData::ExtendedPlugInfoPlugInputSpecificData*
344 ExtendedPlugInfoPlugInputSpecificData::clone() const
345 {
346     return new ExtendedPlugInfoPlugInputSpecificData( *this );
347 }
348
349 /////////////////////////////////////////
350 /////////////////////////////////////////
351
352 ExtendedPlugInfoPlugOutputSpecificData::ExtendedPlugInfoPlugOutputSpecificData()
353     : IBusData()
354     , m_nrOfOutputPlugs( 0 )
355 {
356 }
357
358 ExtendedPlugInfoPlugOutputSpecificData::ExtendedPlugInfoPlugOutputSpecificData( const ExtendedPlugInfoPlugOutputSpecificData& rhs)
359     : IBusData()
360     , m_nrOfOutputPlugs( rhs.m_nrOfOutputPlugs )
361 {
362     for ( PlugAddressVector::const_iterator it = rhs.m_outputPlugAddresses.begin();
363           it != rhs.m_outputPlugAddresses.end();
364           ++it )
365     {
366         m_outputPlugAddresses.push_back( ( *it )->clone() );
367     }
368
369 }
370
371
372 ExtendedPlugInfoPlugOutputSpecificData::~ExtendedPlugInfoPlugOutputSpecificData()
373 {
374     for ( PlugAddressVector::iterator it = m_outputPlugAddresses.begin();
375           it != m_outputPlugAddresses.end();
376           ++it )
377     {
378         delete *it;
379     }
380 }
381
382 bool
383 ExtendedPlugInfoPlugOutputSpecificData::serialize( Util::IOSSerialize& se )
384 {
385     se.write( m_nrOfOutputPlugs, "ExtendedPlugInfoPlugOutputSpecificData: number of output plugs" );
386     for ( PlugAddressVector::const_iterator it = m_outputPlugAddresses.begin();
387           it != m_outputPlugAddresses.end();
388           ++it )
389     {
390         ( *it )->serialize( se );
391     }
392
393     return true;
394 }
395
396 bool
397 ExtendedPlugInfoPlugOutputSpecificData::deserialize( Util::IISDeserialize& de )
398 {
399     de.read( &m_nrOfOutputPlugs );
400
401     for ( int i = 0; i < m_nrOfOutputPlugs; ++i )
402     {
403         UnitPlugSpecificDataPlugAddress
404             unitPlug( UnitPlugSpecificDataPlugAddress::ePT_PCR,  0x00 );
405         PlugAddressSpecificData* plugAddress
406             = new PlugAddressSpecificData( PlugAddressSpecificData::ePD_Output,
407                                            PlugAddressSpecificData::ePAM_Unit,
408                                            unitPlug );
409         if ( !plugAddress->deserialize( de ) ) {
410             return false;
411         }
412
413         m_outputPlugAddresses.push_back( plugAddress );
414     }
415
416     return true;
417 }
418
419 ExtendedPlugInfoPlugOutputSpecificData::ExtendedPlugInfoPlugOutputSpecificData*
420 ExtendedPlugInfoPlugOutputSpecificData::clone() const
421 {
422     return new ExtendedPlugInfoPlugOutputSpecificData( *this );
423 }
424
425 /////////////////////////////////////////
426 /////////////////////////////////////////
427 ExtendedPlugInfoClusterInfoSpecificData::ExtendedPlugInfoClusterInfoSpecificData()
428     : IBusData()
429     , m_clusterIndex( 0 )
430     , m_portType( ePT_NoType )
431     , m_stringLength( 0xff )
432 {
433 }
434
435 ExtendedPlugInfoClusterInfoSpecificData::~ExtendedPlugInfoClusterInfoSpecificData()
436 {
437 }
438
439 bool
440 ExtendedPlugInfoClusterInfoSpecificData::serialize( Util::IOSSerialize& se )
441 {
442     se.write( m_clusterIndex,
443               "ExtendedPlugInfoClusterInfoSpecificData: cluster index" );
444     se.write( m_portType,
445               "ExtendedPlugInfoClusterInfoSpecificData: port type" );
446     se.write( m_stringLength,
447               "ExtendedPlugInfoClusterInfoSpecificData: string length" );
448     for ( unsigned int i = 0; i < m_clusterName.length(); ++i ) {
449         se.write( static_cast<byte_t>( m_clusterName[i] ),
450                   "ExtendedPlugInfoClusterInfoSpecificData: char" );
451     }
452
453     return true;
454 }
455
456 bool
457 ExtendedPlugInfoClusterInfoSpecificData::deserialize( Util::IISDeserialize& de )
458 {
459
460     de.read( &m_clusterIndex );
461     de.read( &m_portType );
462     de.read( &m_stringLength );
463
464     char* name = new char[m_stringLength+1];
465     for ( int i = 0; i < m_stringLength; ++i ) {
466         byte_t c;
467         de.read( &c );
468         // \todo do correct encoding
469         if ( c == '&' ) {
470             c = '+';
471         }
472         name[i] = c;
473     }
474     name[m_stringLength] = '\0';
475     m_clusterName = name;
476     delete[] name;
477
478     return true;
479 }
480
481 ExtendedPlugInfoClusterInfoSpecificData::ExtendedPlugInfoClusterInfoSpecificData*
482 ExtendedPlugInfoClusterInfoSpecificData::clone() const
483 {
484     return new ExtendedPlugInfoClusterInfoSpecificData( *this );
485 }
486
487 const char* extendedPlugInfoPortTypeStrings[] =
488 {
489     "Speaker",
490     "Headphone",
491     "Microphone",
492     "Line",
493     "SPDIF",
494     "ADAT",
495     "TDIF",
496     "MADI",
497     "Analog",
498     "Digital",
499     "MIDI",
500 };
501
502 const char* extendedPlugInfoClusterInfoPortTypeToString( port_type_t portType )
503 {
504     if ( portType > ( ( sizeof( extendedPlugInfoPortTypeStrings ) )
505                       / ( sizeof( extendedPlugInfoPortTypeStrings[0] ) ) ) ) {
506         return "Unknown";
507     } else {
508         return extendedPlugInfoPortTypeStrings[portType];
509     }
510 }
511
512 /////////////////////////////////////////
513 /////////////////////////////////////////
514 /////////////////////////////////////////
515 /////////////////////////////////////////
516
517 ExtendedPlugInfoInfoType::ExtendedPlugInfoInfoType(EInfoType eInfoType)
518     : IBusData()
519     , m_infoType( eInfoType )
520     , m_plugType( 0 )
521     , m_plugName( 0 )
522     , m_plugNrOfChns( 0 )
523     , m_plugChannelPosition( 0 )
524     , m_plugChannelName( 0 )
525     , m_plugInput( 0 )
526     , m_plugOutput( 0 )
527     , m_plugClusterInfo( 0 )
528 {
529 }
530
531 ExtendedPlugInfoInfoType::ExtendedPlugInfoInfoType( const ExtendedPlugInfoInfoType& rhs )
532     : IBusData()
533     , m_infoType( rhs.m_infoType )
534     , m_plugType( 0 )
535     , m_plugName( 0 )
536     , m_plugNrOfChns( 0 )
537     , m_plugChannelPosition( 0 )
538     , m_plugChannelName( 0 )
539     , m_plugInput( 0 )
540     , m_plugOutput( 0 )
541     , m_plugClusterInfo( 0 )
542 {
543     switch( m_infoType ) {
544     case eIT_PlugType:
545         m_plugType =
546             new ExtendedPlugInfoPlugTypeSpecificData( *rhs.m_plugType );
547         break;
548     case eIT_PlugName:
549         m_plugName =
550             new ExtendedPlugInfoPlugNameSpecificData( *rhs.m_plugName );
551         break;
552     case eIT_NoOfChannels:
553         m_plugNrOfChns =
554             new ExtendedPlugInfoPlugNumberOfChannelsSpecificData( *rhs.m_plugNrOfChns );
555         break;
556     case eIT_ChannelPosition:
557         m_plugChannelPosition =
558             new ExtendedPlugInfoPlugChannelPositionSpecificData( *rhs.m_plugChannelPosition );
559         break;
560     case eIT_ChannelName:
561         m_plugChannelName =
562             new ExtendedPlugInfoPlugChannelNameSpecificData( *rhs.m_plugChannelName );
563         break;
564     case eIT_PlugInput:
565         m_plugInput =
566             new ExtendedPlugInfoPlugInputSpecificData( *rhs.m_plugInput );
567         break;
568     case eIT_PlugOutput:
569         m_plugOutput =
570             new ExtendedPlugInfoPlugOutputSpecificData( *rhs.m_plugOutput );
571         break;
572     case eIT_ClusterInfo:
573         m_plugClusterInfo =
574             new ExtendedPlugInfoClusterInfoSpecificData( *rhs.m_plugClusterInfo );
575         break;
576     }
577 }
578
579 ExtendedPlugInfoInfoType::~ExtendedPlugInfoInfoType()
580 {
581     delete( m_plugType );
582     delete( m_plugName );
583     delete( m_plugNrOfChns );
584     delete( m_plugChannelPosition );
585     delete( m_plugChannelName );
586     delete( m_plugInput );
587     delete( m_plugOutput );
588     delete( m_plugClusterInfo );
589  }
590
591 bool
592 ExtendedPlugInfoInfoType::initialize()
593 {
594     switch ( m_infoType ) {
595     case eIT_PlugType:
596         m_plugType = new ExtendedPlugInfoPlugTypeSpecificData;
597         break;
598     case eIT_PlugName:
599         m_plugName = new ExtendedPlugInfoPlugNameSpecificData;
600         break;
601     case eIT_NoOfChannels:
602         m_plugNrOfChns = new ExtendedPlugInfoPlugNumberOfChannelsSpecificData;
603         break;
604     case eIT_ChannelPosition:
605         m_plugChannelPosition = new ExtendedPlugInfoPlugChannelPositionSpecificData;
606         break;
607     case eIT_ChannelName:
608         m_plugChannelName = new ExtendedPlugInfoPlugChannelNameSpecificData;
609         break;
610     case eIT_PlugInput:
611         m_plugInput = new ExtendedPlugInfoPlugInputSpecificData;
612         break;
613     case eIT_PlugOutput:
614         m_plugOutput = new ExtendedPlugInfoPlugOutputSpecificData;
615         break;
616     case eIT_ClusterInfo:
617         m_plugClusterInfo = new ExtendedPlugInfoClusterInfoSpecificData;
618         break;
619     default:
620         return false;
621     }
622
623     return true;
624 }
625
626 bool
627 ExtendedPlugInfoInfoType::serialize( Util::IOSSerialize& se )
628 {
629     // XXX \todo improve Util::IOSSerialize::write interface
630     char* buf;
631     asprintf( &buf, "ExtendedPlugInfoInfoType infoType (%s)",
632               extendedPlugInfoInfoTypeToString( m_infoType ) );
633     se.write( m_infoType, buf );
634
635     free(buf);
636
637     switch ( m_infoType ) {
638     case eIT_PlugType:
639         if ( m_plugType ) {
640             m_plugType->serialize( se );
641         }
642         break;
643     case eIT_PlugName:
644         if ( m_plugName ) {
645             m_plugName->serialize( se );
646         }
647         break;
648     case eIT_NoOfChannels:
649         if ( m_plugNrOfChns ) {
650             m_plugNrOfChns->serialize( se );
651         }
652         break;
653     case eIT_ChannelPosition:
654         if ( m_plugChannelPosition ) {
655             m_plugChannelPosition->serialize( se );
656         }
657         break;
658     case eIT_ChannelName:
659         if ( m_plugChannelName ) {
660             m_plugChannelName->serialize( se );
661         }
662         break;
663     case eIT_PlugInput:
664         if ( m_plugInput ) {
665             m_plugInput->serialize( se );
666         }
667         break;
668     case eIT_PlugOutput:
669         if ( m_plugOutput ) {
670             m_plugOutput->serialize( se );
671         }
672         break;
673     case eIT_ClusterInfo:
674         if ( m_plugClusterInfo ) {
675             m_plugClusterInfo->serialize( se );
676         }
677         break;
678     default:
679         return false;
680     }
681
682     return true;
683 }
684
685 bool
686 ExtendedPlugInfoInfoType::deserialize( Util::IISDeserialize& de )
687 {
688     bool status = false;
689
690     de.read( &m_infoType );
691
692     switch ( m_infoType ) {
693     case eIT_PlugType:
694         if ( !m_plugType ) {
695             m_plugType = new ExtendedPlugInfoPlugTypeSpecificData;
696         }
697         status = m_plugType->deserialize( de );
698         break;
699     case eIT_PlugName:
700         if ( !m_plugName ) {
701             m_plugName = new ExtendedPlugInfoPlugNameSpecificData;
702         }
703         status = m_plugName->deserialize( de );
704         break;
705     case eIT_NoOfChannels:
706         if ( !m_plugNrOfChns ) {
707             m_plugNrOfChns =
708                 new ExtendedPlugInfoPlugNumberOfChannelsSpecificData;
709         }
710         status = m_plugNrOfChns->deserialize( de );
711         break;
712     case eIT_ChannelPosition:
713         if ( !m_plugChannelPosition ) {
714             m_plugChannelPosition =
715                 new ExtendedPlugInfoPlugChannelPositionSpecificData;
716         }
717         status = m_plugChannelPosition->deserialize( de );
718         break;
719     case eIT_ChannelName:
720         if ( !m_plugChannelName ) {
721             m_plugChannelName =
722                 new ExtendedPlugInfoPlugChannelNameSpecificData;
723         }
724         status = m_plugChannelName->deserialize( de );
725         break;
726     case eIT_PlugInput:
727         if ( !m_plugInput ) {
728             m_plugInput = new ExtendedPlugInfoPlugInputSpecificData;
729         }
730         status = m_plugInput->deserialize( de );
731         break;
732     case eIT_PlugOutput:
733         if ( !m_plugOutput ) {
734             m_plugOutput = new ExtendedPlugInfoPlugOutputSpecificData;
735         }
736         status = m_plugOutput->deserialize( de );
737         break;
738     case eIT_ClusterInfo:
739         if ( !m_plugClusterInfo ) {
740             m_plugClusterInfo = new ExtendedPlugInfoClusterInfoSpecificData;
741         }
742         status =m_plugClusterInfo->deserialize( de );
743         break;
744     default:
745         return false;
746     }
747
748     return status;
749 }
750
751 ExtendedPlugInfoInfoType*
752 ExtendedPlugInfoInfoType::clone() const
753 {
754    ExtendedPlugInfoInfoType* extPlugInfoInfoType
755        = new ExtendedPlugInfoInfoType( *this );
756    extPlugInfoInfoType->initialize();
757    return extPlugInfoInfoType;
758 }
759
760 const char* extendedPlugInfoInfoTypeStrings[] =
761 {
762     "PlugType",
763     "PlugName",
764     "NoOfChannels",
765     "ChannelPosition",
766     "ChannelName",
767     "PlugInput",
768     "PlugOutput",
769     "ClusterInfo",
770 };
771
772 const char* extendedPlugInfoInfoTypeToString( info_type_t infoType )
773 {
774     if ( infoType > ( ( sizeof( extendedPlugInfoInfoTypeStrings ) )
775                       / ( sizeof( extendedPlugInfoInfoTypeStrings[0] ) ) ) )  {
776         return "Unknown";
777     } else {
778         return extendedPlugInfoInfoTypeStrings[infoType];
779     }
780 }
781
782
783 //////////////////////////////////////////////
784
785 ExtendedPlugInfoCmd::ExtendedPlugInfoCmd( Ieee1394Service& ieee1394service,
786                                           ESubFunction eSubFunction )
787     : AVCCommand( ieee1394service, AVC1394_CMD_PLUG_INFO )
788 {
789     setSubFunction( eSubFunction );
790     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0x00 );
791     m_plugAddress = new PlugAddress( PlugAddress::ePD_Output,
792                                       PlugAddress::ePAM_Unit,
793                                       unitPlugAddress );
794     m_infoType =
795         new ExtendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugType );
796     m_infoType->initialize();
797 }
798
799 ExtendedPlugInfoCmd::ExtendedPlugInfoCmd( const ExtendedPlugInfoCmd& rhs )
800     : AVCCommand( rhs )
801 {
802     m_subFunction = rhs.m_subFunction;
803     m_plugAddress = new PlugAddress( *rhs.m_plugAddress );
804     m_infoType = new ExtendedPlugInfoInfoType( *rhs.m_infoType );
805 }
806
807 ExtendedPlugInfoCmd::~ExtendedPlugInfoCmd()
808 {
809     delete m_plugAddress;
810     m_plugAddress = 0;
811     delete m_infoType;
812     m_infoType = 0;
813 }
814
815 bool
816 ExtendedPlugInfoCmd::serialize( Util::IOSSerialize& se )
817 {
818     bool status = false;
819     AVCCommand::serialize( se );
820     se.write( m_subFunction, "ExtendedPlugInfoCmd subFunction" );
821     status = m_plugAddress->serialize( se );
822     status &= m_infoType->serialize( se );
823
824     return status;
825 }
826
827 bool
828 ExtendedPlugInfoCmd::deserialize( Util::IISDeserialize& de )
829 {
830     bool status = false;
831     AVCCommand::deserialize( de );
832     de.read( &m_subFunction );
833     status = m_plugAddress->deserialize( de );
834     status &= m_infoType->deserialize( de );
835
836     return status;
837 }
838
839 bool
840 ExtendedPlugInfoCmd::setPlugAddress( const PlugAddress& plugAddress )
841 {
842     delete m_plugAddress;
843     m_plugAddress = plugAddress.clone();
844     return true;
845 }
846
847 bool
848 ExtendedPlugInfoCmd::setSubFunction( ESubFunction subFunction )
849 {
850     m_subFunction = subFunction;
851     return true;
852 }
853
854 bool
855 ExtendedPlugInfoCmd::setInfoType( const ExtendedPlugInfoInfoType& infoType )
856 {
857     delete m_infoType;
858     m_infoType = infoType.clone();
859     return true;
860 }
861
862 }
Note: See TracBrowser for help on using the browser.