blob: e7acc71a7c5cd0e983e5a3ef1799585ed8d69755 [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
9 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry6035cd52017-08-27 22:56:01 -070010 /*
Davide Pesaventob07d7a92020-05-13 23:30:07 -040011 * Copyright (c) [Year(s)] [Copyright Holder(s)].
Junxiao Shif6351f52015-04-06 21:06:52 -070012 *
13 * This file is part of ndn-tools (Named Data Networking Essential Tools).
14 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
15 *
16 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
17 * of the GNU General Public License as published by the Free Software Foundation,
18 * either version 3 of the License, or (at your option) any later version.
19 *
20 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
21 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22 * PURPOSE. See the GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License along with
25 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28## Directory Structure and Build Script
29
Davide Pesaventob07d7a92020-05-13 23:30:07 -040030All tools are placed in subdirectories of the [`tools`](tools) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070031
32A tool can consist of one or more programs.
33For instance, a pair of consumer and producer programs that are designed to work together
34should be considered a single tool, not two separate tools.
35
Davide Pesaventob07d7a92020-05-13 23:30:07 -040036Each tool must have a `wscript` build script in its subdirectory. This script will be
37invoked automatically if the corresponding tool is selected for the build. It should
38compile the source code and produce one or more binaries in the `build/bin` directory
39(e.g., use `target='../../bin/foo'`).
Junxiao Shif6351f52015-04-06 21:06:52 -070040
41### Shared Modules
42
Davide Pesaventob07d7a92020-05-13 23:30:07 -040043Modules shared among multiple tools should be placed in the [`core`](core) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070044They are available for use in all tools.
45
46A header in `core/` can be included in a tool like `#include "core/foo.hpp"`.
47
Davide Pesaventob07d7a92020-05-13 23:30:07 -040048The `wscript` of a tool can link a program with modules in `core/` with `use='core-objects'`.
Junxiao Shif6351f52015-04-06 21:06:52 -070049
50### Documentation
51
Davide Pesaventob07d7a92020-05-13 23:30:07 -040052A file named `README.md` in the subdirectory of each tool should provide a brief
53description.
Junxiao Shif6351f52015-04-06 21:06:52 -070054
Davide Pesaventob07d7a92020-05-13 23:30:07 -040055Manual pages for each program should be written in reStructuredText format
56and placed in the [`manpages`](manpages) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070057
58## Code Guidelines
59
Davide Pesaventob07d7a92020-05-13 23:30:07 -040060C++ code should conform to the
Davide Pesaventodb9613e2023-01-20 20:52:21 -050061[ndn-cxx code style](https://docs.named-data.net/ndn-cxx/current/code-style.html).
Junxiao Shif6351f52015-04-06 21:06:52 -070062
63### Namespace
64
Davide Pesaventob07d7a92020-05-13 23:30:07 -040065Types in each tool should be declared in a sub-namespace inside `namespace ndn`.
66For example, a tool in `tools/foo` directory has namespace `ndn::foo`.
Junxiao Shif6351f52015-04-06 21:06:52 -070067This allows the tool to reference ndn-cxx types with unqualified name lookup.
68This also prevents name conflicts between ndn-cxx and tools.
69
Davide Pesaventob07d7a92020-05-13 23:30:07 -040070Types in `core/` should be declared directly inside `namespace ndn`,
Junxiao Shif6351f52015-04-06 21:06:52 -070071or in a sub-namespace if desired.
72
Junxiao Shif6351f52015-04-06 21:06:52 -070073### main Function
74
Davide Pesaventob07d7a92020-05-13 23:30:07 -040075The `main` function of a program should be declared as a static function in
Davide Pesaventoda85e252019-03-18 11:42:01 -040076the namespace of the corresponding tool. This allows referencing types in
77ndn-cxx and the tool via unqualified name lookup.
Junxiao Shif6351f52015-04-06 21:06:52 -070078
Davide Pesaventoda85e252019-03-18 11:42:01 -040079Then, another (non-static) `main` function must be defined in the global
80namespace, and from there call the `main` function in the tool namespace.
Junxiao Shif6351f52015-04-06 21:06:52 -070081
Davide Pesaventob07d7a92020-05-13 23:30:07 -040082These two functions should appear in a file named `main.cpp` in the tool's
Davide Pesaventoda85e252019-03-18 11:42:01 -040083subdirectory.
84
85Example:
Junxiao Shif6351f52015-04-06 21:06:52 -070086
Davide Pesaventodb9613e2023-01-20 20:52:21 -050087```cpp
88namespace ndn {
89namespace foo {
Eric Newberry6035cd52017-08-27 22:56:01 -070090
Davide Pesaventodb9613e2023-01-20 20:52:21 -050091class Bar
92{
93public:
94 explicit
95 Bar(Face& face);
Eric Newberry6035cd52017-08-27 22:56:01 -070096
Davide Pesaventodb9613e2023-01-20 20:52:21 -050097 void
98 run();
99};
Eric Newberry6035cd52017-08-27 22:56:01 -0700100
Davide Pesaventodb9613e2023-01-20 20:52:21 -0500101static int
102main(int argc, char* argv[])
103{
104 Face face;
105 Bar program(face);
106 program.run();
107 return 0;
108}
Eric Newberry6035cd52017-08-27 22:56:01 -0700109
Davide Pesaventodb9613e2023-01-20 20:52:21 -0500110} // namespace foo
111} // namespace ndn
Eric Newberry6035cd52017-08-27 22:56:01 -0700112
Davide Pesaventodb9613e2023-01-20 20:52:21 -0500113int
114main(int argc, char* argv[])
115{
116 return ndn::foo::main(argc, argv);
117}
118```
Junxiao Shif6351f52015-04-06 21:06:52 -0700119
120### Command Line Arguments
121
Davide Pesavento2ab04a22023-09-15 22:08:22 -0400122[Boost.Program\_options](https://www.boost.org/doc/libs/1_71_0/doc/html/program_options.html)
Davide Pesaventob07d7a92020-05-13 23:30:07 -0400123is strongly preferred over `getopt(3)` for parsing command line arguments.