root/trunk/libffado/src/libutil/cmd_serialize.h

Revision 824, 4.9 kB (checked in by wagi, 16 years ago)

- moved cmd_serialize.h Util:: namespace to Util::Cmd:: in order to avoid ambiguities with serialize.h
- bebob: enhanced mixer stuff added (not finished)

  • 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 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 3 of the License, or
12  * (at your option) any later version.
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 #ifndef UTIL_CMD_SERIALIZE_H
25 #define UTIL_CMD_SERIALIZE_H
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <libraw1394/raw1394.h> // byte_t and quadlet_t declaration
30 #include <string>
31
32 namespace Util {
33         namespace Cmd {
34
35 // Interfaces
36
37 class IOSSerialize {
38 public:
39     IOSSerialize() {}
40     virtual ~IOSSerialize() {}
41
42     virtual bool write( byte_t value, const char* name = "" ) = 0;
43     virtual bool write( uint16_t value, const char* name = "" ) = 0;
44     virtual bool write( quadlet_t value, const char* name = "" ) = 0;
45     virtual bool write( const char *values, size_t len, const char* name = "" ) = 0;
46 };
47
48 class IISDeserialize {
49 public:
50     IISDeserialize() {}
51     virtual ~IISDeserialize() {}
52
53     virtual bool read( byte_t* value ) = 0;
54     virtual bool read( uint16_t* value ) = 0;
55     virtual bool read( quadlet_t* value ) = 0;
56     // note that the value pointer is not valid outside deserialize()
57     virtual bool read( char** value, size_t length ) = 0;
58     virtual bool peek( byte_t* value ) = 0;
59     virtual bool peek( uint16_t* value, size_t offset )=0;
60     virtual bool skip( size_t length ) = 0;
61     virtual int getNrOfConsumedBytes()  const = 0;
62 };
63
64 // Specialized implementations of previously defined interfaces
65
66 class CoutSerializer: public IOSSerialize {
67 public:
68     CoutSerializer()
69         : IOSSerialize()
70         , m_cnt( 0 )
71         {}
72     virtual ~CoutSerializer() {}
73
74     virtual bool write( byte_t value, const char* name = "" );
75     virtual bool write( uint16_t value, const char* name = "" );
76     virtual bool write( quadlet_t value,  const char* name = "" );
77     virtual bool write( const char *values, size_t len, const char* name = "" );
78
79 private:
80     unsigned int m_cnt;
81     DECLARE_DEBUG_MODULE;
82
83 };
84
85 class StringSerializer: public IOSSerialize {
86 public:
87     StringSerializer()
88         : IOSSerialize()
89         , m_cnt( 0 )
90         {}
91     virtual ~StringSerializer() {}
92
93     virtual bool write( byte_t value, const char* name = "" );
94     virtual bool write( uint16_t value, const char* name = "" );
95     virtual bool write( quadlet_t value,  const char* name = "" );
96     virtual bool write( const char *values, size_t len, const char* name = "" );
97     virtual std::string getString( ) { return m_string;};
98
99 private:
100     unsigned int m_cnt;
101     std::string m_string;
102     DECLARE_DEBUG_MODULE;
103 };
104
105 class BufferSerialize: public IOSSerialize {
106 public:
107     BufferSerialize( unsigned char* buffer, size_t length )
108         : IOSSerialize()
109         , m_buffer( buffer )
110         , m_curPos( m_buffer )
111         , m_length( length )
112         {}
113     virtual ~BufferSerialize() {}
114
115     virtual bool write( byte_t value, const char* name = "" );
116     virtual bool write( uint16_t value, const char* name = "" );
117     virtual bool write( quadlet_t value,  const char* name = "" );
118     virtual bool write( const char *values, size_t len, const char* name = "" );
119
120     int getNrOfProducesBytes() const
121     { return m_curPos - m_buffer; }
122
123 protected:
124     inline bool isCurPosValid() const;
125
126 private:
127     unsigned char* m_buffer;
128     unsigned char* m_curPos;
129     size_t m_length;
130     DECLARE_DEBUG_MODULE;
131 };
132
133 class BufferDeserialize: public IISDeserialize {
134 public:
135     BufferDeserialize( const unsigned char* buffer, size_t length )
136         : IISDeserialize()
137         , m_buffer( const_cast<unsigned char*>( buffer ) )
138         , m_curPos( m_buffer )
139         , m_length( length )
140         {}
141     virtual ~BufferDeserialize() {}
142
143     virtual bool read( byte_t* value );
144     virtual bool read( uint16_t* value );
145     virtual bool read( quadlet_t* value );
146     // note that the value pointer is not valid outside deserialize()
147     virtual bool read( char** value, size_t length );
148     virtual bool peek( byte_t* value );
149     virtual bool peek( uint16_t* value, size_t offset );
150     virtual bool skip( size_t length );
151
152     int getNrOfConsumedBytes()  const
153         { return m_curPos - m_buffer; }
154
155 protected:
156     inline bool isCurPosValid() const;
157
158 private:
159     unsigned char* m_buffer; // start of the buffer
160     unsigned char* m_curPos; // current read pos
161     size_t m_length;         // size of buffer
162     DECLARE_DEBUG_MODULE;
163 };
164
165         }
166 }
167 #endif // UTIL_CMD_SERIALIZE_H
168
Note: See TracBrowser for help on using the browser.