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

Revision 445, 3.7 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_serialize.h"
25
26 #include <iostream>
27 #include <iomanip>
28
29 #include <netinet/in.h>
30
31 IMPL_DEBUG_MODULE( CoutSerializer, CoutSerializer, DEBUG_LEVEL_NORMAL );
32
33 bool
34 CoutSerializer::write( byte_t d, const char* name )
35 {
36     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:\t0x%02x\t%s\n", m_cnt, d, name );
37     m_cnt += sizeof( byte_t );
38
39     return true;
40 }
41
42 bool
43 CoutSerializer::write( quadlet_t d, const char* name )
44 {
45     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:\t0x%08x\t%s\n", m_cnt, d, name );
46     m_cnt += sizeof( quadlet_t );
47     return true;
48 }
49
50 //////////////////////////////////////////////////
51
52 bool
53 StringSerializer::write( byte_t d, const char* name )
54 {
55     char* result;
56     asprintf( &result, "  %3d:\t0x%02x\t%s\n", m_cnt, d, name );
57
58     m_string += result;
59     free( result );
60
61     m_cnt += sizeof( byte_t );
62
63     return true;
64 }
65
66 bool
67 StringSerializer::write( quadlet_t d, const char* name )
68 {
69     char* result;
70     asprintf( &result, "  %3d:\t0x%08x\t%s\n", m_cnt, d, name );
71
72     m_string += result;
73     free( result );
74
75     m_cnt += sizeof( quadlet_t );
76     return true;
77 }
78
79 //////////////////////////////////////////////////
80
81 bool
82 BufferSerialize::write( byte_t value, const char* name )
83 {
84     bool result = false;
85     if ( isCurPosValid() ) {
86         *m_curPos = value;
87         m_curPos += sizeof( byte_t );
88         result = true;
89     }
90     return result;
91 }
92
93 bool
94 BufferSerialize::write( quadlet_t value,  const char* name )
95 {
96     bool result = false;
97     if ( isCurPosValid() ) {
98         * ( quadlet_t* )m_curPos = value;
99         m_curPos += sizeof( quadlet_t );
100         result = true;
101     }
102     return result;
103 }
104
105 bool
106 BufferSerialize::isCurPosValid() const
107 {
108     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
109         return false;
110     }
111     return true;
112 }
113
114 //////////////////////////////////////////////////
115
116 bool
117 BufferDeserialize::read( byte_t* value )
118 {
119     bool result = false;
120     if ( isCurPosValid() ) {
121         *value = *m_curPos;
122         m_curPos += sizeof( byte_t );
123         result = true;
124     }
125     return result;
126 }
127
128 bool
129 BufferDeserialize::read( quadlet_t* value )
130 {
131     bool result = false;
132     if ( isCurPosValid() ) {
133         *value = *( ( quadlet_t* )m_curPos );
134         m_curPos += sizeof( quadlet_t );
135         result = true;
136     }
137     return result;
138 }
139
140 bool
141 BufferDeserialize::read( char** value, size_t length )
142 {
143     bool result = false;
144     if ( isCurPosValid() ) {
145         *value = ( char* )m_curPos;
146         m_curPos += length;
147         result = true;
148     }
149     return result;
150 }
151
152 bool
153 BufferDeserialize::peek( byte_t* value )
154 {
155     bool result = false;
156     if ( isCurPosValid() ) {
157         *value = *m_curPos;
158         result = true;
159     }
160     return result;
161 }
162
163 bool
164 BufferDeserialize::isCurPosValid() const
165 {
166     if ( static_cast<size_t>( ( m_curPos - m_buffer ) ) >= m_length ) {
167         return false;
168     }
169     return true;
170 }
171
Note: See TracBrowser for help on using the browser.