This repository contains
- A framework for developing robust applications in C++.
- An application built using the framework.
- Tools for the static analysis of C++ software.
- A framework for developing a bot that can play the board game Diplomacy.
The framework that supports robust applications is referred to as the Robust Services Core (RSC). RSC will put your project on the right path and jump-start it if you're developing or reengineering a system whose requirements can be characterized as
- highly available, reliable, and/or scalable;
- embedded, reactive, stateful, and/or distributed.
The design patterns used in RSC make developers more productive. They have been proven in flagship telecom products, including (from the author's experience as its chief software architect) the core network server that handles all of the calls in AT&T's cellular network. A pattern language that summarizes the patterns appears in the second chapter of Robust Communications Software. The document RSC Software Overview describes which of them are currently available in this repository and points to the primary code files that implement them, and this tutorial provides more information about some of them.
The development of RSC has been somewhat sidetracked by the development of C++
static analysis tools. These tools detect violations of various C++ design
guidelines, such as those found in Scott Meyers' Effective C++. They also
analyze #include
directives to determine which ones to add or delete. Their
editor then allows you to easily and interactively fix about two-thirds of the
140 or so warning types. Even if you're not developing applications with RSC,
you might find these tools useful. An overview of them is provided
here.
Including an application with a framework serves to test it and illustrate its use. This repository therefore includes a POTS (Plain Ordinary Telephone Service) application. POTS was chosen for several reasons. For one thing, the author had extensive experience with similar applications while working in the telecom industry. But more importantly, POTS is a non-trivial application, yet everyone has a reasonable understanding of what it does. You should therefore be able to figure out what the POTS code is doing without reading a large specification. An overview of the POTS application is provided here.
In 2002, a group in the UK began to design a protocol that allows software bots to play the board game Diplomacy. See their website for various useful links and downloads, amongst which is the executable for a Diplomacy server. Bots log into this server, which sends them the state of the game, allows them to communicate with one another using the protocol, and adjudicates the moves that they submit. Their website also provides base software for developing bots. It seemed that it would be interesting to refactor this software while decoupling it from Windows and bringing it more in line with C++11. This would help RSC evolve to better support standalone clients that use IP (TCP, in this case). The resulting software is available in the dip directory and is described in some further detail here.
This page provides an overview of RSC. There is also a page which lists documents that go into far more depth on many topics.
Download one of the releases. Code checked since the latest release is work in progress and may be unstable or incomplete, so downloading from the green "Code" dropdown menu on the home page is not recommended.
After you download and extract the repository, its top-level directory will have a name like robust-services-core-v0.n.n now that releases are tagged. So will the directory directly underneath it. Rename that second-level directory rsc. This is because, when the executable starts, it looks for its configuration file on the path ../rsc/input/element.config.txt.
RSC
- requires C++17;
- is a console application;
- runs on both Windows and Linux;
- defines an abstraction layer, in the form of generic C++ .h's and platform-specific .cpp's, that should allow it to be ported to other systems fairly easily.
If you don't want to build RSC, debug and release executables are provided with each release.
The directories that contain RSC's source code, and the dependencies between
them, are listed in the comments that precede the implementation of
main
. Each of these directories is built as a separate
static library, with main
residing in its own directory.
RSC is developed using Visual Studio 2022. The Windows build options that RSC uses are described here.
RSC is built using CMake, as described here. Because Visual Studio's .vcxproj files are no longer modified as part of the build process, they have been removed from the repository.
During initialization, RSC displays each module as it is initialized.
(A module is equivalent to a static library.) After all modules
have initialized, the CLI prompt nb>
appears to indicate that CLI commands
in the nb directory are available. The information written to the console
during startup is shown here, and a list of all
CLI commands is provided here.
If you enter >read saveinit
as the first CLI command, a function trace of
the initialization, which starts even before the invocation of main
, is
generated. This trace should look a lot like this.
Each function that appears in such a trace invoked Debug::ft
, which records
the following:
- the function's name
- the time when it was invoked
- the thread that invoked it
- its depth (in frames) on the stack: this controls indentation so that you can see how function calls were nested
- the total time spent in the function (in microseconds)
- the net time spent in the function (in microseconds)
All output appears in the directory ../rsc/excluded/output (the first directory named rsc above the directory from which the .exe was launched). In addition to any specific output that you request, such as the initialization trace, every CLI session produces
- a console file (a transcript of the CLI commands that you entered and what was written to the console)
- a log file (system events that were written to the console asynchronously)
The numeric string yymmdd-hhmmss is appended to the names of these files to record the time when the system initialized (for the console file and initial log file) or the time of the preceding restart (for a subsequent log file).
To use RSC as a framework, create a static library which uses the subset of
RSC that your application requires. This will always include the namespace
NodeBase
(in the nb directory). It might also include
NetworkBase
(in the nw directory) and SessionBase
(in the
sb directory). Using a new namespace for your application is
recommended.
To initialize your application, derive from Module
.
For an example, see NbModule
, which initializes
NodeBase
. Change CreateModules
so that it also
instantiates your module, and comment out its instantiation of modules that
you don't want in your build.
To interact with your application, derive from
CliIncrement
.
For an example, see NbIncrement
, the increment
for NodeBase
. Instantiate your CLI increment in your module's Startup
function. When you launch RSC, you can then access the commands in your
increment through the CLI by entering >incr
, where incr
is the
abbreviation that your increment's constructor passed to CliIncrement
's
constructor.
Most of the files in the input directory are test scripts. The document that describes the POTS application also discusses its tests, which exercise a considerable portion of the RSC software. The tests described below are rather tactical by comparison.
Twenty-eight scripts test the Safety Net capability of the Thread
class.
Most of them cause a POSIX signal to be raised. POSIX signals are handled by
throwing a C++ exception that is caught in Thread.Start
, after which an
appropriate recovery action is taken. Getting the safety net to work could be
challenging when porting RSC to another platform, which is why these tests are
provided. All of the safety net tests can be run with the command
>read test.trap.all.
During each test, the following are generated (see
the recover.* files in the output directory):
- A function trace (*.trace.txt), as described above.
- A function profile (*.funcs.txt) that lists each function that was invoked, along with how many times it was invoked and the total net time spent in it. This information is not that useful here, but it is valuable when you want to pinpoint which functions to focus on in order to improve real-time performance.
- A scheduler trace (*.sched.txt). The first part of this trace lists all threads in the executable, with statistics for each. The second part is a record of all the context switches that occurred during the test.
- A console file of the test (*.cli.txt), as described above.
Entering >nt
in the CLI accesses the "nt" increment (a set of CLI
commands). It provides sets of commands for testing functions in the
NbHeap
, LeakyBucketCounter
,
Q1Way
, Q2Way
, and
Registry
interfaces.
RSC is freely available under the terms of the GNU General Public License, version 3, which basically says that you must also publish your own software, as well as your changes to RSC. If you are developing software that you want to keep proprietary, the GPLv3 license also allows RSC to be licensed under the terms of another license approved by the Free Software Foundation. Some of those licenses allow your software to remain proprietary. However, compensation would be required, and any changes that you make to RSC itself (bug fixes and enhancements) would still have to be published.
How to contribute to RSC is described here.
GitHub now lets you sponsor projects. A "Sponsor" button is located at the top of this page.