Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 1 | # Notes for ndn-tools Developers |
| 2 | |
| 3 | ## Licensing Requirements |
| 4 | |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame^] | 5 | Contributions to ndn-tools MUST be licensed under 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 | /* |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 10 | * 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 | |
| 29 | All tools are placed in subdirectories under `tools/` directory. |
| 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 | |
| 35 | Each tool MUST have a `wscript` build script in its subdirectory. |
| 36 | It will be invoked if this tool is selected for the build. |
| 37 | It SHOULD compile the programs into `build/bin` directory (`target='../../bin/foo'`). |
| 38 | |
| 39 | ### Shared Modules |
| 40 | |
| 41 | Modules shared among multiple tools SHOULD be placed in `core/` directory. |
| 42 | They are available for use in all tools. |
| 43 | |
| 44 | A 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 | |
| 52 | Manual pages for each program SHOULD be written in reStructuredText format |
| 53 | and placed in `manpages/` directory. |
| 54 | |
| 55 | ## Code Guidelines |
| 56 | |
| 57 | C++ code SHOULD conform to |
| 58 | [ndn-cxx code style](http://named-data.net/doc/ndn-cxx/current/code-style.html). |
| 59 | |
| 60 | ### Namespace |
| 61 | |
| 62 | Types in each tool SHOULD be declared in a sub-namespace under `namespace ndn`. |
| 63 | For example, a tool in `tools/foo` directory has namespace `ndn::foo`. |
| 64 | This allows the tool to reference ndn-cxx types with unqualified name lookup. |
| 65 | This also prevents name conflicts between ndn-cxx and tools. |
| 66 | |
| 67 | Types in `core/` SHOULD be declared directly under `namespace ndn`, |
| 68 | or in a sub-namespace if desired. |
| 69 | |
| 70 | `using namespace` SHOULD NOT be used except within block scope. |
| 71 | |
| 72 | ### main Function |
| 73 | |
| 74 | The main function of a program SHOULD be declared within its sub-namespace. |
| 75 | This allows it to reference types in ndn-cxx and the tool with unqualified name lookup. |
| 76 | |
| 77 | Then, another main function in global namespace needs to be defined |
| 78 | to call the main function in sub-namespace. |
| 79 | |
| 80 | For example: |
| 81 | |
| 82 | namespace ndn { |
| 83 | namespace foo { |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame^] | 84 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 85 | class Bar |
| 86 | { |
| 87 | public: |
| 88 | explicit |
| 89 | Bar(Face& face); |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame^] | 90 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 91 | void |
| 92 | run(); |
| 93 | }; |
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 | int |
| 96 | main(int argc, char** argv) |
| 97 | { |
| 98 | Face face; |
| 99 | Bar program(face); |
| 100 | program.run(); |
| 101 | return 0; |
| 102 | } |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame^] | 103 | |
Junxiao Shi | 1d8a581 | 2015-04-14 11:12:15 -0700 | [diff] [blame] | 104 | } // namespace foo |
| 105 | } // namespace ndn |
Eric Newberry | 6035cd5 | 2017-08-27 22:56:01 -0700 | [diff] [blame^] | 106 | |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 107 | int |
| 108 | main(int argc, char** argv) |
| 109 | { |
| 110 | return ndn::foo::main(argc, argv); |
| 111 | } |
| 112 | |
| 113 | ### Command Line Arguments |
| 114 | |
Davide Pesavento | 52401ce | 2016-05-03 18:16:59 +0200 | [diff] [blame] | 115 | [Boost.Program\_options](http://www.boost.org/doc/libs/1_54_0/doc/html/program_options.html) is |
Junxiao Shi | f6351f5 | 2015-04-06 21:06:52 -0700 | [diff] [blame] | 116 | preferred over getopt(3) for parsing command line arguments. |