gr-qtgui: add include file for gcc 4.4.1
[debian/gnuradio] / README.hacking
1 # -*- Outline -*-
2 #
3 # Copyright 2004,2007,2008,2009 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 Random notes on coding conventions, some explanations about why things
24 aren't done differently, etc, etc,
25
26
27 * Boost 1.35
28
29 Until boost 1.35 or later is common in distributions, you'll need to
30 build boost from source yourself.  See README.building-boost.
31
32 Also, when running make distcheck you'll need to provide the
33 DISTCHECK_CONFIGURE_FLAGS.  E.g.,
34
35   $ make distcheck DISTCHECK_CONFIGURE_FLAGS=--with-boost=/opt/boost_1_36_0
36
37
38 * C++ and Python
39
40 GNU Radio is now a hybrid system.  Some parts of the system are built
41 in C++ and some of it in Python.  In general, prefer Python to C++.
42 Signal processing primitives are still built in C++ for performance.
43
44
45 * C++ namespaces
46
47 In the cleanup process, I considered putting everything in the
48 gnuradio namespace and dropping the Gr|gr prefix.  In fact, I think
49 it's probably the right idea, but when I tested it out, I ran into
50 problems with SWIG's handling of namespaces.  Bottom line, SWIG
51 (1.3.21) got confused and generated bad code when I started playing
52 around with namespaces in a not particularly convoluted way.  I saw
53 problems using the boost::shared_ptr template in combination with
54 classes defined in the gnuradio namespace.  It wasn't pretty...
55
56
57 * Naming conventions
58
59 Death to CamelCaseNames!  We've returned to a kinder, gentler era.
60 We're now using the "STL style" naming convention with a couple of
61 modifications since we're not using namespaces.
62
63 With the exception of macros and other constant values, all
64 identifiers shall be lower case with words_separated_like_this.
65
66 Macros and constant values (e.g., enumerated values,
67 static const int FOO = 23) shall be in UPPER_CASE.
68
69
70 ** Global names
71
72 All globally visible names (types, functions, variables, consts, etc)
73 shall begin with a "package prefix", followed by an '_'.  The bulk of
74 the code in GNU Radio logically belongs to the "gr" package, hence
75 names look like gr_open_file (...).
76
77 Large coherent bodies of code may use other package prefixes, but
78 let's try to keep them to a well thought out list.  See the list
79 below.
80
81 *** Package prefixes
82
83 These are the current package prefixes:
84
85     gr_         Almost everything
86
87     gri_        Implementation primitives.  Sometimes we
88                 have both a gr_<foo> and a gri_<foo>.  In that case,
89                 gr_<foo> would be derived from gr_block and gri_<foo>
90                 would be the low level guts of the function.
91
92     atsc_       Code related to the Advanced Television
93                 Standards Committee HDTV implementation
94
95     usrp_       Universal Software Radio Peripheral
96
97     qa_         Quality Assurance.  Test code.
98
99
100 ** Class data members (instance variables)
101
102 All class data members shall begin with d_<foo>.
103
104 The big win is when you're staring at a block of code it's obvious
105 which of the things being assigned to persist outside of the block.
106 This also keeps you from having to be creative with parameter names
107 for methods and constructors.  You just use the same name as the
108 instance variable, without the d_. 
109
110 class gr_wonderfulness {
111   std::string   d_name;
112   double        d_wonderfulness_factor;
113
114 public:
115   gr_wonderfulness (std::string name, double wonderfulness_factor)
116     : d_name (name), d_wonderfulness_factor (wonderfulness_factor)
117   {
118     ...
119   }
120   ...
121 };
122
123
124 ** Class static data members (class variables)
125
126 All class static data members shall begin with s_<foo>.
127
128
129 ** File names
130
131 Each significant class shall be contained in it's own file.  The
132 declaration of class gr_foo shall be in gr_foo.h, the definition in
133 gr_foo.cc.
134
135
136
137 * Storage management
138
139 Strongly consider using the boost smart pointer templates, scoped_ptr
140 and shared_ptr.  scoped_ptr should be used for locals that contain
141 pointers to objects that we need to delete when we exit the current
142 scope.  shared_ptr implements transparent reference counting and is a
143 major win.  You never have to worry about calling delete.  The right
144 thing happens.
145
146 See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
147
148
149 * Unit tests
150
151 Build unit tests for everything non-trivial and run them after every
152 change.  Check out Extreme Programming: 
153 http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap
154
155 Unit tests should also be written for all examples.  This should kill
156 off the bit rot we've been plagued with.
157
158 ** C++ unit tests
159
160 For C++ we're using the cppunit framework.  cppunit has its bad
161 smells, but it's mostly workable.  http://cppunit.sf.net
162
163 Currently each directory <dirname> contains files qa_<dirname>.{h,cc}
164 that bring together all the qa_<foo> test suites in the directory.
165 We ought to be able to automate this without too much trouble.
166
167 The directory gnuradio-core/src/tests contains programs that run
168 the tests.  test_all runs all of the registered C++ unit tests.
169
170 As far as I can tell, the cppunit TestFactoryRegistry maybe able to be
171 tricked into doing what we want.  As is, I don't think it's enough by
172 itself, since there's nothing dragging the qa* files out of the
173 library and into the program.   I haven't tested out this idea.
174
175 ** Python unit tests
176
177 We use the standard unittest package for unit testing of Python code.
178
179
180 * Subversion line ending styles
181
182 All text files in the tree should have the subversion property 
183 'svn:eol-style' set to 'native', with the following exceptions:
184
185 config/*.m4
186 configure.ac
187 gr-howto-write-a-block/config/*.m4
188 gr-howto-write-a-block/configure.ac
189
190 The easiest way to ensure this is to add or edit the following lines in
191 your svn client configuration file (~/.subversion/config):
192
193 enable-auto-props=yes
194
195 [auto-props]
196 *.c = svn:eol-style=native
197 *.cc = svn:eol-style=native  
198 *.i = svn:eol-style=native
199 *.h = svn:eol-style=native
200 *.am = svn:eol-style=native
201 *.py = svn:eol-style=native
202 *.ac = svn:eol-style=LF
203 *.m4 = svn:eol-style=LF
204
205 * Misc tips
206
207 ccache, a compiler cache, can really speed up your builds.
208 See http://ccache.samba.org/
209
210 Be sure to create links for gcc and g++
211
212
213 * Standard command line options
214
215 When writing programs that are executable from the command line,
216 please follow these guidelines for command line argument names (short
217 and long) and types of the arguments.  We list them below using the
218 Python optparse syntax.  In general, the default value should be coded
219 into the help string using the "... [default=%default]" syntax.
220
221 ** Mandatory options by gr_block
222
223 *** USRP source
224
225 Any program using a USRP source (usrp.source_*) shall include:
226
227   add_option("", "--which-usrp", type="intx", default=0,
228              help="select which USRP to use [default=%default]")
229
230   add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
231              help="select USRP Rx side A or B [default=A]")
232
233 You are free to change the default if it makes sense in your application.
234
235
236 *** USRP sink
237
238 Any program using a USRP sink (usrp.sink_*) shall include:
239
240   add_option("", "--which-usrp", type="intx", default=0,
241              help="select which USRP to use [default=%default]")
242
243   add_option("-T", "--tx-subdev-spec", type="subdev", default=(0, 0),
244              help="select USRP Tx side A or B [default=A]")
245
246 You are free to change the default if it makes sense in your application.
247
248
249 *** Audio source
250
251 Any program using an audio source shall include:
252
253   add_option("-I", "--audio-input", type="string", default="",
254              help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
255
256 The default must be "".  This allows an audio module-dependent default
257 to be specified in the user preferences file.
258
259
260 *** Audio sink
261
262   add_option("-O", "--audio-output", type="string", default="",
263              help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
264
265 The default must be "".  This allows an audio module-dependent default
266 to be specified in the user preferences file.
267
268
269 ** Standard options names by parameter
270
271 Whenever you want an integer, use the "intx" type.  This allows the
272 user to input decimal, hex or octal numbers.  E.g., 10, 012, 0xa.
273
274 Whenever you want a float, use the "eng_float" type.  This allows the
275 user to input numbers with SI suffixes.  E.g, 10000, 10k, 10M, 10m, 92.1M
276
277 If your program allows the user to specify values for any of the
278 following parameters, please use these options to specify them:
279
280
281 To specify a frequency (typically an RF center frequency) use:
282
283   add_option("-f", "--freq", type="eng_float", default=<your-default-here>,
284              help="set frequency to FREQ [default=%default]")
285
286
287 To specify a decimation factor use:
288
289   add_option("-d", "--decim", type="intx", default=<your-default-here>,
290              help="set decimation rate to DECIM [default=%default]")
291
292
293 To specify an interpolation factor use:
294
295   add_option("-i", "--interp", type="intx", default=<your-default-here>,
296              help="set interpolation rate to INTERP [default=%default]")
297
298
299 To specify a gain setting use:
300
301   add_option("-g", "--gain", type="eng_float", default=<your-default-here>,
302              help="set gain in dB [default=%default]")
303
304
305 If your application specifies both a tx and an rx gain, use:
306
307   add_option("", "--rx-gain", type="eng_float", default=<your-default-here>,
308              help="set receive gain in dB [default=%default]")
309
310   add_option("", "--tx-gain", type="eng_float", default=<your-default-here>,
311              help="set transmit gain in dB [default=%default]")
312
313
314 To specify the number of channels of something use:
315
316   add_option("-n", "--nchannels", type="intx", default=1,
317              help="specify number of channels [default=%default]")
318
319
320 To specify an output filename use:
321
322   add_option("-o", "--output-filename", type="string", default=<your-default-here>,
323              help="specify output-filename [default=%default]")
324
325
326 To specify a rate use:
327
328   add_option("-r", "--bit-rate", type="eng_float", default=<your-default-here>,
329              help="specify bit-rate [default=%default]")
330      or
331
332   add_option("-r", "--sample-rate", type="eng_float", default=<your-default-here>,
333              help="specify sample-rate [default=%default]")
334   
335
336 If your application has a verbose option, use:
337
338   add_option('-v', '--verbose', action="store_true", default=False,
339              help="verbose output")
340
341
342 If your application allows the user to specify the "fast USB" options, use: 
343
344   add_option("", "--fusb-block-size", type="intx", default=0,
345              help="specify fast usb block size [default=%default]")
346
347   add_option("", "--fusb-nblocks", type="intx", default=0,
348              help="specify number of fast usb blocks [default=%default]")