blob: d3b2cec3695f6b2570a1347fc5d6b6acb9fbd681 [file] [log] [blame] [view]
Junxiao Shif6351f52015-04-06 21:06:52 -07001# Notes for ndn-tools Developers
2
3## Licensing Requirements
4
Eric Newberry6035cd52017-08-27 22:56:01 -07005Contributions to ndn-tools MUST be licensed under 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 /*
Junxiao Shif6351f52015-04-06 21:06:52 -070010 * Copyright (c) [Year(s)], [Copyright Holder(s)].
11 *
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
29All tools are placed in subdirectories under `tools/` directory.
30
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
35Each tool MUST have a `wscript` build script in its subdirectory.
36It will be invoked if this tool is selected for the build.
37It SHOULD compile the programs into `build/bin` directory (`target='../../bin/foo'`).
38
39### Shared Modules
40
41Modules shared among multiple tools SHOULD be placed in `core/` directory.
42They are available for use in all tools.
43
44A header in `core/` can be included in a tool like `#include "core/foo.hpp"`.
45
46`wscript` of a tool can link a program with modules in `core/` with `use='core-objects'`.
47
48### Documentation
49
50`README.md` in the subdirectory of a tool SHOULD give a brief description.
51
52Manual pages for each program SHOULD be written in reStructuredText format
53and placed in `manpages/` directory.
54
55## Code Guidelines
56
57C++ code SHOULD conform to
58[ndn-cxx code style](http://named-data.net/doc/ndn-cxx/current/code-style.html).
59
60### Namespace
61
Davide Pesaventoda85e252019-03-18 11:42:01 -040062Types in each tool SHOULD be declared in a sub-namespace inside `namespace ndn`.
Junxiao Shif6351f52015-04-06 21:06:52 -070063For example, a tool in `tools/foo` directory has namespace `ndn::foo`.
64This allows the tool to reference ndn-cxx types with unqualified name lookup.
65This also prevents name conflicts between ndn-cxx and tools.
66
Davide Pesaventoda85e252019-03-18 11:42:01 -040067Types in `core/` SHOULD be declared directly inside `namespace ndn`,
Junxiao Shif6351f52015-04-06 21:06:52 -070068or in a sub-namespace if desired.
69
Davide Pesaventoda85e252019-03-18 11:42:01 -040070`using namespace` SHOULD NOT be used except in block scope.
Junxiao Shif6351f52015-04-06 21:06:52 -070071
72### main Function
73
Davide Pesaventoda85e252019-03-18 11:42:01 -040074The `main` function of a program SHOULD be declared as a static function in
75the 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 Pesaventoda85e252019-03-18 11:42:01 -040081These two functions SHOULD appear in a file named `main.cpp` in the tool's
82subdirectory.
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 Pesavento26ea1ac2018-05-10 20:20:03 -0400119[Boost.Program\_options](https://www.boost.org/doc/libs/1_58_0/doc/html/program_options.html) is
Junxiao Shif6351f52015-04-06 21:06:52 -0700120preferred over getopt(3) for parsing command line arguments.