blob: dc3e937f2a4f3d0f5df9e7575d468bffa966da37 [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
62Types in each tool SHOULD be declared in a sub-namespace under `namespace ndn`.
63For 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
67Types in `core/` SHOULD be declared directly under `namespace ndn`,
68or in a sub-namespace if desired.
69
70`using namespace` SHOULD NOT be used except within block scope.
71
72### main Function
73
74The main function of a program SHOULD be declared within its sub-namespace.
75This allows it to reference types in ndn-cxx and the tool with unqualified name lookup.
76
77Then, another main function in global namespace needs to be defined
78to call the main function in sub-namespace.
79
80For example:
81
82 namespace ndn {
83 namespace foo {
Eric Newberry6035cd52017-08-27 22:56:01 -070084
Junxiao Shif6351f52015-04-06 21:06:52 -070085 class Bar
86 {
87 public:
88 explicit
89 Bar(Face& face);
Eric Newberry6035cd52017-08-27 22:56:01 -070090
Junxiao Shif6351f52015-04-06 21:06:52 -070091 void
92 run();
93 };
Eric Newberry6035cd52017-08-27 22:56:01 -070094
Junxiao Shif6351f52015-04-06 21:06:52 -070095 int
96 main(int argc, char** argv)
97 {
98 Face face;
99 Bar program(face);
100 program.run();
101 return 0;
102 }
Eric Newberry6035cd52017-08-27 22:56:01 -0700103
Junxiao Shi1d8a5812015-04-14 11:12:15 -0700104 } // namespace foo
105 } // namespace ndn
Eric Newberry6035cd52017-08-27 22:56:01 -0700106
Junxiao Shif6351f52015-04-06 21:06:52 -0700107 int
108 main(int argc, char** argv)
109 {
110 return ndn::foo::main(argc, argv);
111 }
112
113### Command Line Arguments
114
Davide Pesavento52401ce2016-05-03 18:16:59 +0200115[Boost.Program\_options](http://www.boost.org/doc/libs/1_54_0/doc/html/program_options.html) is
Junxiao Shif6351f52015-04-06 21:06:52 -0700116preferred over getopt(3) for parsing command line arguments.