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

Revision 1824, 23.3 kB (checked in by arnonym, 5 years ago)

Apply the patch from #255 (also from #278) to build on gcc4.5.

Tested here with gcc4.4 where it doesn't break:-)

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