blob: d29f34b9ca5afa20bc3087675c06feebe6ab8895 [file] [log] [blame] [view]
Davide Pesaventoa22a7422023-02-14 23:56:46 -05001# Notes for ndn-tools developers
Junxiao Shif6351f52015-04-06 21:06:52 -07002
3## Licensing Requirements
4
Davide Pesaventoa22a7422023-02-14 23:56:46 -05005Contributions to ndn-tools must be licensed under the GPL v3 or a compatible license.
6If you choose the GPL v3, please use the following license boilerplate in all `.hpp`
7and `.cpp` files:
Junxiao Shif6351f52015-04-06 21:06:52 -07008
Davide Pesaventof6d75992024-02-27 19:56:06 -05009```cpp
10/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
11/*
12 * Copyright (c) [Year(s)], [Copyright Holder(s)].
13 *
14 * This file is part of ndn-tools (Named Data Networking Essential Tools).
15 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
16 *
17 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
18 * of the GNU General Public License as published by the Free Software Foundation,
19 * either version 3 of the License, or (at your option) any later version.
20 *
21 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
22 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
23 * PURPOSE. See the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License along with
26 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
27 */
28```
Junxiao Shif6351f52015-04-06 21:06:52 -070029
30## Directory Structure and Build Script
31
Davide Pesaventob07d7a92020-05-13 23:30:07 -040032All tools are placed in subdirectories of the [`tools`](tools) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070033
34A tool can consist of one or more programs.
35For instance, a pair of consumer and producer programs that are designed to work together
36should be considered a single tool, not two separate tools.
37
Davide Pesaventob07d7a92020-05-13 23:30:07 -040038Each tool must have a `wscript` build script in its subdirectory. This script will be
39invoked automatically if the corresponding tool is selected for the build. It should
40compile the source code and produce one or more binaries in the `build/bin` directory
41(e.g., use `target='../../bin/foo'`).
Junxiao Shif6351f52015-04-06 21:06:52 -070042
43### Shared Modules
44
Davide Pesaventob07d7a92020-05-13 23:30:07 -040045Modules shared among multiple tools should be placed in the [`core`](core) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070046They are available for use in all tools.
47
48A header in `core/` can be included in a tool like `#include "core/foo.hpp"`.
49
Davide Pesaventob07d7a92020-05-13 23:30:07 -040050The `wscript` of a tool can link a program with modules in `core/` with `use='core-objects'`.
Junxiao Shif6351f52015-04-06 21:06:52 -070051
52### Documentation
53
Davide Pesaventob07d7a92020-05-13 23:30:07 -040054A file named `README.md` in the subdirectory of each tool should provide a brief
55description.
Junxiao Shif6351f52015-04-06 21:06:52 -070056
Davide Pesaventob07d7a92020-05-13 23:30:07 -040057Manual pages for each program should be written in reStructuredText format
58and placed in the [`manpages`](manpages) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070059
60## Code Guidelines
61
Davide Pesaventob07d7a92020-05-13 23:30:07 -040062C++ code should conform to the
Davide Pesaventodb9613e2023-01-20 20:52:21 -050063[ndn-cxx code style](https://docs.named-data.net/ndn-cxx/current/code-style.html).
Junxiao Shif6351f52015-04-06 21:06:52 -070064
65### Namespace
66
Davide Pesaventob07d7a92020-05-13 23:30:07 -040067Types in each tool should be declared in a sub-namespace inside `namespace ndn`.
68For example, a tool in `tools/foo` directory has namespace `ndn::foo`.
Junxiao Shif6351f52015-04-06 21:06:52 -070069This allows the tool to reference ndn-cxx types with unqualified name lookup.
70This also prevents name conflicts between ndn-cxx and tools.
71
Davide Pesaventob07d7a92020-05-13 23:30:07 -040072Types in `core/` should be declared directly inside `namespace ndn`,
Junxiao Shif6351f52015-04-06 21:06:52 -070073or in a sub-namespace if desired.
74
Junxiao Shif6351f52015-04-06 21:06:52 -070075### main Function
76
Davide Pesaventob07d7a92020-05-13 23:30:07 -040077The `main` function of a program should be declared as a static function in
Davide Pesaventoda85e252019-03-18 11:42:01 -040078the namespace of the corresponding tool. This allows referencing types in
79ndn-cxx and the tool via unqualified name lookup.
Junxiao Shif6351f52015-04-06 21:06:52 -070080
Davide Pesaventoda85e252019-03-18 11:42:01 -040081Then, another (non-static) `main` function must be defined in the global
82namespace, and from there call the `main` function in the tool namespace.
Junxiao Shif6351f52015-04-06 21:06:52 -070083
Davide Pesaventob07d7a92020-05-13 23:30:07 -040084These two functions should appear in a file named `main.cpp` in the tool's
Davide Pesaventoda85e252019-03-18 11:42:01 -040085subdirectory.
86
87Example:
Junxiao Shif6351f52015-04-06 21:06:52 -070088
Davide Pesaventodb9613e2023-01-20 20:52:21 -050089```cpp
90namespace ndn {
91namespace foo {
Eric Newberry6035cd52017-08-27 22:56:01 -070092
Davide Pesaventodb9613e2023-01-20 20:52:21 -050093class Bar
94{
95public:
96 explicit
97 Bar(Face& face);
Eric Newberry6035cd52017-08-27 22:56:01 -070098
Davide Pesaventodb9613e2023-01-20 20:52:21 -050099 void
100 run();
101};
Eric Newberry6035cd52017-08-27 22:56:01 -0700102
Davide Pesaventodb9613e2023-01-20 20:52:21 -0500103static int
104main(int argc, char* argv[])
105{
106 Face face;
107 Bar program(face);
108 program.run();
109 return 0;
110}
Eric Newberry6035cd52017-08-27 22:56:01 -0700111
Davide Pesaventodb9613e2023-01-20 20:52:21 -0500112} // namespace foo
113} // namespace ndn
Eric Newberry6035cd52017-08-27 22:56:01 -0700114
Davide Pesaventodb9613e2023-01-20 20:52:21 -0500115int
116main(int argc, char* argv[])
117{
118 return ndn::foo::main(argc, argv);
119}
120```
Junxiao Shif6351f52015-04-06 21:06:52 -0700121
122### Command Line Arguments
123
Davide Pesavento2ab04a22023-09-15 22:08:22 -0400124[Boost.Program\_options](https://www.boost.org/doc/libs/1_71_0/doc/html/program_options.html)
Davide Pesaventob07d7a92020-05-13 23:30:07 -0400125is strongly preferred over `getopt(3)` for parsing command line arguments.