Statistics
| Branch: | Tag: | Revision:

root / README.hacking @ master

History | View | Annotate | Download (9.1 kB)

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
33
* C++ and Python
34
35
GNU Radio is now a hybrid system.  Some parts of the system are built
36
in C++ and some of it in Python.  In general, prefer Python to C++.
37
Signal processing primitives are still built in C++ for performance.
38
39
40
* C++ namespaces
41
42
In the cleanup process, I considered putting everything in the
43
gnuradio namespace and dropping the Gr|gr prefix.  In fact, I think
44
it's probably the right idea, but when I tested it out, I ran into
45
problems with SWIG's handling of namespaces.  Bottom line, SWIG
46
(1.3.21) got confused and generated bad code when I started playing
47
around with namespaces in a not particularly convoluted way.  I saw
48
problems using the boost::shared_ptr template in combination with
49
classes defined in the gnuradio namespace.  It wasn't pretty...
50
51
52
* Naming conventions
53
54
Death to CamelCaseNames!  We've returned to a kinder, gentler era.
55
We're now using the "STL style" naming convention with a couple of
56
modifications since we're not using namespaces.
57
58
With the exception of macros and other constant values, all
59
identifiers shall be lower case with words_separated_like_this.
60
61
Macros and constant values (e.g., enumerated values,
62
static const int FOO = 23) shall be in UPPER_CASE.
63
64
65
** Global names
66
67
All globally visible names (types, functions, variables, consts, etc)
68
shall begin with a "package prefix", followed by an '_'.  The bulk of
69
the code in GNU Radio logically belongs to the "gr" package, hence
70
names look like gr_open_file (...).
71
72
Large coherent bodies of code may use other package prefixes, but
73
let's try to keep them to a well thought out list.  See the list
74
below.
75
76
*** Package prefixes
77
78
These are the current package prefixes:
79
80
    gr_		Almost everything
81
82
    gri_	Implementation primitives.  Sometimes we
83
		have both a gr_<foo> and a gri_<foo>.  In that case,
84
		gr_<foo> would be derived from gr_block and gri_<foo>
85
		would be the low level guts of the function.
86
87
    atsc_	Code related to the Advanced Television
88
	       	Standards Committee HDTV implementation
89
90
    qa_		Quality Assurance.  Test code.
