Documented coding guidelines (file naming, class naming etc)
[senf.git] / Mainpage.dox
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \mainpage SENF: The Simple and Extensible Network Framework
22
23     The SENF Simple and Extensible Network Framework aims to be a complete set of libraries to
24     facilitate the development of network applications focusing on network protocols on the layers
25     below the application layer. However, the framework includes many general purpose utilities and
26     will be expedient to use well beyond its primary objective.
27
28     \section Goals
29
30     The main goals of this library are (in no particular order):
31
32     \li modular framework design
33     \li utilizing the power of modern C++
34     \li very low overhead for frequently called members
35     \li extensible design
36     \li concise interface
37
38     \section start Getting started
39
40     To get started using this library, begin by checking out the code from the <a
41     href="http://developer.berlios.de/svn/?group_id=7489">BerliOS SVN repository</a>. You may find
42     help on using the library at '\ref usage'. If you are interested in SENF, feel free to subscribe
43     to the <a href="http://developer.berlios.de/mail/?group_id=7489">SENF mailing lists</a>. If you
44     want to contribute, read the docs and \e please adhere to the \ref conventions.
45
46     \see \ref usage\n
47          \ref example
48 */
49
50 /** \page usage Using the SENF framework
51
52     The SENF Framework is a collection of loosely coupled modules. The libraries are heavily object
53     oriented and template based. For compatibility reasons, the libraries are therefore built
54     together with every project making use of the framework.
55
56     When starting a new Projekt based on the SENF framework, it is advisable, to make use of the
57     SENFSCons build environment and use SVN to manage the code repository. This is the
58     configuration, described in this documentation.
59
60     \see \ref build \n
61          \ref components \n
62          \ref svnsetup \n
63          \ref overview
64
65     \section Preliminaries
66
67     Before starting the devlopment, make sure to fulfill the following requirements:
68
69     \li GNU g++, version at least 3.4
70     \li The Boost libraries (http://www.boost.org)
71     \li The SCons build tool (http://www.scons.org)
72
73     If you want to build the documentation, you additionally need
74
75     \li Doxygen (http://www.doxygen.org)
76     \li The \c dia diagram editor (http://www.gnome.org/projects/dia/)
77     \li HTML \c tidy (http://tidy.sourceforge.net/)
78     \li The \c xsltproc XSLT processor (http://xmlsoft.org/XSLT/xsltproc2.html)
79
80
81     The library is only tested with gcc-3.4 and 4.0 on Linux. On other POSIX platforms with a BSD
82     Socket API, the library should be usable, possibly with some tweaking (except for the Scheduler,
83     which relies on \c epoll)
84  */
85
86 /** \page build Building the framework
87
88     This procedure will test building the complete framework including the unit tests and the
89     Sniffer test application. This build is \e not needed to use the framework since every project
90     will include the full SENF source code itself (via Subversion).
91
92     After you have successfully built the library tests, you can continue to setup your own project
93     using SENF.
94
95     \see \ref components \n
96          \ref svnsetup
97
98     \section checkout Getting the code
99
100     To access the code, check out the code from the BerliOS repository. Change to your development
101     directory and use the following subversion command
102
103     <pre>
104     $ svn checkout http://svn.berlios.de/svnroot/repos/senf/trunk senf
105     </pre>
106
107     This will create a new directory \c senf within the current directory. For further documentation
108     on the use of Subversion, see the \c svn manpage or the subversion homepage at
109     http://subversion.tigris.org. A very good introduction and reference to subversion is available
110     at http://svnbook.red-bean.com.
111
112     \section compile Building
113
114     To build the library, execute all unit tests and build the Sniffer test application, use
115
116     <pre>
117     $ scons
118     $ scons all_tests
119     </pre>
120
121     in the \c senf directory. This assumes, that you want to build the library with your default gcc
122     and requires the boost libraries to be available in the system include paths. If this is not the
123     case, you can take a look at <tt>SConfig.template</tt> file. Copy this file to <tt>SConfig</tt>
124     and comment out all the variables you don't want to change (The \e values in the template file
125     are just arbitrary examples).
126  */
127
128 /** \page components The SENF modules
129
130     The framework is made up of several modular components. When using the library, it is possible
131     to selectively choose to use only a subset of the implemented modules.
132
133     \see \ref build \n
134          \ref svnsetup
135
136     \section libSocket libSocket: C++ abstraction of the BSD socket API
137
138     This library provides a high performance and object oriented abstraction of the standard socket
139     API. It utilizes a flexible and extensible policy based design. The library provides predefined
140     types for the important socket types (UDP and TCP sockets etc) including raw and packet
141     sockets. \n
142
143     \see <a href="../../Socket/doc/html/index.html">libSocket API
144     reference</a>
145
146     \section libPackets libPackets: Network packet manipulation
147
148     This libarary provides a very flexible infrastructure to parse, create and otherwise manipulate
149     packetized network data. Included is a library of several protocol parsers covering the basic
150     IPv4 and IPv6 network protocols down to the Ethernet layer.
151
152     \see <a href="../../Packets/doc/html/index.html">libPackets API
153     reference</a>
154
155     \section libScheduler libScheduler: Asynchronous event handling
156
157     The scheduler library provides an object oriented interface to the standard UNIX \c select type
158     event dispatcher. It is based on the high performance \c epoll system call. It provides support
159     for read/write events as well as simple timer based events.
160
161     \see <a href="../../Scheduler/doc/html/index.html">libScheduler API reference</a>
162
163     \section libUtils libUtils: Collection of arbitrary utilities
164
165     This library is used be most all of the other modules for miscellaneous tools and utilities. We
166     have
167
168     \li Simple functions to manage daemon processes
169     \li Standard exception classes
170     \li senf::intrusive_refcount to simplify the implementation of classes usable with
171         boost::intrusive_ptr
172     \li boost::bind extensions
173     \li An interface to the \c g++ demangler integrated with type_info
174     \li Typedefs and rudimentary methods to simplify handling high-resolution time values
175
176     \see <a href="../../Utils/doc/html/index.html">libUtils API reference</a>
177
178     \section senfscons SENFSCons, the SENF build environment
179
180     SENF relies on SCons (http://www.scons.org) to build. To further simplify the common tasks, SENF
181     includes a library of custom routines and builders comprising a very concise build
182     environment. Included are a number of templates to help bootstrapping a new project or
183     component.
184
185     \see <a href="../../senfscons/doc/html/index.html">SENFSCons reference</a>
186  */
187
188 /** \page svnsetup Setting up a new project using SENF
189
190     The preferred way to use SENF in a new project is to rely on Subversion and make use of the
191     SENFSCons build environment. The following sections will describe, how this setup works.
192
193     \see \ref build \n
194          \ref components \n
195          \ref overview
196
197     \section svnext Setting up the project repository
198
199     The most seamless integration is possible if you rely on Subversion to manage the new
200     project. Subversion does support 'external repositories'. This allows to import code from a
201     foreign repository into the checkout without importing it into your repository. The code will
202     always stay at the remote repository, updates are automatically available.
203
204     First setup a new empty repository as described for example in the Subversion book at
205     http://svnbook.red-bean.com or as mandated by your site policy. We will call the project 'Foo'
206     and assume, that the project has been checked out into the 'Foo' directory.
207
208     You now have to decide, which modules you want to use. Every module resides in it's own
209     subdirectory in the SENF repository. Instead of directly checking out the code, we will use \c
210     svn:externals. This will instruct \c svn to auutomatically check out the needed directories from
211     the BerliOS SENF repository. Change to the 'Foo' directory and type
212
213     <pre>
214     $ svn propedit svn:externals .
215     </pre>
216
217     The default editor (probably VI) will be started with the current value of the svn:externals
218     property (which will probably be empty). Now add all the modules you want plus \c senfscons and
219     possibly \c doclib (if you want to build the documentation). You will almost certainly neeed the
220     \c Utils module, since all other modules depend on it.
221
222     For example, if you want to use the \c Scheduler and \c Socket module, the file will look like
223
224     <pre>
225     senfscons http://svn.berlios.de/svnroot/repos/senf/trunk/senfscons
226     Utils http://svn.berlios.de/svnroot/repos/senf/trunk/Utils
227     Scheduler http://svn.berlios.de/svnroot/repos/senf/trunk/Scheduler
228     Socket http://svn.berlios.de/svnroot/repos/senf/trunk/Socket
229     </pre>
230
231     exit the editor and the property will be set. Now run
232
233     <pre>
234     $ svn update
235     </pre>
236
237     and the code will be checked out into the corresponding directories.
238
239     \section new_conf Configuring SENFSCons
240
241     To set up the build environment, copy the <tt>senfscons/SConstruct.template</tt> to
242     <tt>SConstruct</tt> in the project root. The default setup of this file is to build all
243     subdirectories (using the \c SConscript files of the subdirectories). You can add additonal
244     global targets and configuration parameters here.
245
246     If you want to use a non-default compiler or the boost library is not installed in the system
247     directories, you will have to copy <tt>senfscons/SConfig.template</tt> to <tt>SConfig</tt> in
248     the project root and edit it there. You should \e never add \c SConfig to the repository since
249     it should only contain local settings necessary for building on your local system. You should
250     therefore add \c SConfig to the list of files ignored by Subversion in the project root. In the
251     project root execute
252
253     <pre>
254     $ svn propedit svn:ignore .
255     </pre>
256
257     and add \c SConfig as a new line to the property.
258
259     \section new_build Building the project
260
261     You should now be able to build your project using
262
263     <pre>
264     $ scons
265     </pre>
266
267     If you have not changed the \c SConstruct file, this will build all modules you have importet
268     into your project. To build and execute the unit tests, use
269
270     <pre>
271     $ scons all_tests
272     </pre>
273
274     you can also build only a subdirectory by changing to it and running
275
276     <pre>
277     $ scons -u [target]
278     </pre>
279
280     \see <a href="../../senfscons/doc/html/index.html">SENFSCons reference</a> \n
281          <a class="ext" href="http://www.scons.org/documentation.php">SCons documentation</a> \n
282          <a class="ext" href="http://svnbook.red-bean.com">Subversion online book</a> \n
283          <a class="ext" href="http://subversion.tigris.org">Subversion Homepage</a>
284  */
285
286 /** \page overview Introduction to the framework
287
288     The SENF framework is relatively complex and makes use of advanced features of the C++
289     language. To make the most efficient use of the framework, you should have at least a basic
290     understanding of C++ templates and the standard library concepts.
291
292     The library implementation at places makes heavy use of advanced template techniques and relies
293     on some very advanced template libraries from Boost. The aim was however for the \e external
294     interface of the library to be as simple as possible without sacrificing important functionality
295     or adversely impacting the runtime performance.
296
297     As already mentioned several times, the library relies on Boost (http://www.boost.org) as a
298     generic library of high quality reusable C++ components. It also makes frequent use of the
299     standard library. It is designed, to integrate well into both libraries and to use the same
300     concepts and ideas.
301
302     \section startup Getting starting developing with SENF
303
304     To introduce the framework and it's general structure, a simple example application is provided
305     in the SENF repository in the \c Sniffer module. Peruse this example to get a first look at how
306     to make use of SENF.
307
308     When building a network Application with SENF, you will use several modules:
309
310     \li Use the <a href="../../Socket/doc/html/index.html">Socket library</a> for network
311         communication needs. This library includes support for raw and packet sockets to allow low
312         level network access.
313     \li Use the <a href="../../Scheduler/doc/html/index.html">Scheduler library</a> to coordinate
314         the asynchronous event processing. This drastically reduces the number of threads needed in
315         your application and will greatly enhance the overall responsiveness.
316     \li To interpret low level network packets, use the <a
317         href="../../Packets/doc/html/index.html">Packets library</a>. This library will provide
318         efficient and convenient access to all protocol fields. It supports parsing as well as
319         modifying and creating packets. It has default support for the most important internet
320         protocols and is highly extensible with new protocols.
321     \li Go over the <a href="../../Utils/doc/html/index.html">Utils library</a>. It contains small
322         helpers to simplify tasks like daemonization, exception handling, debugging and so on.
323
324     The simplest way to get started is: copy the Sniffer application and start to modify it.
325
326     \see \ref example \n
327          \ref components \n
328          \ref svnsetup \n
329          \ref build
330
331     \section conventions Coding Conventions
332     
333     Here we have laid down the coding conventions used throughout the SENF framework. Please adhere
334     to these conventions when changing or adding code. If you use emacs, you can use the C++ IDE for
335     emacs from http://g0dil.de which greatly simplifies following these conventions.
336
337     \subsection conventions_file_naming File Naming
338
339     Files should be named according to the main class they define. A single header file should
340     define only one main class. Exceptions to this rule are OK.
341
342     \par Rationale:
343         This simplifies finding the implementation/header for a given class and also reduces the
344         size of each single file.
345     
346     The implementation is divided into a number of different files:
347
348     <table class="glossary"> <tr><td>\c .h</td><td>C public header</td></tr>
349
350     <tr><td>\c .hh</td><td>C++ public header</td></tr>
351
352     <tr><td>\c .ih</td><td>C++ internal header used only by the implementation. This header will
353     probably be included indirectly by the public header but is not meant to be perused by the
354     library user</td></tr>
355
356     <tr><td>\c .c</td><td>C implementation</td></tr>
357
358     <tr><td>\c .cc</td><td>C++ implementation of non-inline non-template functions and
359     members</td></tr>
360
361     <tr><td>\c .ct</td><td>C++ implementation of non-inline template functions and members</td></tr>
362
363     <tr><td>\c .cci</td><td>C++ implementation of inline non-template functions and
364     members</td></tr>
365     
366     <tr><td>\c .cti</td><td>C++ implementation of inline template fuanctions and members</td></tr>
367
368     <tr><td>\c .mpp</td><td>Special include file used for external iteration by the
369     Boost.Preprocessor library</td></tr> </table>
370
371     \par Rationale:
372         There are two part's to this: First, separating the implementation of inlines and tempaltes
373         out of the header file makes the header file much easier to read. This is important, since
374         the header file will be used as a reference by the developers.
375     \par
376         Separating inline from non-inline members is used together with the \c prefix_ convention
377         below to ensure the correct placement of inline vs non-inline members in the source
378         code. The C++ language requires, that inline members must be included into \e every
379         compilation unit, non-inline members however must be included \e only in one compilation
380         unit. Placing the inline members into a separate file allows to automate this: Simply moving
381         an implementation from one of the inline files into one of the non-inline files will change
382         the type of implementation accordingly.
383
384     \subsection conventions_type_naming Type Naming
385
386     SENF prefers the use of the CapitalziedLettersToSeparateWords convention for class names. In
387     this case, class names must start with a capital letter. There are some exceptions to this rule:
388     Types which define new basic data types to be used like other built-in types may be named using
389     lowercase letters plus underscores. Also, if a type or class is directly related to some other
390     library (STL or Boost) which uses the underscore convention, it might be more sensible to follow
391     this convention. This is open to debate.
392
393     \par Rationale:
394         Naming types with capital letters nicely gives a visual clue, that a symbol is a type
395         name. This can also be used by the editor to highlight type names correctly. Additionally,
396         this convention is compact and does not add additional or repeated overhead.
397
398     \subsection conventions_impl Implementation
399
400     Only in very few places, SENF allows the use of inline implementations (not to be confused with
401     inline functions). An \e implementation is inline, if it is written directly into the class
402     definition in the header file. Again there are exceptions to this rule but they are very few:
403     \li When defining simple exception classes, the 'what()' member may be defined inline if it
404         returns a string constant.
405     \li It may be OK to use inline implementations for one-line implementations in internal
406         headers. 
407     \li The Packet library allows inline implementations for the definition of parsers since doing
408         so outside the declaration just gets to verbose and parsers definitions are quite length but
409         very simple and straight forward.
410
411     \par Rationale:
412         Implementing members inline inside the class declaration makes the declaration much harder
413         to read. Since the declaration in the header file will be used as a reference by the
414         developer, the header files should be as readable as possible.
415
416     Every function or method implementation in one of the implementation files must \e always be
417     prefixed with \c prefix_. This symbol is defined at the beginning of the file and undefined at
418     the end. The symbol must be defined to be \c inline in the \c .cti and \c .cci files and must be
419     defined empty in the \c .cc and \c .ct files.
420
421     \par Rationale:
422         Together with splitting inlines and non-inlines into separate files, this allows to
423         automatically include the inline definitions at the right places. See above.
424
425  */
426
427 \f
428 // Local Variables:
429 // mode: c++
430 // fill-column: 100
431 // c-file-style: "senf"
432 // indent-tabs-mode: nil
433 // ispell-local-dictionary: "american"
434 // mode: flyspell
435 // mode: auto-fill
436 // End: