]> sigrok.org Git - libsigrokdecode.git/blob - HACKING
guess_bitrate: start() doesn't take a metadata argument anymore.
[libsigrokdecode.git] / HACKING
1 -------------------------------------------------------------------------------
2 HACKING
3 -------------------------------------------------------------------------------
4
5 Coding style
6 ------------
7
8 This project is programmed using the Linux kernel coding style, see
9 http://lxr.linux.no/linux/Documentation/CodingStyle for details.
10
11 Please use the same style for any code contributions, thanks!
12
13 The Python decoders should follow the usual Python conventions and use
14 Python idioms as far as it makes sense. The coding style should mostly follow
15 the Python PEP-8, which includes the convention of 4 spaces for indentation.
16 See http://www.python.org/dev/peps/pep-0008/ for details.
17
18
19 Contributions
20 -------------
21
22  - Patches should be sent to the development mailinglist at
23    sigrok-devel@lists.sourceforge.net (please subscribe to the list first).
24
25    https://lists.sourceforge.net/lists/listinfo/sigrok-devel
26
27  - Alternatively, you can also clone the git repository and let us know
28    from where to pull/review your changes. You can use gitorious.org,
29    github.com, or any other public git hosting site.
30
31
32 Random notes
33 ------------
34
35  - Consistently use g_try_malloc() / g_try_malloc0(). Do not use standard
36    malloc()/calloc() if it can be avoided (sometimes other libs such
37    as libftdi can return malloc()'d memory, for example).
38
39  - Always properly match allocations with the proper *free() functions. If
40    glib's g_try_malloc()/g_try_malloc0() was used, use g_free() to free the
41    memory. Otherwise use standard free(). Never use the wrong function!
42
43  - Never use g_malloc() or g_malloc0(). These functions do not return NULL
44    if not enough memory is available but rather lead to an exit() or segfault
45    instead. This behaviour is not acceptable for libraries.
46    Use g_try_malloc()/g_try_malloc0() instead and check the return value.
47
48  - You should never print any messages (neither to stdout nor stderr nor
49    elsewhere) "manually" via e.g. printf() or g_log() or similar functions.
50    Only srd_err()/srd_warn()/srd_info()/srd_dbg()/srd_spew() should be used.
51
52  - Use glib's gboolean / TRUE / FALSE for boolean types consistently.
53    Do not use <stdbool.h> and its true / false, and do not invent private
54    definitions for this either.
55
56  - Consistently use the same naming convention for #include guards in headers:
57    <PROJECTNAME>_<PATH_TO_FILE>_<FILE>
58    This ensures that all #include guards are always unique and consistent.
59    Example: LIBSIGROKDECODE_SIGROKDECODE_INTERNAL_H
60
61  - Consistently use the same naming convention for API functions:
62    <libprefix>_<groupname>_<action>().
63
64    Examples:
65      srd_log_loglevel_set(), srd_log_loglevel_get(), srd_log_handler_set(),
66      srd_log_handler_set_default(), and so on.
67
68    Getter/setter function names should usually end with "_get" or "_set".
69    Functions creating new "objects" should end with "_new".
70    Functions destroying "objects" should end with "_destroy".
71    Functions adding or removing items (e.g. from lists) should end with
72    either "_add" or "_remove".
73    Functions operating on all items from a list (not on only one of them),
74    should end with "_all", e.g. "_remove_all", "_get_all", and so on.
75    Use "_remove_all" in favor of "_clear" for consistency.
76
77
78 Doxygen
79 -------
80
81  - In Doxygen comments, put an empty line between the block of @param lines
82    and the final @return line. The @param lines themselves (if there is more
83    than one) are not separated by empty lines.
84
85  - Mark private functions (SRD_PRIV) with /** @private */, so that Doxygen
86    doesn't include them in the output. Functions that are "static" anyway
87    don't need to be marked like this.
88
89  - Mark private variables/#defines with /** @cond PRIVATE */ and
90    /** @endcond */, so that Doxygen doesn't include them in the output.
91    Variables that are "static" don't need to be marked like this.
92
93  - Mark all public API functions (SRD_API) with a @since tag which indicates
94    in which release the respective function was added. If the function has
95    existed before, but its API changed later, document this as well.
96
97    Non-public functions (static ones, and those marked SRD_PRIV) don't need
98    to have @since markers.
99
100    The @since tag should be the last one, i.e. it should come after @param,
101    @return, @see, and so on.
102
103    Examples:
104
105      @since 0.1.0
106
107      @since 0.1.1 (but the API changed in 0.2.0)
108
109
110 Protocol decoder guidelines
111 ---------------------------
112
113  - The 'desc' metadata field for a protocol decoder, which contains a
114    short, one-line description of the protocol/bus, should be at most 55
115    characters long, and end with a full stop. This short description can be
116    displayed on the command-line using "sigrok-cli -V -l 3", or in various
117    different places in GUIs.
118
119  - Longer, multi-line descriptions should be placed in the protocol
120    decoder's __init__.py file as docstring. It can be viewed (for a specific
121    protocol decoder, e.g., UART) via "sigrok-cli -a uart", or in various
122    other places in GUIs.
123
124  - Generally use strings for states (of the PD state machine), not integers.
125    This avoids having to keep a list of state definitions at the top of file.
126    The performance overhead for this is negligible in practice.
127
128    Recommended:
129      self.state = 'IDLE'
130      self.state = 'GET STOP BIT'
131    Not recommended:
132      self.state = IDLE
133      self.state = GET_STOP_BIT
134      (where IDLE = 0 and GET_STOP_BIT = 1, for example)
135
136  - Generally use strings for commands/IDs in generated protocol packets.
137    This avoids having to know magic numbers of the PD in higher-level PDs.
138    The performance overhead for this is negligible in practice.
139
140    Recommended:
141      self.put(x, y, p, ['STOPBIT', 0, 0])
142      self.put(x, y, p, ['ADDRESS READ', 0x51])
143    Not recommended:
144      self.put(x, y, p, [STOPBIT, 0, 0])
145      self.put(x, y, p, [ADDRESS_READ, 0x51])
146      (with STOPBIT = 3 and ADDRESS_READ = 7, for example)
147
148  - Use ALL-CAPS names for PD states and protocol packet commands/ID.
149    Words should be separated by spaces (not underscores or the like).
150
151    Recommended:
152      'FIND ADDRESS', 'GET TEMPERATURE', 'START'
153    Not recommended:
154      'FIND_ADDRESS', 'Get Temperature', 'start'
155
156
157 Release engineering
158 -------------------
159
160 See
161
162  http://sigrok.org/wiki/Developers/Release_process
163
164 for a list of items that need to be done when releasing a new tarball.
165