91
92
93
** Class data members (instance variables)
94
95
All class data members shall begin with d_<foo>.
96
97
The big win is when you're staring at a block of code it's obvious
98
which of the things being assigned to persist outside of the block.
99
This also keeps you from having to be creative with parameter names
100
for methods and constructors.  You just use the same name as the
101
instance variable, without the d_.
102
103
class gr_wonderfulness {
104
  std::string	d_name;
105
  double	d_wonderfulness_factor;
106
107
public:
108
  gr_wonderfulness (std::string name, double wonderfulness_factor)
109
    : d_name (name), d_wonderfulness_factor (wonderfulness_factor)
110
  {
111
    ...
112
  }
113
  ...
114
};
115
116
117
** Class static data members (class variables)
118
119
All class static data members shall begin with s_<foo>.
120
121
122
** File names
123
124
Each significant class shall be contained in it's own file.  The
125
declaration of class gr_foo shall be in gr_foo.h, the definition in
126
gr_foo.cc.
127
128
129
130
* Storage management
131
132
Strongly consider using the boost smart pointer templates, scoped_ptr
133
and shared_ptr.  scoped_ptr should be used for locals that contain
134
pointers to objects that we need to delete when we exit the current
135
scope.  shared_ptr implements transparent reference counting and is a
136
major win.  You never have to worry about calling delete.  The right
137
thing happens.
138
139
See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
140
141
142
* Unit tests
143
144
Build unit tests for everything non-trivial and run them after every
145
change.  Check out Extreme Programming:
146
http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap
147
148
Unit tests should also be written for all examples.  This should kill
149
off the bit rot we've been plagued with.
150
151
** C++ unit tests
152
153
For C++ we're using the cppunit framework.  cppunit has its bad
154
smells, but it's mostly workable.  http://cppunit.sf.net
155
156
Currently each directory <dirname> contains files qa_<dirname>.{h,cc}
157
that bring together all the qa_<foo> test suites in the directory.
158
We ought to be able to automate this without too much trouble.
159
160
The directory gnuradio-core/src/tests contains programs that run
161
the tests.  test_all runs all of the registered C++ unit tests.
162
163
As far as I can tell, the cppunit TestFactoryRegistry maybe able to be
164
tricked into doing what we want.  As is, I don't think it's enough by
165
itself, since there's nothing dragging the qa* files out of the
166
library and into the program.   I haven't tested out this idea.
167
168
** Python unit tests
169
170
We use the standard unittest package for unit testing of Python code.
171
172
173
174
* Standard command line options
175
176
When writing programs that are executable from the command line,
177
please follow these guidelines for command line argument names (short
178
and long) and types of the arguments.  We list them below using the
179
Python optparse syntax.  In general, the default value should be coded
180
into the help string using the "... [default=%default]" syntax.
181
182
** Mandatory options by gr_block
183
184
*** Audio source
185
186
Any program using an audio source shall include:
187
188
  add_option("-I", "--audio-input", type="string", default="",
189
             help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
190
191
The default must be "".  This allows an audio module-dependent default
192
to be specified in the user preferences file.
193
194
195
*** Audio sink
196
197
  add_option("-O", "--audio-output", type="string", default="",
198
             help="pcm output device name.  E.g., hw:0,0 or /dev/dsp")
199
200
The default must be "".  This allows an audio module-dependent default
201
to be specified in the user preferences file.
202
203
204
** Standard options names by parameter
205
206
Whenever you want an integer, use the "intx" type.  This allows the
207
user to input decimal, hex or octal numbers.  E.g., 10, 012, 0xa.
208
209
Whenever you want a float, use the "eng_float" type.  This allows the
210
user to input numbers with SI suffixes.  E.g, 10000, 10k, 10M, 10m, 92.1M
211
212
If your program allows the user to specify values for any of the
213
following parameters, please use these options to specify them:
214
215
216
To specify a frequency (typically an RF center frequency) use:
217
218
  add_option("-f", "--freq", type="eng_float", default=<your-default-here>,
219
             help="set frequency to FREQ [default=%default]")
220
221
222
To specify a decimation factor use:
223
224
  add_option("-d", "--decim", type="intx", default=<your-default-here>,
225
             help="set decimation rate to DECIM [default=%default]")
226
227
228
To specify an interpolation factor use:
229
230
  add_option("-i", "--interp", type="intx", default=<your-default-here>,
231
             help="set interpolation rate to INTERP [default=%default]")
232
233
234
To specify a gain setting use:
235
236
  add_option("-g", "--gain", type="eng_float", default=<your-default-here>,
237
	     help="set gain in dB [default=%default]")
238
239
240
If your application specifies both a tx and an rx gain, use:
241
242
  add_option("", "--rx-gain", type="eng_float", default=<your-default-here>,
243
	     help="set receive gain in dB [default=%default]")
244
245
  add_option("", "--tx-gain", type="eng_float", default=<your-default-here>,
246
	     help="set transmit gain in dB [default=%default]")
247
248
249
To specify the number of channels of something use:
250
251
  add_option("-n", "--nchannels", type="intx", default=1,
252
             help="specify number of channels [default=%default]")
253
254
255
To specify an output filename use:
256
257
  add_option("-o", "--output-filename", type="string", default=<your-default-here>,
258
             help="specify output-filename [default=%default]")
259
260
261
To specify a rate use:
262
263
  add_option("-r", "--bit-rate", type="eng_float", default=<your-default-here>,
264
             help="specify bit-rate [default=%default]")
265
     or
266
267
  add_option("-r", "--sample-rate", type="eng_float", default=<your-default-here>,
268
             help="specify sample-rate [default=%default]")
269
270
271
If your application has a verbose option, use:
272
273
  add_option('-v', '--verbose', action="store_true", default=False,
274
	     help="verbose output")
275
276
277
If your application allows the user to specify the "fast USB" options, use:
278
279
  add_option("", "--fusb-block-size", type="intx", default=0,
280
             help="specify fast usb block size [default=%default]")
281
282
  add_option("", "--fusb-nblocks", type="intx", default=0,
283
             help="specify number of fast usb blocks [default=%default]")