Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 1 | # Notes for ndn-tools Developers |
| 2 | |
| 3 | ## Licensing Requirements |
| 4 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 5 | Contributions to ndn-tools must be licensed under the GPL 3.0 or a compatible license. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 6 | If 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 Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame] | 9 | /* |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 10 | * Copyright (c) [Year(s)] [Copyright Holder(s)]. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 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 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 29 | All tools are placed in subdirectories of the [`tools`](tools) directory. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 30 | |
| 31 | A tool can consist of one or more programs. |
| 32 | For instance, a pair of consumer and producer programs that are designed to work together |
| 33 | should be considered a single tool, not two separate tools. |
| 34 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 35 | Each tool must have a `wscript` build script in its subdirectory. This script will be |
| 36 | invoked automatically if the corresponding tool is selected for the build. It should |
| 37 | compile the source code and produce one or more binaries in the `build/bin` directory |
| 38 | (e.g., use `target='../../bin/foo'`). |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 39 | |
| 40 | ### Shared Modules |
| 41 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 42 | Modules shared among multiple tools should be placed in the [`core`](core) directory. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 43 | They are available for use in all tools. |
| 44 | |
| 45 | A header in `core/` can be included in a tool like `#include "core/foo.hpp"`. |
| 46 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 47 | The `wscript` of a tool can link a program with modules in `core/` with `use='core-objects'`. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 48 | |
| 49 | ### Documentation |
| 50 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 51 | A file named `README.md` in the subdirectory of each tool should provide a brief |
| 52 | description. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 53 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 54 | Manual pages for each program should be written in reStructuredText format |
| 55 | and placed in the [`manpages`](manpages) directory. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 56 | |
| 57 | ## Code Guidelines |
| 58 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 59 | C++ code should conform to the |
| 60 | [ndn-cxx code style](https://named-data.net/doc/ndn-cxx/current/code-style.html). |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 61 | |
| 62 | ### Namespace |
| 63 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 64 | Types in each tool should be declared in a sub-namespace inside `namespace ndn`. |
| 65 | For example, a tool in `tools/foo` directory has namespace `ndn::foo`. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 66 | This allows the tool to reference ndn-cxx types with unqualified name lookup. |
| 67 | This also prevents name conflicts between ndn-cxx and tools. |
| 68 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 69 | Types in `core/` should be declared directly inside `namespace ndn`, |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 70 | or in a sub-namespace if desired. |
| 71 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 72 | ### main Function |
| 73 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 74 | The `main` function of a program should be declared as a static function in |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 75 | the namespace of the corresponding tool. This allows referencing types in |
| 76 | ndn-cxx and the tool via unqualified name lookup. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 77 | |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 78 | Then, another (non-static) `main` function must be defined in the global |
| 79 | namespace, and from there call the `main` function in the tool namespace. |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 80 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 81 | These two functions should appear in a file named `main.cpp` in the tool's |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 82 | subdirectory. |
| 83 | |
| 84 | Example: |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 85 | |
| 86 | namespace ndn { |
| 87 | namespace foo { |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame] | 88 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 89 | class Bar |
| 90 | { |
| 91 | public: |
| 92 | explicit |
| 93 | Bar(Face& face); |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame] | 94 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 95 | void |
| 96 | run(); |
| 97 | }; |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame] | 98 | |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 99 | static int |
| 100 | main(int argc, char* argv[]) |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 101 | { |
| 102 | Face face; |
| 103 | Bar program(face); |
| 104 | program.run(); |
| 105 | return 0; |
| 106 | } |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame] | 107 | |
Junxiao Shi | 1d8a581 | 2015-04-14 11:12:15 -0700 | [diff] [blame] | 108 | } // namespace foo |
| 109 | } // namespace ndn |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 111 | int |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 112 | main(int argc, char* argv[]) |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 113 | { |
| 114 | return ndn::foo::main(argc, argv); |
| 115 | } |
| 116 | |
| 117 | ### Command Line Arguments |
| 118 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 119 | [Boost.Program\_options](https://www.boost.org/doc/libs/1_65_1/doc/html/program_options.html) |
| 120 | is strongly preferred over `getopt(3)` for parsing command line arguments. |