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

Revision 618, 23.3 kB (checked in by ppalmers, 17 years ago)

move serialization routines to libutil such that they can be used for non-AVC stuff too (fireworks EFC)

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