root/branches/echoaudio/src/libavc/general/avc_extended_plug_info.cpp

Revision 502, 23.2 kB (checked in by ppalmers, 17 years ago)

Restructure the libavc directory in order to improve maintainability when
extending the implemented AV/C standards. The new directory structure is
a reflection of the specifications: the files in each directory (roughly)
correspond to the same specification.

The breakdown is:

general : AV/C Digital Interface Command Set General Specification
audiosubunit : Audio Subunit Specification
musicsubunit : Music Subunit Specification
ccm : Connection and Compatibility Management Specification
descriptors : AV/C Descriptor Mechanism Specification

util : Various utility classes (not from specs)

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