blob: 0a76f226370185c347c14926ad04989fdcbb1508 [file] [log] [blame] [view]
Junxiao Shif6351f52015-04-06 21:06:52 -07001# Notes for ndn-tools Developers
2
3## Licensing Requirements
4
Davide Pesaventob07d7a92020-05-13 23:30:07 -04005Contributions to ndn-tools must be licensed under the GPL 3.0 or a compatible license.
Junxiao Shif6351f52015-04-06 21:06:52 -07006If you choose GPL 3.0, include the following license boilerplate into all C++ code files:
7
8 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry6035cd52017-08-27 22:56:01 -07009 /*
Davide Pesaventob07d7a92020-05-13 23:30:07 -040010 * Copyright (c) [Year(s)] [Copyright Holder(s)].
Junxiao Shif6351f52015-04-06 21:06:52 -070011 *
12 * This file is part of ndn-tools (Named Data Networking Essential Tools).
13 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
14 *
15 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
16 * of the GNU General Public License as published by the Free Software Foundation,
17 * either version 3 of the License, or (at your option) any later version.
18 *
19 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21 * PURPOSE. See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along with
24 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27## Directory Structure and Build Script
28
Davide Pesaventob07d7a92020-05-13 23:30:07 -040029All tools are placed in subdirectories of the [`tools`](tools) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070030
31A tool can consist of one or more programs.
32For instance, a pair of consumer and producer programs that are designed to work together
33should be considered a single tool, not two separate tools.
34
Davide Pesaventob07d7a92020-05-13 23:30:07 -040035Each tool must have a `wscript` build script in its subdirectory. This script will be
36invoked automatically if the corresponding tool is selected for the build. It should
37compile the source code and produce one or more binaries in the `build/bin` directory
38(e.g., use `target='../../bin/foo'`).
Junxiao Shif6351f52015-04-06 21:06:52 -070039
40### Shared Modules
41
Davide Pesaventob07d7a92020-05-13 23:30:07 -040042Modules shared among multiple tools should be placed in the [`core`](core) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070043They are available for use in all tools.
44
45A header in `core/` can be included in a tool like `#include "core/foo.hpp"`.
46
Davide Pesaventob07d7a92020-05-13 23:30:07 -040047The `wscript` of a tool can link a program with modules in `core/` with `use='core-objects'`.
Junxiao Shif6351f52015-04-06 21:06:52 -070048
49### Documentation
50
Davide Pesaventob07d7a92020-05-13 23:30:07 -040051A file named `README.md` in the subdirectory of each tool should provide a brief
52description.
Junxiao Shif6351f52015-04-06 21:06:52 -070053
Davide Pesaventob07d7a92020-05-13 23:30:07 -040054Manual pages for each program should be written in reStructuredText format
55and placed in the [`manpages`](manpages) directory.
Junxiao Shif6351f52015-04-06 21:06:52 -070056
57## Code Guidelines
58
Davide Pesaventob07d7a92020-05-13 23:30:07 -040059C++ code should conform to the
60[ndn-cxx code style](https://named-data.net/doc/ndn-cxx/current/code-style.html).
Junxiao Shif6351f52015-04-06 21:06:52 -070061
62### Namespace
63
Davide Pesaventob07d7a92020-05-13 23:30:07 -040064Types in each tool should be declared in a sub-namespace inside `namespace ndn`.
65For example, a tool in `tools/foo` directory has namespace `ndn::foo`.
Junxiao Shif6351f52015-04-06 21:06:52 -070066This allows the tool to reference ndn-cxx types with unqualified name lookup.
67This also prevents name conflicts between ndn-cxx and tools.
68
Davide Pesaventob07d7a92020-05-13 23:30:07 -040069Types in `core/` should be declared directly inside `namespace ndn`,
Junxiao Shif6351f52015-04-06 21:06:52 -070070or in a sub-namespace if desired.
71
Junxiao Shif6351f52015-04-06 21:06:52 -070072### main Function
73
Davide Pesaventob07d7a92020-05-13 23:30:07 -040074The `main` function of a program should be declared as a static function in
Davide Pesaventoda85e252019-03-18 11:42:01 -040075the namespace of the corresponding tool. This allows referencing types in
76ndn-cxx and the tool via unqualified name lookup.
Junxiao Shif6351f52015-04-06 21:06:52 -070077
Davide Pesaventoda85e252019-03-18 11:42:01 -040078Then, another (non-static) `main` function must be defined in the global
79namespace, and from there call the `main` function in the tool namespace.
Junxiao Shif6351f52015-04-06 21:06:52 -070080
Davide Pesaventob07d7a92020-05-13 23:30:07 -040081These two functions should appear in a file named `main.cpp` in the tool's
Davide Pesaventoda85e252019-03-18 11:42:01 -040082subdirectory.
83
84Example:
Junxiao Shif6351f52015-04-06 21:06:52 -070085
86 namespace ndn {
87 namespace foo {
Eric Newberry6035cd52017-08-27 22:56:01 -070088
Junxiao Shif6351f52015-04-06 21:06:52 -070089 class Bar
90 {
91 public:
92 explicit
93 Bar(Face& face);
Eric Newberry6035cd52017-08-27 22:56:01 -070094
Junxiao Shif6351f52015-04-06 21:06:52 -070095 void
96 run();
97 };
Eric Newberry6035cd52017-08-27 22:56:01 -070098
Davide Pesaventoda85e252019-03-18 11:42:01 -040099 static int
100 main(int argc, char* argv[])
Junxiao Shif6351f52015-04-06 21:06:52 -0700101 {
102 Face face;
103 Bar program(face);
104 program.run();
105 return 0;
106 }
Eric Newberry6035cd52017-08-27 22:56:01 -0700107
Junxiao Shi1d8a5812015-04-14 11:12:15 -0700108 } // namespace foo
109 } // namespace ndn
Eric Newberry6035cd52017-08-27 22:56:01 -0700110
Junxiao Shif6351f52015-04-06 21:06:52 -0700111 int
Davide Pesaventoda85e252019-03-18 11:42:01 -0400112 main(int argc, char* argv[])
Junxiao Shif6351f52015-04-06 21:06:52 -0700113 {
114 return ndn::foo::main(argc, argv);
115 }
116
117### Command Line Arguments
118
Davide Pesaventob07d7a92020-05-13 23:30:07 -0400119[Boost.Program\_options](https://www.boost.org/doc/libs/1_65_1/doc/html/program_options.html)
120is strongly preferred over `getopt(3)` for parsing command line arguments.