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