root/trunk/libffado/src/libavc/avc_extended_subunit_info.cpp

Revision 445, 4.6 kB (checked in by pieterpalmers, 17 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

  • 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_subunit_info.h"
25 #include "avc_serialize.h"
26 #include "libieee1394/ieee1394service.h"
27
28 #include <netinet/in.h>
29
30 #define NR_OF_PAGE_DATA 5
31 #define SIZE_OF_PAGE_ENTRY 5
32
33 ExtendedSubunitInfoPageData::ExtendedSubunitInfoPageData()
34     : IBusData()
35     , m_functionBlockType( 0xff )
36     , m_functionBlockId( 0xff )
37     , m_functionBlockSpecialPupose( eSP_NoSpecialPupose )
38     , m_noOfInputPlugs( 0xff )
39     , m_noOfOutputPlugs( 0xff )
40 {
41 }
42
43 ExtendedSubunitInfoPageData::~ExtendedSubunitInfoPageData()
44 {
45 }
46
47 bool
48 ExtendedSubunitInfoPageData::serialize( IOSSerialize& se )
49 {
50     se.write( m_functionBlockType, "ExtendedSubunitInfoPageData: function block type" );
51     se.write( m_functionBlockId, "ExtendedSubunitInfoPageData: function block id" );
52     se.write( m_functionBlockSpecialPupose, "ExtendedSubunitInfoPageData: function block special purpose" );
53     se.write( m_noOfInputPlugs, "ExtendedSubunitInfoPageData: number of input plugs" );
54     se.write( m_noOfOutputPlugs, "ExtendedSubunitInfoPageData: number of output plugs" );
55
56     return true;
57 }
58
59 bool
60 ExtendedSubunitInfoPageData::deserialize( IISDeserialize& de )
61 {
62     de.read( &m_functionBlockType );
63     de.read( &m_functionBlockId );
64     de.read( &m_functionBlockSpecialPupose );
65     de.read( &m_noOfInputPlugs );
66     de.read( &m_noOfOutputPlugs );
67     return true;
68 }
69
70 ExtendedSubunitInfoPageData*
71 ExtendedSubunitInfoPageData::clone() const
72 {
73     return new ExtendedSubunitInfoPageData( *this );
74 }
75
76 //////////////////////////////////////////////
77
78 ExtendedSubunitInfoCmd::ExtendedSubunitInfoCmd( Ieee1394Service& ieee1394service )
79     : AVCCommand( ieee1394service, AVC1394_CMD_SUBUNIT_INFO )
80     , m_page( 0xff )
81     , m_fbType( eFBT_AllFunctinBlockType )
82 {
83 }
84
85 ExtendedSubunitInfoCmd::ExtendedSubunitInfoCmd( const ExtendedSubunitInfoCmd& rhs )
86     : AVCCommand( rhs )
87     , m_page( rhs.m_page )
88     , m_fbType( rhs.m_fbType )
89 {
90     for ( ExtendedSubunitInfoPageDataVector::const_iterator it =
91               rhs.m_infoPageDatas.begin();
92           it != rhs.m_infoPageDatas.end();
93           ++it )
94     {
95         m_infoPageDatas.push_back( ( *it )->clone() );
96     }
97 }
98
99 ExtendedSubunitInfoCmd::~ExtendedSubunitInfoCmd()
100 {
101     for ( ExtendedSubunitInfoPageDataVector::iterator it =
102               m_infoPageDatas.begin();
103           it != m_infoPageDatas.end();
104           ++it )
105     {
106         delete *it;
107     }
108 }
109
110 bool
111 ExtendedSubunitInfoCmd::serialize( IOSSerialize& se )
112 {
113     bool status = false;
114     status = AVCCommand::serialize( se );
115     status &= se.write( m_page, "ExtendedSubunitInfoCmd: page" );
116     status &= se.write( m_fbType, "ExtendedSubunitInfoCmd: function block type" );
117     for ( ExtendedSubunitInfoPageDataVector::const_iterator it =
118               m_infoPageDatas.begin();
119           it != m_infoPageDatas.end();
120           ++it )
121     {
122         status &= ( *it )->serialize( se );
123     }
124
125     int startIndex = m_infoPageDatas.size() * SIZE_OF_PAGE_ENTRY;
126     int endIndex = SIZE_OF_PAGE_ENTRY * NR_OF_PAGE_DATA;
127     for ( int i = startIndex; i < endIndex; ++i ) {
128         byte_t dummy = 0xff;
129         se.write( dummy, "ExtendedSubunitInfoCmd: space fill" );
130     }
131     return status;
132 }
133
134 bool
135 ExtendedSubunitInfoCmd::deserialize( IISDeserialize& de )
136 {
137     bool status = false;
138     status = AVCCommand::deserialize( de );
139     status &= de.read( &m_page );
140     status &= de.read( &m_fbType );
141     for ( int i = 0; i < 5; ++i ) {
142         byte_t next;
143         de.peek( &next );
144         if ( next != 0xff ) {
145             ExtendedSubunitInfoPageData* infoPageData =
146                 new ExtendedSubunitInfoPageData();
147             if ( !infoPageData->deserialize( de ) ) {
148                 return false;
149             }
150             m_infoPageDatas.push_back( infoPageData );
151         } else {
152             return status;
153         }
154     }
155
156     return status;
157 }
Note: See TracBrowser for help on using the browser.