From 992db82b91b6058b4f9b9d0187d6310a8ff3b008 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 00:17:41 +0000 Subject: [PATCH] feat(docs): add the documentation site - Astro and Starlight site in docs/ for https://fairrootgroup.github.io/FairMQ/ - 64 pages in eight groups: start, concepts, guides, shared memory, examples, tools, reference and project - API reference and source browser from the Doxygen XML of fairmq/ - Code samples are snippets of the repository files; the build fails when a snippet does not match - Option tables take the names, types and defaults from the code - Interactive diagrams: state machine, zero-copy transfer, region acknowledgements, session objects, topology and channel anatomy - The 404 page sends the URLs of the Doxygen site to the new pages - scripts/check-pages.mjs checks pages, snippets and links without a build; scripts/check-links.mjs checks all links in dist/ Co-Authored-By: Claude Opus 5.5 --- docs/.gitignore | 5 + docs/Doxyfile | 36 + docs/README.md | 51 + docs/astro.config.mjs | 102 + docs/package-lock.json | 5394 +++++++++++++++++ docs/package.json | 27 + docs/public/favicon.svg | 10 + docs/scripts/api.mjs | 776 +++ docs/scripts/base-links.mjs | 26 + docs/scripts/build-info.mjs | 37 + docs/scripts/check-links.mjs | 75 + docs/scripts/check-pages.mjs | 181 + docs/scripts/integration.mjs | 77 + docs/scripts/nowrap-code.mjs | 24 + docs/scripts/options.mjs | 159 + docs/scripts/print-api.mjs | 40 + docs/scripts/snippet.mjs | 82 + docs/scripts/source.mjs | 163 + docs/scripts/xml.mjs | 68 + docs/src/components/CopyButton.astro | 44 + docs/src/components/Glyph.astro | 21 + docs/src/components/OptionsTable.astro | 263 + docs/src/components/Snippet.astro | 68 + docs/src/components/api/Member.astro | 109 + .../components/diagrams/ChannelAnatomy.astro | 124 + docs/src/components/diagrams/Explainer.astro | 331 + .../components/diagrams/PatternDiagram.astro | 125 + .../diagrams/RegionAckExplainer.astro | 352 ++ docs/src/components/diagrams/SessionMap.astro | 162 + .../components/diagrams/StateMachine.astro | 580 ++ docs/src/components/diagrams/Topology.astro | 348 ++ .../diagrams/ZeroCopyExplainer.astro | 274 + docs/src/components/home/HomeCode.astro | 94 + docs/src/components/home/HomePaths.astro | 96 + docs/src/components/overrides/Footer.astro | 61 + docs/src/components/overrides/Header.astro | 174 + docs/src/components/overrides/Hero.astro | 121 + .../overrides/MobileMenuFooter.astro | 44 + .../components/overrides/PageSidebar.astro | 87 + docs/src/components/overrides/PageTitle.astro | 54 + docs/src/content.config.ts | 26 + docs/src/content/docs/concepts/channels.mdx | 206 + .../content/docs/concepts/configuration.mdx | 140 + docs/src/content/docs/concepts/devices.mdx | 240 + docs/src/content/docs/concepts/messages.mdx | 246 + docs/src/content/docs/concepts/plugins.mdx | 264 + docs/src/content/docs/concepts/states.mdx | 272 + docs/src/content/docs/concepts/threads.mdx | 250 + docs/src/content/docs/concepts/transports.mdx | 238 + docs/src/content/docs/examples/1-1.mdx | 240 + docs/src/content/docs/examples/1-n-1.mdx | 181 + .../content/docs/examples/builtin-devices.mdx | 150 + docs/src/content/docs/examples/copypush.mdx | 159 + .../docs/examples/custom-controller.mdx | 156 + docs/src/content/docs/examples/dds.mdx | 198 + docs/src/content/docs/examples/multipart.mdx | 200 + .../docs/examples/multiple-channels.mdx | 193 + .../docs/examples/multiple-transports.mdx | 186 + docs/src/content/docs/examples/n-m.mdx | 186 + docs/src/content/docs/examples/qc.mdx | 144 + docs/src/content/docs/examples/readout.mdx | 138 + docs/src/content/docs/examples/region.mdx | 207 + docs/src/content/docs/examples/req-rep.mdx | 149 + docs/src/content/docs/guides/benchmark.mdx | 253 + .../docs/guides/channels-without-device.mdx | 282 + .../docs/guides/configure-channels.mdx | 237 + .../content/docs/guides/control-from-code.mdx | 540 ++ .../content/docs/guides/design-topology.mdx | 284 + docs/src/content/docs/guides/end-of-run.mdx | 344 ++ .../content/docs/guides/errors-timeouts.mdx | 421 ++ docs/src/content/docs/guides/fairmq-tidy.mdx | 207 + .../src/content/docs/guides/migrate-names.mdx | 195 + docs/src/content/docs/guides/pmr.mdx | 173 + .../src/content/docs/guides/poll-channels.mdx | 187 + docs/src/content/docs/guides/receive-data.mdx | 235 + .../content/docs/guides/send-data-types.mdx | 357 ++ .../docs/guides/several-transports.mdx | 199 + docs/src/content/docs/guides/test-devices.mdx | 415 ++ docs/src/content/docs/guides/write-plugin.mdx | 226 + docs/src/content/docs/index.mdx | 24 + .../src/content/docs/project/contributing.mdx | 407 ++ docs/src/content/docs/project/license.mdx | 120 + .../content/docs/project/release-notes.mdx | 181 + .../docs/reference/channel-properties.mdx | 246 + docs/src/content/docs/reference/cmake.mdx | 301 + docs/src/content/docs/reference/glossary.mdx | 404 ++ docs/src/content/docs/reference/json.mdx | 145 + docs/src/content/docs/reference/options.mdx | 98 + docs/src/content/docs/reference/states.mdx | 234 + docs/src/content/docs/reference/tools.mdx | 388 ++ .../content/docs/reference/transfer-codes.mdx | 159 + docs/src/content/docs/shmem/how-it-works.mdx | 174 + docs/src/content/docs/shmem/monitor.mdx | 340 ++ docs/src/content/docs/shmem/regions.mdx | 296 + docs/src/content/docs/shmem/sessions.mdx | 247 + docs/src/content/docs/shmem/side-channel.mdx | 157 + docs/src/content/docs/shmem/tuning.mdx | 264 + docs/src/content/docs/start/cmake.mdx | 288 + docs/src/content/docs/start/first-device.mdx | 218 + docs/src/content/docs/start/install.mdx | 236 + docs/src/content/docs/start/overview.mdx | 79 + .../content/docs/tools/builtin-devices.mdx | 261 + docs/src/content/docs/tools/fairmq-tidy.mdx | 219 + docs/src/content/docs/tools/logging.mdx | 270 + docs/src/content/docs/tools/shmmonitor.mdx | 179 + docs/src/data/option-texts.mjs | 55 + docs/src/env.d.ts | 20 + docs/src/lib/families.mjs | 33 + docs/src/lib/model.mjs | 93 + docs/src/lib/nav.ts | 41 + docs/src/pages/404.astro | 91 + docs/src/pages/api/[...slug].astro | 365 ++ docs/src/pages/api/index.astro | 64 + docs/src/pages/source/[...path].astro | 142 + docs/src/pages/source/index.astro | 67 + docs/src/styles/api.css | 323 + docs/src/styles/code-theme.json | 39 + docs/src/styles/source.css | 201 + docs/src/styles/theme.css | 668 ++ docs/tsconfig.json | 5 + 120 files changed, 27931 insertions(+) create mode 100644 docs/.gitignore create mode 100644 docs/Doxyfile create mode 100644 docs/README.md create mode 100644 docs/astro.config.mjs create mode 100644 docs/package-lock.json create mode 100644 docs/package.json create mode 100644 docs/public/favicon.svg create mode 100644 docs/scripts/api.mjs create mode 100644 docs/scripts/base-links.mjs create mode 100644 docs/scripts/build-info.mjs create mode 100644 docs/scripts/check-links.mjs create mode 100644 docs/scripts/check-pages.mjs create mode 100644 docs/scripts/integration.mjs create mode 100644 docs/scripts/nowrap-code.mjs create mode 100644 docs/scripts/options.mjs create mode 100644 docs/scripts/print-api.mjs create mode 100644 docs/scripts/snippet.mjs create mode 100644 docs/scripts/source.mjs create mode 100644 docs/scripts/xml.mjs create mode 100644 docs/src/components/CopyButton.astro create mode 100644 docs/src/components/Glyph.astro create mode 100644 docs/src/components/OptionsTable.astro create mode 100644 docs/src/components/Snippet.astro create mode 100644 docs/src/components/api/Member.astro create mode 100644 docs/src/components/diagrams/ChannelAnatomy.astro create mode 100644 docs/src/components/diagrams/Explainer.astro create mode 100644 docs/src/components/diagrams/PatternDiagram.astro create mode 100644 docs/src/components/diagrams/RegionAckExplainer.astro create mode 100644 docs/src/components/diagrams/SessionMap.astro create mode 100644 docs/src/components/diagrams/StateMachine.astro create mode 100644 docs/src/components/diagrams/Topology.astro create mode 100644 docs/src/components/diagrams/ZeroCopyExplainer.astro create mode 100644 docs/src/components/home/HomeCode.astro create mode 100644 docs/src/components/home/HomePaths.astro create mode 100644 docs/src/components/overrides/Footer.astro create mode 100644 docs/src/components/overrides/Header.astro create mode 100644 docs/src/components/overrides/Hero.astro create mode 100644 docs/src/components/overrides/MobileMenuFooter.astro create mode 100644 docs/src/components/overrides/PageSidebar.astro create mode 100644 docs/src/components/overrides/PageTitle.astro create mode 100644 docs/src/content.config.ts create mode 100644 docs/src/content/docs/concepts/channels.mdx create mode 100644 docs/src/content/docs/concepts/configuration.mdx create mode 100644 docs/src/content/docs/concepts/devices.mdx create mode 100644 docs/src/content/docs/concepts/messages.mdx create mode 100644 docs/src/content/docs/concepts/plugins.mdx create mode 100644 docs/src/content/docs/concepts/states.mdx create mode 100644 docs/src/content/docs/concepts/threads.mdx create mode 100644 docs/src/content/docs/concepts/transports.mdx create mode 100644 docs/src/content/docs/examples/1-1.mdx create mode 100644 docs/src/content/docs/examples/1-n-1.mdx create mode 100644 docs/src/content/docs/examples/builtin-devices.mdx create mode 100644 docs/src/content/docs/examples/copypush.mdx create mode 100644 docs/src/content/docs/examples/custom-controller.mdx create mode 100644 docs/src/content/docs/examples/dds.mdx create mode 100644 docs/src/content/docs/examples/multipart.mdx create mode 100644 docs/src/content/docs/examples/multiple-channels.mdx create mode 100644 docs/src/content/docs/examples/multiple-transports.mdx create mode 100644 docs/src/content/docs/examples/n-m.mdx create mode 100644 docs/src/content/docs/examples/qc.mdx create mode 100644 docs/src/content/docs/examples/readout.mdx create mode 100644 docs/src/content/docs/examples/region.mdx create mode 100644 docs/src/content/docs/examples/req-rep.mdx create mode 100644 docs/src/content/docs/guides/benchmark.mdx create mode 100644 docs/src/content/docs/guides/channels-without-device.mdx create mode 100644 docs/src/content/docs/guides/configure-channels.mdx create mode 100644 docs/src/content/docs/guides/control-from-code.mdx create mode 100644 docs/src/content/docs/guides/design-topology.mdx create mode 100644 docs/src/content/docs/guides/end-of-run.mdx create mode 100644 docs/src/content/docs/guides/errors-timeouts.mdx create mode 100644 docs/src/content/docs/guides/fairmq-tidy.mdx create mode 100644 docs/src/content/docs/guides/migrate-names.mdx create mode 100644 docs/src/content/docs/guides/pmr.mdx create mode 100644 docs/src/content/docs/guides/poll-channels.mdx create mode 100644 docs/src/content/docs/guides/receive-data.mdx create mode 100644 docs/src/content/docs/guides/send-data-types.mdx create mode 100644 docs/src/content/docs/guides/several-transports.mdx create mode 100644 docs/src/content/docs/guides/test-devices.mdx create mode 100644 docs/src/content/docs/guides/write-plugin.mdx create mode 100644 docs/src/content/docs/index.mdx create mode 100644 docs/src/content/docs/project/contributing.mdx create mode 100644 docs/src/content/docs/project/license.mdx create mode 100644 docs/src/content/docs/project/release-notes.mdx create mode 100644 docs/src/content/docs/reference/channel-properties.mdx create mode 100644 docs/src/content/docs/reference/cmake.mdx create mode 100644 docs/src/content/docs/reference/glossary.mdx create mode 100644 docs/src/content/docs/reference/json.mdx create mode 100644 docs/src/content/docs/reference/options.mdx create mode 100644 docs/src/content/docs/reference/states.mdx create mode 100644 docs/src/content/docs/reference/tools.mdx create mode 100644 docs/src/content/docs/reference/transfer-codes.mdx create mode 100644 docs/src/content/docs/shmem/how-it-works.mdx create mode 100644 docs/src/content/docs/shmem/monitor.mdx create mode 100644 docs/src/content/docs/shmem/regions.mdx create mode 100644 docs/src/content/docs/shmem/sessions.mdx create mode 100644 docs/src/content/docs/shmem/side-channel.mdx create mode 100644 docs/src/content/docs/shmem/tuning.mdx create mode 100644 docs/src/content/docs/start/cmake.mdx create mode 100644 docs/src/content/docs/start/first-device.mdx create mode 100644 docs/src/content/docs/start/install.mdx create mode 100644 docs/src/content/docs/start/overview.mdx create mode 100644 docs/src/content/docs/tools/builtin-devices.mdx create mode 100644 docs/src/content/docs/tools/fairmq-tidy.mdx create mode 100644 docs/src/content/docs/tools/logging.mdx create mode 100644 docs/src/content/docs/tools/shmmonitor.mdx create mode 100644 docs/src/data/option-texts.mjs create mode 100644 docs/src/env.d.ts create mode 100644 docs/src/lib/families.mjs create mode 100644 docs/src/lib/model.mjs create mode 100644 docs/src/lib/nav.ts create mode 100644 docs/src/pages/404.astro create mode 100644 docs/src/pages/api/[...slug].astro create mode 100644 docs/src/pages/api/index.astro create mode 100644 docs/src/pages/source/[...path].astro create mode 100644 docs/src/pages/source/index.astro create mode 100644 docs/src/styles/api.css create mode 100644 docs/src/styles/code-theme.json create mode 100644 docs/src/styles/source.css create mode 100644 docs/src/styles/theme.css create mode 100644 docs/tsconfig.json diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 00000000..80c62b0c --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,5 @@ +# Dependencies and build output of the docs site +node_modules/ +dist/ +.astro/ +build/ diff --git a/docs/Doxyfile b/docs/Doxyfile new file mode 100644 index 00000000..0dbad012 --- /dev/null +++ b/docs/Doxyfile @@ -0,0 +1,36 @@ +# Doxygen reads the FairMQ sources for the API and source pages of the site. +# It writes XML only. scripts/api.mjs turns the XML into page data. + +PROJECT_NAME = FairMQ +OUTPUT_DIRECTORY = build/doxygen +INPUT = ../fairmq +FILE_PATTERNS = *.h *.cxx +RECURSIVE = YES +STRIP_FROM_PATH = .. +FULL_PATH_NAMES = YES + +GENERATE_HTML = NO +GENERATE_LATEX = NO +GENERATE_XML = YES +XML_PROGRAMLISTING = YES + +EXTRACT_ALL = YES +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = NO +EXTRACT_ANON_NSPACES = NO +HIDE_FRIEND_COMPOUNDS = YES +BUILTIN_STL_SUPPORT = YES +INLINE_INHERITED_MEMB = NO + +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = .. + +QUIET = YES +WARNINGS = NO +WARN_IF_UNDOCUMENTED = NO +WARN_IF_DOC_ERROR = NO diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..c9453bbc --- /dev/null +++ b/docs/README.md @@ -0,0 +1,51 @@ +# FairMQ documentation site + +This folder is the source of . The site +uses [Astro](https://astro.build/) with [Starlight](https://starlight.astro.build/). +The workflow [`docs.yml`](../.github/workflows/docs.yml) builds the site for each +pull request and deploys it to GitHub Pages for each push to `dev`. + +## Requirements + +* Node.js 22.23.4 or newer +* Doxygen 1.9 or newer. The API reference and the source browser use its XML output. +* git. The site shows the version from `git describe`. + +## Build + +```sh +cd docs +npm ci +npm run dev # local server at http://localhost:4321/FairMQ/, it reloads after changes +npm run build # writes the site to dist/ +npm run check # checks all links in dist/ +npm run preview # serves dist/ +``` + +The build runs Doxygen on `fairmq/` and writes the XML to `build/doxygen/`. The next +builds run Doxygen again only when a file in `fairmq/` is newer than the XML. + +## Contents + +| Path | Contents | +| --- | --- | +| `src/content/docs/` | The pages, in MDX. Each folder is a group of the sidebar. | +| `src/pages/api/` | The API reference, from the Doxygen XML | +| `src/pages/source/` | The source browser, from the Doxygen XML | +| `src/pages/404.astro` | The 404 page. It sends the URLs of the old Doxygen site to the new pages. | +| `src/components/` | Components for the pages: `Snippet`, the diagrams, the option tables | +| `src/data/option-texts.mjs` | The descriptions of the command-line options. Names, types and defaults come from the code. | +| `scripts/` | The data for the generated pages, and the checks | + +## Write a page + +* Each page starts with frontmatter: `title`, `description` and `sidebar.order`. +* Show code of the repository with ``, not with a copy. Then the samples + are code that CI compiles, and the build fails when the code changes and the + sample does not agree. `src/components/Snippet.astro` shows the usage. +* Write links root-relative and without the base: `/concepts/channels/`, + `/api/fair/mq/Channel/`, `/source/fairmq/Channel.h/#L36`. +* Run `node scripts/check-pages.mjs` before you build. It checks the frontmatter, the + MDX syntax, the snippets and all links in a few seconds. +* Write in the style of ASD-STE100 (Simplified Technical English): short sentences, + one instruction for each sentence, the active voice. diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs new file mode 100644 index 00000000..ebd25dbf --- /dev/null +++ b/docs/astro.config.mjs @@ -0,0 +1,102 @@ +// @ts-check +import { readFileSync } from 'node:fs'; +import { defineConfig } from 'astro/config'; +import starlight from '@astrojs/starlight'; +import starlightLinksValidator from 'starlight-links-validator'; +import { satteri } from '@astrojs/markdown-satteri'; +import baseLinks from './scripts/base-links.mjs'; +import nowrapCode from './scripts/nowrap-code.mjs'; +import fairmqData from './scripts/integration.mjs'; + +const base = '/FairMQ'; +const codeTheme = JSON.parse(readFileSync(new URL('./src/styles/code-theme.json', import.meta.url), 'utf8')); + +export default defineConfig({ + site: 'https://fairrootgroup.github.io', + base, + markdown: { + processor: satteri({ hastPlugins: [baseLinks({ base }), nowrapCode()] }), + // Keep -- and ... as typed: options like --rate and quoted log output must stay exact. + smartypants: false, + }, + integrations: [ + fairmqData(), + starlight({ + title: 'FairMQ', + description: 'FairMQ is a C++17 message queuing library and framework for large-scale data processing.', + favicon: '/favicon.svg', + social: [{ icon: 'github', label: 'GitHub', href: 'https://github.com/FairRootGroup/FairMQ' }], + editLink: { baseUrl: 'https://github.com/FairRootGroup/FairMQ/edit/dev/docs/' }, + lastUpdated: true, + disable404Route: true, + customCss: [ + '@fontsource-variable/archivo/wdth.css', + '@fontsource-variable/jetbrains-mono/wght.css', + '@fontsource-variable/jetbrains-mono/wght-italic.css', + './src/styles/theme.css', + ], + components: { + Header: './src/components/overrides/Header.astro', + PageTitle: './src/components/overrides/PageTitle.astro', + Footer: './src/components/overrides/Footer.astro', + PageSidebar: './src/components/overrides/PageSidebar.astro', + Hero: './src/components/overrides/Hero.astro', + MobileMenuFooter: './src/components/overrides/MobileMenuFooter.astro', + }, + expressiveCode: { + themes: [codeTheme], + useStarlightDarkModeSwitch: false, + useStarlightUiThemeColors: false, + styleOverrides: { + borderRadius: '6px', + borderColor: 'var(--fmq-code-rule)', + codeBackground: 'var(--fmq-code-bg)', + codeFontFamily: 'var(--fmq-font-mono)', + codeFontSize: '0.84rem', + codeLineHeight: '1.65', + uiFontFamily: 'var(--fmq-font-body)', + frames: { + editorBackground: 'var(--fmq-code-bg)', + editorTabBarBackground: 'var(--fmq-code-bg)', + editorActiveTabBackground: 'var(--fmq-code-bg)', + editorActiveTabIndicatorTopColor: 'transparent', + editorActiveTabIndicatorBottomColor: 'var(--fmq-saffron)', + editorTabBarBorderBottomColor: 'var(--fmq-code-rule)', + terminalBackground: 'var(--fmq-code-bg)', + terminalTitlebarBackground: 'var(--fmq-code-bg)', + terminalTitlebarBorderBottomColor: 'var(--fmq-code-rule)', + terminalTitlebarDotsForeground: 'var(--fmq-stage-line)', + terminalTitlebarDotsOpacity: '1', + frameBoxShadowCssValue: 'none', + inlineButtonBorder: 'var(--fmq-code-rule)', + }, + }, + }, + sidebar: [ + { label: 'Start', items: [{ autogenerate: { directory: 'start' } }] }, + { label: 'Concepts', items: [{ autogenerate: { directory: 'concepts' } }] }, + { label: 'Guides', items: [{ autogenerate: { directory: 'guides' } }] }, + { label: 'Shared memory', items: [{ autogenerate: { directory: 'shmem' } }] }, + { label: 'Tools', items: [{ autogenerate: { directory: 'tools' } }] }, + { label: 'Reference', items: [{ autogenerate: { directory: 'reference' } }] }, + { label: 'Examples', collapsed: true, items: [{ autogenerate: { directory: 'examples' } }] }, + { label: 'Project', collapsed: true, items: [{ autogenerate: { directory: 'project' } }] }, + { + label: 'Code', + items: [ + { label: 'API reference', link: '/api/' }, + { label: 'Source browser', link: '/source/' }, + ], + }, + ], + plugins: [ + starlightLinksValidator({ + errorOnRelativeLinks: false, + // Generated pages, and the row anchors of (the validator sees only + // headings). scripts/check-links.mjs checks these links in dist/. + exclude: ['/FairMQ/api/**', '/FairMQ/source/**', '/FairMQ/reference/options/#opt-*'], + }), + ], + }), + ], +}); diff --git a/docs/package-lock.json b/docs/package-lock.json new file mode 100644 index 00000000..41cf3c52 --- /dev/null +++ b/docs/package-lock.json @@ -0,0 +1,5394 @@ +{ + "name": "fairmq-docs", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fairmq-docs", + "version": "0.0.0", + "dependencies": { + "@astrojs/markdown-satteri": "0.4.6", + "@astrojs/starlight": "0.42.9", + "@fontsource-variable/archivo": "5.3.0", + "@fontsource-variable/jetbrains-mono": "5.3.0", + "astro": "7.4.5", + "fast-xml-parser": "5.12.0", + "shiki": "4.6.0" + }, + "devDependencies": { + "starlight-links-validator": "0.27.0" + }, + "engines": { + "node": ">=22.23.4" + } + }, + "node_modules/@astrojs/compiler-binding": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding/-/compiler-binding-0.5.2.tgz", + "integrity": "sha512-lEn76+0JcMQ5RDXU0wSMWJg2ZppiZvSULpghC29cfv4o9bhvWFDbQjsCtvjjXN9iVLFQ7fL3wTR2L2UU13mP8g==", + "license": "MIT", + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@astrojs/compiler-binding-android-arm64": "0.5.2", + "@astrojs/compiler-binding-darwin-arm64": "0.5.2", + "@astrojs/compiler-binding-darwin-x64": "0.5.2", + "@astrojs/compiler-binding-linux-arm64-gnu": "0.5.2", + "@astrojs/compiler-binding-linux-arm64-musl": "0.5.2", + "@astrojs/compiler-binding-linux-x64-gnu": "0.5.2", + "@astrojs/compiler-binding-linux-x64-musl": "0.5.2", + "@astrojs/compiler-binding-wasm32-wasi": "0.5.2", + "@astrojs/compiler-binding-win32-arm64-msvc": "0.5.2", + "@astrojs/compiler-binding-win32-x64-msvc": "0.5.2" + } + }, + "node_modules/@astrojs/compiler-binding-android-arm64": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-android-arm64/-/compiler-binding-android-arm64-0.5.2.tgz", + "integrity": "sha512-kckIxon6Rm/Bxzh9mGPYpRRqUbToUQoHptCmpMmE+Yt0Xumq8CqrKUidyYhrBsrHVO7bxuRzzWUUqvpf+iYceQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-darwin-arm64": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-darwin-arm64/-/compiler-binding-darwin-arm64-0.5.2.tgz", + "integrity": "sha512-1ZG5Ar3dD8HtodX9XH1mRmE0qBXZlvjYXSFfpgFwocqfWnvhFuqtGUNseL8wgfImiRMztIjpQqlogQFQQtgiag==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-darwin-x64": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-darwin-x64/-/compiler-binding-darwin-x64-0.5.2.tgz", + "integrity": "sha512-+kl35S7hiHJ2cb7eujwEsPFYYuSgE11uEE2Z20lAJ+undpgulMcW+weQqFPOSSZccEKHOiLIY+kQHkb4e4092w==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-linux-arm64-gnu": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-linux-arm64-gnu/-/compiler-binding-linux-arm64-gnu-0.5.2.tgz", + "integrity": "sha512-BqlR0EHNQLPLwgL9+xogjsAc7zGf0cHho2CPdhv0P1yqbVMwGVaGAqrANP6VYAXCqSC43AF4Czcxc2n+oqdesg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-linux-arm64-musl": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-linux-arm64-musl/-/compiler-binding-linux-arm64-musl-0.5.2.tgz", + "integrity": "sha512-GRGyby3AZWw5d6JQzidyxPyvGgHWsSusrpgKyFVpDTKctABF7L3Pd5V1cRJbV36/rcu+Eh292/wL7pF7MkmGkQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-linux-x64-gnu": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-linux-x64-gnu/-/compiler-binding-linux-x64-gnu-0.5.2.tgz", + "integrity": "sha512-9XAqGTMQAtIslMsjK3xdyY6OI9d59OZqcLBB6pvD/DcoR0daYswfrKx2azdDERDY4AqAnWPC7odVM1BmxYv3Vw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-linux-x64-musl": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-linux-x64-musl/-/compiler-binding-linux-x64-musl-0.5.2.tgz", + "integrity": "sha512-jOViewGeTh9bSfS8vK72ECxoy2yvmA+Pd/ZcEvBI5c7+7IcfHwZ5qA4L9fRYuOhSrAifvQ2dV4vm1XAtloaWBw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-wasm32-wasi": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-wasm32-wasi/-/compiler-binding-wasm32-wasi-0.5.2.tgz", + "integrity": "sha512-Z7p64doar1uvR5C9Xs6j1CV9lGlPVQX7OQ2aAtZ/xKC5aGS6GB13nyc2UfQXTQLvZrvVwsyaflTQy6ziY5Bekw==", + "cpu": [ + "wasm32" + ], + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "1.11.3", + "@emnapi/runtime": "1.11.3", + "@napi-rs/wasm-runtime": "^1.2.5" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-win32-arm64-msvc": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-win32-arm64-msvc/-/compiler-binding-win32-arm64-msvc-0.5.2.tgz", + "integrity": "sha512-Tr13bh+ahTWsjXjzctK7pFpWV+dUU4FtBfETlR7gO+ueex0F+RDch7eRr0YfKysaRhk9tWm14lsCJ5uWyFPNHQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-binding-win32-x64-msvc": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-binding-win32-x64-msvc/-/compiler-binding-win32-x64-msvc-0.5.2.tgz", + "integrity": "sha512-SfKkI+jOQYLh6wojPvVPV0lFfQnxisweN9B+qCzRvZp7DHAuGif8Y0WcC5PUgN4jb8VKy57LggQDtggR46Du1g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@astrojs/compiler-rs": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler-rs/-/compiler-rs-0.5.2.tgz", + "integrity": "sha512-IvwYLB8t1M86rKO4oPdBi9GP4gzXcgrVlNgocjwos1jeeUuEIV8d9Crn1PvYD/5IKteWOxpIHomf7e8iYlkE+Q==", + "license": "MIT", + "dependencies": { + "@astrojs/compiler-binding": "0.5.2" + }, + "engines": { + "node": ">=22.12.0" + } + }, + "node_modules/@astrojs/internal-helpers": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@astrojs/internal-helpers/-/internal-helpers-0.13.0.tgz", + "integrity": "sha512-20jxQqnSmpskcGyad7N5l6Xf1gz0UCa6lNde44bEBdaXGpncEYfAZJ142r2ZgzBaG4dUyzGmhqZWv1INU2eiHQ==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.5", + "@types/mdast": "^4.0.4", + "picomatch": "^4.0.7", + "retext-smartypants": "^6.2.0", + "shiki": "^4.5.0", + "smol-toml": "^1.9.1", + "unified": "^11.0.5", + "yaml": "^2.9.1" + } + }, + "node_modules/@astrojs/markdown-satteri": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/@astrojs/markdown-satteri/-/markdown-satteri-0.4.6.tgz", + "integrity": "sha512-6biKp2lEAYycF3jhv91br+Otyf4EgDFkF1oRL9ks0u/m/YRGmI7XkGQ2MgaM35DslT03f7NtozKtlqfBNkp6bw==", + "license": "MIT", + "dependencies": { + "@astrojs/internal-helpers": "0.13.0", + "@astrojs/prism": "4.1.2", + "github-slugger": "^2.0.0", + "satteri": "^0.10.5" + } + }, + "node_modules/@astrojs/mdx": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@astrojs/mdx/-/mdx-8.1.2.tgz", + "integrity": "sha512-ZIUVfosVtK4SKcFrGOH+1+HwG0encjxQOxu76M9VuTqeQNZWQ//2eY2Iz+W1eq87AOT5JD4wOHyZ8xFwlcFteg==", + "license": "MIT", + "dependencies": { + "@astrojs/internal-helpers": "0.13.0", + "@astrojs/markdown-satteri": "0.4.6", + "es-module-lexer": "^3.0.3" + }, + "engines": { + "node": ">=22.23.4" + }, + "peerDependencies": { + "@astrojs/markdown-remark": "^7.3.0", + "@astrojs/markdown-satteri": "^0.4.0", + "astro": "^7.2.10" + }, + "peerDependenciesMeta": { + "@astrojs/markdown-remark": { + "optional": true + } + } + }, + "node_modules/@astrojs/prism": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/@astrojs/prism/-/prism-4.1.2.tgz", + "integrity": "sha512-jMrUEpFDarDO1KWPvVc9eSa8DSfwBlwEOHwX+8zvZQpiqXRGDxFnOXHsYqV6DP7w+0qIgTr98gS1GdQlm8ypWg==", + "license": "MIT", + "dependencies": { + "prismjs": "^1.30.0" + }, + "engines": { + "node": ">=22.23.4" + } + }, + "node_modules/@astrojs/sitemap": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/@astrojs/sitemap/-/sitemap-3.7.4.tgz", + "integrity": "sha512-LbKNC24bdUWcQf/pThB6qLlSqHojxGjZDURIzFocY8rlWnAn2t74nnhnK6S5x0NHriHoAduLEpVjRykmeGiVvA==", + "license": "MIT", + "dependencies": { + "sitemap": "^9.0.0", + "zod": "^4.3.6" + } + }, + "node_modules/@astrojs/starlight": { + "version": "0.42.9", + "resolved": "https://registry.npmjs.org/@astrojs/starlight/-/starlight-0.42.9.tgz", + "integrity": "sha512-kMqDdFDWBClBNY9fc3pWAlR+eFh6JhOd7lIr4RczNDXUVk9EzzxVQvYizRuxlx0aVbSk8Gb1rVHiJlxgybwc/g==", + "license": "MIT", + "dependencies": { + "@astrojs/markdown-satteri": "^0.4.3", + "@astrojs/mdx": "^8.0.3", + "@astrojs/sitemap": "^3.7.4", + "@pagefind/default-ui": "^1.3.0", + "@types/hast": "^3.0.5", + "@types/mdast": "^4.0.4", + "astro-expressive-code": "^0.44.0", + "bcp-47": "^2.1.0", + "hast-util-format": "^1.1.0", + "hast-util-select": "^6.0.4", + "hast-util-to-html": "^9.0.5", + "hast-util-to-string": "^3.0.1", + "hastscript": "^9.0.1", + "i18next": "^26.0.7", + "klona": "^2.0.6", + "magic-string": "^1.2.3", + "mdast-util-directive": "^3.1.0", + "mdast-util-to-markdown": "^2.1.2", + "mdast-util-to-string": "^4.0.0", + "pagefind": "^1.5.2", + "remark-directive": "^4.0.0", + "satteri": "^0.10.3", + "ultrahtml": "^1.6.0", + "unified": "^11.0.5", + "unist-util-visit": "^5.1.0", + "vfile": "^6.0.3", + "yaml": "^2.9.1" + }, + "peerDependencies": { + "@astrojs/markdown-remark": "^7.3.0", + "astro": "^7.2.10" + }, + "peerDependenciesMeta": { + "@astrojs/markdown-remark": { + "optional": true + } + } + }, + "node_modules/@astrojs/telemetry": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/@astrojs/telemetry/-/telemetry-3.4.2.tgz", + "integrity": "sha512-2JOMRUxJrBSfiVDfeKLv1wBmvSIx1Y6u2YEO8awZ9qSq3u/rNAiUyFdOYi8dHv91kHrmYEQX7pRDw0J4xyj3UA==", + "license": "MIT", + "dependencies": { + "ci-info": "^4.4.0", + "dset": "^3.1.4", + "is-docker": "^4.0.0", + "package-manager-detector": "^1.9.0" + }, + "engines": { + "node": ">=22.23.4" + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.13.tgz", + "integrity": "sha512-fWegr+WsEsiMVW4KUNdIIzzMTZSzNiqhy0//6+2MRi2d5NFNsL/AYwBQW8eBnRbTBVRnDVzjaJEUqKaCWjMMdQ==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/parser": { + "version": "7.29.13", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.13.tgz", + "integrity": "sha512-fJM50YYjlTiBhgdkGmC1tBpv+FMAyo4annf2X6Aks+0yRlaiVkYW/3f07xAfVVkYIoZ9fFZp+mEThUFnuybhkQ==", + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.11" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.11", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.11.tgz", + "integrity": "sha512-WCsemW40Cpc6gouC1SrY6PBaZ+oLRlEVY9XBvZBI7il/HyUrb2nJ505wE1MHEFyDZNnrWDEuy4jL50WVHfTTSQ==", + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.29.11", + "@babel/helper-validator-identifier": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@bruits/satteri-darwin-arm64": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-darwin-arm64/-/satteri-darwin-arm64-0.10.5.tgz", + "integrity": "sha512-27KTVl4TJkVahMy/ohyA7qd4938G5UNneFUz/PsScYfpIhj0IVAS23mpcJXdPF44sa6nva198lmV/cKIb2YPyA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@bruits/satteri-darwin-x64": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-darwin-x64/-/satteri-darwin-x64-0.10.5.tgz", + "integrity": "sha512-IjnLe3nKspq6qaeqGgjT7MT8VrTV74yWRlaag7ZdNsI8TDAYZ0iPxMCo+9KQZHUk5EyVB+reBI/PFWL5KuFw9Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@bruits/satteri-linux-arm64-gnu": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-linux-arm64-gnu/-/satteri-linux-arm64-gnu-0.10.5.tgz", + "integrity": "sha512-glkYXZCJywjP13v67eAyAMSJdF+ncvEbYvgi/wOtffL9tQ27lr/zsyzUfgs+ovjJ9d8JNQKiXeiArJcX8PJL9w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@bruits/satteri-linux-arm64-musl": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-linux-arm64-musl/-/satteri-linux-arm64-musl-0.10.5.tgz", + "integrity": "sha512-yWdgG1g17Nh2QyGVlFUxGRa3FEFwiMcpZEyMNWkbM3deC94cmVc+/i9OuyFpdKuWo3GkgoCtYVOoxk1uCnCZIA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@bruits/satteri-linux-x64-gnu": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-linux-x64-gnu/-/satteri-linux-x64-gnu-0.10.5.tgz", + "integrity": "sha512-FVaLoPT1fBgGl0J+AYebyyXJYBachGl8Oyyrf1lye4RTqCB4S0Gwkj1uM9RJyThUOvx5VUmAT1CnNh1SFHA+kw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@bruits/satteri-linux-x64-musl": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-linux-x64-musl/-/satteri-linux-x64-musl-0.10.5.tgz", + "integrity": "sha512-EHpVAx2bqW3GINHTKkljtxVfQmVDGWIuwOYOP5YghTj+0PkBa2o8oKPRtQ9Kbsr1Fye8jtUcDjhwj2jMNugZKg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@bruits/satteri-wasm32-wasi": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-wasm32-wasi/-/satteri-wasm32-wasi-0.10.5.tgz", + "integrity": "sha512-ypz8c/Zmipxp4IoeDa228Gstv6TLzVmNs3yC6wKCoNSOjx1iwpgzu87Y3hTkXFdwChVGU85qeUDuOIarGUZQLw==", + "cpu": [ + "wasm32" + ], + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/core": "1.11.1", + "@emnapi/runtime": "1.11.1", + "@napi-rs/wasm-runtime": "^1.2.3" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@bruits/satteri-wasm32-wasi/node_modules/@emnapi/core": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.1.tgz", + "integrity": "sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ==", + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.2", + "tslib": "^2.4.0" + } + }, + "node_modules/@bruits/satteri-wasm32-wasi/node_modules/@emnapi/runtime": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.1.tgz", + "integrity": "sha512-vgj7R3y3Wgx24IQaGPA/R6YFXLHVMOZ0uVEyIQPaWs+rd1AzfEMXlAC22FYwO1XkKR6NPsq7mUandH8oIRdZFw==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@bruits/satteri-wasm32-wasi/node_modules/@emnapi/wasi-threads": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz", + "integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@bruits/satteri-win32-arm64-msvc": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-win32-arm64-msvc/-/satteri-win32-arm64-msvc-0.10.5.tgz", + "integrity": "sha512-siTV88nb0LRqNpkL2gXboqCwVdq95sLtzMHS1/3eONV2gLbB3NAK46wmSMvCO/yquBvI2lvaFIfd8P12ecsxBw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@bruits/satteri-win32-x64-msvc": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@bruits/satteri-win32-x64-msvc/-/satteri-win32-x64-msvc-0.10.5.tgz", + "integrity": "sha512-C3IfPvfvMXmlzBxaMPKFS1XiuV9pu2mC7YqkPk7PSvTgPZ8gbdASIpHpztDLvTTQjqZ0z1Ol8tK5X+V6XXC0wQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@capsizecss/unpack": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@capsizecss/unpack/-/unpack-4.0.1.tgz", + "integrity": "sha512-CuNiSqg7+e1cO/GjffyMOm5Tt2jUF9CWHHnvQ/UkqvtkGfHdgwEC0wpmq7fkN3gxwpRnrAN0WzO3vREKmNolMQ==", + "license": "MIT", + "dependencies": { + "fontkitten": "^1.0.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@clack/core": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@clack/core/-/core-1.5.1.tgz", + "integrity": "sha512-iHTrHA8MtVuLl2TfZySmcKv1qO2PoyC9Z7pfSDozEuV5vtY3/wcOPKJXlqJ5Oq2Cx5DDGQGAMVx6HZfRRoVEbQ==", + "license": "MIT", + "dependencies": { + "fast-wrap-ansi": "^0.2.0", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 20.12.0" + } + }, + "node_modules/@clack/prompts": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/@clack/prompts/-/prompts-1.8.1.tgz", + "integrity": "sha512-dlT1m5e/0yUL0kRNcQn7yGLVThkgbB0Ga/1AmfDDC/8ik6AIiSf2QLQO2zPYvefsHP0aFgxO93cVLCCfDp7kzQ==", + "license": "MIT", + "dependencies": { + "@clack/core": "1.5.1", + "fast-string-width": "^3.0.2", + "fast-wrap-ansi": "^0.2.0", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 20.12.0" + } + }, + "node_modules/@ctrl/tinycolor": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@ctrl/tinycolor/-/tinycolor-4.2.2.tgz", + "integrity": "sha512-9rQHijqB2Rq6qOEC/xHaA6aPlsKGi5kmCQW50O1asn9g63XFeD5NmBwysriistW5Xx0JPafyD/TA7yk2S3pXGQ==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, + "node_modules/@emnapi/core": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.3.tgz", + "integrity": "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==", + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.3", + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime": { + "version": "1.11.3", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz", + "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/wasi-threads": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz", + "integrity": "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@expressive-code/core": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/@expressive-code/core/-/core-0.44.3.tgz", + "integrity": "sha512-pffktF0TJoxC08dgNcutl/0LcSnTrjF6vXR39qVpwZ0EyxpwO9zjI7dbni6sO7w3yHpRBO0voLFvhzB+EPJRsA==", + "license": "MIT", + "dependencies": { + "@ctrl/tinycolor": "^4.0.4", + "hast-util-select": "^6.0.2", + "hast-util-to-html": "^9.0.1", + "hast-util-to-text": "^4.0.1", + "hastscript": "^9.0.0", + "postcss": "^8.4.38", + "postcss-nested": "^7.0.2", + "unist-util-visit": "^5.0.0", + "unist-util-visit-parents": "^6.0.1" + } + }, + "node_modules/@expressive-code/plugin-frames": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/@expressive-code/plugin-frames/-/plugin-frames-0.44.3.tgz", + "integrity": "sha512-ysW4VXk9vXEliA99Ur6ApUepVtx74sPolp6o/j45BRjZQoL5O6kXKMhSP4koQLih8HbC5B3ImIvO+HKKhkv/oA==", + "license": "MIT", + "dependencies": { + "@expressive-code/core": "^0.44.3" + } + }, + "node_modules/@expressive-code/plugin-shiki": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/@expressive-code/plugin-shiki/-/plugin-shiki-0.44.3.tgz", + "integrity": "sha512-jAibAZPG7lDmi61EFJADZjoSZzjHiwZZdbbgR/mTlWXM4ON/Pyo/9tB2vrqQNKylsci6jqtCi6idrwqQXF53xA==", + "license": "MIT", + "dependencies": { + "@expressive-code/core": "^0.44.3", + "shiki": "^4.0.2" + } + }, + "node_modules/@expressive-code/plugin-text-markers": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/@expressive-code/plugin-text-markers/-/plugin-text-markers-0.44.3.tgz", + "integrity": "sha512-4Ae2xRSDV5kdWPsi40xWbOtoihbzM0zLVjQKkDAnD5KzFXl+6/kd+VhuWOlTRVaJ5cqGk++vCbAaf0MR1XbZlw==", + "license": "MIT", + "dependencies": { + "@expressive-code/core": "^0.44.3" + } + }, + "node_modules/@fontsource-variable/archivo": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/archivo/-/archivo-5.3.0.tgz", + "integrity": "sha512-HogK8FJelrD1o7TlZlkIVtHgc20bO5PZRWE7mUeUTdMN055alznQV6/00J00IBeu8FQAH4s3zW9UJNvKExXf+g==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/jetbrains-mono": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/jetbrains-mono/-/jetbrains-mono-5.3.0.tgz", + "integrity": "sha512-F32xpS2NsGYoQi2ADSkKTgpJj7ozajsGgDJ8woTnqjmIB+dxDIqImjl4pXZVEExu8UFZ2ndhmX18EBS/hdz3Lw==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@img/colour": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", + "integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.35.5.tgz", + "integrity": "sha512-QRUlFQ0WxvdWyqqG/WtI3iupfD5rBzmCHXSdPsY91sAtVtTo7Q4cb6zOccZ3gqEqkr0f1As1ehLqmEpDsRf+lg==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.35.5.tgz", + "integrity": "sha512-+BR255RhDlpygUpOc/Jdt1nT6DQ3XG/ERo5wbcdOf5Q320dKtPCKPLR1LJs9VGXRaMa8l1uUa0tkCNOXiAxZUw==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-freebsd-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.5.tgz", + "integrity": "sha512-Y/z91nEZ4uIBX5X3nfTovjU9lHNKFYbL2lpHCLVNmXQK03VIZvXBBt0KxbPGp2SdGSF+2mQU4e+hQaWOt86iAw==", + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "dependencies": { + "@img/sharp-wasm32": "0.35.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.3.4.tgz", + "integrity": "sha512-5R89nBYiRdUlSWJxPhO+GVtaXzXSxKnRu/xqMn3KTA3L9EB9Oy/P+Nn2f2vlhPuUdy/Zusb2DarbyTpGCfEDuw==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.3.4.tgz", + "integrity": "sha512-iR2OKH80yi0U+dUplyh3/xdpFvps6YkCwsXenIJxqxR1v9o+xtKTGbS9H7cps+2Vxjc8B1j96p75NmTGjIhtpQ==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.3.4.tgz", + "integrity": "sha512-LmRtTsOHuvM2+wlO2Db37dx5MiZhB0FvSunciw48YjdOkZz9KAiRbm8ujeMOA1INqmei5NapFxYEK1D1ZSidmw==", + "cpu": [ + "arm" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.3.4.tgz", + "integrity": "sha512-Y3dgX/6lE2QhQb+Gxy0WZxfg9MEm/JBjamZpS2IklP7xIQoKN4hzAm7KcMVGtaVDt3neE9OKBC7vAfonA/Lr1A==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-ppc64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.3.4.tgz", + "integrity": "sha512-Le6boB8Tai0Nis+gIxIpKx68UDVVIqdR8Tin5Yf1z2LJJQLDJvCDRqRu+jC2qCoD+eIomonmOwB4smBRxfVpYQ==", + "cpu": [ + "ppc64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-riscv64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.3.4.tgz", + "integrity": "sha512-aHkkIEHPRdQEegJN20MLmGtxYD9R2wQr3Cwpddnu5+YKMt6Uzax7S9h5gpZTo8wyrGuZSlfQ63OevL5mTyOC7Q==", + "cpu": [ + "riscv64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.3.4.tgz", + "integrity": "sha512-ra/mB6MikESDUO7Yg+Mi95bFBb9GsObURuhnOv3OqknjGe9sZrG8tCe9q0xSIGrtLgvgw0gKnFWcK4blSgQOuQ==", + "cpu": [ + "s390x" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.3.4.tgz", + "integrity": "sha512-GJ//SSXbnwSDes02umB3nDJLFcQzw8a18V8fyhqr6tV515tOEMdImjjxj1AoafMRz56F3PHgftnj1QEKSU1zkw==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.3.4.tgz", + "integrity": "sha512-hvulFwtjUcagsis6BBxHwGFwWoNZjgYmULGVrZcyfNbjA8hKILbRxGg15/7w5HDyXHXUos/j6baAWqnCyQ2DWA==", + "cpu": [ + "arm64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.3.4.tgz", + "integrity": "sha512-6zXKeE/p39I1AmA3cJG35eyBGNqNddLnUXjhwBnsGjFPWqf5VKkDBEqaEkPDoTEtkxwi2vv8Tcr2mDyP4So7Fg==", + "cpu": [ + "x64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.35.5.tgz", + "integrity": "sha512-LEaXK2WdXVK5ykcw0buWyPMsmLLL2vpHLD6yrNSW+JGEL3BZPA4tpKN6iaMc4AxTTAoaX/sU1rOL51lcIz48ZQ==", + "cpu": [ + "arm" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.35.5.tgz", + "integrity": "sha512-LYVx5JTsOM2CBzmxreh+nl64/3H6Xb09iSLknqH47z2T2DFFxDeFLP5y4dJwe6H7uGQlHPyEEtIqyo3DYsRwdQ==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-ppc64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.35.5.tgz", + "integrity": "sha512-QVxAAq8evVRI9ia2vqgwrmWucn5Dfv+JdWzj75pD8omHLPSP7f8p20O8jxzjCcuCEQEOtYOZUmX1hkiZ0kdevA==", + "cpu": [ + "ppc64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-ppc64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-riscv64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.35.5.tgz", + "integrity": "sha512-LtdreXguaavKODPIfzJ4kffx7UNt1omwtK0rch4EBbbSTXPnxWmYSayXdLJw0fJzQ97kHt1gL/yh4tvU+nCyRQ==", + "cpu": [ + "riscv64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-riscv64": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.35.5.tgz", + "integrity": "sha512-UZasTOFiYzotTsGOCu42BfUzP6Tu6Do/947iRm1RsLKvlllxwGcn4RN27LibGWceix4Y+Pmw3jsnTcCQIgWjqA==", + "cpu": [ + "s390x" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.3.4" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.35.5.tgz", + "integrity": "sha512-SxFtLTeJInhAA9Q836kux2vZNeOBQEx658qvbboZScr0wIARym3IcGmW7KpVD5sbVg0Ojy+udFQdayYIZyoNog==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.35.5.tgz", + "integrity": "sha512-9HbMclmI1zlNkFRs3z9/eBtDjfD0sGlrX1z6b1qwmiFY5ElDLh4BC0LPBdVp7z1DXFiKlIcznf+ZlsuZzLxQqg==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.3.4" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.35.5.tgz", + "integrity": "sha512-4KOphqB035HrVdqLZfCgMzzERrQkkzOwRhl4OAkRO1YCldbaFjySXMaK534Mo0V+LndnlJk+sbUyLeU0ULyD1A==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.3.4" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.5.tgz", + "integrity": "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ==", + "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.11.3" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-webcontainers-wasm32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.5.tgz", + "integrity": "sha512-hfhF/FmoQyTUkA0bIKFOtw536BQSeBMe6BF6QyWlrPxT754+TFLaZ7sKKTfvvM0yJgKgaYTwnFCIZ/GuDw5SUA==", + "cpu": [ + "wasm32" + ], + "license": "Apache-2.0", + "optional": true, + "dependencies": { + "@img/sharp-wasm32": "0.35.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-arm64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.35.5.tgz", + "integrity": "sha512-X4t7g+7ZA5DKblCBEXGjUqqemj4vczING/5viFwAL8h4N3qYeyjwdCvRLHi4EdOUI+2Z7UFlp1VM+p/AuEtm6Q==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.35.5.tgz", + "integrity": "sha512-5Zm82LoBc43nhwNybZlG7Y1KO//Zhsn306fQl29ZOuStHLGTo3BWL83q3cznX0poxSAMuYL1On/BHBxkBeKr6A==", + "cpu": [ + "ia32" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.35.5.tgz", + "integrity": "sha512-x76eH0vEiHlcMQu8Y8IenntaACtddpT6W0wmXtWrnKcnKI7ME5DdgqhAD6SEWOEl1v2zDvkZDhFA9KnURwpfqg==", + "cpu": [ + "x64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "license": "MIT" + }, + "node_modules/@napi-rs/wasm-runtime": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.7.tgz", + "integrity": "sha512-zJccwplOAbgfZju95IUHazLnx9RAPtPN2YGJXI6UbrgeaR9QfPjGrQL6ERkSAtnVCA4Q+83ApGyaX5zdpCaKkQ==", + "license": "MIT", + "optional": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3", + "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2 || 2.0.0-beta.3" + } + }, + "node_modules/@nodable/entities": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-3.1.0.tgz", + "integrity": "sha512-LsS/DjHr+uDM647Gru/cA8+J3a3HfhttwCKLyuoyN7yXTFCxKBtSgMQBvrW9yNPa2/zDRUNuGPaH5QUFoa4arQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/nodable" + } + ], + "license": "MIT" + }, + "node_modules/@oslojs/encoding": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@oslojs/encoding/-/encoding-1.1.0.tgz", + "integrity": "sha512-70wQhgYmndg4GCPxPPxPGevRKqTIJ2Nh4OkiMWmDAVYsTQ+Ta7Sq+rPevXyXGdzr30/qZBnyOalCszoMxlyldQ==", + "license": "MIT" + }, + "node_modules/@oxc-project/types": { + "version": "0.156.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz", + "integrity": "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@pagefind/darwin-arm64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.6.0.tgz", + "integrity": "sha512-611gl64aqN12UcMyKPtZ8+vRWBKlJFSh2JgO8uScxa1Eyjo1dXz9r4wZuRno0yCUE/KN0FauEoKZ3KEwUYHCCg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@pagefind/darwin-x64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-x64/-/darwin-x64-1.6.0.tgz", + "integrity": "sha512-rd3ZbtuxyYqjASKZAPuIV7eeQQHJ7VYpoNKKG8CvglaD3g30eT5Nb7XGNLYwVReBsCccpkURwrGwWjSwr8nyQQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@pagefind/default-ui": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/default-ui/-/default-ui-1.6.0.tgz", + "integrity": "sha512-Wj93IzlLnaYYrMpOYrsqUerzA7+Vrs5Ri1U78hBh3zuKHNVkcjApNo5DUM99MzAam6f437VGG64jDenAObIt+w==", + "license": "MIT" + }, + "node_modules/@pagefind/freebsd-x64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/freebsd-x64/-/freebsd-x64-1.6.0.tgz", + "integrity": "sha512-d+sXqsaThszmPWGVDSRKqIz9GpZcj/bAksNZfg19asSxU0ogNPOMND4kV4giQvOjPFMsltUFf6hQJfoHQ6+hSQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@pagefind/linux-arm64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/linux-arm64/-/linux-arm64-1.6.0.tgz", + "integrity": "sha512-SLB2I+XqCZma8NvIGIH8nyKblgKIxw5PmqsVtofWOKxNHhEtOEsddbqU+hsrNcT3EV0faM6UmKDHVIxcPYq29w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@pagefind/linux-x64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/linux-x64/-/linux-x64-1.6.0.tgz", + "integrity": "sha512-IbMSx/+Vr/Xk0TTBlLkjgK+rvnbOXGmmb2/MKxQu99AR5DsqQoV3NKEA9PQz2tAhuCZjeD5xJBp4w5N5DHIC7Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@pagefind/windows-arm64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/windows-arm64/-/windows-arm64-1.6.0.tgz", + "integrity": "sha512-wUrniW3REr7VWJHz6xE6F/p/AQgHDFpGZiY9sbWT71KfEijDE5Jnc37V8zc7cilV9h/QkwJGXoEP2+ZLwDmhtw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@pagefind/windows-x64": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@pagefind/windows-x64/-/windows-x64-1.6.0.tgz", + "integrity": "sha512-cUA2+yXfbymdJllyMjY5YTBwuOgh0/H53Pn5fYKjDnDjk154Ft4U5RVj3TenWySPL/jG6zJfARUWSlyUyXHlZw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.16.tgz", + "integrity": "sha512-ia3DwAs0OsMGS7+IConptSiyk9pEXkOx/AbJ2n/lAGxH3QkWQus1t8d7gnAT38FCU2sQu8lUbeR6AiZFv4JxaA==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.16.tgz", + "integrity": "sha512-kx5wBiMB6E7TEvpl2B9gjLU004BkvEm2Dr941BFjx/SontPwSzNuQUIoVKxHHoSjpFIfHMmcguyLOtyn0hObRg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.16.tgz", + "integrity": "sha512-qslZrXnKJU4cUpjoAmtAo/KQM9e2IRMlmpig6Zpwj+8KWxW8v+nkAf9216Bsek9lOC1jvg2yCjygCFo2f83msQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.16.tgz", + "integrity": "sha512-FdF+y48ND13eAyM2mQn+85kvAqNlvRWROy2rhgA463X/0Gv4vGtazZtfaF1mRBLscYvtOlh4QnLjOWiFzX69OQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.16.tgz", + "integrity": "sha512-ddjqFM5e95AgLbUPtKIS7V1KTVlA0RUgCVr5mn+/IEhsdy3pr+Vuj/HZ7nlMN2FyxIwUktOH1LEPIQXO1v9y1Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.16.tgz", + "integrity": "sha512-tHdKWbFkFBI687iim3LIyIvyL7j66VvQYkDPss5Stn/qyE2tWkR1YD0dXmXPFKKqT/o5ZEJVsaRsWS2meQwGOA==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.16.tgz", + "integrity": "sha512-FJiLGAblPBMlBEdbOqw6kW6QcXDWAf/oJu7gYs9ZJZwmg+K+/zjFLxPTIY9izJUzxzc24FHvmseyA0IvJSl17w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.16.tgz", + "integrity": "sha512-hrJpblMsrQ58U9veWpbXzkhV5zStunds6HWLprqq1qauvgBr1E6P+24kLj6lSLI9vjRn/RYpjprhkHQPKGWpNg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.16.tgz", + "integrity": "sha512-qJd/dC6j6CwLG9/s/RP2nb1RZ0GIgj7Ioj7x/SYa3RzjVrlzrmH0fhIOpfvqQDeIsdP0loi+kHaMhJzY1PBIaA==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.16.tgz", + "integrity": "sha512-Vx7Xg5uUJuNcujJjI70OICaH0EYj80BtOLZTSN7uOYg8QOLlyKnaG0IW7Fn/J0IpJsaKzmDKMhOQv1JBM9m9vg==", + "cpu": [ + "s390x" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.16.tgz", + "integrity": "sha512-TNKhgE3uJTsTzatUSSYt0Kgo+Oa2uSlSjz4r1aEIea7HX6ULBym4fAlYUhG1i6pjNf2njfCUAfKwr6C3E9Xg1w==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.16.tgz", + "integrity": "sha512-7chXdpjXZ8qG0+mIxECN3cT9kvhZ3/oZhMX6Pp876P7CDrIy8nJswva6Mq357JR7eYXfuskwZxMeV1SzoZdHrA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.16.tgz", + "integrity": "sha512-Kwjt+7uNTJK5/MDkGWGVO2KQPnj8yAV75dMpfwyHZrJSXWHrniOB0aUEWlVYf3H1hOqFLIStLdM5QXq6bnKmOQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.16.tgz", + "integrity": "sha512-/LH6WfjDRXXJz/p5xl4TmU+jpcnwcxbKEQBW/GZE0JHfN0lGIyTtsUEGaQ/q/GikkGJ2yLKe6pwm7AnEWO8pdw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.16.tgz", + "integrity": "sha512-1lv1KvX0Z871zfk7vw+dnXMMnHNyDwMzWG8Kv3HxDXMOhzCX4SHc7HK319fInP0i+0p9D8brkfzL7pJOaGl+tw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "license": "MIT" + }, + "node_modules/@shikijs/core": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-4.6.0.tgz", + "integrity": "sha512-bfd4OKgvoyXYiYmMRuleA656P4V7M/Du9lcTl38Ngm6KszMj7bq4J1IGZwSYR4c95Tv5UQALtYNWUwaI9UT3xw==", + "license": "MIT", + "dependencies": { + "@shikijs/primitive": "4.6.0", + "@shikijs/types": "4.6.0", + "@shikijs/vscode-textmate": "^10.1.0", + "@types/hast": "^3.0.5", + "hast-util-to-html": "^9.0.6" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/engine-javascript": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-4.6.0.tgz", + "integrity": "sha512-K0oqxFoL+kEMdz89mHLFO15Tsbv3kFZ6WR1cXZKMvLSc+oqaM00A6pyga1qSeXB22dP0tTiSApRcGBaKWsEccg==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.6.0", + "@shikijs/vscode-textmate": "^10.1.0", + "oniguruma-to-es": "^4.3.6" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/engine-oniguruma": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-4.6.0.tgz", + "integrity": "sha512-aggd6Q7SuJOXNnsUbfG2XesxBJKBMAw/PDTUo9PyRjMaaJJ2dNrI+q0C+25ARXAK9yLHAlwxc9oRT2u68YKZ7w==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.6.0", + "@shikijs/vscode-textmate": "^10.1.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/langs": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-4.6.0.tgz", + "integrity": "sha512-1yMEX3oCVV54LUq/ovfpRkDQoYDkcvjSWFFa/YLUDMiSoRzMi2uxLJYbv41ahT8Lu9lFMaa7hecd3Q39trqUyg==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.6.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/primitive": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/primitive/-/primitive-4.6.0.tgz", + "integrity": "sha512-c54+TQEo9ToqgfL/AU8FpjnV09+GA9Oa7M5ROkkXteZfp5XzpAJGXjjvZQFQioJOwm/w/6Z3lIzQstAkl8coag==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.6.0", + "@shikijs/vscode-textmate": "^10.1.0", + "@types/hast": "^3.0.5" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/themes": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-4.6.0.tgz", + "integrity": "sha512-qHAVAs80RiGD+IRuH9G+JPDOEc9A/kHsng4EzCUCwB9bLzW6Z0y9WETh2YyCcADJBmfrIaJ1Jp7KBNP6FHkgtQ==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.6.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/types": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-4.6.0.tgz", + "integrity": "sha512-+ENG1adsKt/X7cRYw1Nl7BEpBmPOjmQ7bR/eGmHuMlT8gtOFf3KEi5l31DJYyAWhW6Y6bjP1plU7FmaxWGENFw==", + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.1.0", + "@types/hast": "^3.0.5" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/vscode-textmate": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.1.0.tgz", + "integrity": "sha512-cVBuhDQjBZaNMTwBquYfPydrUP+E3hE6oYGasx8h6ZrODIM7/r+gxLDXdd66oszbrggZHEntdE6j+5gYIVyMWQ==", + "license": "MIT" + }, + "node_modules/@tybys/wasm-util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz", + "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==", + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@types/debug": { + "version": "4.1.13", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.13.tgz", + "integrity": "sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==", + "license": "MIT", + "dependencies": { + "@types/ms": "*" + } + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "license": "MIT" + }, + "node_modules/@types/estree-jsx": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree-jsx/-/estree-jsx-1.0.5.tgz", + "integrity": "sha512-52CcUVNFyfb1A2ALocQw/Dd1BQFNmSdkuC3BkZ6iqhdMfQz7JWOFRuJFloOzjk+6WijU56m9oKXFAXc7o3Towg==", + "license": "MIT", + "dependencies": { + "@types/estree": "*" + } + }, + "node_modules/@types/hast": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.5.tgz", + "integrity": "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g==", + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, + "node_modules/@types/mdast": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", + "integrity": "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==", + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, + "node_modules/@types/ms": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", + "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", + "license": "MIT" + }, + "node_modules/@types/nlcst": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@types/nlcst/-/nlcst-2.0.3.tgz", + "integrity": "sha512-vSYNSDe6Ix3q+6Z7ri9lyWqgGhJTmzRjZRqyq15N0Z/1/UnVsno9G/N40NBijoYx2seFDIl0+B2mgAb9mezUCA==", + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, + "node_modules/@types/node": { + "version": "24.19.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.19.2.tgz", + "integrity": "sha512-93d49wCWJkCyN87MxLpNN6KXPCwFw7bVUg79mGUV1OS40JGWwVCr8n61DXCSqz7CV6/VfPkb7xec7uP2M+QHWQ==", + "license": "MIT", + "dependencies": { + "undici-types": ">=7.24.0 <7.24.7" + } + }, + "node_modules/@types/sax": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz", + "integrity": "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/unist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", + "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==", + "license": "MIT" + }, + "node_modules/@ungap/structured-clone": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.4.0.tgz", + "integrity": "sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==", + "license": "ISC" + }, + "node_modules/am-i-vibing": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/am-i-vibing/-/am-i-vibing-0.5.0.tgz", + "integrity": "sha512-KLcsDhqf1XRrJmJr+9I/C0EX2K+sGrAGZFgkmd84c8TJO9zJBu+/kFInjazu1KfJWFhWDKdRWkpBzEs7s35DVA==", + "license": "MIT", + "dependencies": { + "process-ancestry": "^0.1.0" + }, + "bin": { + "am-i-vibing": "dist/cli.mjs" + } + }, + "node_modules/ansi-escapes": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.3.0.tgz", + "integrity": "sha512-BvU8nYgGQBxcmMuEeUEmNTvrMVjJNSH7RgW24vXexN4Ven6qCvy4TntnvlnwnMLTVlcRQQdbRY8NKnaIoeWDNg==", + "dev": true, + "license": "MIT", + "dependencies": { + "environment": "^1.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/anymatch/node_modules/picomatch": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/anynum": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/anynum/-/anynum-1.0.1.tgz", + "integrity": "sha512-N6//FLET/tXYNM/F6ABca1oH6fWB+KlTt909Le28WMDBk8oaT4vY17DCrwg2MvmuqUKt3Ni4N5dGJ/EoBgcO6A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT" + }, + "node_modules/arg": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", + "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", + "license": "MIT" + }, + "node_modules/aria-query": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.2.tgz", + "integrity": "sha512-COROpnaoap1E2F000S62r6A60uHZnmlvomhfyT2DlTcrY1OrBKn2UhH7qn5wTC9zMvD0AY7csdPSNwKP+7WiQw==", + "license": "Apache-2.0", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/astro": { + "version": "7.4.5", + "resolved": "https://registry.npmjs.org/astro/-/astro-7.4.5.tgz", + "integrity": "sha512-n5lET11/qnrOWn4wNpXxD9g2VKkTIa162hHgrkMPChMQC5q/xh2lY2OerK5mpsEAFCNmXsYA7NISE+9Uo7Cxxg==", + "license": "MIT", + "dependencies": { + "@astrojs/compiler-rs": "^0.5.1", + "@astrojs/internal-helpers": "0.13.0", + "@astrojs/markdown-satteri": "0.4.6", + "@astrojs/telemetry": "3.4.2", + "@capsizecss/unpack": "^4.0.1", + "@clack/prompts": "^1.8.1", + "@oslojs/encoding": "^1.1.0", + "am-i-vibing": "^0.5.0", + "aria-query": "^5.3.2", + "axobject-query": "^4.1.0", + "ci-info": "^4.4.0", + "clsx": "^2.1.1", + "common-ancestor-path": "^2.0.0", + "cookie": "^2.0.1", + "devalue": "^6.0.2", + "diff": "^9.0.0", + "dset": "^3.1.4", + "es-module-lexer": "^3.0.3", + "flattie": "^1.1.1", + "fontace": "~0.4.1", + "get-tsconfig": "5.0.0-beta.6", + "github-slugger": "^2.0.0", + "html-escaper": "3.0.3", + "http-cache-semantics": "^4.3.0", + "jsonc-parser": "^3.3.1", + "magic-string": "^1.4.3", + "magicast": "^0.5.5", + "mrmime": "^2.0.1", + "neotraverse": "^1.0.1", + "obug": "^3.0.0", + "p-limit": "^7.3.3", + "p-queue": "^9.3.5", + "package-manager-detector": "^1.9.0", + "piccolore": "^0.1.3", + "picomatch": "^4.0.7", + "rolldown": "^1.2.14", + "shiki": "^4.5.0", + "smol-toml": "^1.9.1", + "svgo": "^4.1.0", + "tinyclip": "^1.0.3", + "tinyexec": "^1.3.1", + "tinyglobby": "^0.2.17", + "tinyps": "^0.5.0", + "ultrahtml": "^1.7.0", + "unifont": "^1.0.3", + "unstorage": "^1.17.5", + "verkit": "^0.5.0", + "vite": "^8.3.5", + "vitefu": "^1.1.3", + "xxhash-wasm": "^1.1.0", + "yargs-parser": "^22.0.0", + "zod": "^4.6.6" + }, + "bin": { + "astro": "bin/astro.mjs" + }, + "engines": { + "node": ">=22.23.4", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/astrodotbuild" + }, + "optionalDependencies": { + "sharp": "^0.35.4" + }, + "peerDependencies": { + "@astrojs/markdown-remark": "^7.3.0" + }, + "peerDependenciesMeta": { + "@astrojs/markdown-remark": { + "optional": true + } + } + }, + "node_modules/astro-expressive-code": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/astro-expressive-code/-/astro-expressive-code-0.44.3.tgz", + "integrity": "sha512-LUpQmmvzr90JXP5QIAopgdjlOKLuT3x0wlPAUpc4OZtPtFS8sbflPcGPpL/lG3pQuUCQV2CXUFgYNBYNu9tphA==", + "license": "MIT", + "dependencies": { + "rehype-expressive-code": "^0.44.3", + "url-extras": "^0.1.0" + }, + "peerDependencies": { + "astro": "^4.0.0-beta || ^5.0.0-beta || ^3.3.0 || ^6.0.0-beta || ^7.0.0" + } + }, + "node_modules/axobject-query": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz", + "integrity": "sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==", + "license": "Apache-2.0", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/bail": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/bail/-/bail-2.0.2.tgz", + "integrity": "sha512-0xO6mYd7JB2YesxDKplafRpsiOzPt9V02ddPCLbY1xYGPOX24NTyN50qnUxgCPcSoYMhKpAuBTjQoRZCAkUDRw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/bcp-47": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/bcp-47/-/bcp-47-2.1.2.tgz", + "integrity": "sha512-wsv86UuNFuPnVieKLyECTT+CP1WSAHeoIg5P3xu2kA9Z+7fVPoKt7dxzSeEhtJel0AI+NW3fIW3KtTKQKUCngg==", + "license": "MIT", + "dependencies": { + "is-alphabetical": "^2.0.0", + "is-alphanumerical": "^2.0.0", + "is-decimal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/bcp-47-match": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/bcp-47-match/-/bcp-47-match-2.0.3.tgz", + "integrity": "sha512-JtTezzbAibu8G0R9op9zb3vcWZd9JF6M0xOYGPn0fNCd7wOpRB1mU2mH9T8gaBGbAAyIIVgB2G7xG0GP98zMAQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", + "license": "ISC" + }, + "node_modules/ccount": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz", + "integrity": "sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/character-entities/-/character-entities-2.0.2.tgz", + "integrity": "sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities-html4": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz", + "integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities-legacy": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz", + "integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-reference-invalid": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/character-reference-invalid/-/character-reference-invalid-2.0.1.tgz", + "integrity": "sha512-iBZ4F4wRbyORVsu0jPV7gXkOsGYjGHPmAyv+HiHG8gi5PtC9KI2j1+v8/tlibRvjoWX027ypmG/n0HtO5t7unw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/chokidar": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", + "integrity": "sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==", + "license": "MIT", + "dependencies": { + "readdirp": "^5.0.0" + }, + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/ci-info": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.4.0.tgz", + "integrity": "sha512-77PSwercCZU2Fc4sX94eF8k8Pxte6JAwL4/ICZLFjJLqegs7kCuAsqqj/70NQF6TvDpgFjkubQB2FW2ZZddvQg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/clsx": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", + "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/comma-separated-tokens": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/commander": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "license": "MIT", + "engines": { + "node": ">=16" + } + }, + "node_modules/common-ancestor-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/common-ancestor-path/-/common-ancestor-path-2.0.0.tgz", + "integrity": "sha512-dnN3ibLeoRf2HNC+OlCiNc5d2zxbLJXOtiZUudNFSXZrNSydxcCsSpRzXwfu7BBWCIfHPw+xTayeBvJCP/D8Ng==", + "license": "BlueOak-1.0.0", + "engines": { + "node": ">= 18" + } + }, + "node_modules/cookie": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-2.0.1.tgz", + "integrity": "sha512-yuToqVvRrj6pfDXREyQAAv8SkAEk/8GS3jQRTiUMm66TVtBYmqQeoEjL2Lmq8Rpo6271vH76InTChTitEAm65w==", + "license": "MIT", + "engines": { + "node": ">=22" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cookie-es": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/cookie-es/-/cookie-es-1.2.3.tgz", + "integrity": "sha512-lXVyvUvrNXblMqzIRrxHb57UUVmqsSWlxqt3XIjCkUP0wDAf6uicO6KMbEgYrMNtEvWgWHwe42CKxPu9MYAnWw==", + "license": "MIT" + }, + "node_modules/crossws": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/crossws/-/crossws-0.3.5.tgz", + "integrity": "sha512-ojKiDvcmByhwa8YYqbQI/hg7MEU0NC03+pSdEq4ZUnZR9xXpwk7E43SMNGkn+JxJGPFtNvQ48+vV2p+P1ml5PA==", + "license": "MIT", + "dependencies": { + "uncrypto": "^0.1.3" + } + }, + "node_modules/css-select": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-6.0.0.tgz", + "integrity": "sha512-rZZVSLle8v0+EY8QAkDWrKhpgt6SA5OtHsgBnsj6ZaLb5dmDVOWUDtQitd9ydxxvEjhewNudS6eTVU7uOyzvXw==", + "license": "BSD-2-Clause", + "dependencies": { + "boolbase": "^1.0.0", + "css-what": "^7.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.2.2", + "nth-check": "^2.1.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/css-selector-parser": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/css-selector-parser/-/css-selector-parser-3.3.0.tgz", + "integrity": "sha512-Y2asgMGFqJKF4fq4xHDSlFYIkeVfRsm69lQC1q9kbEsH5XtnINTMrweLkjYMeaUgiXBy/uvKeO/a1JHTNnmB2g==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/mdevils" + }, + { + "type": "patreon", + "url": "https://patreon.com/mdevils" + } + ], + "license": "MIT" + }, + "node_modules/css-tree": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.2.1.tgz", + "integrity": "sha512-X7sjQzceUhu1u7Y/ylrRZFU2FS6LRiFVp6rKLPg23y3x3c3DOKAwuXGDp+PAGjh6CSnCjYeAul8pcT8bAl+lSA==", + "license": "MIT", + "dependencies": { + "mdn-data": "2.27.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" + } + }, + "node_modules/css-what": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-7.0.0.tgz", + "integrity": "sha512-wD5oz5xibMOPHzy13CyGmogB3phdvcDaB5t0W/Nr5Z2O/agcB8YwOz6e2Lsp10pNDzBoDO9nVa3RGs/2BttpHQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">= 6" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/cssesc": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", + "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==", + "license": "MIT", + "bin": { + "cssesc": "bin/cssesc" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/csso": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/csso/-/csso-5.0.5.tgz", + "integrity": "sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==", + "license": "MIT", + "dependencies": { + "css-tree": "~2.2.0" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/csso/node_modules/css-tree": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.2.1.tgz", + "integrity": "sha512-OA0mILzGc1kCOCSJerOeqDxDQ4HOh+G8NbOJFOTgOCzpw7fCBubk0fEyxp8AgOL/jvLgYA/uV0cMbe43ElF1JA==", + "license": "MIT", + "dependencies": { + "mdn-data": "2.0.28", + "source-map-js": "^1.0.1" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/csso/node_modules/mdn-data": { + "version": "2.0.28", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.28.tgz", + "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==", + "license": "CC0-1.0" + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decode-named-character-reference": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz", + "integrity": "sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q==", + "license": "MIT", + "dependencies": { + "character-entities": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/defu": { + "version": "6.1.7", + "resolved": "https://registry.npmjs.org/defu/-/defu-6.1.7.tgz", + "integrity": "sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ==", + "license": "MIT" + }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/destr": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/destr/-/destr-2.0.5.tgz", + "integrity": "sha512-ugFTXCtDZunbzasqBxrK93Ik/DRYsO6S/fedkWEMKqt04xZ4csmnmwGDBAb07QWNaGMAmnTIemsYZCksjATwsA==", + "license": "MIT" + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/devalue": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/devalue/-/devalue-6.0.3.tgz", + "integrity": "sha512-3woMEITftG1wKeO/4d/QXH1DVKctTSZg3jNGPpjp9hNr5Hos8MCFF5McTML5ZtgKDObm2R591B0spRp2IVernA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/devlop": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz", + "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==", + "license": "MIT", + "dependencies": { + "dequal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/diff": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz", + "integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/direction": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/direction/-/direction-2.0.1.tgz", + "integrity": "sha512-9S6m9Sukh1cZNknO1CWAr2QAWsbKLafQiyM5gZ7VgXHeuaoUwffKN4q6NC4A/Mf9iiPlOXQEKW/Mv/mh9/3YFA==", + "license": "MIT", + "bin": { + "direction": "cli.js" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "license": "MIT", + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "license": "BSD-2-Clause" + }, + "node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "license": "BSD-2-Clause", + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/domutils": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz", + "integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==", + "license": "BSD-2-Clause", + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, + "node_modules/dset": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/dset/-/dset-3.1.4.tgz", + "integrity": "sha512-2QF/g9/zTaPDc3BjNcVTGoBbXBgYfMTTceLaYcFJ/W9kggFUkhxD/hMEeuLKbugyef9SqAx8cpgwlIP/jinUTA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/environment": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz", + "integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/es-module-lexer": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-3.0.4.tgz", + "integrity": "sha512-BldNY5mwkVu+cQ5Ymn3e6hB9Sx8XHx4ZevWbiUyZbfKxJxYO27Hf0wfzkxIaD5CAJMaGl3YspKELj0ff/7nCMA==", + "license": "MIT" + }, + "node_modules/eventemitter3": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz", + "integrity": "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==", + "license": "MIT" + }, + "node_modules/expressive-code": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/expressive-code/-/expressive-code-0.44.3.tgz", + "integrity": "sha512-7RGslhJTNt01pdn5I3QmVh5C8ZIiSm0A+ORQ9j9r39oOgJVKjn/7dXl9rMT/SqmFLE6pJkTYI7UjW0BxJnW7OQ==", + "license": "MIT", + "dependencies": { + "@expressive-code/core": "^0.44.3", + "@expressive-code/plugin-frames": "^0.44.3", + "@expressive-code/plugin-shiki": "^0.44.3", + "@expressive-code/plugin-text-markers": "^0.44.3" + } + }, + "node_modules/extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "license": "MIT" + }, + "node_modules/fast-string-truncated-width": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/fast-string-truncated-width/-/fast-string-truncated-width-3.0.3.tgz", + "integrity": "sha512-0jjjIEL6+0jag3l2XWWizO64/aZVtpiGE3t0Zgqxv0DPuxiMjvB3M24fCyhZUO4KomJQPj3LTSUnDP3GpdwC0g==", + "license": "MIT" + }, + "node_modules/fast-string-width": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/fast-string-width/-/fast-string-width-3.0.2.tgz", + "integrity": "sha512-gX8LrtNEI5hq8DVUfRQMbr5lpaS4nMIWV+7XEbXk2b8kiQIizgnlr12B4dA3ZEx3308ze0O4Q1R+cHts8kyUJg==", + "license": "MIT", + "dependencies": { + "fast-string-truncated-width": "^3.0.2" + } + }, + "node_modules/fast-wrap-ansi": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/fast-wrap-ansi/-/fast-wrap-ansi-0.2.2.tgz", + "integrity": "sha512-7F2Fl+TjRSenLqlU3UjSH0iyqopqoZIu7eZVpEirP2g1GtWa2G/ecEmBdgz31+Mxr+ELclgg6sokpSFIQiZ02Q==", + "license": "MIT", + "dependencies": { + "fast-string-width": "^3.0.2" + } + }, + "node_modules/fast-xml-builder": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.3.1.tgz", + "integrity": "sha512-pIM/1n3ntFXKYrUZwW7QCK0gAW7XY+wzj1YMIV3tLDvPj/V+zTGJK5e3/4WJfwj0qWw2ElNXiTixda/R+3YSug==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "path-expression-matcher": "^1.6.2", + "xml-naming": "^0.3.0" + } + }, + "node_modules/fast-xml-parser": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.12.0.tgz", + "integrity": "sha512-/pXxRBtwxY9w8z7YbgsvIPPcPvFDsTbIkWwTQJhzNJPokj+TbN6ftmcv4j/pEQDvOCNnKGDzuk5Bo2oogIOiFg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "@nodable/entities": "^3.1.0", + "fast-xml-builder": "^1.3.1", + "is-unsafe": "^2.0.3", + "path-expression-matcher": "^1.6.2", + "strnum": "^2.5.1", + "xml-naming": "^0.3.0" + }, + "bin": { + "fxparser": "src/cli/cli.js" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/flattie": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/flattie/-/flattie-1.1.1.tgz", + "integrity": "sha512-9UbaD6XdAL97+k/n+N7JwX46K/M6Zc6KcFYskrYL8wbBV/Uyk0CTAMY0VT+qiK5PM7AIc9aTWYtq65U7T+aCNQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/fnv1a-64": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/fnv1a-64/-/fnv1a-64-0.1.2.tgz", + "integrity": "sha512-mJbcILTPybAR1jdOwt/lVv8N2cffeJFFP+gVbSAwLEx1ujXH27RpPd8Rokec/KX9c76UYIB6Co+H4lQzxPnJfA==", + "license": "MIT" + }, + "node_modules/fontace": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/fontace/-/fontace-0.4.1.tgz", + "integrity": "sha512-lDMvbAzSnHmbYMTEld5qdtvNH2/pWpICOqpean9IgC7vUbUJc3k+k5Dokp85CegamqQpFbXf0rAVkbzpyTA8aw==", + "license": "MIT", + "dependencies": { + "fontkitten": "^1.0.2" + } + }, + "node_modules/fontkitten": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/fontkitten/-/fontkitten-1.0.3.tgz", + "integrity": "sha512-Wp1zXWPVUPBmfoa3Cqc9ctaKuzKAV6uLstRqlR56kSjplf5uAce+qeyYym7F+PHbGTk+tCEdkCW6RD7DX/gBZw==", + "license": "MIT", + "dependencies": { + "tiny-inflate": "^1.0.3" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-tsconfig": { + "version": "5.0.0-beta.6", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-5.0.0-beta.6.tgz", + "integrity": "sha512-X6fBC0pmImC70gvX2zm56go9hx0MyoGVdG0tUCkg/D+Xnh5TJsOZ7iDbOdI3PvmtrDxnu1YdDufpK2QJX1Meqw==", + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "engines": { + "node": ">=20.20.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/github-slugger": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-2.0.0.tgz", + "integrity": "sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw==", + "license": "ISC" + }, + "node_modules/h3": { + "version": "1.15.11", + "resolved": "https://registry.npmjs.org/h3/-/h3-1.15.11.tgz", + "integrity": "sha512-L3THSe2MPeBwgIZVSH5zLdBBU90TOxarvhK9d04IDY2AmVS8j2Jz2LIWtwsGOU3lu2I5jCN7FNvVfY2+XyF+mg==", + "license": "MIT", + "dependencies": { + "cookie-es": "^1.2.3", + "crossws": "^0.3.5", + "defu": "^6.1.6", + "destr": "^2.0.5", + "iron-webcrypto": "^1.2.1", + "node-mock-http": "^1.0.4", + "radix3": "^1.1.2", + "ufo": "^1.6.3", + "uncrypto": "^0.1.3" + } + }, + "node_modules/has-flag": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-5.0.1.tgz", + "integrity": "sha512-CsNUt5x9LUdx6hnk/E2SZLsDyvfqANZSUq4+D3D8RzDJ2M+HDTIkF60ibS1vHaK55vzgiZw1bEPFG9yH7l33wA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/hast-util-embedded": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-embedded/-/hast-util-embedded-3.0.0.tgz", + "integrity": "sha512-naH8sld4Pe2ep03qqULEtvYr7EjrLK2QHY8KJR6RJkTUjPGObe1vnx585uzem2hGra+s1q08DZZpfgDVYRbaXA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-is-element": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-format": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/hast-util-format/-/hast-util-format-1.1.0.tgz", + "integrity": "sha512-yY1UDz6bC9rDvCWHpx12aIBGRG7krurX0p0Fm6pT547LwDIZZiNr8a+IHDogorAdreULSEzP82Nlv5SZkHZcjA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-embedded": "^3.0.0", + "hast-util-minify-whitespace": "^1.0.0", + "hast-util-phrasing": "^3.0.0", + "hast-util-whitespace": "^3.0.0", + "html-whitespace-sensitive-tag-names": "^3.0.0", + "unist-util-visit-parents": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-from-html": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/hast-util-from-html/-/hast-util-from-html-2.0.3.tgz", + "integrity": "sha512-CUSRHXyKjzHov8yKsQjGOElXy/3EKpyX56ELnkHH34vDVw1N1XSQ1ZcAvTyAPtGqLTuKP/uxM+aLkSPqF/EtMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "devlop": "^1.1.0", + "hast-util-from-parse5": "^8.0.0", + "parse5": "^7.0.0", + "vfile": "^6.0.0", + "vfile-message": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-from-parse5": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/hast-util-from-parse5/-/hast-util-from-parse5-8.0.4.tgz", + "integrity": "sha512-Yq7XlXor0Cpb71sI2E0zpv8QxQ5a6rfhDEETk4bcgrFX2SvJAY2PHocWwFtL6U9qyfiyByW3wZ6sZEfP2kW81g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/unist": "^3.0.0", + "devlop": "^1.0.0", + "hastscript": "^9.0.0", + "property-information": "^7.0.0", + "vfile": "^6.0.0", + "vfile-location": "^5.0.0", + "web-namespaces": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-has-property": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-has-property/-/hast-util-has-property-3.0.0.tgz", + "integrity": "sha512-MNilsvEKLFpV604hwfhVStK0usFY/QmM5zX16bo7EjnAEGofr5YyI37kzopBlZJkHD4t887i+q/C8/tr5Q94cA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-is-body-ok-link": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/hast-util-is-body-ok-link/-/hast-util-is-body-ok-link-3.0.1.tgz", + "integrity": "sha512-0qpnzOBLztXHbHQenVB8uNuxTnm/QBFUOmdOSsEn7GnBtyY07+ENTWVFBAnXd/zEgd9/SUG3lRY7hSIBWRgGpQ==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-is-element": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-is-element/-/hast-util-is-element-3.0.0.tgz", + "integrity": "sha512-Val9mnv2IWpLbNPqc/pUem+a7Ipj2aHacCwgNfTiK0vJKl0LF+4Ba4+v1oPHFpf3bLYmreq0/l3Gud9S5OH42g==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-minify-whitespace": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/hast-util-minify-whitespace/-/hast-util-minify-whitespace-1.0.1.tgz", + "integrity": "sha512-L96fPOVpnclQE0xzdWb/D12VT5FabA7SnZOUMtL1DbXmYiHJMXZvFkIZfiMmTCNJHUeO2K9UYNXoVyfz+QHuOw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-embedded": "^3.0.0", + "hast-util-is-element": "^3.0.0", + "hast-util-whitespace": "^3.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-parse-selector": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/hast-util-parse-selector/-/hast-util-parse-selector-4.0.0.tgz", + "integrity": "sha512-wkQCkSYoOGCRKERFWcxMVMOcYE2K1AaNLU8DXS9arxnLOUEWbOXKXiJUNzEpqZ3JOKpnha3jkFrumEjVliDe7A==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-phrasing": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/hast-util-phrasing/-/hast-util-phrasing-3.0.1.tgz", + "integrity": "sha512-6h60VfI3uBQUxHqTyMymMZnEbNl1XmEGtOxxKYL7stY2o601COo62AWAYBQR9lZbYXYSBoxag8UpPRXK+9fqSQ==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-embedded": "^3.0.0", + "hast-util-has-property": "^3.0.0", + "hast-util-is-body-ok-link": "^3.0.0", + "hast-util-is-element": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-select": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/hast-util-select/-/hast-util-select-6.0.4.tgz", + "integrity": "sha512-RqGS1ZgI0MwxLaKLDxjprynNzINEkRHY2i8ln4DDjgv9ZhcYVIHN9rlpiYsqtFwrgpYU361SyWDQcGNIBVu3lw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/unist": "^3.0.0", + "bcp-47-match": "^2.0.0", + "comma-separated-tokens": "^2.0.0", + "css-selector-parser": "^3.0.0", + "devlop": "^1.0.0", + "direction": "^2.0.0", + "hast-util-has-property": "^3.0.0", + "hast-util-to-string": "^3.0.0", + "hast-util-whitespace": "^3.0.0", + "nth-check": "^2.0.0", + "property-information": "^7.0.0", + "space-separated-tokens": "^2.0.0", + "unist-util-visit": "^5.0.0", + "zwitch": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-to-html": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.6.tgz", + "integrity": "sha512-1SZUxCN3TtJAE7e2BQN2MBHsoZ1gnmi9GoCP5Di59CSWptIezSAW09yDZyVbanb78V9eCwrKqdQsjtfVTxYHWA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "comma-separated-tokens": "^2.0.0", + "hast-util-whitespace": "^3.0.0", + "html-void-elements": "^3.0.0", + "mdast-util-to-hast": "^13.0.0", + "property-information": "^7.0.0", + "space-separated-tokens": "^2.0.0", + "stringify-entities": "^4.0.0", + "zwitch": "^2.0.4" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-to-string": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/hast-util-to-string/-/hast-util-to-string-3.0.1.tgz", + "integrity": "sha512-XelQVTDWvqcl3axRfI0xSeoVKzyIFPwsAGSLIsKdJKQMXDYJS4WYrBNF/8J7RdhIcFI2BOHgAifggsvsxp/3+A==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-to-text": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/hast-util-to-text/-/hast-util-to-text-4.0.3.tgz", + "integrity": "sha512-5yrlWOvGFs6CqHriUpSsNrjzT/Tdo+IOQudbznxOn8K5qblp18MJyzOg8IgDOKQ8MYgQcJA7SusuCjSpDr8mSA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-whitespace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz", + "integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hastscript": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/hastscript/-/hastscript-9.0.3.tgz", + "integrity": "sha512-1ALZXSmCGmW3h8AMz4R4+QKSKFi7sNgXLVwmwB8FYVtl1CwQ3WDkSAEY/d5tp1g/vbQgq2s1WlHgfO3jbw1TsA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "comma-separated-tokens": "^2.0.0", + "hast-util-parse-selector": "^4.0.0", + "property-information": "^7.0.0", + "space-separated-tokens": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/html-escaper": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz", + "integrity": "sha512-RuMffC89BOWQoY0WKGpIhn5gX3iI54O6nRA0yC124NYVtzjmFWBIiFd8M0x+ZdX0P9R4lADg1mgP8C7PxGOWuQ==", + "license": "MIT" + }, + "node_modules/html-void-elements": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-3.0.0.tgz", + "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/html-whitespace-sensitive-tag-names": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/html-whitespace-sensitive-tag-names/-/html-whitespace-sensitive-tag-names-3.0.1.tgz", + "integrity": "sha512-q+310vW8zmymYHALr1da4HyXUQ0zgiIwIicEfotYPWGN0OJVEN/58IJ3A4GBYcEq3LGAZqKb+ugvP0GNB9CEAA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/http-cache-semantics": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.3.0.tgz", + "integrity": "sha512-M5t5LlJpS1UHMjvwRQVdFHvPISGeLAxNcrWuJkeGh0KxsqCHZ1O3NXZU/8x7cD0BDcGW8kapxMKTvwlqrNkHkA==", + "license": "BSD-2-Clause" + }, + "node_modules/i18next": { + "version": "26.7.1", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-26.7.1.tgz", + "integrity": "sha512-cX+3RRVczel/V2kCMTACckSGSpqgtWYEA6beXNYVms7dOQiHojdPYHD26lT4IKimNeoGWrLvtPgjftbRvmZJVw==", + "funding": [ + { + "type": "individual", + "url": "https://www.locize.com/i18next" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + }, + { + "type": "individual", + "url": "https://www.locize.com" + } + ], + "license": "MIT", + "peerDependencies": { + "typescript": "^5 || ^6 || ^7" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/iron-webcrypto": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/iron-webcrypto/-/iron-webcrypto-1.2.1.tgz", + "integrity": "sha512-feOM6FaSr6rEABp/eDfVseKyTMDt+KGpeB35SkVn9Tyn0CqvVsY3EwI0v5i8nMHyJnzCIQf7nsy3p41TPkJZhg==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/brc-dd" + } + }, + "node_modules/is-absolute-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-absolute-url/-/is-absolute-url-5.0.0.tgz", + "integrity": "sha512-sdJyNpBnQHuVnBunfzjAecOhZr2+A30ywfFvu3EnxtKLUWfwGgyWUmqHbGZiU6vTfHpCPm5GvLe4BAvlU9n8VQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-alphabetical": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-alphabetical/-/is-alphabetical-2.0.1.tgz", + "integrity": "sha512-FWyyY60MeTNyeSRpkM2Iry0G9hpr7/9kD40mD/cGQEuilcZYS4okz8SN2Q6rLCJ8gbCt6fN+rC+6tMGS99LaxQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-alphanumerical": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-alphanumerical/-/is-alphanumerical-2.0.1.tgz", + "integrity": "sha512-hmbYhX/9MUMF5uh7tOXyK/n0ZvWpad5caBA17GsC6vyuCqaWliRG5K1qS9inmUhEMaOBIW7/whAnSwveW/LtZw==", + "license": "MIT", + "dependencies": { + "is-alphabetical": "^2.0.0", + "is-decimal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-decimal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-decimal/-/is-decimal-2.0.1.tgz", + "integrity": "sha512-AAB9hiomQs5DXWcRB1rqsxGUstbRroFOPPVAomNk/3XHR5JyEZChOyTWe2oayKnsSsr/kcGqF+z6yuH6HHpN0A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-docker": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-4.0.0.tgz", + "integrity": "sha512-LHE+wROyG/Y/0ZnbktRCoTix2c1RhgWaZraMZ8o1Q7zCh0VSrICJQO5oqIIISrcSBtrXv0o233w1IYwsWCjTzA==", + "license": "MIT", + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-hexadecimal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-2.0.1.tgz", + "integrity": "sha512-DgZQp241c8oO6cA1SbTEWiXeoxV42vlcJxgH+B3hi1AiqqKruZR3ZGF8In3fj4+/y/7rHvlOZLZtgJ/4ttYGZg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-plain-obj": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-4.1.0.tgz", + "integrity": "sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-unsafe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/is-unsafe/-/is-unsafe-2.0.3.tgz", + "integrity": "sha512-ZBllczCCO267vgdFb6Tq3pv+LhHaCiGMdr+ZsuL+OopruAg7S+3ZDs1vD0RPC0uSrkjzbraxaGjtX1YBxjPeFQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT" + }, + "node_modules/jsonc-parser": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "license": "MIT" + }, + "node_modules/klona": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/klona/-/klona-2.0.6.tgz", + "integrity": "sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==", + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/longest-streak": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz", + "integrity": "sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/lru-cache": { + "version": "11.5.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.3.tgz", + "integrity": "sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg==", + "license": "BlueOak-1.0.0", + "engines": { + "node": "20 || >=22" + } + }, + "node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/magicast": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.5.tgz", + "integrity": "sha512-UicdXN8zQ3JHlxVq+28afMXPr1z7WNY6+7EJnzTdQWkTAlMLF5fNCCKxJHBQwGaNGR11581EiQmQzx73+MvszA==", + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7", + "source-map-js": "^1.2.1" + } + }, + "node_modules/mdast-util-directive": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/mdast-util-directive/-/mdast-util-directive-3.2.0.tgz", + "integrity": "sha512-Yxq+hH4pBEmtaLIJyMVcNbtBiCIKzdOK3HvDeM+JAqC8XVAT1e5PUYbHBpwFvQLIJuJfO2zCu7aNUXWoyZLmhw==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "devlop": "^1.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.2.0", + "micromark-util-character": "^2.0.0", + "parse-entities": "^4.0.0", + "stringify-entities": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-from-markdown": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mdast-util-from-markdown/-/mdast-util-from-markdown-2.1.0.tgz", + "integrity": "sha512-KRLgmPaP2H1ul2bpoJkOS+9pAcDAAj9Nu1mqLnh8NLeJG5tlvj42TH80PIGBpROWlRXLk0lDrWNuZCFy/tsB4A==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0", + "@types/unist": "^3.0.0", + "decode-named-character-reference": "^1.0.0", + "devlop": "^1.0.0", + "mdast-util-to-string": "^4.0.0", + "micromark": "^4.0.0", + "micromark-util-decode-numeric-character-reference": "^2.0.0", + "micromark-util-decode-string": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0", + "unist-util-stringify-position": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-mdx-jsx": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/mdast-util-mdx-jsx/-/mdast-util-mdx-jsx-3.2.1.tgz", + "integrity": "sha512-oXp1GIa+E9IwIs3a106+tr3Bz2MlTTBvlXjOZMoIat11kk7vjqgmBnksB9WHmWv+gZh7k3IUgpAHlwHB7DH4GQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree-jsx": "^1.0.0", + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "devlop": "^1.1.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0", + "parse-entities": "^4.0.0", + "stringify-entities": "^4.0.0", + "unist-util-stringify-position": "^4.0.0", + "vfile-message": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-phrasing": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/mdast-util-phrasing/-/mdast-util-phrasing-4.1.0.tgz", + "integrity": "sha512-TqICwyvJJpBwvGAMZjj4J2n0X8QWp21b9l0o7eXyVJ25YNWYbJDVIyD1bZXE6WtV6RmKJVYmQAKWa0zWOABz2w==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-to-hast": { + "version": "13.2.1", + "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.1.tgz", + "integrity": "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@ungap/structured-clone": "^1.0.0", + "devlop": "^1.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "trim-lines": "^3.0.0", + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-to-markdown": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/mdast-util-to-markdown/-/mdast-util-to-markdown-2.2.2.tgz", + "integrity": "sha512-ELNT5jYDUdx0B/hlUSSAiAEtvqkY3Oriwkp1KEYseF1Ccu4MnKkmE5yK3oE3WGT/Pq8VTE+XwP0GLL5pafY8yA==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0", + "@types/unist": "^3.0.0", + "longest-streak": "^3.0.0", + "mdast-util-phrasing": "^4.0.0", + "mdast-util-to-string": "^4.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-classify-character": "^2.0.0", + "micromark-util-decode-string": "^2.0.0", + "micromark-util-html-tag-name": "^2.0.0", + "unist-util-visit": "^5.0.0", + "zwitch": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdast-util-to-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mdast-util-to-string/-/mdast-util-to-string-4.0.0.tgz", + "integrity": "sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdn-data": { + "version": "2.27.1", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.27.1.tgz", + "integrity": "sha512-9Yubnt3e8A0OKwxYSXyhLymGW4sCufcLG6VdiDdUGVkPhpqLxlvP5vl1983gQjJl3tqbrM731mjaZaP68AgosQ==", + "license": "CC0-1.0" + }, + "node_modules/micromark": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.3.tgz", + "integrity": "sha512-oGYfQzHSG5dOMovQcJ3fyTmZlWAWpi0XA0sJwJs+i6OT88o1+Jtw/8z0CmdowSLxGhhFK89rQ/oXph/wN02PNw==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "@types/debug": "^4.0.0", + "debug": "^4.0.0", + "decode-named-character-reference": "^1.0.0", + "devlop": "^1.0.0", + "micromark-core-commonmark": "^2.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-chunked": "^2.0.0", + "micromark-util-combine-extensions": "^2.0.0", + "micromark-util-decode-numeric-character-reference": "^2.0.0", + "micromark-util-edit-map": "^1.0.0", + "micromark-util-encode": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-resolve-all": "^2.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "micromark-util-subtokenize": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-core-commonmark": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/micromark-core-commonmark/-/micromark-core-commonmark-2.0.4.tgz", + "integrity": "sha512-wxEeE8v8XVvOrxn1TZj74qYhAtTQsSqufHVS3uNVyT1MupXxhyaHk8/9xDNPh9BmL77QNDgWTkZ3RsYHB2ry7w==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "decode-named-character-reference": "^1.0.0", + "devlop": "^1.0.0", + "micromark-factory-destination": "^2.0.0", + "micromark-factory-label": "^2.0.0", + "micromark-factory-space": "^2.1.0", + "micromark-factory-title": "^2.0.0", + "micromark-factory-whitespace": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-chunked": "^2.0.0", + "micromark-util-classify-character": "^2.0.0", + "micromark-util-edit-map": "^1.0.0", + "micromark-util-html-tag-name": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-resolve-all": "^2.0.0", + "micromark-util-subtokenize": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.3" + } + }, + "node_modules/micromark-extension-directive": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/micromark-extension-directive/-/micromark-extension-directive-4.0.0.tgz", + "integrity": "sha512-/C2nqVmXXmiseSSuCdItCMho7ybwwop6RrrRPk0KbOHW21JKoCldC+8rFOaundDoRBUWBnJJcxeA/Kvi34WQXg==", + "license": "MIT", + "dependencies": { + "devlop": "^1.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-factory-whitespace": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0", + "parse-entities": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/micromark-factory-destination": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-factory-destination/-/micromark-factory-destination-2.0.1.tgz", + "integrity": "sha512-Xe6rDdJlkmbFRExpTOmRj9N3MaWmbAgdpSrBQvCFqhezUn4AHqJHbaEnfbVYYiexVSs//tqOdY/DxhjdCiJnIA==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-factory-label": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-factory-label/-/micromark-factory-label-2.0.1.tgz", + "integrity": "sha512-VFMekyQExqIW7xIChcXn4ok29YE3rnuyveW3wZQWWqF4Nv9Wk5rgJ99KzPvHjkmPXF93FXIbBp6YdW3t71/7Vg==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "devlop": "^1.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-factory-space": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-factory-space/-/micromark-factory-space-2.1.0.tgz", + "integrity": "sha512-fS8hnLIjnjvdQIj39Geug8wWsR0HrYZ43KShKxNfwT7t2LOHo/LbWZEzEaSOjwtjdCsjoE6syHhonEzW0zv0+Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-factory-title": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-factory-title/-/micromark-factory-title-2.0.1.tgz", + "integrity": "sha512-5bZ+3CjhAd9eChYTHsjy6TGxpOFSKgKKJPJxr293jTbfry2KDoWkhBb6TcPVB4NmzaPhMs1Frm9AZH7OD4Cjzw==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-factory-whitespace": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-factory-whitespace/-/micromark-factory-whitespace-2.0.1.tgz", + "integrity": "sha512-Ob0nuZ3PKt/n0hORHyvoD9uZhr+Za8sFoP+OnMcnWK5lngSzALgQYKMr9RJVOWLqQYuyn6ulqGWSXdwf6F80lQ==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-character": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", + "integrity": "sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-chunked": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-chunked/-/micromark-util-chunked-2.0.1.tgz", + "integrity": "sha512-QUNFEOPELfmvv+4xiNg2sRYeS/P84pTW0TCgP5zc9FpXetHY0ab7SxKyAQCNCc1eK0459uoLI1y5oO5Vc1dbhA==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-classify-character": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-classify-character/-/micromark-util-classify-character-2.0.1.tgz", + "integrity": "sha512-K0kHzM6afW/MbeWYWLjoHQv1sgg2Q9EccHEDzSkxiP/EaagNzCm7T/WMKZ3rjMbvIpvBiZgwR3dKMygtA4mG1Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-combine-extensions": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-combine-extensions/-/micromark-util-combine-extensions-2.0.1.tgz", + "integrity": "sha512-OnAnH8Ujmy59JcyZw8JSbK9cGpdVY44NKgSM7E9Eh7DiLS2E9RNQf0dONaGDzEG9yjEl5hcqeIsj4hfRkLH/Bg==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-chunked": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-decode-numeric-character-reference": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/micromark-util-decode-numeric-character-reference/-/micromark-util-decode-numeric-character-reference-2.0.2.tgz", + "integrity": "sha512-ccUbYk6CwVdkmCQMyr64dXz42EfHGkPQlBj5p7YVGzq8I7CtjXZJrubAYezf7Rp+bjPseiROqe7G6foFd+lEuw==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-decode-string": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-decode-string/-/micromark-util-decode-string-2.0.1.tgz", + "integrity": "sha512-nDV/77Fj6eH1ynwscYTOsbK7rR//Uj0bZXBwJZRfaLEJ1iGBR6kIfNmlNqaqJf649EP0F3NWNdeJi03elllNUQ==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "decode-named-character-reference": "^1.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-decode-numeric-character-reference": "^2.0.0", + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-edit-map": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/micromark-util-edit-map/-/micromark-util-edit-map-1.0.0.tgz", + "integrity": "sha512-Pa2ljlsEL6sVwFaYeyrOLSYbQt73JvGbPOYFq+9AElXiSnfI5Q4465RRZ1sHv7lDjDOnGRDDaqPXqClqWK/q1Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-encode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-encode/-/micromark-util-encode-2.0.1.tgz", + "integrity": "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-html-tag-name": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-html-tag-name/-/micromark-util-html-tag-name-2.0.1.tgz", + "integrity": "sha512-2cNEiYDhCWKI+Gs9T0Tiysk136SnR13hhO8yW6BGNyhOC4qYFnwF1nKfD3HFAIXA5c45RrIG1ub11GiXeYd1xA==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-normalize-identifier": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-normalize-identifier/-/micromark-util-normalize-identifier-2.0.1.tgz", + "integrity": "sha512-sxPqmo70LyARJs0w2UclACPUUEqltCkJ6PhKdMIDuJ3gSf/Q+/GIe3WKl0Ijb/GyH9lOpUkRAO2wp0GVkLvS9Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-resolve-all": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-resolve-all/-/micromark-util-resolve-all-2.0.1.tgz", + "integrity": "sha512-VdQyxFWFT2/FGJgwQnJYbe1jjQoNTS4RjglmSjTUlpUMa95Htx9NHeYW4rGDJzbjvCsl9eLjMQwGeElsqmzcHg==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-sanitize-uri": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-sanitize-uri/-/micromark-util-sanitize-uri-2.0.1.tgz", + "integrity": "sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-encode": "^2.0.0", + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-subtokenize": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-subtokenize/-/micromark-util-subtokenize-2.1.0.tgz", + "integrity": "sha512-XQLu552iSctvnEcgXw6+Sx75GflAPNED1qx7eBJ+wydBb2KCbRZe+NwvIEEMM83uml1+2WSXpBAcp9IUCgCYWA==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "devlop": "^1.0.0", + "micromark-util-chunked": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-symbol": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.1.tgz", + "integrity": "sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-types": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.3.tgz", + "integrity": "sha512-oxB2Ik03hI0gv+VNn9tnh1t1YEe9MDPptViAEgfdf3YQHsn0pzGTgCdlSCJXcwhqm8phaEuM7zeEu3QQzVBrPg==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/mrmime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", + "integrity": "sha512-Y3wQdFg2Va6etvQ5I82yUhGdsKrcYox6p7FfL1LbK2J4V01F9TGlepTIhnK24t7koZibmg82KGglhA1XK5IsLQ==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/neotraverse": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/neotraverse/-/neotraverse-1.0.1.tgz", + "integrity": "sha512-WmmLty1YWwJl9yZi77v2dVIV6X2kuYV8YYBI/G3LWGKdGHmHUvL1z7FW0iDvEvGAwNEoc5x1tOOOyDnf5jJw/w==", + "license": "MIT", + "engines": { + "node": ">= 10" + } + }, + "node_modules/nlcst-to-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/nlcst-to-string/-/nlcst-to-string-4.0.0.tgz", + "integrity": "sha512-YKLBCcUYKAg0FNlOBT6aI91qFmSiFKiluk655WzPF+DDMA02qIyy8uiRqI8QXtcFpEvll12LpL5MXqEmAZ+dcA==", + "license": "MIT", + "dependencies": { + "@types/nlcst": "^2.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/node-fetch-native": { + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/node-fetch-native/-/node-fetch-native-1.6.7.tgz", + "integrity": "sha512-g9yhqoedzIUm0nTnTqAQvueMPVOuIY16bqgAJJC8XOOubYFNwz6IER9qs0Gq2Xd0+CecCKFjtdDTMA4u4xG06Q==", + "license": "MIT" + }, + "node_modules/node-mock-http": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/node-mock-http/-/node-mock-http-1.0.5.tgz", + "integrity": "sha512-KQyt/wLjG3TAc7DOUhpqWzgd4ERxR80JOlTK5VE5R1S12IaPVN5qkj4klBce9HPG1Njuup4Sb5bljaT34lIyjw==", + "license": "MIT" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "license": "BSD-2-Clause", + "dependencies": { + "boolbase": "^1.0.0" + }, + "funding": { + "url": "https://github.com/fb55/nth-check?sponsor=1" + } + }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/ofetch": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/ofetch/-/ofetch-1.5.1.tgz", + "integrity": "sha512-2W4oUZlVaqAPAil6FUg/difl6YhqhUR7x2eZY4bQCko22UXg3hptq9KLQdqFClV+Wu85UX7hNtdGTngi/1BxcA==", + "license": "MIT", + "dependencies": { + "destr": "^2.0.5", + "node-fetch-native": "^1.6.7", + "ufo": "^1.6.1" + } + }, + "node_modules/oniguruma-parser": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/oniguruma-parser/-/oniguruma-parser-0.12.2.tgz", + "integrity": "sha512-6HVa5oIrgMC6aA6WF6XyyqbhRPJrKR02L20+2+zpDtO5QAzGHAUGw5TKQvwi5vctNnRHkJYmjAhRVQF2EKdTQw==", + "license": "MIT" + }, + "node_modules/oniguruma-to-es": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-4.3.6.tgz", + "integrity": "sha512-csuQ9x3Yr0cEIs/Zgx/OEt9iBw9vqIunAPQkx19R/fiMq2oGVTgcMqO/V3Ybqefr1TBvosI6jU539ksaBULJyA==", + "license": "MIT", + "dependencies": { + "oniguruma-parser": "^0.12.2", + "regex": "^6.1.0", + "regex-recursion": "^6.0.2" + } + }, + "node_modules/p-limit": { + "version": "7.3.3", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-7.3.3.tgz", + "integrity": "sha512-SKgVvDU5TNIxQ4r30U75BNLC6a+6GOEjngrk/ysM5+Zu3oJuk1SC5ApzIzY/7PjCEjoVPMWJ0zho/4QUiEB7TQ==", + "license": "MIT", + "dependencies": { + "yocto-queue": "^1.2.1" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-queue": { + "version": "9.3.5", + "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-9.3.5.tgz", + "integrity": "sha512-Lki/zhXFVmDhesBUn/yHRLW9Bte7mE7xoFHzTR8sIomV7a2z+LxYAPkGvdfidNiu4fKSfjtawixxSHcZci5QcQ==", + "license": "MIT", + "dependencies": { + "eventemitter3": "^5.0.4", + "p-timeout": "^7.0.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-timeout": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-7.0.2.tgz", + "integrity": "sha512-prbX4Z3YszrFNgH+MW5Zoeq3baXrMtP/MQnFeET90UB/GtGcGDQ5Usg9OCy6ETjTTntOw1SL2z9fMPUppN3Guw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/package-manager-detector": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/package-manager-detector/-/package-manager-detector-1.9.0.tgz", + "integrity": "sha512-zAMfbta9nPA8AKkA4WdmNAT8R8s6Dk0/xwPsqNnRidMFcLo1YkLuPDTgs2f64XdzS8vbLNnoJ+uUIkgbz7oRHA==", + "license": "MIT" + }, + "node_modules/pagefind": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/pagefind/-/pagefind-1.6.0.tgz", + "integrity": "sha512-yeOd9EA0TUE1PUfbQIluBxzPadBG5/0BV48FAxwMVLkhZcOvwCz6TX4/a/Ofz97pF9/FwwT7CVbTC97BfmI+LQ==", + "license": "MIT", + "bin": { + "pagefind": "lib/runner/bin.cjs" + }, + "optionalDependencies": { + "@pagefind/darwin-arm64": "1.6.0", + "@pagefind/darwin-x64": "1.6.0", + "@pagefind/freebsd-x64": "1.6.0", + "@pagefind/linux-arm64": "1.6.0", + "@pagefind/linux-x64": "1.6.0", + "@pagefind/windows-arm64": "1.6.0", + "@pagefind/windows-x64": "1.6.0" + } + }, + "node_modules/parse-entities": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-4.0.2.tgz", + "integrity": "sha512-GG2AQYWoLgL877gQIKeRPGO1xF9+eG1ujIb5soS5gPvLQ1y2o8FL90w2QWNdf9I361Mpp7726c+lj3U0qK1uGw==", + "license": "MIT", + "dependencies": { + "@types/unist": "^2.0.0", + "character-entities-legacy": "^3.0.0", + "character-reference-invalid": "^2.0.0", + "decode-named-character-reference": "^1.0.0", + "is-alphanumerical": "^2.0.0", + "is-decimal": "^2.0.0", + "is-hexadecimal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/parse-entities/node_modules/@types/unist": { + "version": "2.0.11", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.11.tgz", + "integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==", + "license": "MIT" + }, + "node_modules/parse5": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.3.0.tgz", + "integrity": "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^6.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5/node_modules/entities": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz", + "integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/path-expression-matcher": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.6.2.tgz", + "integrity": "sha512-enSlaiat05iasnzmgNxRj8reFdj3puY2QpNgP1aPIaVfT6nn9ICuPoFlKHk8EN22HcwewshO+mN2DGbkCEOtqQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/piccolore": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/piccolore/-/piccolore-0.1.3.tgz", + "integrity": "sha512-o8bTeDWjE086iwKrROaDf31K0qC/BENdm15/uH9usSC/uZjJOKb2YGiVHfLY4GhwsERiPI1jmwI2XrA7ACOxVw==", + "license": "ISC" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", + "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/postcss-nested": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-7.0.2.tgz", + "integrity": "sha512-5osppouFc0VR9/VYzYxO03VaDa3e8F23Kfd6/9qcZTUI8P58GIYlArOET2Wq0ywSl2o2PjELhYOFI4W7l5QHKw==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "postcss-selector-parser": "^7.0.0" + }, + "engines": { + "node": ">=18.0" + }, + "peerDependencies": { + "postcss": "^8.2.14" + } + }, + "node_modules/postcss-selector-parser": { + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.7.tgz", + "integrity": "sha512-wWBro/7hJ40ye6TPiXkUQoXKCw23xSsjriUvqd7Uls9Sso3oLiON1flc18cCdnjgCRXw4fBVqUJJeOdDTh3P3g==", + "license": "MIT", + "dependencies": { + "cssesc": "^3.0.0", + "util-deprecate": "^1.0.2" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/prismjs": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.30.0.tgz", + "integrity": "sha512-DEvV2ZF2r2/63V+tK8hQvrR2ZGn10srHbXviTlcv7Kpzw8jWiNTqbVgjO3IY8RxrrOUF8VPMQQFysYYYv0YZxw==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/process-ancestry": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/process-ancestry/-/process-ancestry-0.1.0.tgz", + "integrity": "sha512-tGqJW/UnclpYASFcM6Xh8D8l/BMtaQ9+CSG0vlJSJTcdMM4lDRv4c6H0Pdcsfted+bVczdYSfk2fdukg2gQkZg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/property-information": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-7.2.0.tgz", + "integrity": "sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/radix3": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/radix3/-/radix3-1.1.2.tgz", + "integrity": "sha512-b484I/7b8rDEdSDKckSSBA8knMpcdsXudlE/LNL639wFoHKwLbEkQFZHWEYwDC0wa0FKUcCY+GAF73Z7wxNVFA==", + "license": "MIT" + }, + "node_modules/readdirp": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.1.1.tgz", + "integrity": "sha512-Kko+Y5XQ6fM+Ce3dq3m9YGxnacYZYl9cA1wZjaF3Vbry2L3i1qVg8+CAgNPsXRArPMUMCaOR7oa9Nqntc43JKA==", + "license": "MIT", + "engines": { + "node": ">= 20.19.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/regex/-/regex-6.1.0.tgz", + "integrity": "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg==", + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-recursion": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-6.0.2.tgz", + "integrity": "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg==", + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-utilities": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz", + "integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==", + "license": "MIT" + }, + "node_modules/rehype-expressive-code": { + "version": "0.44.3", + "resolved": "https://registry.npmjs.org/rehype-expressive-code/-/rehype-expressive-code-0.44.3.tgz", + "integrity": "sha512-vaVuQPobFXvmtcHXQ5uqXZlzuuPnLyIuZcX/03sX1U/Qfj9fZrPYI9w66OSr/PUx6alzRYmreEwgYBbsVx8HsA==", + "license": "MIT", + "dependencies": { + "expressive-code": "^0.44.3" + } + }, + "node_modules/remark-directive": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/remark-directive/-/remark-directive-4.0.0.tgz", + "integrity": "sha512-7sxn4RfF1o3izevPV1DheyGDD6X4c9hrGpfdUpm7uC++dqrnJxIZVkk7CoKqcLm0VUMAuOol7Mno3m6g8cfMuA==", + "license": "MIT", + "dependencies": { + "@types/mdast": "^4.0.0", + "mdast-util-directive": "^3.0.0", + "micromark-extension-directive": "^4.0.0", + "unified": "^11.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/retext-smartypants": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/retext-smartypants/-/retext-smartypants-6.2.0.tgz", + "integrity": "sha512-kk0jOU7+zGv//kfjXEBjdIryL1Acl4i9XNkHxtM7Tm5lFiCog576fjNC9hjoR7LTKQ0DsPWy09JummSsH1uqfQ==", + "license": "MIT", + "dependencies": { + "@types/nlcst": "^2.0.0", + "nlcst-to-string": "^4.0.0", + "unist-util-visit": "^5.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/rolldown": { + "version": "1.2.16", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.16.tgz", + "integrity": "sha512-bWvlMpFKiTfDKfnK7FC2MPgPeWCf/Kpwsq49ApdW+FQaBZb6O6dZ4MAPbPUjp7hYQrw/RobqCzn64BRrQecGHw==", + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.156.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.16", + "@rolldown/binding-android-arm64": "1.2.16", + "@rolldown/binding-darwin-arm64": "1.2.16", + "@rolldown/binding-darwin-x64": "1.2.16", + "@rolldown/binding-freebsd-x64": "1.2.16", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.16", + "@rolldown/binding-linux-arm64-gnu": "1.2.16", + "@rolldown/binding-linux-arm64-musl": "1.2.16", + "@rolldown/binding-linux-ppc64-gnu": "1.2.16", + "@rolldown/binding-linux-s390x-gnu": "1.2.16", + "@rolldown/binding-linux-x64-gnu": "1.2.16", + "@rolldown/binding-linux-x64-musl": "1.2.16", + "@rolldown/binding-openharmony-arm64": "1.2.16", + "@rolldown/binding-win32-arm64-msvc": "1.2.16", + "@rolldown/binding-win32-x64-msvc": "1.2.16" + } + }, + "node_modules/satteri": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/satteri/-/satteri-0.10.5.tgz", + "integrity": "sha512-Ao1LKpAEa9Wdg0otgbVKViZHEq9ebdXe4DMrp3s9vQAU0HNIuHnFEuMuOcm0ZIXyV0Yzxj91NvhLpvXZJO/5ZQ==", + "license": "MIT", + "dependencies": { + "@types/estree-jsx": "^1.0.5", + "@types/hast": "^3.0.5", + "@types/mdast": "^4.0.4", + "@types/unist": "^3.0.3" + }, + "optionalDependencies": { + "@bruits/satteri-darwin-arm64": "0.10.5", + "@bruits/satteri-darwin-x64": "0.10.5", + "@bruits/satteri-linux-arm64-gnu": "0.10.5", + "@bruits/satteri-linux-arm64-musl": "0.10.5", + "@bruits/satteri-linux-x64-gnu": "0.10.5", + "@bruits/satteri-linux-x64-musl": "0.10.5", + "@bruits/satteri-wasm32-wasi": "0.10.5", + "@bruits/satteri-win32-arm64-msvc": "0.10.5", + "@bruits/satteri-win32-x64-msvc": "0.10.5" + } + }, + "node_modules/sax": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz", + "integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==", + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=11.0.0" + } + }, + "node_modules/semver": { + "version": "7.8.6", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", + "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==", + "license": "ISC", + "optional": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/sharp": { + "version": "0.35.5", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.5.tgz", + "integrity": "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g==", + "license": "Apache-2.0", + "optional": true, + "dependencies": { + "@img/colour": "^1.1.0", + "detect-libc": "^2.1.2", + "semver": "^7.8.5" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.35.5", + "@img/sharp-darwin-x64": "0.35.5", + "@img/sharp-freebsd-wasm32": "0.35.5", + "@img/sharp-libvips-darwin-arm64": "1.3.4", + "@img/sharp-libvips-darwin-x64": "1.3.4", + "@img/sharp-libvips-linux-arm": "1.3.4", + "@img/sharp-libvips-linux-arm64": "1.3.4", + "@img/sharp-libvips-linux-ppc64": "1.3.4", + "@img/sharp-libvips-linux-riscv64": "1.3.4", + "@img/sharp-libvips-linux-s390x": "1.3.4", + "@img/sharp-libvips-linux-x64": "1.3.4", + "@img/sharp-libvips-linuxmusl-arm64": "1.3.4", + "@img/sharp-libvips-linuxmusl-x64": "1.3.4", + "@img/sharp-linux-arm": "0.35.5", + "@img/sharp-linux-arm64": "0.35.5", + "@img/sharp-linux-ppc64": "0.35.5", + "@img/sharp-linux-riscv64": "0.35.5", + "@img/sharp-linux-s390x": "0.35.5", + "@img/sharp-linux-x64": "0.35.5", + "@img/sharp-linuxmusl-arm64": "0.35.5", + "@img/sharp-linuxmusl-x64": "0.35.5", + "@img/sharp-webcontainers-wasm32": "0.35.5", + "@img/sharp-win32-arm64": "0.35.5", + "@img/sharp-win32-ia32": "0.35.5", + "@img/sharp-win32-x64": "0.35.5" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/shiki": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-4.6.0.tgz", + "integrity": "sha512-imjLsVHgPuWhvpU3P+zOekvMYqnel7QmKsFC4Sn0fCuAvaaalBsxwKEsrU8Ko5BdFnZA6Go/8a0RzahS634UgA==", + "license": "MIT", + "dependencies": { + "@shikijs/core": "4.6.0", + "@shikijs/engine-javascript": "4.6.0", + "@shikijs/engine-oniguruma": "4.6.0", + "@shikijs/langs": "4.6.0", + "@shikijs/themes": "4.6.0", + "@shikijs/types": "4.6.0", + "@shikijs/vscode-textmate": "^10.1.0", + "@types/hast": "^3.0.5" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "license": "MIT" + }, + "node_modules/sitemap": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-9.0.1.tgz", + "integrity": "sha512-S6hzjGJSG3d6if0YoF5kTyeRJvia6FSTBroE5fQ0bu1QNxyJqhhinfUsXi9fH3MgtXODWvwo2BDyQSnhPQ88uQ==", + "license": "MIT", + "dependencies": { + "@types/node": "^24.9.2", + "@types/sax": "^1.2.1", + "arg": "^5.0.0", + "sax": "^1.4.1" + }, + "bin": { + "sitemap": "dist/esm/cli.js" + }, + "engines": { + "node": ">=20.19.5", + "npm": ">=10.8.2" + } + }, + "node_modules/smol-toml": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.9.1.tgz", + "integrity": "sha512-j7WyPdf0CJoutMzMoPLF/bVXHtKZIT9Rb4eGeEbWw8X2t5oirjPgpL+OpaENZrILYaXqYwnVH+qgUwVbl+pUJQ==", + "license": "BSD-3-Clause", + "engines": { + "node": ">= 18" + }, + "funding": { + "url": "https://github.com/sponsors/cyyynthia" + } + }, + "node_modules/source-map-js": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/space-separated-tokens": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/starlight-links-validator": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/starlight-links-validator/-/starlight-links-validator-0.27.0.tgz", + "integrity": "sha512-UvPl8L9hfWR+yWbLOEtljLmpJCGcM6AVseVy5IO9dmqdOjW4R+Y8FaYyVA5axCC8RvxM5xU7M1WTerpwU8rYbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@astrojs/markdown-satteri": "^0.4.0", + "github-slugger": "^2.0.0", + "hast-util-from-html": "^2.0.3", + "is-absolute-url": "^5.0.0", + "mdast-util-mdx-jsx": "^3.2.0", + "mdast-util-to-hast": "^13.2.1", + "picomatch": "^4.0.3", + "satteri": "^0.10.3", + "terminal-link": "^5.0.0", + "unist-util-visit": "^5.1.0", + "yaml": "^2.8.3" + }, + "peerDependencies": { + "@astrojs/starlight": ">=0.42.0", + "astro": ">=7.2.10" + } + }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "license": "MIT" + }, + "node_modules/stringify-entities": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz", + "integrity": "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==", + "license": "MIT", + "dependencies": { + "character-entities-html4": "^2.0.0", + "character-entities-legacy": "^3.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/strnum": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.5.1.tgz", + "integrity": "sha512-UM4nTLWzQiDBseVxUGxN0wJzIk0UU89Qi7pKXz9qISo+lhviJikTuikBsK/oFRlpvYHvSdz0TVoLyQ+sEpYwxA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "anynum": "^1.0.1" + } + }, + "node_modules/supports-color": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-10.2.2.tgz", + "integrity": "sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/supports-hyperlinks": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-4.6.0.tgz", + "integrity": "sha512-FL/q/YePS4tFFTNiBOR+zPk2ZrKheqNtmTJ/9OUZ4e1wKHJofDbGQSmSsxS0XNnabSkqexryCaXGvEKz1vf9UQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^5.0.1", + "supports-color": "^10.2.2" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/chalk/supports-hyperlinks?sponsor=1" + } + }, + "node_modules/svgo": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/svgo/-/svgo-4.1.0.tgz", + "integrity": "sha512-bkxnTg1kSU0guhIBmibA6UUhrQmPVA1XsQLN+ylCd+UWzbnLkySOcXpyk1mrl05f+pcaCx2eHb+sp6BgMZWX+Q==", + "license": "MIT", + "dependencies": { + "commander": "^11.1.0", + "css-select": "^6.0.0", + "css-tree": "^3.0.1", + "css-what": "^7.0.0", + "csso": "^5.0.5", + "picocolors": "^1.1.1", + "sax": "1.6.1" + }, + "bin": { + "svgo": "bin/svgo.js" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/svgo" + } + }, + "node_modules/terminal-link": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/terminal-link/-/terminal-link-5.0.0.tgz", + "integrity": "sha512-qFAy10MTMwjzjU8U16YS4YoZD+NQLHzLssFMNqgravjbvIPNiqkGFR4yjhJfmY9R5OFU7+yHxc6y+uGHkKwLRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-escapes": "^7.0.0", + "supports-hyperlinks": "^4.1.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/tiny-inflate": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz", + "integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==", + "license": "MIT" + }, + "node_modules/tinyclip": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tinyclip/-/tinyclip-1.0.3.tgz", + "integrity": "sha512-nTv2raKFMzGG6JJp0lpNDsRPdfFE6UHlu2rVEjXo8vkx1ZS3LW2CVXqIaLu8xZlu+6tbFs9V58Qc/Jmk/Ii7wA==", + "license": "MIT", + "engines": { + "node": "^16.14.0 || >= 17.3.0" + } + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyps": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/tinyps/-/tinyps-0.5.1.tgz", + "integrity": "sha512-B6Ykif5HflC3AdDkS4Zst/2muYVfeXoVMy+KorqH80s/1x4vunIORpNySH681X7fjj+dFM9MDKD6/Hsccjb87Q==", + "license": "MIT" + }, + "node_modules/trim-lines": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", + "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/trough": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/trough/-/trough-2.2.0.tgz", + "integrity": "sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/tslib": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz", + "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==", + "license": "0BSD", + "optional": true + }, + "node_modules/ufo": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.4.tgz", + "integrity": "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==", + "license": "MIT" + }, + "node_modules/ultrahtml": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ultrahtml/-/ultrahtml-1.7.0.tgz", + "integrity": "sha512-2xRd0VHoAQE4M+vF/DvFFB7pUV0ZxTW1TLi7lHQWnF/Sb5TPeEUV/l+hxcNnGO00ZXGnR0voCMmYRKQf+rvJ2g==", + "license": "MIT" + }, + "node_modules/uncrypto": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/uncrypto/-/uncrypto-0.1.3.tgz", + "integrity": "sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==", + "license": "MIT" + }, + "node_modules/undici": { + "version": "8.12.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-8.12.3.tgz", + "integrity": "sha512-+fdndUTwBP86cVjihTp21hZHo7d6oj1c/47XPA3lL8mM0XHs+C4EkcjmgRsFnFk2f/UONGDy9ItBItmXsLOQHw==", + "license": "MIT", + "engines": { + "node": ">=22.19.0" + } + }, + "node_modules/undici-types": { + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz", + "integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==", + "license": "MIT" + }, + "node_modules/unified": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/unified/-/unified-11.0.5.tgz", + "integrity": "sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "bail": "^2.0.0", + "devlop": "^1.0.0", + "extend": "^3.0.0", + "is-plain-obj": "^4.0.0", + "trough": "^2.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unifont": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/unifont/-/unifont-1.0.3.tgz", + "integrity": "sha512-XGnEwj5sWdCbiBX01mWLSBncS0yMRjnLygau3IfdOlfjMacNIQvTGW4VH7pWBq+gGWArfSef/CensMLjMmIr/A==", + "license": "MIT", + "dependencies": { + "css-tree": "^3.1.0", + "fnv1a-64": "^0.1.2", + "std-env": "^4.2.0", + "undici": "^8.0.0" + } + }, + "node_modules/unist-util-is": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", + "integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-position": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", + "integrity": "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-stringify-position": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", + "integrity": "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.2.0.tgz", + "integrity": "sha512-fpsYs/VVoZxfGY9/j3FQpZmN8wdLJaV1Pt38AaJNZu9uKIHcFU3halCdBveEq1HGKO1OEfJY65w1zvoFV1b3qQ==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit-parents": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.1.0.tgz", + "integrity": "sha512-vKXxz6O38sKDj1mtx/k2cWvkkFBuYGx6uGrlzBkVeWCRF/F8sdI0j3Wbkz/5rVNRRuVc8UrgRdbCxNhmYXgP3w==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unstorage": { + "version": "1.17.6", + "resolved": "https://registry.npmjs.org/unstorage/-/unstorage-1.17.6.tgz", + "integrity": "sha512-gjKtcmn/KwZuJZO9o2sc0esAQnhmTw0LviDHwevTXbJMYs0dRTp8ZEEWXHU0vTpzbN3cA0yxlTeyXssMp3zDqw==", + "license": "MIT", + "dependencies": { + "anymatch": "^3.1.3", + "chokidar": "^5.0.0", + "destr": "^2.0.5", + "h3": "^1.15.11", + "lru-cache": "^11.5.3", + "node-fetch-native": "^1.6.7", + "ofetch": "^1.5.1", + "ufo": "^1.6.4" + }, + "peerDependencies": { + "@azure/app-configuration": "^1.8.0", + "@azure/cosmos": "^4.2.0", + "@azure/data-tables": "^13.3.0", + "@azure/identity": "^4.6.0", + "@azure/keyvault-secrets": "^4.9.0", + "@azure/storage-blob": "^12.26.0", + "@capacitor/preferences": "^6 || ^7 || ^8", + "@deno/kv": ">=0.9.0", + "@netlify/blobs": "^6.5.0 || ^7.0.0 || ^8.1.0 || ^9.0.0 || ^10.0.0 || ^11.0.0", + "@planetscale/database": "^1.19.0", + "@upstash/redis": "^1.34.3", + "@vercel/blob": ">=0.27.1", + "@vercel/functions": "^2.2.12 || ^3.0.0", + "@vercel/kv": "^1 || ^2 || ^3", + "aws4fetch": "^1.0.20", + "db0": ">=0.2.1", + "idb-keyval": "^6.2.1", + "ioredis": "^5.4.2", + "uploadthing": "^7.4.4" + }, + "peerDependenciesMeta": { + "@azure/app-configuration": { + "optional": true + }, + "@azure/cosmos": { + "optional": true + }, + "@azure/data-tables": { + "optional": true + }, + "@azure/identity": { + "optional": true + }, + "@azure/keyvault-secrets": { + "optional": true + }, + "@azure/storage-blob": { + "optional": true + }, + "@capacitor/preferences": { + "optional": true + }, + "@deno/kv": { + "optional": true + }, + "@netlify/blobs": { + "optional": true + }, + "@planetscale/database": { + "optional": true + }, + "@upstash/redis": { + "optional": true + }, + "@vercel/blob": { + "optional": true + }, + "@vercel/functions": { + "optional": true + }, + "@vercel/kv": { + "optional": true + }, + "aws4fetch": { + "optional": true + }, + "db0": { + "optional": true + }, + "idb-keyval": { + "optional": true + }, + "ioredis": { + "optional": true + }, + "uploadthing": { + "optional": true + } + } + }, + "node_modules/url-extras": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/url-extras/-/url-extras-0.1.0.tgz", + "integrity": "sha512-8tzwTeXFPuX/5PHuCDQE5Dd9Ts4rwoq2t9aIT+HS4iAVpmj5l4Ao7Q+BuuFjvWRqrLswBhQDk8O96ZicgCqQqw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, + "node_modules/verkit": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/verkit/-/verkit-0.5.0.tgz", + "integrity": "sha512-u4J1hr6Y+C/hit34GwL3eIcUf3wngT8TlYUjK7tk0jxydKLAq3sYvifjdTDA6U3KCKRcQCQDGf/srjxfZF3l7g==", + "license": "MIT", + "engines": { + "node": ">=18.12.0" + }, + "funding": { + "url": "https://github.com/sponsors/sxzz" + } + }, + "node_modules/vfile": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", + "integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "vfile-message": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/vfile-location": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/vfile-location/-/vfile-location-5.0.3.tgz", + "integrity": "sha512-5yXvWDEgqeiYiBe1lbxYF7UMAIm/IcopxMHrMQDq3nvKcjPKIhZklUKL+AE7J7uApI4kwe2snsK+eI6UTj9EHg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/vfile-message": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz", + "integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-stringify-position": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/vite": { + "version": "8.3.5", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.5.tgz", + "integrity": "sha512-z1YpjieJ9g0ebTmQpLBv/oq9E3F9EIlOe+7LahW8SrE3LTiG3udBRUXQOlYXP9b+IC2q2phHeVxj9xGlw34OEQ==", + "license": "MIT", + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.30", + "rolldown": "~1.2.14", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1 || ^0.8.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitefu": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/vitefu/-/vitefu-1.1.3.tgz", + "integrity": "sha512-ub4okH7Z5KLjb6hDyjqrGXqWtWvoYdU3IGm/NorpgHncKoLTCfRIbvlhBm7r0YstIaQRYlp4yEbFqDcKSzXSSg==", + "license": "MIT", + "workspaces": [ + "tests/deps/*", + "tests/projects/*", + "tests/projects/workspace/packages/*" + ], + "peerDependencies": { + "vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + } + }, + "node_modules/web-namespaces": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/web-namespaces/-/web-namespaces-2.0.1.tgz", + "integrity": "sha512-bKr1DkiNa2krS7qxNtdrtHAmzuYGFQLiQ13TsorsdT6ULTkPLKuu5+GsFpDlg6JFjUTwX2DyhMPG2be8uPrqsQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/xml-naming": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.3.0.tgz", + "integrity": "sha512-ghig2TBE/H11aOVgmahA3MhimvkBr6JIYknH/Dhdk10nXwdbIqBJsbfMxpvFPG8bAw77gN29aQWvKpmVoPlvPQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/xxhash-wasm": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/xxhash-wasm/-/xxhash-wasm-1.1.0.tgz", + "integrity": "sha512-147y/6YNh+tlp6nd/2pWq38i9h6mz/EuQ6njIrmW8D1BS5nCqs0P6DG+m6zTGnNz5I+uhZ0SHxBs9BsPrwcKDA==", + "license": "MIT" + }, + "node_modules/yaml": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", + "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + }, + "node_modules/yargs-parser": { + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-22.0.0.tgz", + "integrity": "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==", + "license": "ISC", + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=23" + } + }, + "node_modules/yocto-queue": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz", + "integrity": "sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==", + "license": "MIT", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zwitch": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + } + } +} diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 00000000..f6657a83 --- /dev/null +++ b/docs/package.json @@ -0,0 +1,27 @@ +{ + "name": "fairmq-docs", + "version": "0.0.0", + "private": true, + "type": "module", + "engines": { + "node": ">=22.23.4" + }, + "scripts": { + "dev": "astro dev", + "build": "astro build", + "preview": "astro preview", + "check": "node scripts/check-links.mjs" + }, + "dependencies": { + "@astrojs/markdown-satteri": "0.4.6", + "@astrojs/starlight": "0.42.9", + "@fontsource-variable/archivo": "5.3.0", + "@fontsource-variable/jetbrains-mono": "5.3.0", + "astro": "7.4.5", + "fast-xml-parser": "5.12.0", + "shiki": "4.6.0" + }, + "devDependencies": { + "starlight-links-validator": "0.27.0" + } +} diff --git a/docs/public/favicon.svg b/docs/public/favicon.svg new file mode 100644 index 00000000..119f2f11 --- /dev/null +++ b/docs/public/favicon.svg @@ -0,0 +1,10 @@ + + + + + + + diff --git a/docs/scripts/api.mjs b/docs/scripts/api.mjs new file mode 100644 index 00000000..6c935dd1 --- /dev/null +++ b/docs/scripts/api.mjs @@ -0,0 +1,776 @@ +// Turns the Doxygen XML into the model for the API and source pages. +// +// The API pages show the types of the installed headers (FAIRMQ_PUBLIC_HEADER_FILES in +// fairmq/CMakeLists.txt). The source pages show all files in fairmq/. A Doxygen reference +// to a public symbol links to its API page; a reference to another symbol links to the +// line in the source browser. +import { readdirSync, readFileSync } from 'node:fs'; +import path from 'node:path'; +import { parseXmlFile, tagOf, isText, kids, attr, children, child, find, textOf, escapeHtml } from './xml.mjs'; + +const ENTITIES = { + ndash: '–', mdash: '—', nbsp: ' ', lsquo: '‘', rsquo: '’', ldquo: '“', rdquo: '”', hellip: '…', + copy: '©', trade: '™', reg: '®', plusmn: '±', times: '×', divide: '÷', larr: '←', rarr: '→', harr: '↔', + uarr: '↑', darr: '↓', lArr: '⇐', rArr: '⇒', hArr: '⇔', laquo: '«', raquo: '»', deg: '°', micro: 'µ', + middot: '·', bull: '•', le: '≤', ge: '≥', ne: '≠', minus: '−', infin: '∞', sect: '§', para: '¶', + apos: "'", quot: '"', zwj: '', zwnj: '', shy: '', +}; + +const KEYWORDS = + /\b(template|typename|class|struct|union|enum|const|constexpr|static|virtual|explicit|inline|noexcept|override|final|void|bool|int|unsigned|signed|char|short|long|float|double|auto|using|typedef|friend|operator|default|delete|volatile|mutable|decltype|sizeof|true|false|nullptr)\b/g; + +const OPERATOR_NAMES = { + '=': 'assign', '==': 'eq', '!=': 'ne', '<': 'lt', '>': 'gt', '<=': 'le', '>=': 'ge', '<<': 'shl', '>>': 'shr', + '[]': 'index', '()': 'call', '!': 'not', '+': 'plus', '-': 'minus', '*': 'deref', '&': 'and', '|': 'or', + '->': 'arrow', '++': 'inc', '--': 'dec', '+=': 'plus-assign', '-=': 'minus-assign', '<=>': 'cmp', + bool: 'bool', +}; + +/** The headers that `cmake --install` puts into include/fairmq. */ +export function readPublicHeaders(repoRoot) { + const text = readFileSync(path.join(repoRoot, 'fairmq', 'CMakeLists.txt'), 'utf8'); + const m = /set\(FAIRMQ_PUBLIC_HEADER_FILES([\s\S]*?)\)/.exec(text); + if (!m) throw new Error('FAIRMQ_PUBLIC_HEADER_FILES not found in fairmq/CMakeLists.txt'); + return new Set( + m[1] + .split(/\s+/) + .filter((s) => s && !s.startsWith('#') && !s.startsWith('$')) + .map((s) => `fairmq/${s}`), + ); +} + +/** All C++ files in fairmq/, sorted by directory, then by name. */ +export function listSourceFiles(repoRoot) { + const out = []; + const walk = (rel) => { + for (const e of readdirSync(path.join(repoRoot, rel), { withFileTypes: true })) { + const p = `${rel}/${e.name}`; + if (e.isDirectory()) walk(p); + else if (/\.(h|cxx)$/.test(e.name)) out.push(p); + } + }; + walk('fairmq'); + return out.sort((a, b) => { + const da = path.posix.dirname(a); + const db = path.posix.dirname(b); + if (da !== db) return da.localeCompare(db); + return path.posix.basename(a).localeCompare(path.posix.basename(b), 'en', { sensitivity: 'base' }); + }); +} + +function slugPath(name) { + return name.split('::').join('/'); +} + +/** A readable, stable anchor for a member name. */ +export function anchorFor(name) { + let n = name.trim(); + if (n.startsWith('~')) return 'dtor'; + const op = /^operator\s*(.*)$/.exec(n); + if (op) { + const sym = op[1].replace(/\s+/g, ''); + return 'operator-' + (OPERATOR_NAMES[sym] ?? sym.replace(/[^A-Za-z0-9_]/g, (c) => c.charCodeAt(0).toString(16))); + } + return n.replace(/[^A-Za-z0-9_-]/g, '-'); +} + +function normalizeTypeText(s) { + return s + .replace(/<\s+/g, '<') + .replace(/\s+>/g, '>') + .replace(/\s+([&*]+)/g, '$1') + .replace(/\s+,/g, ',') + .replace(/\(\s+/g, '(') + .replace(/\s+\)/g, ')'); +} + +function highlightKeywords(escaped) { + return escaped.replace(KEYWORDS, '$1'); +} + +export function buildModel({ xmlDir, repoRoot, base = '' }) { + const publicHeaders = readPublicHeaders(repoRoot); + const sourceFiles = listSourceFiles(repoRoot); + const sourceSet = new Set(sourceFiles); + + /** @type {Map} */ + const defs = new Map(); + for (const f of readdirSync(xmlDir)) { + if (!f.endsWith('.xml') || f === 'index.xml' || f === 'Doxyfile.xml') continue; + const doc = find(parseXmlFile(path.join(xmlDir, f)), 'doxygen'); + for (const cd of children(doc, 'compounddef')) defs.set(attr(cd, 'id'), cd); + } + + const compounds = new Map(); // id -> class/struct/union/namespace record + const members = new Map(); // id -> member record + const files = new Map(); // path -> file record + const targets = new Map(); // refid -> { href, kind, name, sig, loc } + + // ---------- Pass 1: records ---------- + for (const [id, cd] of defs) { + const kind = attr(cd, 'kind'); + const name = textOf(child(cd, 'compoundname')).trim(); + const loc = child(cd, 'location'); + const file = attr(loc, 'file'); + if (kind === 'file') { + if (!sourceSet.has(file)) continue; + files.set(file, { id, path: file, node: cd, defines: [] }); + continue; + } + if (kind === 'dir' || kind === 'page' || kind === 'example' || kind === 'group') continue; + if (name.includes('@')) continue; + const isType = kind === 'class' || kind === 'struct' || kind === 'union'; + if (!isType && kind !== 'namespace') continue; + const parts = name.split('::'); + const rec = { + id, + kind, + name, + short: parts[parts.length - 1], + scope: parts.slice(0, -1).join('::'), + file, + line: Number(attr(loc, 'line')) || 1, + prot: attr(cd, 'prot') ?? 'public', + node: cd, + url: `${base}/api/${slugPath(name)}/`, + public: false, + members: [], + inner: children(cd, 'innerclass').map((n) => attr(n, 'refid')), + innerNamespaces: children(cd, 'innernamespace').map((n) => attr(n, 'refid')), + }; + if (isType) { + rec.public = !!file && publicHeaders.has(file) && name.startsWith('fair::mq') && rec.prot === 'public'; + const inc = child(cd, 'includes'); + rec.include = inc ? textOf(inc).trim() : file; + } + compounds.set(id, rec); + } + + // Nested classes of a non-public class are not public either. + for (const rec of compounds.values()) { + if (rec.kind === 'namespace' || !rec.public) continue; + const parent = [...compounds.values()].find((c) => c.name === rec.scope); + if (parent && parent.kind !== 'namespace' && !parent.public) rec.public = false; + } + + // Members. Namespace members also appear in file compounds with the same id; the + // namespace (or class) is the owner. + const ownerOrder = (cd) => (attr(cd, 'kind') === 'file' ? 1 : 0); + const sortedDefs = [...defs.values()].sort((a, b) => ownerOrder(a) - ownerOrder(b)); + for (const cd of sortedDefs) { + const ownerId = attr(cd, 'id'); + const owner = compounds.get(ownerId); + const fileRec = attr(cd, 'kind') === 'file' ? files.get(attr(child(cd, 'location'), 'file')) : undefined; + if (!owner && !fileRec) continue; + for (const sec of children(cd, 'sectiondef')) { + const secKind = attr(sec, 'kind'); + for (const md of children(sec, 'memberdef')) { + const mid = attr(md, 'id'); + if (members.has(mid)) continue; + const loc = child(md, 'location'); + const m = { + id: mid, + kind: attr(md, 'kind'), + name: textOf(child(md, 'name')).trim(), + qualified: textOf(child(md, 'qualifiedname')).trim(), + prot: attr(md, 'prot'), + static: attr(md, 'static') === 'yes', + constexpr: attr(md, 'constexpr') === 'yes', + explicit: attr(md, 'explicit') === 'yes', + virt: attr(md, 'virt'), + strong: attr(md, 'strong') === 'yes', + section: secKind, + // A namespace function that a .cxx file defines has the .cxx file as location and + // the header as declfile. The declaration in the header is the API. + file: attr(loc, 'declfile') || attr(loc, 'file'), + line: Number(attr(loc, 'declline') || attr(loc, 'line')) || 1, + owner: owner ? owner.id : null, + fileOwner: fileRec ? fileRec.path : null, + node: md, + }; + if (!m.qualified) m.qualified = owner ? `${owner.name}::${m.name}` : m.name; + members.set(mid, m); + if (owner) owner.members.push(m); + } + } + } + + // ---------- Pass 2: URLs and link targets ---------- + const sourceHref = (file, line) => + file && sourceSet.has(file) ? `${base}/source/${file}/${line ? `#L${line}` : ''}` : null; + + for (const f of files.values()) { + targets.set(f.id, { href: `${base}/source/${f.path}/`, kind: 'file', name: f.path, sig: f.path, loc: f.path }); + } + + // Namespaces get a page when they hold public types or public members. + for (const ns of compounds.values()) { + if (ns.kind !== 'namespace') continue; + const hasTypes = ns.inner.some((id) => compounds.get(id)?.public); + // A name with :: is an explicit instantiation of a member template (extern template). + const pubMembers = ns.members.filter((m) => publicHeaders.has(m.file) && m.kind !== 'define' && !m.name.includes('::')); + ns.public = ns.name.startsWith('fair::mq') && (hasTypes || pubMembers.length > 0); + // C++ has no access control in namespaces. Doxygen marks some functions of .cxx files private. + for (const m of pubMembers) m.prot = 'public'; + ns.publicMembers = pubMembers; + } + + // Anchors per owner, with numbers for overloads. + const assignAnchors = (list) => { + const used = new Map(); + for (const m of list) { + const a = anchorFor(m.name); + const n = (used.get(a) ?? 0) + 1; + used.set(a, n); + m.anchor = n === 1 ? a : `${a}-${n}`; + m.overload = n; + } + }; + + for (const rec of compounds.values()) { + if (rec.kind === 'namespace') { + if (!rec.public) continue; + const list = rec.publicMembers; + const enums = list.filter((m) => m.kind === 'enum'); + const rest = list.filter((m) => m.kind !== 'enum'); + assignAnchors(rest); + for (const m of rest) m.href = `${rec.url}#${m.anchor}`; + for (const e of enums) { + e.anchor = anchorFor(e.name); + e.page = `${rec.url}${e.name}/`; + e.href = e.page; + } + } else if (rec.public) { + const visible = rec.members.filter((m) => m.prot !== 'private'); + assignAnchors(visible); + for (const m of visible) m.href = `${rec.url}#${m.anchor}`; + } + } + + const kindLabel = (m) => { + if (m.kind === 'function') { + const owner = m.owner && compounds.get(m.owner); + if (owner && owner.kind !== 'namespace') { + if (m.name === owner.short) return 'constructor'; + if (m.name === `~${owner.short}`) return 'destructor'; + return m.static ? 'static member function' : 'member function'; + } + return 'function'; + } + if (m.kind === 'variable') return m.owner && compounds.get(m.owner)?.kind !== 'namespace' ? 'data member' : 'variable'; + if (m.kind === 'typedef') return 'type alias'; + if (m.kind === 'enum') return m.strong ? 'enum class' : 'enum'; + return m.kind; + }; + + for (const rec of compounds.values()) { + const href = rec.public ? rec.url : sourceHref(rec.file, rec.line); + if (!href) continue; + targets.set(rec.id, { + href, + kind: rec.kind, + name: rec.name, + sig: `${rec.kind} ${rec.name}`, + loc: `${rec.file}:${rec.line}`, + }); + } + for (const m of members.values()) { + const href = m.href ?? sourceHref(m.file, m.line); + if (!href) continue; + targets.set(m.id, { href, kind: kindLabel(m), name: m.qualified, sig: '', loc: `${m.file}:${m.line}`, member: m }); + if (m.kind === 'enum') { + for (const ev of children(m.node, 'enumvalue')) { + const evName = textOf(child(ev, 'name')).trim(); + targets.set(attr(ev, 'id'), { + href: m.page ? `${m.page}#${anchorFor(evName)}` : m.href ? `${m.href}` : href, + kind: 'enumerator', + name: `${m.qualified}::${evName}`, + sig: `${m.qualified}::${evName}${textOf(child(ev, 'initializer')) ? ' ' + textOf(child(ev, 'initializer')).trim() : ''}`, + loc: `${m.file}:${m.line}`, + }); + } + } + } + + // ---------- Rendering helpers ---------- + const link = (refid, innerHtml) => { + const t = targets.get(refid); + if (!t) return innerHtml; + return `${innerHtml}`; + }; + + /** Linked text (types, initializers): text and only. */ + const linked = (node, { type = false, keywords = true } = {}) => { + if (!node) return ''; + const parts = []; + for (const n of kids(node)) { + if (isText(n)) { + const raw = type ? normalizeTypeText(n['#text']) : n['#text']; + const t = escapeHtml(raw); + parts.push(keywords ? highlightKeywords(t) : t); + } else if (tagOf(n) === 'ref') { + parts.push(link(attr(n, 'refid'), escapeHtml(textOf(n)))); + } else if (tagOf(n) === 'sp') { + parts.push(' '); + } else { + parts.push(linked(n, { type, keywords })); + } + } + return parts.join('').replace(/\s+/g, ' ').trim(); + }; + + const plain = (node, type = false) => { + const t = textOf(node).replace(/\s+/g, ' ').trim(); + return type ? normalizeTypeText(t) : t; + }; + + const renderInline = (n) => { + if (isText(n)) return escapeHtml(n['#text']); + const t = tagOf(n); + if (ENTITIES[t] !== undefined) return ENTITIES[t]; + switch (t) { + case 'sp': + return ' '; + case 'ref': + return link(attr(n, 'refid'), kids(n).map(renderInline).join('')); + case 'computeroutput': + return `${kids(n).map(renderInline).join('')}`; + case 'emphasis': + return `${kids(n).map(renderInline).join('')}`; + case 'bold': + return `${kids(n).map(renderInline).join('')}`; + case 's': + case 'strike': + case 'del': + return `${kids(n).map(renderInline).join('')}`; + case 'underline': + case 'ins': + return `${kids(n).map(renderInline).join('')}`; + case 'subscript': + return `${kids(n).map(renderInline).join('')}`; + case 'superscript': + return `${kids(n).map(renderInline).join('')}`; + case 'small': + return `${kids(n).map(renderInline).join('')}`; + case 'ulink': + return `${kids(n).map(renderInline).join('')}`; + case 'linebreak': + return '
'; + case 'nonbreakablespace': + return ' '; + case 'anchor': + return ''; + case 'formula': + return `${escapeHtml(textOf(n))}`; + case 'emoji': + return attr(n, 'unicode') ?? ''; + case 'image': + case 'htmlonly': + case 'manonly': + case 'xmlonly': + case 'rtfonly': + case 'latexonly': + case 'docbookonly': + case 'dot': + case 'msc': + case 'plantuml': + case 'indexentry': + return ''; + default: + return kids(n).map(renderInline).join(''); + } + }; + + const codeOf = (n) => + children(n, 'codeline') + .map((cl) => textOf(cl)) + .join('\n'); + + const unwrapP = (html) => { + const m = /^

([\s\S]*)<\/p>$/.exec(html); + return m && !m[1].includes('

') ? m[1] : html; + }; + + /** Renders a description into HTML. Parameters, return values and notes go into `out`. */ + const renderBlocks = (nodes, out) => { + let html = ''; + for (const n of nodes) { + if (isText(n)) { + if (n['#text'].trim()) html += `

${escapeHtml(n['#text'].trim())}

`; + continue; + } + const t = tagOf(n); + if (t === 'para') html += renderPara(n, out); + else if (t === 'sect1' || t === 'sect2' || t === 'sect3' || t === 'internal') { + const title = child(n, 'title'); + if (title) html += `

${kids(title).map(renderInline).join('')}

`; + html += renderBlocks( + kids(n).filter((k) => tagOf(k) !== 'title'), + out, + ); + } else html += renderPara({ para: [n] }, out); + } + return html; + }; + + const listItems = (n, out) => + children(n, 'listitem') + .map((li) => `
  • ${unwrapP(renderBlocks(kids(li), out).trim())}
  • `) + .join(''); + + const renderPara = (para, out) => { + let html = ''; + let inline = []; + const flush = () => { + const text = inline.join('').replace(/\s+/g, ' ').trim(); + if (text) html += `

    ${text}

    `; + inline = []; + }; + for (const n of kids(para)) { + if (isText(n)) { + inline.push(escapeHtml(n['#text'])); + continue; + } + const t = tagOf(n); + switch (t) { + case 'parameterlist': { + flush(); + const kind = attr(n, 'kind'); + for (const item of children(n, 'parameteritem')) { + const names = children(child(item, 'parameternamelist'), 'parametername').map((pn) => ({ + name: textOf(pn).trim(), + dir: attr(pn, 'direction'), + })); + const desc = unwrapP(renderBlocks(kids(child(item, 'parameterdescription')), out).trim()); + for (const { name, dir } of names) { + const entry = { name, dir, html: desc }; + if (kind === 'templateparam') out.tparams.push(entry); + else if (kind === 'retval') out.retvals.push(entry); + else if (kind === 'exception') out.throws.push(entry); + else out.params.push(entry); + } + } + break; + } + case 'simplesect': { + flush(); + const kind = attr(n, 'kind'); + const body = renderBlocks( + kids(n).filter((k) => tagOf(k) !== 'title'), + out, + ).trim(); + if (kind === 'return') out.returns = out.returns ? `${out.returns} ${unwrapP(body)}` : unwrapP(body); + else if (kind === 'see') out.see.push(unwrapP(body)); + else if (kind === 'since') out.since = textOf(n).trim(); + else if (kind === 'note' || kind === 'remark' || kind === 'attention' || kind === 'important') + html += `
    Note${body}
    `; + else if (kind === 'warning') html += `
    Caution${body}
    `; + else if (kind === 'pre') html += `

    Precondition: ${unwrapP(body)}

    `; + else if (kind === 'post') html += `

    Postcondition: ${unwrapP(body)}

    `; + else if (kind === 'invariant') html += `

    Invariant: ${unwrapP(body)}

    `; + else if (kind === 'par') { + const title = child(n, 'title'); + const label = title ? kids(title).map(renderInline).join('').trim() : ''; + html += `
    ${label || 'Note'}${body}
    `; + } + // author, authors, version, date, copyright: not shown + break; + } + case 'xrefsect': { + flush(); + const title = textOf(child(n, 'xreftitle')).trim(); + const body = renderBlocks(kids(child(n, 'xrefdescription')), out).trim(); + if (/deprecated/i.test(title)) out.deprecated = unwrapP(body) || 'Deprecated.'; + else html += `
    ${escapeHtml(title)}${body}
    `; + break; + } + case 'itemizedlist': + flush(); + html += `
      ${listItems(n, out)}
    `; + break; + case 'orderedlist': + flush(); + html += `
      ${listItems(n, out)}
    `; + break; + case 'programlisting': + flush(); + html += `
    ${escapeHtml(codeOf(n))}
    `; + break; + case 'verbatim': + case 'preformatted': + flush(); + html += `
    ${escapeHtml(textOf(n))}
    `; + break; + case 'heading': + flush(); + html += `

    ${kids(n).map(renderInline).join('')}

    `; + break; + case 'blockquote': + flush(); + html += `
    ${renderBlocks(kids(n), out)}
    `; + break; + case 'hruler': + flush(); + html += '
    '; + break; + case 'table': { + flush(); + const rows = children(n, 'row') + .map((r) => { + const cells = children(r, 'entry') + .map((e) => { + const tag = attr(e, 'thead') === 'yes' ? 'th' : 'td'; + return `<${tag}>${unwrapP(renderBlocks(kids(e), out).trim())}`; + }) + .join(''); + return `${cells}`; + }) + .join(''); + html += `
    ${rows}
    `; + break; + } + case 'variablelist': { + flush(); + let dl = ''; + for (const k of kids(n)) { + if (tagOf(k) === 'varlistentry') dl += `
    ${kids(child(k, 'term')).map(renderInline).join('')}
    `; + if (tagOf(k) === 'listitem') dl += `
    ${unwrapP(renderBlocks(kids(k), out).trim())}
    `; + } + html += `
    ${dl}
    `; + break; + } + case 'para': + flush(); + html += renderPara(n, out); + break; + default: + inline.push(renderInline(n)); + } + } + flush(); + return html; + }; + + const newOut = () => ({ params: [], tparams: [], retvals: [], throws: [], returns: '', see: [], since: '', deprecated: '' }); + + const describe = (node) => { + const out = newOut(); + const briefNode = child(node, 'briefdescription'); + const brief = briefNode + ? children(briefNode, 'para') + .map((p) => unwrapP(renderPara(p, out))) + .join(' ') + .trim() + : ''; + const detailNode = child(node, 'detaileddescription'); + const detail = detailNode ? renderBlocks(kids(detailNode), out).trim() : ''; + const documented = + !!brief || + !!detail || + out.params.some((p) => p.html) || + !!out.returns || + out.retvals.length > 0 || + !!out.deprecated; + return { brief, detail, ...out, documented }; + }; + + const tparamList = (node) => { + const tpl = child(node, 'templateparamlist'); + if (!tpl) return null; + const ps = children(tpl, 'param').map((p) => { + const type = linked(child(p, 'type'), { type: true }); + const decl = textOf(child(p, 'declname')).trim(); + const defval = child(p, 'defval'); + let s = type; + if (decl && !new RegExp(`\\b${decl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`).test(plain(child(p, 'type')))) s += ` ${escapeHtml(decl)}`; + if (defval) s += ` = ${linked(defval, { type: true })}`; + return s; + }); + return `template<${ps.join(', ')}>`; + }; + + /** The text after the parameter list in an argsstring, e.g. "const", "noexcept=default". */ + const qualifiersOf = (args) => { + const s = args ?? ''; + const start = s.indexOf('('); + if (start < 0) return s.trim(); + let depth = 0; + for (let i = start; i < s.length; i++) { + if (s[i] === '(') depth++; + else if (s[i] === ')') { + depth--; + if (depth === 0) return s.slice(i + 1).trim(); + } + } + return ''; + }; + + const formatQualifiers = (q) => + q + .replace(/\s*=\s*(default|delete|0)\s*$/, ' = $1') + .replace(/\s+/g, ' ') + .trim(); + + const signature = (m) => { + const node = m.node; + const name = `${escapeHtml(m.name)}`; + const tpl = tparamList(node); + const typeHtml = linked(child(node, 'type'), { type: true }); + const typeText = plain(child(node, 'type'), true); + // Doxygen keeps some specifiers in the type text; do not repeat them. + const typeWords = new Set(typeText.split(/\s+/).slice(0, 4)); + const pre = []; + if (m.kind === 'friend' && !typeWords.has('friend')) pre.push('friend'); + if (m.static && !typeWords.has('static')) pre.push('static'); + if (m.constexpr && !typeWords.has('constexpr')) pre.push('constexpr'); + if (m.explicit && !typeWords.has('explicit')) pre.push('explicit'); + if ((m.virt === 'virtual' || m.virt === 'pure-virtual') && !typeWords.has('virtual')) pre.push('virtual'); + const preHtml = pre.map((p) => `${p} `).join(''); + const argsstring = textOf(child(node, 'argsstring')); + let body; + let text; + if (m.kind === 'function' || (m.kind === 'friend' && argsstring.includes('('))) { + const params = children(node, 'param').map((p) => { + const ptype = linked(child(p, 'type'), { type: true }); + const decl = textOf(child(p, 'declname')).trim(); + const arr = textOf(child(p, 'array')).trim(); + const defval = child(p, 'defval'); + let s = ptype; + if (decl) s += `${ptype ? ' ' : ''}${escapeHtml(decl)}`; + if (arr) s += escapeHtml(arr); + if (defval) s += ` = ${linked(defval)}`; + return s; + }); + const paramText = children(node, 'param').map((p) => { + let s = plain(child(p, 'type'), true); + const decl = textOf(child(p, 'declname')).trim(); + if (decl) s += ` ${decl}`; + if (child(p, 'defval')) s += ` = ${plain(child(p, 'defval'))}`; + return s; + }); + const qual = formatQualifiers(qualifiersOf(argsstring)); + const qualHtml = qual ? ' ' + highlightKeywords(escapeHtml(qual)) : ''; + const oneLine = `${pre.join(' ')} ${typeText} ${m.name}(${paramText.join(', ')}) ${qual}`.trim(); + const multi = oneLine.length > 78 && params.length > 1; + const paramsHtml = multi ? `\n ${params.join(',\n ')}\n` : params.join(', '); + // "void" as the only parameter type with no name means no parameters. + body = `${preHtml}${typeHtml ? typeHtml + ' ' : ''}${name}(${paramsHtml})${qualHtml}`; + text = `${pre.length ? pre.join(' ') + ' ' : ''}${typeText ? typeText + ' ' : ''}${m.name}(${paramText.join(', ')})${qual ? ' ' + qual : ''}`; + } else if (m.kind === 'variable') { + const init = child(node, 'initializer'); + const initHtml = init ? ' ' + linked(init) : ''; + body = `${preHtml}${typeHtml} ${name}${escapeHtml(argsstring)}${initHtml}`; + text = `${pre.join(' ')} ${typeText} ${m.name}${argsstring}${init ? ' ' + plain(init) : ''}`.trim(); + } else if (m.kind === 'typedef') { + const def = textOf(child(node, 'definition')).trim(); + if (def.startsWith('using')) { + body = `using ${name} = ${typeHtml}`; + text = `using ${m.name} = ${typeText}`; + } else { + body = `typedef ${typeHtml} ${name}${escapeHtml(argsstring)}`; + text = `typedef ${typeText} ${m.name}${argsstring}`; + } + } else if (m.kind === 'enum') { + const under = typeHtml ? ` : ${typeHtml}` : ''; + body = `enum${m.strong ? ' class' : ''} ${name}${under}`; + text = `enum${m.strong ? ' class' : ''} ${m.name}${typeText ? ' : ' + typeText : ''}`; + } else if (m.kind === 'friend') { + body = `friend ${typeHtml} ${name}`; + text = `friend ${typeText} ${m.name}`; + } else if (m.kind === 'define') { + body = `#define ${name}${escapeHtml(argsstring)}`; + text = `#define ${m.name}${argsstring}`; + } else { + body = `${typeHtml} ${name}${escapeHtml(argsstring)}`; + text = `${typeText} ${m.name}${argsstring}`; + } + return { html: tpl ? `${tpl}\n${body}` : body, text: text.replace(/\s+/g, ' ').trim(), template: !!tpl }; + }; + + // ---------- Pass 3: render public records ---------- + for (const m of members.values()) { + const sig = signature(m); + m.sigHtml = sig.html; + m.sigText = sig.text; + m.template = sig.template; + const t = targets.get(m.id); + if (t) t.sig = sig.text; + } + + const renderMember = (m) => { + Object.assign(m, describe(m.node)); + if (m.kind === 'enum') { + m.values = children(m.node, 'enumvalue').map((ev) => { + const out = newOut(); + const b = child(ev, 'briefdescription'); + const d = child(ev, 'detaileddescription'); + const brief = b ? children(b, 'para').map((p) => unwrapP(renderPara(p, out))).join(' ').trim() : ''; + const detail = d ? renderBlocks(kids(d), out).trim() : ''; + return { + name: textOf(child(ev, 'name')).trim(), + anchor: anchorFor(textOf(child(ev, 'name')).trim()), + init: plain(child(ev, 'initializer')).replace(/^=\s*/, ''), + html: [brief, unwrapP(detail)].filter(Boolean).join(' '), + }; + }); + } + }; + + for (const rec of compounds.values()) { + if (!rec.public) continue; + Object.assign(rec, describe(rec.node)); + rec.templ = tparamList(rec.node); + rec.final = attr(rec.node, 'final') === 'yes'; + rec.abstract = attr(rec.node, 'abstract') === 'yes'; + rec.bases = children(rec.node, 'basecompoundref').map((b) => ({ + html: attr(b, 'refid') ? link(attr(b, 'refid'), escapeHtml(textOf(b).trim())) : escapeHtml(textOf(b).trim()), + prot: attr(b, 'prot'), + virt: attr(b, 'virt'), + })); + rec.derived = children(rec.node, 'derivedcompoundref').map((b) => ({ + html: attr(b, 'refid') ? link(attr(b, 'refid'), escapeHtml(textOf(b).trim())) : escapeHtml(textOf(b).trim()), + id: attr(b, 'refid'), + })); + const list = rec.kind === 'namespace' ? rec.publicMembers : rec.members.filter((m) => m.prot !== 'private'); + for (const m of list) renderMember(m); + rec.visible = list; + } + + // Which types and members each file defines, for the source pages. + for (const rec of compounds.values()) { + if (rec.kind !== 'namespace' && files.has(rec.file)) files.get(rec.file).defines.push(rec); + } + + return { + base, + publicHeaders, + sourceFiles, + compounds, + members, + files, + targets, + link, + /** Public classes, structs and unions. */ + types: () => [...compounds.values()].filter((c) => c.public && c.kind !== 'namespace'), + /** Namespaces with a page. */ + namespaces: () => [...compounds.values()].filter((c) => c.public && c.kind === 'namespace'), + /** Enums at namespace scope, which get their own pages. */ + namespaceEnums: () => + [...compounds.values()] + .filter((c) => c.public && c.kind === 'namespace') + .flatMap((ns) => ns.visible.filter((m) => m.kind === 'enum').map((e) => ({ ns, e }))), + compoundByName: (name) => [...compounds.values()].find((c) => c.name === name), + }; +} + +let cached; +let cachedKey; +/** The model, built once per build. */ +export function getModel(opts) { + const key = JSON.stringify(opts); + if (!cached || cachedKey !== key) { + cached = buildModel(opts); + cachedKey = key; + } + return cached; +} diff --git a/docs/scripts/base-links.mjs b/docs/scripts/base-links.mjs new file mode 100644 index 00000000..28bb7ad5 --- /dev/null +++ b/docs/scripts/base-links.mjs @@ -0,0 +1,26 @@ +// Sätteri hast plugin: prefixes root-relative links and images in Markdown and MDX +// with the site base, so that pages can link to `/concepts/channels/` +// instead of `/FairMQ/concepts/channels/`. + +function prefix(url, base) { + if (typeof url !== 'string' || !url.startsWith('/') || url.startsWith('//')) return url; + if (url === base || url.startsWith(base + '/')) return url; + return base + url; +} + +export default function baseLinks({ base }) { + const b = base.replace(/\/$/, ''); + return { + name: 'fairmq-base-links', + element: { + filter: ['a', 'img'], + visit(node, ctx) { + if (!b) return; + const key = node.tagName === 'a' ? 'href' : 'src'; + const value = node.properties?.[key]; + const next = prefix(value, b); + if (next !== value) ctx.setProperty(node, key, next); + }, + }, + }; +} diff --git a/docs/scripts/build-info.mjs b/docs/scripts/build-info.mjs new file mode 100644 index 00000000..e7807824 --- /dev/null +++ b/docs/scripts/build-info.mjs @@ -0,0 +1,37 @@ +// Version and commit of the FairMQ checkout that the site is built from. +import { execFileSync } from 'node:child_process'; + +function git(cwd, ...args) { + try { + return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim(); + } catch { + return ''; + } +} + +export function buildInfo(cwd = process.cwd()) { + const commit = process.env.GITHUB_SHA || git(cwd, 'rev-parse', 'HEAD') || 'unknown'; + const commitShort = commit.slice(0, 7); + const date = git(cwd, 'show', '-s', '--format=%cs', 'HEAD'); + const branch = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || git(cwd, 'rev-parse', '--abbrev-ref', 'HEAD'); + // `git describe` gives e.g. v1.11.0-23-ge366c40; a checkout without tags gives nothing. + const describe = git(cwd, 'describe', '--tags', '--match', 'v[0-9]*', '--long'); + const m = /^v(\d+)\.(\d+)\.(\d+)-(\d+)-g[0-9a-f]+$/.exec(describe); + const release = m ? `v${m[1]}.${m[2]}.${m[3]}` : ''; + const ahead = m ? Number(m[4]) : -1; + let label; + if (m && ahead === 0) label = release; + else if (m) label = `v${m[1]}.${m[2]}`; + else label = 'dev'; + return { + commit, + commitShort, + date, + branch, + release, + ahead, + label, + unreleased: ahead !== 0, + repo: 'https://github.com/FairRootGroup/FairMQ', + }; +} diff --git a/docs/scripts/check-links.mjs b/docs/scripts/check-links.mjs new file mode 100644 index 00000000..2138c16f --- /dev/null +++ b/docs/scripts/check-links.mjs @@ -0,0 +1,75 @@ +// Checks all internal links and anchors in the built site (dist/). +// node scripts/check-links.mjs [distDir] +// Exit code 1 if a link points to a missing page or a missing anchor. +import { readFileSync, readdirSync, statSync, existsSync } from 'node:fs'; +import path from 'node:path'; + +const dist = path.resolve(process.argv[2] ?? new URL('../dist', import.meta.url).pathname); +const base = '/FairMQ'; + +function walk(dir, out = []) { + for (const name of readdirSync(dir)) { + const p = path.join(dir, name); + if (statSync(p).isDirectory()) walk(p, out); + else if (name.endsWith('.html')) out.push(p); + } + return out; +} + +const pages = walk(dist); +const ids = new Map(); +const links = []; +const idRe = /\sid="([^"]+)"/g; +const linkRe = /\s(href|src)="([^"]+)"/g; +for (const file of pages) { + const html = readFileSync(file, 'utf8'); + ids.set(file, new Set([...html.matchAll(idRe)].map((m) => m[1]))); + // Skip the content of + + diff --git a/docs/src/components/Glyph.astro b/docs/src/components/Glyph.astro new file mode 100644 index 00000000..39ba9035 --- /dev/null +++ b/docs/src/components/Glyph.astro @@ -0,0 +1,21 @@ +--- +// The FairMQ mark: two devices and a message on the channel between them. +interface Props { + size?: number; +} +const { size = 28 } = Astro.props; +--- + + + + diff --git a/docs/src/components/OptionsTable.astro b/docs/src/components/OptionsTable.astro new file mode 100644 index 00000000..88654311 --- /dev/null +++ b/docs/src/components/OptionsTable.astro @@ -0,0 +1,263 @@ +--- +// Table of command-line options, read from the C++ code at build time. +// +// all options of a device made with runDevice.h +// only some groups, without the filter +// the options of a tool +import { paths } from 'virtual:fairmq/data'; +import { deviceOptions, readOptions } from '../../scripts/options.mjs'; +import { deviceOptionTexts } from '../data/option-texts.mjs'; + +interface Props { + file?: string; + groups?: string[]; + texts?: Record; + filter?: boolean; + id?: string; +} +const { file, groups, texts, filter, id = 'opt' } = Astro.props; +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +let options = file + ? readOptions(paths.repoRoot, [{ file, source: file.split('/').pop(), group: 'Options' }]) + : deviceOptions(paths.repoRoot); +const curated = texts ?? (file ? {} : deviceOptionTexts); +for (const key of Object.keys(curated)) { + if (!options.some((o: any) => o.name === key)) throw new Error(`OptionsTable: no option --${key} in the code (${file ?? 'device options'})`); +} +if (groups) options = options.filter((o: any) => groups.includes(o.group)); +const order = ['Device', 'Shared memory', 'Control', 'Logging', 'Plugins', 'General', 'Options']; +const allGroups = [...new Set(options.map((o: any) => o.group))].sort((a: any, b: any) => order.indexOf(a) - order.indexOf(b)); +const showFilter = filter ?? (!groups && options.length > 12); +const sorted = [...options].sort((a: any, b: any) => order.indexOf(a.group) - order.indexOf(b.group)); +const fmt = (v: string | undefined) => (v === undefined ? undefined : v === '' ? '""' : v); +--- + +
    + { + showFilter && ( +
    + +
    + + {allGroups.map((g) => ( + + ))} +
    +

    + {options.length} options +

    +
    + ) + } +
    + + + + + + + + + + { + sorted.map((o: any) => ( + + + + + + )) + } + + + + +
    OptionDefaultDescription
    + + + {o.short && `-${o.short}, `}--{o.name} + + + {o.flag ? 'flag' : o.type}{o.multitoken ? ', several values' : ''} + + {fmt(o.default) !== undefined ? {fmt(o.default)} : o.implicit !== undefined ? no value: {o.implicit} : —} + + ')} /> + + {o.source} + +
    +
    +
    + + + + diff --git a/docs/src/components/Snippet.astro b/docs/src/components/Snippet.astro new file mode 100644 index 00000000..b5439c27 --- /dev/null +++ b/docs/src/components/Snippet.astro @@ -0,0 +1,68 @@ +--- +// Shows code from a file of the repository, so that samples are code that CI compiles. +// +// whole file, without the license header +// lines between the markers //! [run] +// a line range (1-based, inclusive) +// +// from the first line that contains the text to the line that closes its braces +// +// from the start line to the next line that matches end (text, or /regex/ like "^}") +// +// The build fails if the file, the region, the lines or the start text do not exist. +import { Code } from '@astrojs/starlight/components'; +import path from 'node:path'; +import { paths, build } from 'virtual:fairmq/data'; +import { extractSnippet } from '../../scripts/snippet.mjs'; + +interface Props { + file: string; + region?: string; + lines?: string; + start?: string; + end?: string; + lang?: string; + title?: string; + mark?: string | string[]; + link?: boolean; +} +const { file, region, lines, start, end, lang, title, mark, link = true } = Astro.props; +const { code, first, last: lastLine } = extractSnippet(paths.repoRoot, { file, region, lines, start, end }); + +const ext = path.extname(file).slice(1); +const language = + lang ?? ({ cxx: 'cpp', cpp: 'cpp', h: 'cpp', hpp: 'cpp', sh: 'sh', json: 'json', cmake: 'cmake', txt: 'cmake', py: 'python', in: 'sh' } as Record)[ext] ?? 'text'; +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const sourceLink = /^fairmq\/.*\.(h|cxx)$/.test(file) ? `${base}/source/${file}/#L${first}-L${lastLine}` : `${build.repo}/blob/${build.commit}/${file}#L${first}-L${lastLine}`; +--- + +
    + + { + link && ( + + {file}:{first}–{lastLine} + + ) + } +
    + + diff --git a/docs/src/components/api/Member.astro b/docs/src/components/api/Member.astro new file mode 100644 index 00000000..007dc304 --- /dev/null +++ b/docs/src/components/api/Member.astro @@ -0,0 +1,109 @@ +--- +// One member of a class or namespace: signature, comment, parameters, source line. +import { base } from '../../lib/model.mjs'; +import { family } from '../../lib/families.mjs'; + +interface Props { + m: any; + owner?: any; +} +const { m, owner } = Astro.props; +const badges: { text: string; cls?: string }[] = []; +if (m.template) badges.push({ text: 'template' }); +if (m.static && m.kind === 'function') badges.push({ text: 'static' }); +if (m.virt === 'pure-virtual') badges.push({ text: 'pure virtual' }); +else if (m.virt === 'virtual') badges.push({ text: 'virtual' }); +if (m.prot === 'protected') badges.push({ text: 'protected' }); +if (m.deprecated) badges.push({ text: 'deprecated', cls: 'deprecated' }); +if (m.since) badges.push({ text: `since ${m.since}`, cls: 'since' }); +const src = `${base}/source/${m.file}/#L${m.line}`; +const fileName = m.file.split('/').pop(); +const fam = owner ? family(m, owner) : ''; +const Heading = m.overload > 1 ? 'p' : 'h3'; +const hasDetails = m.params.length || m.tparams.length || m.returns || m.retvals.length || m.throws.length; +--- + +
    +
    + {m.name} + {badges.map((b) => {b.text})} + {fileName}:{m.line} +
    +
    + {m.deprecated &&
    Deprecated
    } + {m.brief &&

    } + {m.detail &&

    } + { + hasDetails ? ( +
    + {m.tparams.map((p: any) => ( + <> +
    + {p.name} template parameter +
    +
    + + ))} + {m.params.map((p: any) => ( + <> +
    + {p.name} + {p.dir && {p.dir}} +
    +
    + + ))} + {m.returns && ( + <> +
    Returns
    +
    + + )} + {m.retvals.map((p: any) => ( + <> +
    + {p.name} return value +
    +
    + + ))} + {m.throws.map((p: any) => ( + <> +
    + {p.name} throws +
    +
    + + ))} +
    + ) : null + } + { + m.values && m.values.length > 0 && ( +
    + + + + + + + + + + {m.values.map((v: any) => ( + + + + + ))} + +
    EnumeratorValueDescription
    + {v.name} + {v.init ? {v.init} : —}—'} /> +
    +
    + ) + } + {m.see.length > 0 &&

    See also:

    } + {!m.documented &&

    No comment in the header yet.

    } +
    diff --git a/docs/src/components/diagrams/ChannelAnatomy.astro b/docs/src/components/diagrams/ChannelAnatomy.astro new file mode 100644 index 00000000..4319ae39 --- /dev/null +++ b/docs/src/components/diagrams/ChannelAnatomy.astro @@ -0,0 +1,124 @@ +--- +// A device with two channels. A channel is a vector of sub-channels; each sub-channel owns one socket. +// Facts: fairmq/Device.h (fChannels: name → std::vector, GetChannel(name, index)), +// fairmq/Channel.h (type, method, address, transport). +const subs = [ + { x: 28, ch: 'data-in', i: 0, type: 'pull', method: 'connect', addr: 'tcp://sampler:5555', side: 'in' }, + { x: 336, ch: 'data-out', i: 0, type: 'push', method: 'bind', addr: 'tcp://*:5556', side: 'out' }, + { x: 486, ch: 'data-out', i: 1, type: 'push', method: 'bind', addr: 'tcp://*:5557', side: 'out' }, +]; +--- + +
    + + + device · --id processor1 + + channel "data-in" + + channel "data-out" + { + subs.map((s) => ( + + + + sub-channel [{s.i}] + + + type {s.type} + + + method {s.method} + + + {s.addr} + + + + 1 socket + + + )) + } + + + + GetChannel("data-in") + GetChannel("data-out", 0) + GetChannel("data-out", 1) + +
    + A channel has a name and one or more sub-channels. Each sub-channel owns one socket, with its own type, method and address. The index of the sub-channel is the + second argument of GetChannel(), and the third argument of Send() and Receive(). The default index is 0. +
    +
    + + diff --git a/docs/src/components/diagrams/Explainer.astro b/docs/src/components/diagrams/Explainer.astro new file mode 100644 index 00000000..457c72ee --- /dev/null +++ b/docs/src/components/diagrams/Explainer.astro @@ -0,0 +1,331 @@ +--- +// A step-by-step explainer: a dark stage with an SVG, a caption, a line of code and controls. +// The slot holds the SVG. It must have the attribute data-stage. For step n (1-based), the +// script sets the classes r1 … rn and now on the SVG, so CSS can show each step. Elements +// with data-slot="name" get the text of step.set[name]. +interface Step { + cap: string; + code?: string; + set?: Record; +} +interface Props { + title: string; + meta?: string; + steps: Step[]; +} +const { title, meta, steps } = Astro.props; +--- + +
    +
    + {title} + {meta && {meta}} +
    + +
    +

    {steps[0].cap}

    + {steps[0].code} +
    +
    + + + + +
    + { + steps.map((_, k) => ( + + )) + } +
    + 1 / {steps.length} +
    +
    + All steps as text +
      + { + steps.map((s) => ( +
    1. + {s.cap} + {s.code && ( + <> + {' '} + {s.code} + + )} +
    2. + )) + } +
    +
    +
    + + + + diff --git a/docs/src/components/diagrams/PatternDiagram.astro b/docs/src/components/diagrams/PatternDiagram.astro new file mode 100644 index 00000000..dce37e90 --- /dev/null +++ b/docs/src/components/diagrams/PatternDiagram.astro @@ -0,0 +1,125 @@ +--- +// The four common socket patterns. Socket types: fairmq/Channel.cxx (Validate). +// shmem rejects pub and sub: fairmq/shmem/Socket.h. +const patterns = [ + { a: 'push', b: 'pull', fan: true, cap: 'push → pull', m: 'round-robin', both: 1 }, + { a: 'pub', b: 'sub', fan: true, cap: 'pub → sub', m: 'a copy to each', both: 2, note: 'zeromq only' }, + { a: 'req', b: 'rep', fan: false, cap: 'req ⇄ rep', m: 'request, then reply' }, + { a: 'pair', b: 'pair', fan: false, cap: 'pair ⇄ pair', m: 'two peers only' }, +]; +--- + +
    + + + + + { + patterns.map((p, i) => ( + + + + {p.a} + + {p.fan ? ( + <> + + + {p.b} + + + + {p.b} + + + + + {p.both === 2 && } + + ) : ( + <> + + + {p.b} + + + + + )} + + {p.cap} + + + {p.m} + + {p.note && ( + + {p.note} + + )} + + )) + } + +
    + FairMQ also accepts dealer, router, xpub and xsub. The shmem transport does not support pub and sub. +
    +
    + + diff --git a/docs/src/components/diagrams/RegionAckExplainer.astro b/docs/src/components/diagrams/RegionAckExplainer.astro new file mode 100644 index 00000000..5f89a5e6 --- /dev/null +++ b/docs/src/components/diagrams/RegionAckExplainer.astro @@ -0,0 +1,352 @@ +--- +// How the creator of an unmanaged region learns that its blocks are free again. +// Facts: fairmq/shmem/UnmanagedRegion.h (ReleaseBlock, SendAcks, ReceiveAcks, fAckBunchSize = 256, +// wait_for 500 ms, queue name "rgq", bulk callback or one call per block), Manager.h (with a callback the +// creator starts an ack receiver and an ack sender; a device that opens a remote region starts an ack +// sender), Message.h (GetData opens the region, Deallocate). +import Explainer from './Explainer.astro'; + +const steps = [ + { + cap: 'The sampler creates an unmanaged region and gives a bulk callback. The memory of the region belongs to the sampler. Because of the callback, FairMQ starts an ack receiver in the sampler. It also starts an ack sender there, for messages that come back.', + code: 'auto region = NewUnmanagedRegionFor("data", 0, 10000000, callback);', + set: { a: 'NewUnmanagedRegionFor(…)' }, + }, + { + cap: 'The sampler writes data into the region and makes messages that point to it. The transport allocates no memory in the managed segment for these messages.', + code: 'auto msg = NewMessageFor("data", 0, region, ptr, size, hint);', + set: { a: 'NewMessageFor(…)' }, + }, + { + cap: 'Send() puts only a MetaHeader for each message into the socket. The data stays in the region.', + code: 'Send(parts, "data");', + set: { a: 'Send(parts, "data")' }, + }, + { + cap: 'The sink receives the messages. At the first GetData(), the sink opens the region and reads the data in place. FairMQ starts an ack sender in the sink.', + code: 'Receive(parts, "data");', + set: { b: 'Receive(parts, "data")' }, + }, + { + cap: 'The sink destroys the messages. The transport puts each block, with its size and its hint, into a list in the sink.', + code: '} // parts are destroyed: the blocks go into the list', + set: { b: '~Message()' }, + }, + { + cap: 'The ack sender sends the list as one bunch into the region queue. It sends when the list holds 256 blocks, or after 500 ms.', + code: 'fmq__rgq_', + }, + { + cap: 'The ack receiver of the sampler gets the bunch. It calls the bulk callback one time with all blocks of the bunch: pointer, size and hint. A RegionCallback runs one time for each block.', + code: '[](const std::vector& blocks) { … }', + set: { a: 'callback(blocks)' }, + }, + { + cap: 'In the callback, the sampler marks the blocks as free. Then it can write new data into them.', + code: 'fNumUnackedMsgs -= blocks.size();', + set: { a: 'blocks are free' }, + }, +]; +const blocks = [96, 196, 296, 396]; +--- + + + + + + + + + + + + + channel "data" + + + + region queue + + + + + + + + + + + /dev/shm/fmq_<shmId>_rg_<regionId> + unmanaged region · memory of the sampler + + { + blocks.map((x) => ( + + + + + + )) + } + data + released by the sink + free again + + read in place + + + + + sampler + creates the region + + + + ack receiver + + + + callback + + + + + sink + opens the region + + + + ack sender + + + + + + + + + + + + + + bunch · ≤ 256 blocks + + + + + + + + + + diff --git a/docs/src/components/diagrams/SessionMap.astro b/docs/src/components/diagrams/SessionMap.astro new file mode 100644 index 00000000..fe727fea --- /dev/null +++ b/docs/src/components/diagrams/SessionMap.astro @@ -0,0 +1,162 @@ +--- +// The shared memory objects of one session. Names: fairmq/shmem/Common.h (MakeShmName) and the +// callers in Manager.h, UnmanagedRegion.h and Monitor.cxx. Sizes: kManagementSegmentSize, +// --shm-segment-size, RegionConfig::rcSegmentSize. +const rows = [ + { name: 'fmq_eca859e3_mng', kind: 'management segment', size: '6.25 MiB', w: 18, what: 'The session info, the heartbeat, the counters of devices, events and automatic region IDs, and the lists of segments and regions.' }, + { name: 'fmq_eca859e3_m_0', kind: 'managed segment', size: '--shm-segment-size, 2 GiB', w: 100, what: 'The buffers of NewMessage(). More segments are possible: _m_1, _m_2 …', accent: true }, + { name: 'fmq_eca859e3_rg_', kind: 'unmanaged region', size: 'size from the creator', w: 60, what: 'Memory that a device creates with NewUnmanagedRegion() and fills itself.', accent: true }, + { name: 'fmq_eca859e3_rrc_', kind: 'reference counts', size: 'rcSegmentSize, 100 MB', w: 34, what: 'The reference counts of copied region messages. It exists only if rcSegmentSize is more than 0.' }, + { name: 'fmq_eca859e3_rgq_', kind: 'message queue', size: '1024 bunches of up to 6 KiB', w: 18, what: 'The acknowledgements of region blocks, back to the creator of the region.' }, + { name: 'sem.fmq_eca859e3_ms', kind: 'named mutex', size: '', w: 2, what: 'fairmq-shmmonitor creates it. It shows that a monitor runs for the session.' }, +]; +--- + +
    +
    + user ID 1000 + + + session default + → SHA-256 → first 4 bytes → + shmId eca859e3 +
    +
      + { + rows.map((r) => ( +
    1. +
      + /dev/shm/{r.name} + {r.kind} +
      + +

      + {r.what} {r.size && {r.size}} +

      +
    2. + )) + } +
    +
    + All devices with the same session name and the same user open the same objects. The last device that leaves removes them, unless --shm-no-cleanup is true. It does not remove the + mutex of the monitor. A region with a path is a file in that path, not an object in /dev/shm. Bars show the size only roughly. +
    +
    + + diff --git a/docs/src/components/diagrams/StateMachine.astro b/docs/src/components/diagrams/StateMachine.astro new file mode 100644 index 00000000..6e68e00e --- /dev/null +++ b/docs/src/components/diagrams/StateMachine.astro @@ -0,0 +1,580 @@ +--- +// Interactive state machine of a FairMQ device. +// The layout follows the diagram that `--control interactive` prints (fairmq/plugins/control/Control.cxx). +// States and transitions come from fairmq/States.h and fairmq/StateMachine.cxx. +const H = 38; +type Kind = 'idle' | 'work' | 'end' | 'error'; +const N: Record = { + IDLE: [16, 24, 296, 'idle'], + EXITING: [344, 24, 60, 'end'], + 'INITIALIZING DEVICE': [16, 86, 236, 'work'], + 'RESETTING DEVICE': [276, 86, 128, 'work'], + INITIALIZED: [16, 148, 236, 'idle'], + BINDING: [16, 210, 236, 'work'], + BOUND: [16, 272, 236, 'idle'], + CONNECTING: [16, 334, 236, 'work'], + 'DEVICE READY': [16, 396, 388, 'idle'], + 'INITIALIZING TASK': [16, 458, 236, 'work'], + 'RESETTING TASK': [276, 458, 128, 'work'], + READY: [16, 520, 388, 'idle'], + RUNNING: [16, 582, 388, 'work'], + ERROR: [16, 652, 388, 'error'], +}; +// [from, to, transition, key, path points, label position] +const E: [string, string, string, string, number[][], number[]][] = [ + ['IDLE', 'INITIALIZING DEVICE', 'InitDevice', 'i', [[134, 62], [134, 86]], [148, 74]], + ['IDLE', 'EXITING', 'End', 'q', [[312, 43], [344, 43]], [328, 43]], + ['INITIALIZING DEVICE', 'INITIALIZED', 'CompleteInit', '', [[134, 124], [134, 148]], [142, 139]], + ['INITIALIZED', 'BINDING', 'Bind', 'b', [[134, 186], [134, 210]], [148, 198]], + ['INITIALIZED', 'RESETTING DEVICE', 'ResetDevice', 'd', [[252, 167], [340, 167], [340, 124]], [296, 167]], + ['BINDING', 'BOUND', 'Auto', '', [[134, 248], [134, 272]], [142, 263]], + ['BOUND', 'CONNECTING', 'Connect', 'x', [[134, 310], [134, 334]], [148, 322]], + ['BOUND', 'RESETTING DEVICE', 'ResetDevice', 'd', [[252, 291], [340, 291], [340, 124]], [296, 291]], + ['CONNECTING', 'DEVICE READY', 'Auto', '', [[134, 372], [134, 396]], [142, 387]], + ['DEVICE READY', 'INITIALIZING TASK', 'InitTask', 'j', [[134, 434], [134, 458]], [148, 446]], + ['DEVICE READY', 'RESETTING DEVICE', 'ResetDevice', 'd', [[340, 396], [340, 124]], [354, 382]], + ['INITIALIZING TASK', 'READY', 'Auto', '', [[134, 496], [134, 520]], [142, 511]], + ['READY', 'RESETTING TASK', 'ResetTask', 't', [[340, 520], [340, 496]], [354, 508]], + ['RESETTING TASK', 'DEVICE READY', 'Auto', '', [[340, 458], [340, 434]], [348, 449]], + ['READY', 'RUNNING', 'Run', 'r', [[134, 558], [134, 582]], [148, 570]], + ['RUNNING', 'READY', 'Stop', 's', [[300, 582], [300, 558]], [314, 570]], + ['RESETTING DEVICE', 'IDLE', 'Auto', '', [[296, 86], [296, 62]], [304, 77]], +]; +const I: Record = { + IDLE: [ + 'Idling state', + 'The state machine starts here. The device has no channels yet. The config plugin reads --mq-config or --channel-config when INITIALIZING DEVICE starts.', + '—', + ], + 'INITIALIZING DEVICE': [ + 'Working state', + 'The device waits for CompleteInit. A controller can set properties now. Then the device calls Init(), reads rate, init-timeout and transport, and makes the transports and the channels.', + 'Init()', + ], + INITIALIZED: ['Idling state', 'The configuration is complete and the channels exist. Nothing is bound or connected yet.', '—'], + BINDING: ['Working state', 'The device binds all channels with the method bind. Then it calls Bind().', 'Bind()'], + BOUND: ['Idling state', 'All channels with the method bind have an endpoint.', '—'], + CONNECTING: [ + 'Working state', + 'The device connects all channels with the method connect. If an address is not valid yet, it tries again every 50 ms. After init-timeout (default 120 s), it goes to ERROR. When all channels are connected, it calls Connect().', + 'Connect()', + ], + 'DEVICE READY': ['Idling state', 'All channels are bound or connected.', '—'], + 'INITIALIZING TASK': ['Working state', 'The device prepares the task. Read your own options and allocate resources here.', 'InitTask()'], + READY: ['Idling state', 'The task is ready. The device waits for Run.', '—'], + RUNNING: [ + 'Working state', + 'The device calls PreRun(). Then it calls your OnData() callbacks, or it calls ConditionalRun() until it returns false or a transition is pending, and then Run(). If no transition is pending, the device requests Stop. It calls PostRun() and then goes to READY.', + 'PreRun() · OnData() or ConditionalRun() and Run() · PostRun()', + ], + 'RESETTING TASK': ['Working state', 'The device calls ResetTask(). Undo the work of InitTask() here.', 'ResetTask()'], + 'RESETTING DEVICE': ['Working state', 'The device resets and removes its transports, calls Reset(), and removes all channels.', 'Reset()'], + EXITING: ['Final state', 'The state machine stops. The device process can end.', '—'], + ERROR: [ + 'Error state', + 'An exception in a hook, or the transition ErrorFound, moves the device here. No transition leaves ERROR. The controller stops without the shutdown sequence, so ResetTask() and Reset() do not run. The process ends with the exit code 1.', + '—', + ], +}; +const data = JSON.stringify({ N, E: E.map(([f, t, n, k]) => [f, t, n, k]), I }); +const d = (pts: number[][]) => 'M' + pts.map((p) => p.join(' ')).join(' L'); +--- + +
    +
    + + + + + + + {E.map((e, i) => )} + + + { + Object.entries(N).map(([name, [x, y, w, k]]) => ( + + + {k === 'work' && } + + {name} + + + )) + } + + + +
    +
    +
    +
    +
    Idling state
    +

    IDLE

    +
    +
    +

    What happens

    +

    {I.IDLE[1]}

    +

    Your code

    +

    —

    +

    Leave with

    +
    +
    +
    +
    
    +    
    +

    + Select a state to read about it. The buttons and the keys i + b + x + j + r + s + t + d + q work like the interactive controller (--control interactive). q runs the shutdown sequence (Stop, ResetTask, ResetDevice, End) from RUNNING and from each idling state. c prints the current state. +

    +
    +
    + + + + diff --git a/docs/src/components/diagrams/Topology.astro b/docs/src/components/diagrams/Topology.astro new file mode 100644 index 00000000..53105373 --- /dev/null +++ b/docs/src/components/diagrams/Topology.astro @@ -0,0 +1,348 @@ +--- +// A topology like example 1-n-1, animated: a sampler, three processors and a sink. +// (The start script of example 1-n-1 runs two processors.) +// The switch shows what the shmem transport changes: only a MetaHeader goes through each socket. +--- + +
    +
    +
    + + +
    + 1 sampler · 3 processors · 1 sink +
    + + + + + + + + shared memory segment · session "default" + + + + + + sampler + push · bind + + + { + [40, 118, 196].map((y, i) => ( + <> + + + + + processor + + + pull → push + + + )) + } + + + + + sink + pull · bind + + tcp://*:5555 + tcp://*:5556 + + +

    zeromq: the payload goes through each socket.

    +
    + + + + diff --git a/docs/src/components/diagrams/ZeroCopyExplainer.astro b/docs/src/components/diagrams/ZeroCopyExplainer.astro new file mode 100644 index 00000000..cc2a486a --- /dev/null +++ b/docs/src/components/diagrams/ZeroCopyExplainer.astro @@ -0,0 +1,274 @@ +--- +// One message through the shmem transport, step by step. +// Facts: fairmq/shmem/Common.h (MetaHeader, MakeShmName, makeShmIdStr), Socket.h (Send, Receive), +// Message.h (Deallocate), plugins/config/Config.cxx (--shm-segment-size default 2 GiB). +import Explainer from './Explainer.astro'; + +const steps = [ + { + cap: 'Two devices run on one host. Both map the same managed segment. FairMQ makes the name of the segment from the session name and the user ID.', + code: '--transport shmem --session default', + }, + { + cap: 'The sampler asks for a message of 1 MiB. The transport allocates a block in the segment.', + code: 'auto msg = NewMessage(1 << 20);', + set: { a: 'NewMessage(1 << 20)' }, + }, + { + cap: 'The sampler writes the payload into the block. The payload stays in the segment.', + code: 'std::memcpy(msg->GetData(), src, msg->GetSize());', + set: { a: 'write the payload' }, + }, + { + cap: 'Send() puts only a MetaHeader of 40 bytes into a ZeroMQ message. It holds the size, the hint, the handle of the block, the handle of the reference count of a copied region block, the IDs of the region and the segment, and a flag for segment or region. The message of the sampler no longer owns the block.', + code: 'Send(msg, "data");', + set: { a: 'Send(msg, "data")' }, + }, + { + cap: 'The sink receives the MetaHeader. At the first GetData(), it changes the handle into an address in its own mapping of the segment.', + code: 'Receive(msg, "data");', + set: { b: 'Receive(msg, "data")' }, + }, + { + cap: 'The sink reads the payload in place. The transport copied no byte of the payload.', + code: 'auto* data = static_cast(msg->GetData());', + set: { b: 'msg->GetData()' }, + }, + { + cap: 'The message of the sink goes out of scope. The transport gives the block back to the segment.', + code: '} // msg is destroyed: the block is free again', + set: { b: '~Message()' }, + }, + { + cap: 'Compare: with the zeromq transport, the full payload goes through the socket on each hop.', + code: '--transport zeromq', + set: { a: 'Send(msg, "data")', b: 'Receive(msg, "data")' }, + }, +]; +--- + + + + + + + + + + channel "data" · push → pull + + + + maps + maps + + + + + /dev/shm/fmq_<shmId>_m_0 + managed segment · 2 GiB + + + + + 1 MiB payload + + + read in place + the block is free again + + handle → address + + + sampler + process A + + + + + sink + process B + + + + + MetaHeader · 40 B + + + + 1 MiB + + + + + diff --git a/docs/src/components/home/HomeCode.astro b/docs/src/components/home/HomeCode.astro new file mode 100644 index 00000000..a6949618 --- /dev/null +++ b/docs/src/components/home/HomeCode.astro @@ -0,0 +1,94 @@ +--- +// "A complete device": the smallest program that runs with runDevice.h, and its log. +import { Code } from '@astrojs/starlight/components'; +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const device = `#include +#include + +struct Sampler : fair::mq::Device +{ + bool ConditionalRun() override + { + auto msg = NewSimpleMessage("Hello"); + LOG(info) << "Sending \\"Hello\\""; + return Send(msg, "data") >= 0; // false ends RUNNING + } +}; + +void addCustomOptions(boost::program_options::options_description&) {} + +std::unique_ptr getDevice(fair::mq::ProgOptions&) +{ + return std::make_unique(); +}`; +const run = `fairmq-ex-1-1-sampler --id sampler1 --rate 1 \\ + --channel-config "name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"`; +const log = `[10:42:07][STATE] IDLE ---> INITIALIZING DEVICE +... +[10:42:07][STATE] READY ---> RUNNING +[10:42:07][INFO] fair::mq::Device running... +[10:42:07][INFO] Sending "Hello" +[10:42:08][INFO] Sending "Hello"`; +--- + +
    +
    +

    A complete device

    +

    Derive from fair::mq::Device and override one hook. runDevice.h adds the main() function. It parses the command line, loads the plugins and runs the state machine.

    +

    In the state RUNNING, the device calls ConditionalRun() in a loop, at the rate of --rate. Each call sends one message. When the function returns false, the device leaves the state RUNNING.

    + Your first device → +
    +
    + + +
    +
    + + diff --git a/docs/src/components/home/HomePaths.astro b/docs/src/components/home/HomePaths.astro new file mode 100644 index 00000000..dc437707 --- /dev/null +++ b/docs/src/components/home/HomePaths.astro @@ -0,0 +1,96 @@ +--- +// Three ways into the docs, below the hero of the home page. +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const cols = [ + { + label: 'Start', + links: [ + ['Install', '/start/install/'], + ['Your first device', '/start/first-device/'], + ['Use FairMQ in a CMake project', '/start/cmake/'], + ], + }, + { + label: 'Understand', + links: [ + ['Device states', '/concepts/states/'], + ['Channels and sockets', '/concepts/channels/'], + ['How shared memory works', '/shmem/how-it-works/'], + ], + }, + { + label: 'Operate', + links: [ + ['Command-line options', '/reference/options/'], + ['Sessions and segments', '/shmem/sessions/'], + ['Built-in devices', '/tools/builtin-devices/'], + ], + }, +]; +--- + + + + diff --git a/docs/src/components/overrides/Footer.astro b/docs/src/components/overrides/Footer.astro new file mode 100644 index 00000000..2ad2866d --- /dev/null +++ b/docs/src/components/overrides/Footer.astro @@ -0,0 +1,61 @@ +--- +// Page footer: edit link, last change, pagination, and the site line. +import EditLink from '@astrojs/starlight/components/EditLink.astro'; +import LastUpdated from '@astrojs/starlight/components/LastUpdated.astro'; +import Pagination from '@astrojs/starlight/components/Pagination.astro'; +import { build } from 'virtual:fairmq/data'; +--- + + + + diff --git a/docs/src/components/overrides/Header.astro b/docs/src/components/overrides/Header.astro new file mode 100644 index 00000000..d186f060 --- /dev/null +++ b/docs/src/components/overrides/Header.astro @@ -0,0 +1,174 @@ +--- +// Site header: logo and version, search, main sections, GitHub and theme. +import Search from '@astrojs/starlight/components/Search.astro'; +import SocialIcons from '@astrojs/starlight/components/SocialIcons.astro'; +import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro'; +import { build } from 'virtual:fairmq/data'; +import Glyph from '../Glyph.astro'; +import { sections } from '../../lib/nav'; + +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const path = Astro.url.pathname; +--- + +
    + + + +
    +
    + +
    +
    + + diff --git a/docs/src/components/overrides/Hero.astro b/docs/src/components/overrides/Hero.astro new file mode 100644 index 00000000..c45a30f8 --- /dev/null +++ b/docs/src/components/overrides/Hero.astro @@ -0,0 +1,121 @@ +--- +// The hero of the home page: the claim, two actions, the install command and the topology. +import Topology from '../diagrams/Topology.astro'; +import CopyButton from '../CopyButton.astro'; + +const { data } = Astro.locals.starlightRoute.entry; +const { title = data.title, tagline, actions = [] } = data.hero ?? {}; +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const href = (link: string) => (link.startsWith('/') && !link.startsWith(base + '/') ? base + link : link); +const install = 'spack install fairmq'; +--- + +
    +
    +

    C++17 message queuing · LGPL-3.0

    +

    {title}

    + {tagline &&

    } +

    + { + actions.map((a) => ( + + {a.text} + + )) + } +
    +
    + + {install} + +
    +
    + +
    + + diff --git a/docs/src/components/overrides/MobileMenuFooter.astro b/docs/src/components/overrides/MobileMenuFooter.astro new file mode 100644 index 00000000..1f4419bc --- /dev/null +++ b/docs/src/components/overrides/MobileMenuFooter.astro @@ -0,0 +1,44 @@ +--- +// Footer of the phone menu: the main sections, then GitHub and the theme. +import Default from '@astrojs/starlight/components/MobileMenuFooter.astro'; +import { sections } from '../../lib/nav'; + +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const path = Astro.url.pathname; +--- + + + + + diff --git a/docs/src/components/overrides/PageSidebar.astro b/docs/src/components/overrides/PageSidebar.astro new file mode 100644 index 00000000..1618ec4e --- /dev/null +++ b/docs/src/components/overrides/PageSidebar.astro @@ -0,0 +1,87 @@ +--- +// Right column: the page contents, then the source files and guides of the page. +import Default from '@astrojs/starlight/components/PageSidebar.astro'; + +const { entry, toc } = Astro.locals.starlightRoute; +const data = entry.data as typeof entry.data & { + code?: string[]; + guides?: { label: string; link: string }[]; +}; +const base = import.meta.env.BASE_URL.replace(/\/$/, ''); +const code = data.code ?? []; +const guides = data.guides ?? []; +const withBase = (link: string) => (link.startsWith('/') && !link.startsWith(base + '/') ? base + link : link); +--- + + +{ + toc && (code.length > 0 || guides.length > 0) && ( + + ) +} + + diff --git a/docs/src/components/overrides/PageTitle.astro b/docs/src/components/overrides/PageTitle.astro new file mode 100644 index 00000000..b27df5f0 --- /dev/null +++ b/docs/src/components/overrides/PageTitle.astro @@ -0,0 +1,54 @@ +--- +// Page title with the section label above it and an optional "since" badge. +import { sectionLabel } from '../../lib/nav'; + +const { entry, id } = Astro.locals.starlightRoute; +const data = entry.data as typeof entry.data & { + eyebrow?: string; + titleKind?: string; + since?: string; + searchTitle?: string; +}; +const eyebrow = data.eyebrow ?? sectionLabel(id); +--- + +{eyebrow &&

    {eyebrow}

    } +

    + {data.title} + {data.titleKind && {data.titleKind}} + {data.since && since {data.since}} +

    + + diff --git a/docs/src/content.config.ts b/docs/src/content.config.ts new file mode 100644 index 00000000..59f45da0 --- /dev/null +++ b/docs/src/content.config.ts @@ -0,0 +1,26 @@ +import { defineCollection } from 'astro:content'; +import { z } from 'astro/zod'; +import { docsLoader } from '@astrojs/starlight/loaders'; +import { docsSchema } from '@astrojs/starlight/schema'; + +export const collections = { + docs: defineCollection({ + loader: docsLoader(), + schema: docsSchema({ + extend: z.object({ + /** Text above the title. The default is the name of the sidebar section. */ + eyebrow: z.string().optional(), + /** Kind badge after the title, for API pages. The title is then set in the code font. */ + titleKind: z.string().optional(), + /** Title for the search results, if it differs from the page title. */ + searchTitle: z.string().optional(), + /** First FairMQ release with the feature that the page describes, e.g. "v1.11". */ + since: z.string().optional(), + /** Source files that the page describes, relative to the repository root. */ + code: z.array(z.string()).default([]), + /** Links in the right column under "Guides". The API pages use it. */ + guides: z.array(z.object({ label: z.string(), link: z.string() })).default([]), + }), + }), + }), +}; diff --git a/docs/src/content/docs/concepts/channels.mdx b/docs/src/content/docs/concepts/channels.mdx new file mode 100644 index 00000000..925fbb57 --- /dev/null +++ b/docs/src/content/docs/concepts/channels.mdx @@ -0,0 +1,206 @@ +--- +title: 'Channels and sockets' +description: 'Channels and sub-channels, socket types and patterns, bind and connect, addresses and endpoints, autobind and the transport of a channel.' +sidebar: + order: 3 +code: [fairmq/Channel.h, fairmq/Channel.cxx, fairmq/Device.cxx, fairmq/zeromq/Socket.h, fairmq/shmem/Socket.h] +--- + +import ChannelAnatomy from '../../../components/diagrams/ChannelAnatomy.astro'; +import PatternDiagram from '../../../components/diagrams/PatternDiagram.astro'; +import Snippet from '../../../components/Snippet.astro'; + +A device sends and receives messages through its channels. A channel has a name and one or more sub-channels, and each sub-channel has one socket. The configuration of a sub-channel sets the type of its socket, how the socket finds its peers, and the transport that moves the messages. + + + +## Channels and sub-channels + +A device keeps its channels in a map from the channel name to a list of sub-channels: [`GetChannels()`](/api/fair/mq/Device/#GetChannels) returns a [`fair::mq::ChannelMap`](/api/fair/mq/#ChannelMap), which is a `std::unordered_map>`. Each sub-channel is a [`fair::mq::Channel`](/api/fair/mq/Channel/) with one socket. + +A sub-channel has the name `[]`, for example `data-out[1]`. The index starts at 0. To select a sub-channel, give the channel name and the index: + +- [`GetChannel("data-out", 1)`](/api/fair/mq/Device/#GetChannel) returns the `Channel` object. +- [`Send(msg, "data-out", 1)`](/api/fair/mq/Device/#Send) and [`Receive(msg, "data-in")`](/api/fair/mq/Device/#Receive) send and receive through it. The index is the third argument. Its default is 0. +- [`GetNumSubChannels("data-out")`](/api/fair/mq/Device/#GetNumSubChannels) returns the number of sub-channels. + +For a channel or an index that does not exist, `GetChannel()` logs `GetChannel(): 'data-out[2]' does not exist.` and throws `std::out_of_range` ([Device.h](/source/fairmq/Device.h/#L323-L329)). + +The sampler of the [copypush example](/examples/copypush/) sends a copy of each message to each sub-channel of its channel `data`: + + + +Its start script gives `data` two sub-channels, with one `address=` key for each sub-channel: + + + +A socket can also have several endpoints (see [Addresses and endpoints](#addresses-and-endpoints)). Then the socket itself distributes the messages to its peers, by the rules of its socket type. Use several sub-channels when your code must select the peer for each message. + +## Socket types and patterns + + + +The `type` of a sub-channel is the type of its socket. FairMQ uses the ZeroMQ socket type of the same name ([zeromq/Common.h](/source/fairmq/zeromq/Common.h/#L91-L123)). The `shmem` transport also uses ZeroMQ sockets of this type, for the metadata of the messages. The column Pattern gives the ZeroMQ behavior of each type. The ZeroMQ documentation of `zmq_socket` describes it in full. + +| Type | Peer | Pattern | Example in the repository | +| --- | --- | --- | --- | +| `push` | `pull` | Pipeline. A `push` socket with several peers sends each message to one of them. | [1-n-1](/examples/1-n-1/) | +| `pull` | `push` | Pipeline. A `pull` socket receives from all its peers. | [1-n-1](/examples/1-n-1/) | +| `pub` | `sub` | Publish and subscribe. Each `sub` peer gets a copy. | [multiple-channels](/examples/multiple-channels/) | +| `sub` | `pub` | Publish and subscribe. The `zeromq` transport subscribes each `sub` socket to all messages ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L70-L74)). | [multiple-channels](/examples/multiple-channels/) | +| `req` | `rep` | Request and reply. | [req-rep](/examples/req-rep/) | +| `rep` | `req` | Request and reply. | [req-rep](/examples/req-rep/) | +| `pair` | `pair` | One peer, both directions. | [readout](/examples/readout/) | +| `dealer`, `router`, `xpub`, `xsub` | | The ZeroMQ types of these names. | None | + +[`Channel::Validate()`](/api/fair/mq/Channel/#Validate) accepts these 11 types. For another type, it throws [`ChannelConfigurationError`](/api/fair/mq/Channel/ChannelConfigurationError/) ([Channel.cxx](/source/fairmq/Channel.cxx/#L193-L199)). The tests of the repository cover `push`/`pull`, `pub`/`sub`, `req`/`rep` and `pair`. + +:::caution[pub and sub with shared memory] +The `shmem` transport does not support `pub` and `sub`. It throws `SocketError` with `PUB/SUB socket type is not supported for shared memory transport` when the device makes such a socket ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L59-L62)). +::: + +### Behavior of each socket type + +FairMQ calls ZeroMQ in a loop ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L124)). Each ZeroMQ call waits up to 100 ms. If ZeroMQ cannot take or give a message in this time (`EAGAIN`), the loop checks for an interruption and for the timeout of the call. Then it calls ZeroMQ again. Thus `Send()` returns in one of these ways: + +- The number of bytes, when ZeroMQ accepts the message. +- `TransferCode::timeout` (-2), when the timeout of the call is over. With the timeout 0, `Send()` does not wait. +- `TransferCode::interrupted` (-3), when the device gets a transition request. +- `TransferCode::error` (-1), when ZeroMQ reports another error. FairMQ logs `Failed transfer on socket , errno: , reason: `. For `ETERM` (the context terminates), it logs `Terminating socket ` with the severity `debug`. + +`Receive()` uses the same loop. The `shmem` transport has the same loop for its metadata message ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L118-L161)). What ZeroMQ does with a full queue, a missing peer or a wrong sequence of calls depends on the socket type. The column "ZeroMQ behavior" comes from the ZeroMQ documentation of `zmq_socket` and `zmq_setsockopt`, not from FairMQ. + +| Type | ZeroMQ behavior | Result in FairMQ | +| --- | --- | --- | +| `push` | Sends each message to one peer, in turn (round robin). When the queues of all peers are full, or when it has no peer, the socket blocks and discards nothing. A connecting socket queues messages for its endpoints also before the peer is there. | `Send()` waits until a queue has space, the timeout is over, or a transition interrupts it. FairMQ does not set `ZMQ_IMMEDIATE`, so messages can wait in the queue of a peer that never comes. | +| `pull` | Receives from all peers in turn (fair queuing). | `Receive()` waits for a message. | +| `pub` | Sends a copy to each connected subscriber. A subscriber that is not connected yet gets nothing. When the queue of a subscriber is full, the socket drops the message for this subscriber and does not block. | `Send()` returns the number of bytes also for a dropped message, and the [counters](#socket-counters) count it as sent. | +| `sub` | Receives only the messages that match its subscriptions. A new subscription reaches the publisher some time after the connect. | The `zeromq` transport subscribes each `sub` socket to all messages ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L70-L74)). `SetOption()` has no option name for `ZMQ_SUBSCRIBE` (see [Set socket options directly](/reference/channel-properties/#set-socket-options-directly)), so a `sub` socket of FairMQ receives all messages. | +| `req` | Only the sequence send, receive, send, receive… A reply goes to the last request. | A second `Send()` without a `Receive()` returns `TransferCode::error`. After a receive timeout, the socket still waits for the reply, so the next `Send()` also fails. | +| `rep` | Only the sequence receive, send, receive, send… The reply goes to the peer of the last request. | A `Send()` before a `Receive()` returns `TransferCode::error`. | +| `pair` | One peer. When the queue is full, or when no peer is there, the socket blocks. | As for `push`. | +| `dealer` | Sends in turn to its peers and receives from all peers, in any sequence. When the queues of all peers are full, or when it has no peer, the socket blocks. To talk to a `rep` socket, each message must start with an empty part. | As for `push`. Use `fair::mq::Parts` for the empty part. | +| `router` | Adds a part with the identity of the peer before each received message. Uses the first part of each sent message to select the peer. Drops a message for an unknown peer or a full queue, and does not block. | FairMQ sets the identity of each socket to `..`, for example `sampler1.data[0].dealer` ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L37-L53)). Receive into `fair::mq::Parts`. Part 0 is the identity. | +| `xpub`, `xsub` | As `pub` and `sub`, but the subscriptions are messages: an `xsub` socket subscribes when it sends a message that starts with the byte 1. | FairMQ sets no subscription for these types. | + +The `shmem` transport uses ZeroMQ sockets of the same types for its metadata, so the same rules apply to the types that it supports. It sends and reads one ZeroMQ frame in each call and expects the metadata in it. Thus it cannot handle the extra parts of `dealer` and `router`: the identity part and the empty part. No test of the repository covers `dealer`, `router`, `xpub` and `xsub`. + +The client of the [req-rep example](/examples/req-rep/) receives the reply before it sends the next request: + + + +A `sub` that connects late misses the messages that the `pub` sent before. The test devices of the repository synchronize through a second channel. Each `sub` waits and sends a ready message. The `pub` publishes only after it receives the ready messages: + + + +## Bind and connect + +The `method` of a sub-channel is `bind` or `connect`. A binding socket waits for peers on its endpoints. A connecting socket connects to the endpoints of a peer. The method does not depend on the type: a `push` socket can bind or connect. Usually the device with a fixed place in the topology binds, for example the sampler and the sink in the 1-n-1 example. + +The device attaches its sub-channels in two states ([Device.cxx](/source/fairmq/Device.cxx/#L217-L276)): + +- In `BINDING`, the device binds all binding sub-channels, with one attempt. If one fails, the device goes to `ERROR` with `1 of the binding channels could not initialize`. +- In `CONNECTING`, the device connects all connecting sub-channels. If the address of a sub-channel is not valid or its host name does not resolve, the device tries again every 50 ms. Before each attempt, it reads the address property again. After the time of `--init-timeout` (default 120 s), it goes to `ERROR` with `could not connect all channels after 120 attempts`. The number in this message is the timeout in seconds. + +ZeroMQ connects in the background. Thus a connect to a peer that is not there yet does not fail. You can start the devices of a topology in any sequence. [`GetNumberOfConnectedPeers()`](/api/fair/mq/Device/#GetNumberOfConnectedPeers) returns the number of peers of a sub-channel. + +## Addresses and endpoints + +The `address` of a sub-channel has one endpoint or several endpoints, separated by `,`. An endpoint has the form `[modifier]protocol://location`: + +| Protocol | Example | Use | +| --- | --- | --- | +| `tcp://` | `tcp://*:5555`, `tcp://host1:5555` | Between hosts, or on one host. | +| `ipc://` | `ipc:///tmp/fmq_data` | Between processes on one host, through a Unix domain socket file. | +| `inproc://` | `inproc://data` | Between sub-channels of one device with the same transport. | + +`Validate()` checks the protocol, a `:` after `tcp://`, and a location that is not empty after `ipc://` and `inproc://` ([Channel.cxx](/source/fairmq/Channel.cxx/#L201-L270)). It also accepts `verbs://`, a remainder of the removed `ofi` transport. The `zeromq` and `shmem` transports cannot use it. + +In a TCP bind, the host is `*` for all interfaces, an IPv4 address or a host name. In a TCP connect, the host is an IPv4 address or a host name. The device replaces each host name with its first IPv4 address before it binds or connects ([Device.cxx](/source/fairmq/Device.cxx/#L321-L333)). + +A modifier before an endpoint overrides the `method` for this endpoint ([Device.cxx](/source/fairmq/Device.cxx/#L311-L319)): + +- `@` binds the endpoint. +- `+` or `>` connects the endpoint. + +With modifiers, one socket can bind some endpoints and connect others. A sub-channel without a `method` needs a modifier on each endpoint. The device then attaches it in `CONNECTING`. In this file of the [multipart example](/examples/multipart/), the socket of `sampler1` connects to two sinks. `sink2` binds with `@`, although its method is `connect`: + + + +:::caution[Separators] +Separate several endpoints with `,`. `Validate()` splits the address at `;`, but the device splits it at `,` ([Device.cxx](/source/fairmq/Device.cxx/#L302)). An address with `;` passes the check and then fails in the transport. In `--channel-config`, the `,` separates the keys, so give several endpoints in a JSON file or as a property. +::: + +After the attach, the device writes the address that it uses back to the property `chans...address` ([Device.cxx](/source/fairmq/Device.cxx/#L359-L366)). This value has the resolved IPv4 addresses and the port that autobind selected. + +## Automatic ports + +When a TCP bind fails and `autoBind` is `true` (the default), the device binds to a random port from `portRangeMin` to `portRangeMax` (22000 to 23000). It tries up to 1000 ports ([Channel.cxx](/source/fairmq/Channel.cxx/#L346-L386)). + +FairMQ uses this for binding sub-channels without an address. Such a sub-channel gets the address `tcp://:1`. Without root rights, the bind to port 1 fails, and autobind selects a port. With `--network-interface default`, the device uses the interface of the default route. Code that knows the topology then reads the address property and gives it to the peers, for example a plugin. + +:::caution[Fixed ports] +If the configured port is in use, autobind binds to a random port. The device logs this only with the severity `debug`, and the peers do not find the device. For fixed ports, set `autoBind` to `false`. [Channel properties](/reference/channel-properties/#portrangemin-portrangemax-and-autobind) describes the CMake variable that changes the default. +::: + +## The transport of a sub-channel + +Each sub-channel has a transport: `zeromq` or `shmem`. The `transport` property of the sub-channel selects it. With the value `default`, the sub-channel uses the default transport of the device, from `--transport` (default `zeromq`). The device makes one transport object for each transport that its sub-channels use, and the sub-channels share it ([Device.cxx](/source/fairmq/Device.cxx/#L586-L605)). + +- Give both ends of a connection the same transport, as the examples do. +- With `shmem`, all peers must be on the same host and in the same session. Refer to [Sessions and segments](/shmem/sessions/). +- A poller and the data callbacks of [`OnData()`](/api/fair/mq/Device/#OnData) expect one transport for all sub-channels of a channel. + +[Transports](/concepts/transports/) compares the transports. [Use several transports](/guides/several-transports/) shows a device with channels of both transports. + +## Queues, timeouts and the rate log + +Each sub-channel has more properties. [Channel properties](/reference/channel-properties/) gives all details. + +| Properties | Default | Effect | +| --- | --- | --- | +| `sndBufSize`, `rcvBufSize` | 1000 | Maximum number of messages in the send queue and the receive queue. | +| `sndKernelSize`, `rcvKernelSize` | 0 | Kernel buffer sizes in bytes. 0: the system default. | +| `sndTimeoutMs`, `rcvTimeoutMs` | -1 | Timeout of `Send()` and `Receive()` without a timeout argument. -1: no timeout. | +| `linger` | 500 | Time in ms to keep unsent messages after the socket closes. See [Linger](/guides/end-of-run/#linger). | +| `rateLogging` | 1 | Interval of the rate log in seconds. 0: no rate log. | + +In `RUNNING`, the device logs the rate of each sub-channel with a `rateLogging` above 0, with the severity `info`: + +```txt +data[0]: in: ( MB) out: ( MB) +``` + +### Socket counters + +Each socket counts its transfers. [`Channel`](/api/fair/mq/Channel/) gives the counters of its socket, and [`Socket`](/api/fair/mq/Socket/) has the same four functions: + +| Function | Counts | +| --- | --- | +| [`GetMessagesTx()`](/api/fair/mq/Channel/#GetMessagesTx) | Messages that `Send()` gave to ZeroMQ. | +| [`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) | Bytes of these messages. | +| [`GetMessagesRx()`](/api/fair/mq/Channel/#GetMessagesRx) | Messages that `Receive()` got. | +| [`GetBytesRx()`](/api/fair/mq/Channel/#GetBytesRx) | Bytes of these messages. | + +The rules are in the send and receive functions of the transports ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L255), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L118-L315)): + +- The counters start at 0 when the transport makes the socket. In a device, this occurs in `BINDING` or `CONNECTING`. After `RESET DEVICE`, the next initialization makes new sockets, which start at 0 again. +- Only a successful transfer counts. A timeout, an interruption or an error does not change the counters. +- A multipart message counts as one message. Its bytes are the sum of the sizes of its parts. +- The bytes are the sizes of the messages. The `shmem` transport does not count its metadata message. +- A `pub` socket counts a message also when ZeroMQ drops it for a subscriber. See [Behavior of each socket type](#behavior-of-each-socket-type). + +The counters are `unsigned long` values that only increase. Another thread can read them during the transfers. To log other values, read the counters in your own code, for example `GetChannel("data", 0).GetMessagesTx()`. + +The rate log reads the counters in its own thread. The thread wakes up every second. At each interval, it reads the four counters of each sub-channel and divides the differences by the time since its last wake-up ([Device.cxx](/source/fairmq/Device.cxx/#L613-L705)). Thus with a `rateLogging` above 1, the logged rates are too high by the factor `rateLogging` (a defect of the code). + +[Set socket options directly](/reference/channel-properties/#set-socket-options-directly) tells how to set ZeroMQ options of a socket with [`SetOption()`](/api/fair/mq/Socket/#SetOption). + +## Related pages + +- [Design a topology](/guides/design-topology/): select the patterns, the binding devices and the addresses. +- [Configure channels](/guides/configure-channels/): give the channels with `--channel-config`, a JSON file or code. +- [Channel properties](/reference/channel-properties/): all properties, with their defaults and allowed values. +- [Device states](/concepts/states/): the states `BINDING` and `CONNECTING`. +- [Messages and multipart](/concepts/messages/): what goes through a channel. +- [Poll several channels](/guides/poll-channels/): receive from several sub-channels in one loop. diff --git a/docs/src/content/docs/concepts/configuration.mdx b/docs/src/content/docs/concepts/configuration.mdx new file mode 100644 index 00000000..fceff5d6 --- /dev/null +++ b/docs/src/content/docs/concepts/configuration.mdx @@ -0,0 +1,140 @@ +--- +title: 'Configuration and properties' +description: 'How a device gets its configuration: options, --channel-config, JSON files and plugins all give properties in one store.' +sidebar: + order: 6 +code: [fairmq/ProgOptions.h, fairmq/ProgOptions.cxx, fairmq/Properties.h, fairmq/plugins/config/Config.cxx, fairmq/DeviceRunner.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; + +A device keeps its complete configuration as properties: values with a name, in one store of the type [`fair::mq::ProgOptions`](/api/fair/mq/ProgOptions/). The command-line options, the channel configuration and the values from plugins all go into this store. The device, its plugins and your code read the configuration from there, also while the device runs. + +## The property store + +A property has a key of the type `std::string` and a value of any C++ type. The value is a [`fair::mq::Property`](/api/fair/mq/#Property), which is a `boost::any`. [`fair::mq::Properties`](/api/fair/mq/#Properties) is a `std::map` for several properties. The store protects its data with a mutex, so all threads can use it. + +A device has a pointer to its store: [`fConfig`](/api/fair/mq/Device/#fConfig), also from [`GetConfig()`](/api/fair/mq/Device/#GetConfig). A device that you make with the constructor `Device()` has its own internal store. [`SetConfig()`](/api/fair/mq/Device/#SetConfig) replaces it with another store and discards the internal store ([Device.cxx](/source/fairmq/Device.cxx/#L607-L611)). With `runDevice.h`, the [device runner](/api/fair/mq/DeviceRunner/) makes the store and gives it to the device with `SetConfig()`. + +:::caution[Properties from the device constructor] +With `runDevice.h`, the device runner calls `SetConfig()` after it makes the device ([DeviceRunner.cxx](/source/fairmq/DeviceRunner.cxx/#L172-L173)). A device that uses the constructor `Device()` loses all properties and channels that its constructor sets. Set them in [`Init()`](/api/fair/mq/Device/#Init), or give the store to the constructor `Device(ProgOptions&)`. +::: + +The old name `FairMQProgOptions` is a deprecated alias of `fair::mq::ProgOptions`. Refer to [Move from the FairMQ* names](/guides/migrate-names/). + +## Where the properties come from + +A device made with `runDevice.h` gets its properties in this sequence ([DeviceRunner.cxx](/source/fairmq/DeviceRunner.cxx/#L108-L194)): + +1. The device runner loads the config plugin and the control plugin, and collects the options of all plugins and your `addCustomOptions()`. +2. It parses the command line. Each option becomes a property with the name of the option, for example `id` or `severity`. An option that you do not give gets its default, if it has one. +3. It makes the device with your `getDevice()`, gives it the store, and makes the plugins. +4. It logs all properties with the severity `debug`, and starts the state machine. +5. When the device goes into the state `INITIALIZING DEVICE`, the [config plugin](#the-config-plugin) reads `--mq-config` or `--channel-config`. It stores each channel property as `chans...`. +6. When the controller requests the transition `COMPLETE INIT`, the device reads its properties and makes its sub-channels. + +Without `DeviceRunner`, your program parses the command line itself. See [Parse options without DeviceRunner](/guides/control-from-code/#parse-options-without-devicerunner). + +Plugins and your code can set properties at all times with [`SetProperty()`](/api/fair/mq/ProgOptions/#SetProperty). The device also writes a property: after it binds or connects a sub-channel, it writes the address that it uses to `chans...address` ([Device.cxx](/source/fairmq/Device.cxx/#L359-L366)). + +## When the device reads a property + +The device reads most properties once, at the request of the transition `COMPLETE INIT` ([Device.cxx](/source/fairmq/Device.cxx/#L146-L215)). A later change has an effect only when the device goes through `INITIALIZING DEVICE` again, for example after the transition `RESET DEVICE`. + +| Properties | The device reads them | A later change | +| --- | --- | --- | +| `id`, `rate`, `init-timeout`, `transport`, `network-interface` | At the request of `COMPLETE INIT` | No effect | +| `chans...` | At the request of `COMPLETE INIT` | No effect, except for the address of a connecting sub-channel that the device could not connect yet | +| `io-threads`, `session`, `shmid`, the `shm-*` and `bad-alloc-*` options | When the device makes the transport, at the request of `COMPLETE INIT` | No effect | +| `control`, `catch-signals` | When the device runner makes the control plugin | No effect | +| `severity`, `file-severity`, `verbosity`, `color`, `log-to-file` | After the parse of the command line | The device runner applies the new value at once ([DeviceRunner.cxx](/source/fairmq/DeviceRunner.cxx/#L82-L101)) | +| Your custom options | When your code reads them | Your code decides | + +## Read and change properties + +The device and the plugins use the same functions. A device calls them on `fConfig`. A plugin calls them on itself, for example [`Plugin::GetProperty()`](/api/fair/mq/Plugin/#GetProperty). In a plugin, `Count()` has the name [`PropertyExists()`](/api/fair/mq/Plugin/#PropertyExists). + +| Function | Effect | If the key does not exist | +| --- | --- | --- | +| [`GetProperty(key)`](/api/fair/mq/ProgOptions/#GetProperty) | Returns the value. | Throws [`PropertyNotFoundError`](/api/fair/mq/PropertyNotFoundError/). | +| [`GetProperty(key, ifNotFound)`](/api/fair/mq/ProgOptions/#GetProperty-2) | Returns the value. | Returns `ifNotFound`. | +| [`GetPropertyAsString(key)`](/api/fair/mq/ProgOptions/#GetPropertyAsString) | Returns the value as text. | Throws `PropertyNotFoundError`. | +| [`GetPropertyAsString(key, ifNotFound)`](/api/fair/mq/ProgOptions/#GetPropertyAsString-2) | Returns the value as text. | Returns `ifNotFound`. | +| [`GetProperties(regex)`](/api/fair/mq/ProgOptions/#GetProperties) | Returns the properties whose full key matches the regular expression. | Returns an empty map and logs a warning. | +| [`GetPropertiesStartingWith(prefix)`](/api/fair/mq/ProgOptions/#GetPropertiesStartingWith) | Returns the properties whose key starts with `prefix`. | Returns an empty map. | +| [`GetPropertiesAsString(regex)`](/api/fair/mq/ProgOptions/#GetPropertiesAsString) | The same as `GetProperties()`, with the values as text. | Returns an empty map and logs a warning. | +| [`GetPropertiesAsStringStartingWith(prefix)`](/api/fair/mq/ProgOptions/#GetPropertiesAsStringStartingWith) | The same as `GetPropertiesStartingWith()`, with the values as text. | Returns an empty map. | +| [`GetPropertyKeys()`](/api/fair/mq/ProgOptions/#GetPropertyKeys) | Returns all keys. | | +| [`Count(key)`](/api/fair/mq/ProgOptions/#Count) | Returns 1 if the property exists, otherwise 0. | | +| [`SetProperty(key, value)`](/api/fair/mq/ProgOptions/#SetProperty) | Sets the value. | Makes the property. | +| [`UpdateProperty(key, value)`](/api/fair/mq/ProgOptions/#UpdateProperty) | Sets the value and returns `true`. | Returns `false`. | +| [`SetProperties(properties)`](/api/fair/mq/ProgOptions/#SetProperties) | Sets several values. | Makes the properties. | +| [`UpdateProperties(properties)`](/api/fair/mq/ProgOptions/#UpdateProperties) | Sets several values and returns `true`. | Returns `false` and changes nothing. | +| [`DeleteProperty(key)`](/api/fair/mq/ProgOptions/#DeleteProperty) | Removes the property. | Does nothing. | + +The type `T` must be the exact type of the stored value. For another type, the read throws `boost::bad_any_cast`. The type of an option is the type in its declaration, for example `uint64_t` for `--max-iterations` of the 1-1 sampler. [Command-line options](/reference/options/) shows the type of each option. + +:::caution[String literals] +`SetProperty("key", "text")` stores a `const char*`, not a `std::string`. A later `GetProperty("key")` then throws. Write `SetProperty("key", "text")`. +::: + +## Subscribe to changes + +[`Subscribe()`](/api/fair/mq/ProgOptions/#Subscribe) registers a callback for the changes of all properties of the type `T`. [`SubscribeAsString()`](/api/fair/mq/ProgOptions/#SubscribeAsString) registers a callback that gets each change of each type, with the value as text. `SetProperty()`, `UpdateProperty()`, `SetProperties()` and `UpdateProperties()` call the callbacks ([ProgOptions.h](/source/fairmq/ProgOptions.h/#L268-L279)). + +- The callback gets the key and the new value. It runs in the thread that changes the property, before the change function returns. +- Each subscription has the name of a subscriber. A second subscription with the same name and the same type replaces the first ([EventManager.h](/source/fairmq/EventManager.h/#L124-L144)). +- [`Unsubscribe()`](/api/fair/mq/ProgOptions/#Unsubscribe) and [`UnsubscribeAsString()`](/api/fair/mq/ProgOptions/#UnsubscribeAsString) remove a subscription. For a name without a subscription, they throw `std::out_of_range`. +- A plugin uses [`SubscribeToPropertyChange()`](/api/fair/mq/Plugin/#SubscribeToPropertyChange). The name of the plugin is the name of the subscriber. + +This test of the plugin services shows the callbacks for three types, and the effect of an unsubscribe: + + + +### Your own types + +A property can hold a value of your own type. To convert it to text, register the type with [`PropertyHelper::AddType()`](/api/fair/mq/PropertyHelper/#AddType). The type must have an `operator<<` for `std::ostream`. Without the registration, `GetPropertyAsString()` returns `[unidentified_type]`. `SetProperties()`, `UpdateProperties()`, `GetPropertiesAsString()` and `GetPropertiesAsStringStartingWith()` throw `std::out_of_range` for such a value ([Properties.h](/source/fairmq/Properties.h/#L33-L70)). + +## Channel properties + +The configuration of a sub-channel is a group of properties with the keys `chans...`, for example `chans.data.0.address`. [Channel properties](/reference/channel-properties/) lists all of them. The parsers of `--channel-config` and JSON files make all 15 properties of each sub-channel. + +- [`GetChannelInfo()`](/api/fair/mq/ProgOptions/#GetChannelInfo) counts the sub-channels of each channel by their `type` properties ([ProgOptions.cxx](/source/fairmq/ProgOptions.cxx/#L163-L183)). A sub-channel without a `type` property does not exist for the device. +- The device makes the sub-channels with the indexes 0 to N-1, where N is the count. Thus use the indexes 0, 1, 2 and so on, without gaps. +- The device reads the channel properties at the request of `COMPLETE INIT`. Set them before this request, for example in a plugin in the state `INITIALIZING DEVICE`, or in the hook `Init()` of the device. + +[Configure channels](/guides/configure-channels/) shows the three ways to give the channel properties. + +## The config plugin + +The config plugin is a part of each device made with `runDevice.h`. It declares the options of the groups Device and Shared memory in the [table of options](/reference/options/), and reads the channel configuration ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L25-L53)). + +When the device goes into the state `INITIALIZING DEVICE`, the config plugin: + +1. Takes the value of `--config-key`, or the value of `--id` if `--config-key` is not there. +2. Reads the JSON file of `--mq-config` for this value. If there is no `--mq-config`, it reads `--channel-config`. +3. Stores the channel properties with `SetProperties()`. + +If the parser throws an exception, the plugin logs the message with the severity `error`, and the device continues without these channels. If `--id` and `--config-key` are empty, the plugin logs a warning and reads nothing. [JSON configuration](/reference/json/#errors) lists the errors. + +The device runner makes the plugins of `-P` before the config plugin. In `INITIALIZING DEVICE`, their callbacks thus run first. The config plugin then replaces the values of all channel properties that the configuration also gives. + +## Custom options + +Your own options become properties as well. With `runDevice.h`, declare them in `addCustomOptions()`, and read them with `GetProperty()`, usually in [`InitTask()`](/api/fair/mq/Device/#InitTask). [Command-line options](/reference/options/#custom-options) shows the code of the 1-1 example. + +## Look at the configuration + +- `--print-options` prints all options and their values, and stops. It does not show the channel properties, because the config plugin reads them later. +- At the start, the device logs all properties with the severity `debug`, after the line `Configuration:`. +- With `--severity trace`, the parsers log each property of each sub-channel. +- With `--severity debug`, the device logs `Attached channel to (bind|connect) ()` for each endpoint. +- In your code, [`GetPropertiesAsStringStartingWith("chans.")`](/api/fair/mq/ProgOptions/#GetPropertiesAsStringStartingWith) returns all channel properties as text. + +## Related pages + +- [Command-line options](/reference/options/): all options, with their types and defaults. +- [Channel properties](/reference/channel-properties/): the keys of the channel properties. +- [Configure channels](/guides/configure-channels/): `--channel-config`, JSON files and properties from code. +- [Plugins and control](/concepts/plugins/): the plugins that read and set properties. +- [Device states](/concepts/states/): the states `INITIALIZING DEVICE`, `BINDING` and `CONNECTING`. diff --git a/docs/src/content/docs/concepts/devices.mdx b/docs/src/content/docs/concepts/devices.mdx new file mode 100644 index 00000000..b3aa9592 --- /dev/null +++ b/docs/src/content/docs/concepts/devices.mdx @@ -0,0 +1,240 @@ +--- +title: 'Devices' +description: 'A device is a class derived from fair::mq::Device. It has channels, a configuration, transports, a state machine and hooks for your code.' +sidebar: + order: 1 +code: [fairmq/Device.h, fairmq/Device.cxx, fairmq/DeviceRunner.h, fairmq/DeviceRunner.cxx, fairmq/runDevice.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +A device is the part of a FairMQ topology that does the work. You write a class derived from +[`fair::mq::Device`](/api/fair/mq/Device/) and override its hooks. The state machine of the device +calls the hooks, and the channels of the device connect it to other devices. + +## What a device has + +Each device has these parts: + +| Part | Access | Description | +| --- | --- | --- | +| Channels | [`GetChannels()`](/api/fair/mq/Device/#GetChannels), [`GetChannel()`](/api/fair/mq/Device/#GetChannel) | A map from the channel name to a `std::vector` with the sub-channels. The device makes the channels from its properties in `INITIALIZING DEVICE`. | +| Configuration | [`fConfig`](/api/fair/mq/Device/#fConfig), [`GetConfig()`](/api/fair/mq/Device/#GetConfig) | A pointer to a [`ProgOptions`](/api/fair/mq/ProgOptions/) object. It holds all properties of the device, also the channel properties. | +| Transports | [`Transport()`](/api/fair/mq/Device/#Transport), [`AddTransport()`](/api/fair/mq/Device/#AddTransport) | One transport factory for each transport that the device uses. `Transport()` returns the default transport. | +| State machine | [`ChangeState()`](/api/fair/mq/Device/#ChangeState), [`GetCurrentState()`](/api/fair/mq/Device/#GetCurrentState) | A private member. It calls the hooks. See [Device states](/concepts/states/). | +| Id | [`GetId()`](/api/fair/mq/Device/#GetId) | The value of the property `id`. The device reads it in `INITIALIZING DEVICE`. | +| Version | [`GetVersion()`](/api/fair/mq/Device/#GetVersion) | The [`tools::Version`](/reference/tools/#versionh) that you give to the constructor. The default is `{0, 0, 0}`. | + +The public member [`fChannels`](/api/fair/mq/Device/#fChannels) is deprecated. Use `GetChannels()`. + +A device has four constructors. Copy and move are deleted. + + + +If you do not give a `ProgOptions` object, the device makes its own (`fInternalConfig`). +[`SetConfig()`](/api/fair/mq/Device/#SetConfig) replaces it with your object. `DeviceRunner` calls +`SetConfig()` with its own `ProgOptions` before the device starts. + +### The transports + +In `INITIALIZING DEVICE`, the device reads the property `transport` (default `zeromq`). It makes the +default transport from this value. Then it makes one more transport for each other transport that a +channel uses. All channels with the same transport share one transport factory. See +[Transports](/concepts/transports/) and [Use several transports](/guides/several-transports/). + +## The hooks + +The hooks are protected virtual functions. Their default implementations do nothing, and +`ConditionalRun()` returns `false`. Override only the hooks that your device needs. + +| Hook | State | When the device calls it | +| --- | --- | --- | +| [`Init()`](/api/fair/mq/Device/#Init) | `INITIALIZING DEVICE` | After the controller requests `CompleteInit`, before the device makes the channels. The header recommends `InitTask()` instead. | +| [`Bind()`](/api/fair/mq/Device/#Bind) | `BINDING` | After the device binds all channels with the method `bind`. | +| [`Connect()`](/api/fair/mq/Device/#Connect) | `CONNECTING` | After the device connects all channels with the method `connect`. | +| [`InitTask()`](/api/fair/mq/Device/#InitTask) | `INITIALIZING TASK` | Once. Read your options and allocate your resources here. | +| [`PreRun()`](/api/fair/mq/Device/#PreRun) | `RUNNING` | Once, at the start of `RUNNING`. | +| [`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun) | `RUNNING` | Again and again, while it returns `true` and no transition is pending. | +| [`Run()`](/api/fair/mq/Device/#Run) | `RUNNING` | Once, after the `ConditionalRun()` loop. | +| [`PostRun()`](/api/fair/mq/Device/#PostRun) | `RUNNING` | Once, at the end of `RUNNING`. A transition is pending at this time. | +| [`ResetTask()`](/api/fair/mq/Device/#ResetTask) | `RESETTING TASK` | Once. Undo the work of `InitTask()` here. | +| [`Reset()`](/api/fair/mq/Device/#Reset) | `RESETTING DEVICE` | After the device resets its transports, before it removes all channels. | + +The device does not call `ConditionalRun()` and `Run()` when it has data callbacks (see below). The +state machine calls the hooks through a handler in the constructor of the device: + + + +Each wrapper function calls one or more hooks. For example, `InitTaskWrapper()` calls `InitTask()` +and then requests the transition `Auto`, if no other transition is pending. An exception in a hook moves the device to the state +`ERROR`. See [Handle errors and timeouts](/guides/errors-timeouts/). + +Two more virtual functions are public: + +- [`RegisterChannelEndpoints()`](/api/fair/mq/Device/#RegisterChannelEndpoints): `DeviceRunner` + calls it before the device starts. In it, call + [`RegisterChannelEndpoint()`](/api/fair/mq/Device/#RegisterChannelEndpoint) for each channel that + your device expects, with the minimum and maximum number of sub-channels (default 1 and 1). +- [`LogSocketRates()`](/api/fair/mq/Device/#LogSocketRates): in `RUNNING`, a separate thread runs it + when a channel has the property `rateLogging` larger than 0 (default 1). It logs the message rate + and the data rate of these channels every `rateLogging` seconds. + +### A small example + +This sampler of the example [1-1](/examples/1-1/) reads two options in `InitTask()` and sends one +message in each call of `ConditionalRun()`: + + + +## Data callbacks + +A device can register data callbacks with [`OnData()`](/api/fair/mq/Device/#OnData). The device +then calls the callback for each message that arrives on the channel. A callback receives a message +(`MessagePtr&`) or a multipart message (`Parts&`), and the index of the sub-channel. It returns +`true` to continue, or `false` to end `RUNNING`. + + + +Register the callbacks before the device enters `RUNNING`, for example in the constructor. See +[Receive data with callbacks or loops](/guides/receive-data/) for all forms of `OnData()`. For the +thread that calls the callbacks, see [Which thread runs your code](/concepts/threads/#which-thread-runs-your-code). + +## Helper functions + +The device has helper functions for the work in the hooks: + +| Function | Description | +| --- | --- | +| [`Send(msg, channel, index = 0)`](/api/fair/mq/Device/#Send), [`Receive(msg, channel, index = 0)`](/api/fair/mq/Device/#Receive) | Send or receive a `MessagePtr`, a `Parts` or a `std::vector` on the sub-channel `index` of the channel. Overloads with a fourth argument set a timeout in ms ([`Send-2`](/api/fair/mq/Device/#Send-2), [`Receive-2`](/api/fair/mq/Device/#Receive-2)). They return the number of bytes or a negative [transfer code](/reference/transfer-codes/). | +| [`NewMessage(args...)`](/api/fair/mq/Device/#NewMessage) | Makes a message with the default transport. The arguments go to `TransportFactory::CreateMessage()`. | +| [`NewMessageFor(channel, index, args...)`](/api/fair/mq/Device/#NewMessageFor) | Makes a message with the transport of the sub-channel. | +| [`NewSimpleMessage(data)`](/api/fair/mq/Device/#NewSimpleMessage), [`NewSimpleMessageFor(channel, index, data)`](/api/fair/mq/Device/#NewSimpleMessageFor) | Makes a message with a copy of `data`. | +| [`NewStaticMessage(data)`](/api/fair/mq/Device/#NewStaticMessage), [`NewStaticMessageFor(channel, index, data)`](/api/fair/mq/Device/#NewStaticMessageFor) | Makes a message that does not free `data` after the transfer. The `zeromq` transport uses `data` without a copy. The `shmem` transport copies it. | +| [`NewUnmanagedRegion(args...)`](/api/fair/mq/Device/#NewUnmanagedRegion), [`NewUnmanagedRegionFor(channel, index, args...)`](/api/fair/mq/Device/#NewUnmanagedRegionFor) | Makes an unmanaged region. See [Unmanaged regions](/shmem/regions/). | +| [`NewPoller("a", "b")`](/api/fair/mq/Device/#NewPoller), [`NewPoller(channels)`](/api/fair/mq/Device/#NewPoller-2) | Makes a poller for channel names or for a `std::vector`. All channels must use the same transport. Otherwise the function throws `std::runtime_error`. See [Poll several channels](/guides/poll-channels/). | +| [`GetChannel(name, index = 0)`](/api/fair/mq/Device/#GetChannel) | Returns the sub-channel. Throws `std::out_of_range` if it does not exist. | +| [`GetNumSubChannels(name)`](/api/fair/mq/Device/#GetNumSubChannels) | Returns the number of sub-channels of a channel. | +| [`GetNumberOfConnectedPeers(name, index = 0)`](/api/fair/mq/Device/#GetNumberOfConnectedPeers) | Returns the number of peers that are connected to the sub-channel. | +| [`AddChannel(name, channel)`](/api/fair/mq/Device/#AddChannel) | Adds the properties of a `Channel` object to the configuration, except `sndTimeoutMs` and `rcvTimeoutMs`. The device makes the channel in `INITIALIZING DEVICE`. | +| [`GetConfig()`](/api/fair/mq/Device/#GetConfig) | Returns the `ProgOptions` object. Use `GetConfig()->GetProperty(key)` to read an option. | +| [`GetId()`](/api/fair/mq/Device/#GetId) | Returns the id of the device. | +| [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) | Returns `true` when a transition is requested and the next state has not started yet. | +| [`WaitFor(duration)`](/api/fair/mq/Device/#WaitFor) | Waits for the duration. Returns `false` if a transition is requested before the end of the duration. | +| [`ChangeState(transition)`](/api/fair/mq/Device/#ChangeState), [`ChangeStateOrThrow(transition)`](/api/fair/mq/Device/#ChangeStateOrThrow) | Request a transition. See [States and transitions](/reference/states/). | +| [`GetCurrentState()`](/api/fair/mq/Device/#GetCurrentState), [`GetCurrentStateName()`](/api/fair/mq/Device/#GetCurrentStateName) | Return the current state. | +| [`WaitForState(state)`](/api/fair/mq/Device/#WaitForState), [`WaitForNextState()`](/api/fair/mq/Device/#WaitForNextState) | Wait in another thread for a state of the device. | +| [`SubscribeToStateChange(key, callback)`](/api/fair/mq/Device/#SubscribeToStateChange) | Calls `callback` at the start of each new state, in the thread of the state machine. | +| [`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine) | Runs the state machine in the calling thread, until the state `EXITING` or `ERROR`. | + +Some setters change a property in the configuration, for example +[`SetTransport()`](/api/fair/mq/Device/#SetTransport) (`transport`) and +[`SetNumIoThreads()`](/api/fair/mq/Device/#SetNumIoThreads) (`io-threads`). The device reads most of +these properties in `INITIALIZING DEVICE`. For all properties, see +[Configuration and properties](/concepts/configuration/). + +## How a device starts + +Most devices use the header `fairmq/runDevice.h`. It defines a `main()` function that runs one +device with the class [`DeviceRunner`](/api/fair/mq/DeviceRunner/). + +### Use runDevice.h + + + +1. Include `` in one source file of your executable. + +2. Write the function `addCustomOptions()`. Add your options to the `options_description`. If you + have no options, leave the body empty. + + + +3. Write the function `getDevice()`. Return a new object of your device class. + + + + + +The `main()` function of `runDevice.h` adds these two functions as hooks of `DeviceRunner`: + + + +An exception that reaches `main()` gives the log line `Uncaught exception reached the top of main:` +and the exit code 1. + +:::note[Old header] +`fairmq/runFairMQDevice.h` is the old form of this header. There, `getDevice()` takes a +`const fair::mq::ProgOptions&` and returns a raw pointer. Use `fairmq/runDevice.h` for new code. +::: + +### What DeviceRunner does + +[`DeviceRunner::Run()`](/api/fair/mq/DeviceRunner/#Run) starts the device in this sequence. The +constructor of `DeviceRunner` already loads the plugins of the option `-P`. + + + +1. Load the built-in plugin `config`. +2. Call the hook `LoadPlugins`. +3. Load the built-in plugin `control`. +4. Call the hook `SetCustomCmdLineOptions`. +5. Add the options of all plugins and of the plugin manager. +6. Call the hook `ModifyRawCmdLineArgs`. +7. Parse the command line. For `--help` or `--print-options`, print the output and return 0. +8. Set up the logger from the logging options. +9. Call the hook `InstantiateDevice`. If the hook does not set `fDevice`, log an error and return 1. +10. Call `RegisterChannelEndpoints()` of the device. For `--print-channels` or `--version`, return 0. +11. Give the configuration to the device (`SetConfig()`), and instantiate the plugins. +12. Log the configuration, and call `RunStateMachine()` of the device. +13. When the state machine stops, wait until all plugins release the device control. Return 0. + + + +You add a hook with [`AddHook()`](/api/fair/mq/DeviceRunner/#AddHook). A hook is a function +`void(DeviceRunner&)`. It can use all members of the runner: `fRawCmdLineArgs`, `fConfig`, +`fDevice` and `fPluginManager`. + +| Hook (`fair::mq::hooks::`) | Typical use | +| --- | --- | +| `LoadPlugins` | Load more plugins with `r.fPluginManager.LoadPlugin()`. | +| `SetCustomCmdLineOptions` | Add options with `r.fConfig.AddToCmdLineOptions()`. | +| `ModifyRawCmdLineArgs` | Change the arguments in `r.fRawCmdLineArgs` before the parser reads them. | +| `InstantiateDevice` | Make the device and put it into `r.fDevice`. | + +You can write your own `main()` with `DeviceRunner`. The example +[custom-controller](/examples/custom-controller/) loads its own control plugin in the hook +`LoadPlugins`: + + + +[`RunWithExceptionHandlers()`](/api/fair/mq/DeviceRunner/#RunWithExceptionHandlers) calls `Run()` +and catches all exceptions. It logs `Uncaught exception reached the top of DeviceRunner:` and +returns 1. + +:::caution[Known defect] +For `--print-channels` and `--version`, `DeviceRunner` sets the console severity to `nolog` and then +prints with `LOG`. Thus both options print nothing in this version. The device does not start. +::: + +A process can also run more than one device without `DeviceRunner`. Then your code must call +`RunStateMachine()` and request the transitions. See +[Control a device from code](/guides/control-from-code/). + +## The life of a device + +A device starts in the state `IDLE`. A controller, usually the control plugin, requests the +transitions. The device initializes in steps, for example `BINDING` and `CONNECTING`, until it is +`READY`. In `RUNNING`, the device processes data. When the work ends, the device goes back to +`READY`. Then it resets in two steps back to `IDLE`, and ends in `EXITING`. + +For the states, the transitions and the hooks in each state, see [Device states](/concepts/states/). + +## Related pages + +- [Device states](/concepts/states/): the state machine and the hooks in each state. +- [Receive data with callbacks or loops](/guides/receive-data/): `OnData()`, `ConditionalRun()` and + `Run()`. +- [Channels and sockets](/concepts/channels/): the channels of a device. +- [Configuration and properties](/concepts/configuration/): the properties that a device reads. +- [Plugins and control](/concepts/plugins/): the plugins that control the device. +- [Threads in a device](/concepts/threads/): the thread that runs each hook and callback. diff --git a/docs/src/content/docs/concepts/messages.mdx b/docs/src/content/docs/concepts/messages.mdx new file mode 100644 index 00000000..bb75efa3 --- /dev/null +++ b/docs/src/content/docs/concepts/messages.mdx @@ -0,0 +1,246 @@ +--- +title: 'Messages and multipart' +description: 'How to make a message, who owns its buffer before and after Send(), and how to send several parts in one transfer with fair::mq::Parts.' +sidebar: + order: 4 +code: [fairmq/Message.h, fairmq/Parts.h, fairmq/TransportFactory.h, fairmq/Channel.h] +--- + +import Snippet from '../../../components/Snippet.astro'; + +A message is the unit of data that a channel sends and receives. The transport allocates the buffer +of the message, and the owner of the buffer changes when you send it. A multipart message sends +several messages in one transfer. + +## The message object + +[`fair::mq::Message`](/api/fair/mq/Message/) is an interface. Each transport has its own +implementation: the zeromq message holds a `zmq_msg_t`, the shmem message holds a handle to a buffer +in shared memory. You use a message through [`fair::mq::MessagePtr`](/api/fair/mq/#MessagePtr), +which is a `std::unique_ptr`. You cannot copy or move a `Message` object, but you can move +the `MessagePtr`. + +| Function | What it does | +| --- | --- | +| [`GetData()`](/api/fair/mq/Message/#GetData) | Returns a pointer to the buffer, or `nullptr` if the message has no buffer. | +| [`GetSize()`](/api/fair/mq/Message/#GetSize) | Returns the size of the buffer in bytes. | +| [`SetUsedSize(size, alignment)`](/api/fair/mq/Message/#SetUsedSize) | Makes the buffer smaller. See [Change the size](#change-the-size). | +| [`Rebuild(…)`](/api/fair/mq/Message/#Rebuild) | Releases the buffer and initializes the message again. | +| [`Copy(other)`](/api/fair/mq/Message/#Copy) | Makes the message use the buffer of `other`. | +| [`GetType()`](/api/fair/mq/Message/#GetType) | Returns the transport type, [`Transport::ZMQ`](/api/fair/mq/Transport/#ZMQ) or [`Transport::SHM`](/api/fair/mq/Transport/#SHM). | +| [`GetTransport()`](/api/fair/mq/Message/#GetTransport) | Returns a pointer to the [`TransportFactory`](/api/fair/mq/TransportFactory/) that made the message. | + +## Make a message + +A device makes messages with [`NewMessage(args…)`](/api/fair/mq/Device/#NewMessage). It forwards +the arguments to [`CreateMessage()`](/api/fair/mq/TransportFactory/#CreateMessage) of the default +transport of the device. [`NewMessageFor(channel, index, args…)`](/api/fair/mq/Device/#NewMessageFor) +uses the transport of the sub-channel `index` of `channel`. A +[`Channel`](/api/fair/mq/Channel/#NewMessage) has a `NewMessage(args…)` function too. + +| Arguments | Result | +| --- | --- | +| none | An empty message without a buffer. Use it to receive. | +| `Alignment{64}` | An empty message to receive into. The zeromq transport aligns the received buffer to 64 bytes. | +| `size` | A message with a buffer of `size` bytes from the transport. | +| `size, Alignment{64}` | A buffer of `size` bytes, aligned to 64 bytes. | +| `data, size, ffn, hint` | A message for your buffer. See [Your own buffer](#your-own-buffer). | +| `region, data, size, hint` | A message for a block of an unmanaged region. See [Unmanaged regions](/shmem/regions/). | + +A `std::pmr` container can also become a message without a copy: +[`fair::mq::getMessage()`](/api/fair/mq/#getMessage) makes the message from a container that +allocates from the memory resource of the transport. See +[Use std::pmr memory resources](/guides/pmr/). + +[`fair::mq::Alignment`](/api/fair/mq/Alignment/) is a struct with one `size_t` member. The value 0 +means "no alignment", which is the default. The shmem transport aligns each buffer to at least +`alignof(std::max_align_t)`. It ignores the alignment of an empty message, because the receiver gets +the buffer that the sender allocated. + +:::caution[Use messages only while the transports exist] +The device makes its transports in the state `INITIALIZING DEVICE`, after it calls `Init()`. Do not +call `NewMessage()` in the constructor or in `Init()`. Call it in `InitTask()`, `Run()`, +`ConditionalRun()` or in a data callback. The device destroys its transports in the state +`RESETTING DEVICE`. Destroy the messages that your device class keeps in `ResetTask()`. In a build +with the CMake option `FAIRMQ_DEBUG_MODE`, the shmem transport checks this before the device calls +`Reset()`. It throws `MessageError` if messages still exist. +::: + +### Your own buffer + +`NewMessage(data, size, ffn, hint)` makes a message for a buffer that you allocated. `ffn` is a +deleter of the type [`fair::mq::FreeFn`](/api/fair/mq/#FreeFn), `void(void* data, void* hint)`. The +transport calls `ffn(data, hint)` when it does not need the buffer any more. The +[1-1 example](/examples/1-1/) sends a string this way: + + + +The two transports use the buffer differently: + +- The zeromq transport does not copy the buffer. ZeroMQ calls `ffn` after the transfer. ZeroMQ can + make this call from one of its own threads, so `ffn` must be thread-safe. See + [Threads in a device](/concepts/threads/). +- The shmem transport copies the buffer into the shared memory segment when it makes the message. + Then it calls `ffn` immediately. If `ffn` is `nullptr`, it calls `free(data)` + ([shmem/Message.h](/source/fairmq/shmem/Message.h/#L64-L78)). For a size of 0, it does not call + `ffn` and does not free the buffer. + +Always give a deleter. For a buffer that you release yourself, give +[`TransportFactory::NoCleanup`](/api/fair/mq/TransportFactory/#NoCleanup). + +### Small values and strings + +[`NewSimpleMessage(value)`](/api/fair/mq/Device/#NewSimpleMessage) copies `value` into a new +message, and the message owns the copy. For a type `T`, the message has `sizeof(T)` bytes. `T` must +be trivially copyable, because the receiver gets the bytes only. For a string literal and a +`std::string`, the message holds the characters without the terminating zero. +[Limits of NewSimpleMessage()](/guides/send-data-types/#limits-of-newsimplemessage) lists the types +that do not work. + +[`NewStaticMessage(str)`](/api/fair/mq/Device/#NewStaticMessage) makes a message for the buffer of +the `std::string` `str`, with the deleter `NoCleanup`. The zeromq transport does not copy the buffer +and does not tell you when the transfer ends. Use it only for a string that does not change and that +lives longer than the transport. The transports of a device live until `RESETTING DEVICE`, so a +member of the device is enough. The shmem transport copies the string when it makes the message. +The test of the transport factory shows both functions: + + + +:::caution +Use `NewStaticMessage()` with a `std::string` only. The template overload +`NewStaticMessage(const T& data)` gives `data` itself as the buffer pointer and `sizeof(T)` as the +size ([TransportFactory.h](/source/fairmq/TransportFactory.h/#L225-L229)). +::: + +The functions `NewSimpleMessageFor()` and `NewStaticMessageFor()` take a channel name and a +sub-channel index first, like `NewMessageFor()`. + +## Change the size + +[`SetUsedSize(size)`](/api/fair/mq/Message/#SetUsedSize) makes the buffer smaller. Use it when you +allocate the maximum size first and know the real size later. It returns `true` if the size is +equal to or smaller than the current size, and `false` if the size is larger. The message test shows +the rules: + + + +The zeromq transport keeps the full buffer until it releases the message. The shmem transport +shrinks the buffer in the segment where possible, and `SetUsedSize(0)` releases the buffer. + +## Rebuild and copy a message + +[`Rebuild()`](/api/fair/mq/Message/#Rebuild) releases the buffer of the message and initializes the +message again. It has five overloads with the same arguments as `NewMessage()`, but without the +region overload. Use `Rebuild()` to use one message object for many transfers. + +[`Copy(other)`](/api/fair/mq/Message/#Copy) makes the message use the buffer of `other`. The +current transports share the buffer and do not copy the data, but the interface does not guarantee +it. The shmem transport increments a reference count in shared memory, also for messages of other +processes. The zeromq transport calls `zmq_msg_copy()`. Do not change the buffer after `Copy()`. +Both messages must use the same transport. The [copypush example](/examples/copypush/) +sends one buffer on several sub-channels: + + + +## Send and receive a message + +[`Send(msg, channel, index)`](/api/fair/mq/Device/#Send) takes a reference to the `MessagePtr`. It +returns the number of bytes, or a negative +[transfer code](/reference/transfer-codes/) for a timeout, an interruption or an error. + +After a successful `Send()`, the transport owns the buffer. The `MessagePtr` still holds a message +object, but you must not read or write its data: + +- The zeromq transport gives the message to `zmq_msg_send()`. On success, ZeroMQ empties the + message, and `GetSize()` returns 0. +- The shmem transport keeps the old size and pointer in the message. The buffer belongs to the + receiver now. + +To send the same data on two channels, make a second message with `Copy()` before the first +`Send()`. To use the message object again, call `Rebuild()`. If `Send()` returns a negative value, +the message keeps its buffer, and you can send it again. + +[`Receive(msg, channel, index)`](/api/fair/mq/Device/#Receive) puts the received buffer into `msg`. +Receive into an empty message: make a new one with `NewMessage()`, or call `Rebuild()` on a used +one. The shmem transport does not release a buffer that the message already holds. The received +message owns its buffer. When you destroy the message, the transport releases the buffer. + +### A message of another transport + +[`Channel::Send()`](/api/fair/mq/Channel/#Send) compares the transport of each message with the +transport of the channel ([Channel.h](/source/fairmq/Channel.h/#L421-L480)). If they are different, +the channel makes a new message of its own transport, and your `MessagePtr` points to the new +message after the call: + +- If the channel uses zeromq, the new message points to the buffer of your message. FairMQ does not + copy the data. It destroys your message when zeromq releases the buffer. +- If the channel uses shmem, the new message has a copy of the data in shared memory. FairMQ + destroys your message immediately. +- An empty message becomes an empty message of the channel transport. + +[`Channel::Receive()`](/api/fair/mq/Channel/#Receive) replaces a message of another transport with +an empty message of the channel transport. To prevent the conversion, make the message with +`NewMessageFor()`. See [Use several transports](/guides/several-transports/). + +## Multipart messages + +[`fair::mq::Parts`](/api/fair/mq/Parts/) holds a `std::vector`. Each message in it is a +part. You can move a `Parts` object, but you cannot copy it. + +| Function | What it does | +| --- | --- | +| [`Parts(part1, part2, …)`](/api/fair/mq/Parts/#Parts-4) | Makes a `Parts` object from `MessagePtr` values. | +| [`AddPart(part)`](/api/fair/mq/Parts/#AddPart-2) | Adds a `MessagePtr` at the end. | +| [`AddPart(part1, part2, …)`](/api/fair/mq/Parts/#AddPart-3) | Adds several parts at the end. | +| [`AddPart(otherParts)`](/api/fair/mq/Parts/#AddPart-4) | Moves all parts of another `Parts` object to the end. | +| [`operator[](i)`](/api/fair/mq/Parts/#operator-index) | Returns the part `i` as `Message&`. It does not check the index. | +| [`At(i)`](/api/fair/mq/Parts/#At) | Returns the `MessagePtr&` of the part `i`, and throws `std::out_of_range` for a bad index. You can replace the part through it. | +| [`Size()`](/api/fair/mq/Parts/#Size), [`Empty()`](/api/fair/mq/Parts/#Empty), [`Clear()`](/api/fair/mq/Parts/#Clear) | Return the number of parts, check for zero parts, remove all parts. | +| [`begin()`](/api/fair/mq/Parts/#begin), [`end()`](/api/fair/mq/Parts/#end), `cbegin()`, `cend()` | Iterate over the `MessagePtr` elements, for example in a range-based `for` loop. | + +`AddPart(Message*)` and `AtRef(i)` are deprecated. The old name `FairMQParts` is an alias of +`fair::mq::Parts` (see [Move from the FairMQ* names](/guides/migrate-names/)). + +The sampler of the [multipart example](/examples/multipart/) makes seven parts. It moves three of +them from a second `Parts` object with `AddPart()`, and one part is empty: + + + +The sink receives all parts in one data callback: + + + +### How a multipart message travels + +`Send(parts, …)` sends all parts in one transfer. The receiver gets all parts, in the same order, in +one `Receive(parts, …)` call. `Send()` returns the sum of the sizes of the parts. The channel +counts the transfer as one message in its statistics. + +- The zeromq transport sends one zeromq multipart message, with one frame for each part. +- The shmem transport sends one metadata message with the number of parts and the metadata of each + part. The data of the parts stays in shared memory. + +`Send()` and `Receive()` also accept a `std::vector`. The rules for single messages +apply to each part. This test sends three parts, one of them empty, and receives them: + + + +:::caution[Rules for multipart messages] +- Do not send an empty `Parts` object. The zeromq transport returns `TransferCode::error`, but the + shmem transport sends a message with zero parts. +- Receive with the same form that the sender uses: `Parts` for `Parts`, `MessagePtr` for + `MessagePtr`. The shmem transport cannot read a single message into a `Parts` object. +- `Receive()` adds the received parts at the end of the `Parts` object. Give it an empty one. +- A receiver with [`OnData()`](/api/fair/mq/Device/#OnData-3) must register a callback that takes + `fair::mq::Parts&`. +::: + +## Related pages + +- [Channels and sockets](/concepts/channels/): the channels that send and receive the messages. +- [Transports](/concepts/transports/): how zeromq and shmem move the data. +- [Use several transports](/guides/several-transports/): make messages for the right transport. +- [Unmanaged regions](/shmem/regions/): messages for blocks of your own shared memory. +- [Transfer codes and errors](/reference/transfer-codes/): the return values of `Send()` and `Receive()`. +- [Send your own data types](/guides/send-data-types/): structs, arrays and serialized objects in messages. +- [Use std::pmr memory resources](/guides/pmr/): send a `std::pmr` container without a copy. diff --git a/docs/src/content/docs/concepts/plugins.mdx b/docs/src/content/docs/concepts/plugins.mdx new file mode 100644 index 00000000..0d928526 --- /dev/null +++ b/docs/src/content/docs/concepts/plugins.mdx @@ -0,0 +1,264 @@ +--- +title: 'Plugins and control' +description: 'How plugins extend a device, how the plugin manager loads them, what they can do, and how the built-in control plugin drives the state machine.' +sidebar: + order: 7 +code: [fairmq/Plugin.h, fairmq/PluginManager.cxx, fairmq/PluginServices.h, fairmq/plugins/control/Control.cxx, fairmq/DeviceRunner.cxx] +--- + +import OptionsTable from '../../../components/OptionsTable.astro'; +import Snippet from '../../../components/Snippet.astro'; + +A plugin is a class that runs in the process of a device. It can read and set properties, follow the state of the +device and drive the state machine. Each device that starts with `runDevice.h` has two built-in plugins: `config` +reads the channel configuration, and `control` moves the device through its states. + +## Parts of the plugin system + +| Class | Task | +| --- | --- | +| [`fair::mq::Plugin`](/api/fair/mq/Plugin/) | The base class of all plugins. It holds the name, the version, the maintainer and the homepage of the plugin, and it gives the plugin API. | +| [`fair::mq::PluginManager`](/api/fair/mq/PluginManager/) | Finds, loads, creates and owns the plugins. | +| [`fair::mq::PluginServices`](/api/fair/mq/PluginServices/) | Connects the plugins to the device and to its properties. All plugins of a device use the same object. | +| [`fair::mq::DeviceRunner`](/api/fair/mq/DeviceRunner/) | Starts the device with its properties and its plugins. `runDevice.h` uses it. | + +A plugin does not use the device directly. Each call goes through `PluginServices`: + +```txt +plugin ──► PluginServices ──► Device (state, transitions) + └─► ProgOptions (properties) +``` + +## How a device starts + +[`DeviceRunner::Run()`](/api/fair/mq/DeviceRunner/#Run) loads and creates the plugins in this sequence +([DeviceRunner.cxx](/source/fairmq/DeviceRunner.cxx/#L108-L194)): + +1. The constructor of `DeviceRunner` makes the plugin manager. The plugin manager reads `-S` and `-P` and loads the + plugins of `-P`, in their sequence. +2. `Run()` loads the built-in plugin `config`. +3. The runner hook `hooks::LoadPlugins` runs. Your code can load more plugins here. +4. `Run()` loads the built-in plugin `control`. +5. The runner hook `hooks::SetCustomCmdLineOptions` runs. `runDevice.h` adds the options of `addCustomOptions()` + here. +6. The runner adds the options of all plugins to the command-line options. The runner hook + `hooks::ModifyRawCmdLineArgs` runs. Then the runner parses the command line. With `--help` or `--print-options`, + `Run()` prints the options and returns 0. +7. The runner hook `hooks::InstantiateDevice` makes the device. +8. The plugin manager makes the `PluginServices` object. Then it creates the plugins, in the load sequence. +9. The device runs its state machine until the state `EXITING`. +10. The runner waits until no plugin has the controller role. Then `Run()` returns 0. + +The constructor of a plugin runs after the parsing of the command line, so a plugin can read its options there. The +control plugin comes last. A plugin that takes the controller role in its constructor gets it before the control +plugin. + +To load plugins without `DeviceRunner`, see +[Load plugins without DeviceRunner](/guides/control-from-code/#load-plugins-without-devicerunner). + +## Load a plugin + +Give the name of a plugin to `-P` (`--plugin`), or to +[`PluginManager::LoadPlugin()`](/api/fair/mq/PluginManager/#LoadPlugin) in a runner hook. A prefix selects the +mechanism ([PluginManager.cxx](/source/fairmq/PluginManager.cxx/#L135-L150)): + +| Name | Mechanism | Where the plugin manager looks | +| --- | --- | --- | +| `name` or `d:name` | Dynamic | In a shared library file. See [Plugin files and search paths](#plugin-files-and-search-paths). | +| `p:name` | Prelinked | In the program. The executable links the library of the plugin at build time. | +| `s:name` | Static | In the program: the built-in plugins `config` and `control`, or a plugin that the executable contains. | + +Give `-P` once for each plugin, for example `-P first -P second`. The plugin manager does not split a name at commas. +It loads a dynamic or a prelinked plugin only once, also when you give its name twice. + +### Plugin files and search paths + +For the dynamic plugin `name`, the plugin manager looks for two file names: +`libfairmq-plugin-name.so` and then `libFairMQPlugin_name.so` (the suffix is the one of the platform, `.so` on Linux). +It looks in these places, in this sequence: + +1. Each directory of `-S` (`--plugin-search-path`). +2. The system lookup of the dynamic linker: the system library directories, `RUNPATH` and `LD_LIBRARY_PATH`. + +`-S` takes one or more directories. The paths without a prefix make the list. Then the plugin manager puts each path +with the prefix `<` at the start of the list. It puts each path with the prefix `>` at the end. Without `-S`, the list +is empty. The test `PluginManager.Factory` gives this example: + +```sh +-S '>/lib' '`, because the shell uses these characters for redirection. The plugin manager ignores a directory that does +not exist. A path to a file, or an empty path, gives the error `PluginManager::BadSearchPath`. + +When no file loads, the plugin manager throws `PluginManager::PluginLoadError`: + +```txt +Could not load dynamic plugin name from configured search paths (-S) nor with system lookup (system libdirs, RUNPATH, $LD_LIBRARY_PATH). +``` + +The `main()` function of `runDevice.h` catches the exception, logs it and returns 1. A file that exists but does not +load, for example because of a missing symbol, gives the same error. + +## What a plugin can do + +The functions of `fair::mq::Plugin` call `PluginServices`. They give the name of the plugin as the ID of the +subscriber and of the controller. + +| Area | Functions | +| --- | --- | +| State | [`GetCurrentDeviceState()`](/api/fair/mq/Plugin/#GetCurrentDeviceState), [`SubscribeToDeviceStateChange()`](/api/fair/mq/Plugin/#SubscribeToDeviceStateChange), [`UnsubscribeFromDeviceStateChange()`](/api/fair/mq/Plugin/#UnsubscribeFromDeviceStateChange), [`ToDeviceState()`](/api/fair/mq/Plugin/#ToDeviceState), [`ToDeviceStateTransition()`](/api/fair/mq/Plugin/#ToDeviceStateTransition), [`ToStr()`](/api/fair/mq/Plugin/#ToStr) | +| Control | [`TakeDeviceControl()`](/api/fair/mq/Plugin/#TakeDeviceControl), [`StealDeviceControl()`](/api/fair/mq/Plugin/#StealDeviceControl), [`ReleaseDeviceControl()`](/api/fair/mq/Plugin/#ReleaseDeviceControl), [`ChangeDeviceState()`](/api/fair/mq/Plugin/#ChangeDeviceState) | +| Read properties | [`PropertyExists()`](/api/fair/mq/Plugin/#PropertyExists), [`GetProperty()`](/api/fair/mq/Plugin/#GetProperty), [`GetPropertyAsString()`](/api/fair/mq/Plugin/#GetPropertyAsString), [`GetProperties()`](/api/fair/mq/Plugin/#GetProperties), [`GetPropertiesStartingWith()`](/api/fair/mq/Plugin/#GetPropertiesStartingWith), [`GetPropertiesAsString()`](/api/fair/mq/Plugin/#GetPropertiesAsString), [`GetPropertiesAsStringStartingWith()`](/api/fair/mq/Plugin/#GetPropertiesAsStringStartingWith), [`GetPropertyKeys()`](/api/fair/mq/Plugin/#GetPropertyKeys), [`GetChannelInfo()`](/api/fair/mq/Plugin/#GetChannelInfo) | +| Change properties | [`SetProperty()`](/api/fair/mq/Plugin/#SetProperty), [`SetProperties()`](/api/fair/mq/Plugin/#SetProperties), [`UpdateProperty()`](/api/fair/mq/Plugin/#UpdateProperty), [`UpdateProperties()`](/api/fair/mq/Plugin/#UpdateProperties), [`DeleteProperty()`](/api/fair/mq/Plugin/#DeleteProperty) | +| Property changes | [`SubscribeToPropertyChange()`](/api/fair/mq/Plugin/#SubscribeToPropertyChange), [`UnsubscribeFromPropertyChange()`](/api/fair/mq/Plugin/#UnsubscribeFromPropertyChange), [`SubscribeToPropertyChangeAsString()`](/api/fair/mq/Plugin/#SubscribeToPropertyChangeAsString), [`UnsubscribeFromPropertyChangeAsString()`](/api/fair/mq/Plugin/#UnsubscribeFromPropertyChangeAsString) | +| Logging | [`CycleLogConsoleSeverityUp()`](/api/fair/mq/Plugin/#CycleLogConsoleSeverityUp), [`CycleLogConsoleSeverityDown()`](/api/fair/mq/Plugin/#CycleLogConsoleSeverityDown), [`CycleLogVerbosityUp()`](/api/fair/mq/Plugin/#CycleLogVerbosityUp), [`CycleLogVerbosityDown()`](/api/fair/mq/Plugin/#CycleLogVerbosityDown) | +| Metadata | [`GetName()`](/api/fair/mq/Plugin/#GetName), [`GetVersion()`](/api/fair/mq/Plugin/#GetVersion), [`GetMaintainer()`](/api/fair/mq/Plugin/#GetMaintainer), [`GetHomepage()`](/api/fair/mq/Plugin/#GetHomepage) | + +The state machine calls the state callback at the start of each new state, in the thread of the state machine. The +device starts the handler of the state after all callbacks return, so keep the callbacks short. A callback for a +property change runs in the thread that changes the property. + +`GetNumberOfConnectedPeers()` exists for tests. The code marks it for removal. + +## The controller role + +Only one plugin at a time can change the state of the device. This plugin is the controller. + +| Function | Effect | +| --- | --- | +| `TakeDeviceControl()` | The plugin becomes the controller, if no plugin has the role. If the plugin has the role, nothing changes. If another plugin has the role, the function throws `PluginServices::DeviceControlError`. | +| `ChangeDeviceState(transition)` | Requests a transition. If no plugin has the role, the plugin takes it first. If another plugin has the role, the function throws `DeviceControlError`. It returns `false` when the device cannot do the transition now. | +| `StealDeviceControl()` | The plugin becomes the controller, also when another plugin has the role. The control plugin uses it after a signal. | +| `ReleaseDeviceControl()` | The plugin gives the role back, if it has the role. | + +`DeviceRunner` waits after the end of the state machine until no plugin has the role. Thus a controller must release +the role, normally in the state `EXITING`. + +The device changes the state when the handler of the current state returns. A requested transition interrupts +blocking transfers, and [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) then returns `true`, so that the +handler can return. See [Device states](/concepts/states/). + +## The config plugin + +The built-in plugin `config` adds the device options, for example `--id`, `--transport`, `--session`, `--rate`, +`--mq-config`, `--channel-config` and the options of the `shmem` transport. At the start of the state +`INITIALIZING DEVICE`, it reads the channel configuration and sets the channel properties: + + + +The key of the device in the configuration is `--config-key`, or `--id` if `--config-key` is not set. `--mq-config` +has priority over `--channel-config`. When the parser fails, the plugin logs the error and the device continues. See +[Configuration and properties](/concepts/configuration/). + +## The control plugin + +The built-in plugin `control` has two options: `--control` (default `dynamic`) and `--catch-signals` (default `1`). +Its constructor takes the controller role, unless `--control` is `none`. If another plugin has the role already, the +control plugin logs the reason at the severity `debug` and starts no controller. Its signal handling does not depend +on the controller role. + +### Control modes + +| `--control` | What the control plugin does | +| --- | --- | +| `dynamic` (default), `interactive`, `external` | It runs the startup sequence. Then it reads keys from the terminal until you press `q`, and runs the shutdown sequence. | +| `static` | It runs the startup sequence. When the device goes back to `READY`, for example because `ConditionalRun()` returns `false`, it runs the shutdown sequence. | +| `gui` | It runs the startup sequence. Then it waits for a signal or for the state `ERROR`. | +| `none` | It does not take the controller role. Another plugin or your code must change the states. | +| Another value | It logs `Unrecognized control mode` at the severity `error` and uses `static`. | + +Use `--control static` in scripts. This mode needs no terminal, and it ends the device when the work in `RUNNING` is +done. The test scripts of the examples use it. + +For the effect of each mode on the end of a run, see +[What the controllers do](/guides/end-of-run/#what-the-controllers-do). + +The startup sequence requests the transitions `INIT DEVICE`, `COMPLETE INIT`, `BIND`, `CONNECT`, `INIT TASK` and +`RUN`. Before each request, the plugin waits for the state that the previous transition gives. At the end, the device +is in `RUNNING`. + +The shutdown sequence starts from the current state and repeats until `EXITING`. Then the plugin releases the +controller role. + +| Current state | Transition | +| --- | --- | +| `RUNNING` | `STOP` | +| `READY` | `RESET TASK` | +| `DEVICE READY`, `BOUND`, `INITIALIZED` | `RESET DEVICE` | +| `INITIALIZING DEVICE` | `COMPLETE INIT` | +| `IDLE` | `END` | + +### Keys of the interactive mode + +In the modes `dynamic`, `interactive` and `external`, a key works without Enter, and the terminal does not show it. + +| Key | Action | +| --- | --- | +| `h` | Print the help and the state machine with the keys. | +| `c` | Log the current state, at the severity `state`. | +| `p` | Log the number of connected peers of each sub-channel. | +| `i` | Request `INIT DEVICE`, wait for `INITIALIZING DEVICE`, then request `COMPLETE INIT`. | +| `b` | Request `BIND`. | +| `x` | Request `CONNECT`. | +| `j` | Request `INIT TASK`. | +| `r` | Request `RUN`. | +| `s` | Request `STOP`. | +| `t` | Request `RESET TASK`. | +| `d` | Request `RESET DEVICE`. | +| `k`, `l` | Move the console severity one step up (fewer lines) or down (more lines). | +| `n`, `m` | Move the log verbosity one step up or down. | +| `q` | Stop reading keys and run the shutdown sequence. | +| Another key | Print `Invalid input: […].` and the help. | + +A key that the current state does not accept changes nothing. The state machine logs +`No transition from state … on transition …` at the severity `state`. + +:::caution[One key at a time] +The plugin reads one key each time new input arrives. When several keys arrive together, for example `cq` from a pipe, +the plugin handles only the first one. It reads the next key only after more input arrives. See the disabled test +`ControlPlugin.DISABLED_SeveralKeysInOneInput` in `test/device/_runner.cxx`. +::: + +### Signals + +With `--catch-signals` greater than 0, the control plugin handles `SIGINT` and `SIGTERM` +([Control.cxx](/source/fairmq/plugins/control/Control.cxx/#L439-L469)): + +1. The first signal starts a graceful shutdown. The plugin logs `Received device shutdown request (signal …)` and + `Waiting for graceful device shutdown. Hit Ctrl-C again to abort immediately.` +2. The plugin stops its controller. +3. If its shutdown sequence has not run yet, the plugin takes the controller role with `StealDeviceControl()`, also + from another plugin. Then it runs the shutdown sequence. +4. A `SIGINT` after an earlier signal ends the process at once with `std::abort()`. A second `SIGTERM` has no effect. + +With `--catch-signals 0`, the plugin logs the warning `Signal handling (e.g. Ctrl-C) has been deactivated.` A signal +then has its default effect, and the device does not run the shutdown sequence. + +### When the device goes to ERROR + +An exception in a hook, or the transition `ERROR FOUND`, moves the device to `ERROR`. No transition leaves this state. + +1. The state machine stops, and [`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine) throws: the exception + of the hook, or [`StateMachine::ErrorStateException`](/api/fair/mq/StateMachine/ErrorStateException/). +2. The control plugin stops its controller. It does not run the shutdown sequence. +3. The `main()` function of `runDevice.h` catches the exception, logs + `Uncaught exception reached the top of main: …` and returns 1. + +[`DeviceRunner::RunWithExceptionHandlers()`](/api/fair/mq/DeviceRunner/#RunWithExceptionHandlers) also returns 1. It +logs `Uncaught exception reached the top of DeviceRunner: …`. The tests in `test/device/_exceptions.cxx` check the exit +code 1 for the modes `static` and `interactive`. + +## Options + + + +## Related pages + +- [Write a plugin](/guides/write-plugin/): make your own plugin and load it with `-P`. +- [Control a device from code](/guides/control-from-code/): a controller plugin, runner hooks, or a device in a thread. +- [Device states](/concepts/states/): the states and transitions that a controller requests. +- [custom-controller](/examples/custom-controller/): an example of a controller plugin. +- [dds](/examples/dds/): a topology that needs a DDS plugin to give the addresses to the connecting channels. +- [Command-line options](/reference/options/): all options of a device. diff --git a/docs/src/content/docs/concepts/states.mdx b/docs/src/content/docs/concepts/states.mdx new file mode 100644 index 00000000..4b11f38e --- /dev/null +++ b/docs/src/content/docs/concepts/states.mdx @@ -0,0 +1,272 @@ +--- +title: 'Device states' +description: 'The state machine of a device: idling and working states, the transitions, the hooks in each state, RUNNING, ERROR and the log lines.' +sidebar: + order: 2 +code: [fairmq/States.h, fairmq/StateMachine.cxx, fairmq/Device.cxx, fairmq/plugins/control/Control.cxx] +--- + +import StateMachine from '../../../components/diagrams/StateMachine.astro'; +import Snippet from '../../../components/Snippet.astro'; + +Each device has a state machine. A controller requests transitions, and the state machine calls the +hooks of your device at fixed points. The state tells you what the device does now and which +transitions it accepts. + + + +## Idling states and working states + +The state machine has two kinds of states: + +- In an **idling state**, the device does no work. It waits until a controller requests the next + transition. The idling states are `IDLE`, `INITIALIZED`, `BOUND`, `DEVICE READY` and `READY`. +- In a **working state**, the device does its work and calls your hooks. At the end, the device + itself requests the next transition. The working states are `INITIALIZING DEVICE`, `BINDING`, + `CONNECTING`, `INITIALIZING TASK`, `RUNNING`, `RESETTING TASK` and `RESETTING DEVICE`. + +Two working states are different. In `INITIALIZING DEVICE`, the device waits for the transition +`CompleteInit` from the controller. `RUNNING` ends with the transition `Stop`, from the controller +or from the device. + +`EXITING` is the final state. The state machine stops there, and the process of the device can end. +`ERROR` is the state after an error, see [The ERROR state](#the-error-state). The enum +[`fair::mq::State`](/api/fair/mq/State/) also has the values `Undefined` and `Ok`. A device does not +enter them. + +## Transitions + +A controller requests a transition with [`ChangeState()`](/api/fair/mq/Device/#ChangeState). The +state machine accepts only these transitions: + +| Transition | From | To | Requested by | +| --- | --- | --- | --- | +| `InitDevice` | `IDLE` | `INITIALIZING DEVICE` | Controller | +| `CompleteInit` | `INITIALIZING DEVICE` | `INITIALIZED` | Controller | +| `Bind` | `INITIALIZED` | `BINDING` | Controller | +| `Connect` | `BOUND` | `CONNECTING` | Controller | +| `InitTask` | `DEVICE READY` | `INITIALIZING TASK` | Controller | +| `Run` | `READY` | `RUNNING` | Controller | +| `Stop` | `RUNNING` | `READY` | Controller, or the device when its work ends | +| `ResetTask` | `READY` | `RESETTING TASK` | Controller | +| `ResetDevice` | `INITIALIZED`, `BOUND`, `DEVICE READY` | `RESETTING DEVICE` | Controller | +| `End` | `IDLE` | `EXITING` | Controller | +| `Auto` | `BINDING`, `CONNECTING`, `INITIALIZING TASK`, `RESETTING TASK`, `RESETTING DEVICE` | `BOUND`, `DEVICE READY`, `READY`, `DEVICE READY`, `IDLE` (in this order) | The device, at the end of the working state | +| `ErrorFound` | All states | `ERROR` | The device after an exception in a hook, or your code | + +These rules apply to all transitions: + +- The state machine accepts one transition at a time. While a transition is pending, `ChangeState()` + refuses all other transitions except `ErrorFound`. +- `ChangeState()` returns `false` for a transition that the current state does not accept. The state + does not change. +- The state machine is cooperative. The next state starts only after the hook of the current state + returns. +- A new transition interrupts the transports of the device. A `Send()` or `Receive()` that waits + then returns `TransferCode::interrupted`. The transports resume when the next state starts. + +For the complete tables, see [States and transitions](/reference/states/). + +## The hooks in each state + +The idling states have no hooks. The working states call these hooks: + +| State | Hooks | What the device does | +| --- | --- | --- | +| `INITIALIZING DEVICE` | [`Init()`](/api/fair/mq/Device/#Init) | It waits for `CompleteInit`. Then it reads the property `id` and calls `Init()`. Then it reads `rate`, `init-timeout` and `transport`, and makes the transports and the channels. | +| `BINDING` | [`Bind()`](/api/fair/mq/Device/#Bind) | It binds all channels with the method `bind`, and calls `Bind()`. If a channel cannot bind, the device throws an exception. | +| `CONNECTING` | [`Connect()`](/api/fair/mq/Device/#Connect) | It connects all channels with the method `connect`, and calls `Connect()`. See [Connect with a delay](#connect-with-a-delay). | +| `INITIALIZING TASK` | [`InitTask()`](/api/fair/mq/Device/#InitTask) | It calls `InitTask()`. | +| `RUNNING` | [`PreRun()`](/api/fair/mq/Device/#PreRun), data callbacks or [`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun) and [`Run()`](/api/fair/mq/Device/#Run), [`PostRun()`](/api/fair/mq/Device/#PostRun) | See [The RUNNING state](#the-running-state). | +| `RESETTING TASK` | [`ResetTask()`](/api/fair/mq/Device/#ResetTask) | It calls `ResetTask()`. | +| `RESETTING DEVICE` | [`Reset()`](/api/fair/mq/Device/#Reset) | It resets and removes its transports, calls `Reset()`, and removes all channels. | + +After the hooks of a working state, the device requests `Auto`. It does not request `Auto` when +another transition is already pending. `INITIALIZING DEVICE` and `RUNNING` do not end with `Auto`. + +### Connect with a delay + +In `CONNECTING`, the device tries to connect each channel. If a channel cannot connect, the device +waits 50 ms. Then it reads the address of the channel from the properties again and tries again. A +controller can thus give the address of a peer later. After `init-timeout` seconds (default 120), +the device throws an exception and goes to `ERROR`. + +## The RUNNING state + +`RUNNING` is the state in which the device processes data. This function of the device runs in +`RUNNING`: + + + +The device does these steps: + +1. It logs `fair::mq::Device running...`. If a channel has the property `rateLogging` larger than 0 + (default 1), the device starts a thread that logs the transfer rates. +2. It calls `PreRun()`. +3. With data callbacks ([`OnData()`](/api/fair/mq/Device/#OnData)), it receives the messages and + calls the callbacks. Without data callbacks, it calls `ConditionalRun()` in a loop, and then + calls `Run()` once. +4. If no transition is pending, the device requests `Stop`. +5. It calls `PostRun()`. Then the next state starts, usually `READY`. + +### ConditionalRun(), Run() or data callbacks + +You choose one of three ways to do the work in `RUNNING`: + +- [`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun): the device calls it again and again. + Return `true` to get the next call. The option `--rate` (default 0) limits the number of calls per + second. A value of 0 means no limit. +- [`Run()`](/api/fair/mq/Device/#Run): the device calls it once. For continuous work, write a loop + that ends when [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) returns `true`. +- Data callbacks: the device calls your callback for each message on a channel. The device does not + call `ConditionalRun()` and `Run()` then. + +[Receive data with callbacks or loops](/guides/receive-data/) compares the three ways. + +### What ends RUNNING + +`RUNNING` ends in one of these cases: + +- A controller requests `Stop`. For example, the key `s` of the interactive controller, or a + `SIGINT` (Ctrl-C) that starts the shutdown sequence. The device does not call `ConditionalRun()` + and the data callbacks again. Your `Run()` loop must check `NewStatePending()`. +- The work ends. A data callback returns `false`, `ConditionalRun()` returns `false`, or `Run()` + returns. Then the device requests `Stop` itself. +- A `Receive()` for a data callback fails, for example after a receive timeout of the channel. Then + the device also requests `Stop`. +- A hook throws an exception. The device goes to `ERROR`. + +To stop a topology without losing messages, see +[Stop a topology without losing messages](/guides/end-of-run/). + +:::caution +The state machine does not stop a hook. If your `Run()` does not return, the device cannot leave +`RUNNING`. +::: + +In `PostRun()`, the transition is already pending. Thus `NewStatePending()` returns `true`, +`WaitFor()` returns at once, and a `Send()` or `Receive()` that waits returns +`TransferCode::interrupted`. Use `PostRun()` to stop the work that you started in `PreRun()`. The +sampler of the example [multiple-transports](/examples/multiple-transports/) starts a thread in +`PreRun()` and joins it in `PostRun()`: + + + + + +To add your own thread without a data race, see [Threads in a device](/concepts/threads/#safe-patterns). + +## The ERROR state + +A device goes to `ERROR` in two cases: + +- A hook throws an exception, in any state. +- Your code requests the transition `ErrorFound`, for example with + `ChangeStateOrThrow(fair::mq::Transition::ErrorFound)`. The state machine accepts `ErrorFound` in + all states, also when another transition is pending. + +No transition leaves `ERROR`. The state machine stops, and +[`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine) throws. It throws the exception of the +hook, or [`StateMachine::ErrorStateException`](/api/fair/mq/StateMachine/ErrorStateException/) with +the text `Device transitioned to error state`. With `fairmq/runDevice.h`, the process then logs +`Uncaught exception reached the top of main:` and ends with the exit code 1. The tests +`Exceptions.Throw` and `ErrorState.ChangeState` in `test/device/` check the exit code 1 for each +hook. + +In `ERROR`, the controller of the control plugin stops. It requests no more transitions and no +shutdown sequence. Thus the device does not call `ResetTask()` and `Reset()` after an error. + +:::caution[Known defect] +In `ERROR`, `ChangeState()` can return `true`, but the state does not change. See the disabled test +`StateMachine.RefusesTransitionsInError` in `test/state_machine/`. +::: + +For the handling of errors, see [Handle errors and timeouts](/guides/errors-timeouts/). + +## Wait for a transition in your code + +Two functions tell a hook that a transition is pending: + +- [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) returns `true` when a transition is + requested and the next state has not started yet. +- [`WaitFor(duration)`](/api/fair/mq/Device/#WaitFor) waits for the duration, or until a transition + is requested. It returns `true` after the full duration, and `false` when a transition ended the + wait. + +A `Run()` loop with a pause of 1 s between two steps can look like this: + +```cpp +void Run() override +{ + while (!NewStatePending()) { + // One step of the work. + if (!WaitFor(std::chrono::seconds(1))) { + break; // A transition is pending. + } + } +} +``` + +In the test `WaitFor.Interrupt`, a device calls `WaitFor()` with 60 s in `PreRun()` or `Run()`. A +`SIGINT` makes the control plugin request `Stop`, and the wait ends. In `PostRun()`, the wait ends +at once, because `Stop` is already pending: + + + +## Log lines + +The state machine logs each state change with the severity `state`. A device under the control +`static` that ends its work by itself logs these lines. The lines show only the message text, +without the prefix of the logger. Other log lines between them are left out. + +```txt +Starting FairMQ state machine --> IDLE +IDLE ---> INITIALIZING DEVICE +INITIALIZING DEVICE ---> INITIALIZED +INITIALIZED ---> BINDING +BINDING ---> BOUND +BOUND ---> CONNECTING +CONNECTING ---> DEVICE READY +DEVICE READY ---> INITIALIZING TASK +INITIALIZING TASK ---> READY +READY ---> RUNNING +fair::mq::Device running... +RUNNING ---> READY +READY ---> RESETTING TASK +RESETTING TASK ---> DEVICE READY +DEVICE READY ---> RESETTING DEVICE +RESETTING DEVICE ---> IDLE +IDLE ---> EXITING +``` + +When the device object is destroyed, the state machine logs `Exiting FairMQ state machine`. Two more +lines tell you that the state machine refused a transition: + +| Log line | Cause | +| --- | --- | +| `No transition from state DEVICE_READY on transition RUN` | The current state does not accept the transition. This line uses the internal names with an underscore. | +| `Transition RUN incoming, but another state transition is already ongoing.` | Another transition is pending. | + +## Control modes in short + +The built-in control plugin requests the transitions. The option `--control` selects its mode: + +| `--control` | What the controller does | +| --- | --- | +| `dynamic` (default), `interactive`, `external` | It requests all transitions up to `RUNNING`. Then it reads keys from the terminal, for example `s` for `Stop`. The key `q` starts the shutdown sequence. | +| `static` | It requests all transitions up to `RUNNING`. When the device leaves `RUNNING`, it requests the transitions down to `EXITING`. | +| `gui` | It requests all transitions up to `RUNNING`. Then it waits for a signal. | +| `none` | The control plugin does not control the device. Another plugin or your code must request the transitions. | + +An unknown value logs an error, and the plugin uses `static`. With `--catch-signals 1` (default), +the first `SIGINT` or `SIGTERM` starts the shutdown sequence. A second `SIGINT` aborts the process. +For the details, see [Plugins and control](/concepts/plugins/). + +## Related pages + +- [States and transitions](/reference/states/): all states, transitions and keys as tables. +- [Devices](/concepts/devices/): the class `fair::mq::Device` and its hooks. +- [Receive data with callbacks or loops](/guides/receive-data/): the three ways to work in `RUNNING`. +- [Handle errors and timeouts](/guides/errors-timeouts/): exceptions, `ERROR` and interrupted + transfers. +- [Control a device from code](/guides/control-from-code/): request transitions from your program. diff --git a/docs/src/content/docs/concepts/threads.mdx b/docs/src/content/docs/concepts/threads.mdx new file mode 100644 index 00000000..ffddb03e --- /dev/null +++ b/docs/src/content/docs/concepts/threads.mdx @@ -0,0 +1,250 @@ +--- +title: Threads in a device +description: The threads of a device process, the thread that runs each hook and callback, and the objects that your own threads can share. +sidebar: + order: 7.5 +code: [fairmq/Device.cxx, fairmq/StateMachine.cxx, fairmq/plugins/control/Control.cxx, fairmq/Channel.h, fairmq/ProgOptions.h] +--- + +import Snippet from '../../../components/Snippet.astro'; + +A device process has more than one thread. FairMQ, its plugins and ZeroMQ start threads, and your +code can add more, for example in `PreRun()`. This page tells you which thread runs each hook and +callback, which objects are thread-safe, and how to add a thread without a data race. + +## The threads of a device process + +A device that starts with `fairmq/runDevice.h` can have these threads: + +| Thread | Started by | When it runs | What it does | +| --- | --- | --- | --- | +| Main thread | The process | Always | Runs `main()` and [`DeviceRunner::Run()`](/api/fair/mq/DeviceRunner/#Run). It creates the plugins and then calls [`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine). This thread is the thread of the state machine. | +| Controller thread | The control plugin | With each value of `--control` except `none` | Requests the transitions. In the mode `dynamic` (default), it also reads the keys of the terminal ([Control.cxx](/source/fairmq/plugins/control/Control.cxx/#L67-L92)). | +| Signal handler thread | The control plugin | With `--catch-signals 1` (default) | Checks every 100 ms for `SIGINT` or `SIGTERM`. After the first signal, it stops the controller thread and requests the transitions of the shutdown sequence ([Control.cxx](/source/fairmq/plugins/control/Control.cxx/#L439-L469)). | +| Rate logger thread | The device | In `RUNNING`, if a sub-channel has `rateLogging` above 0 (default 1) | Runs [`LogSocketRates()`](/api/fair/mq/Device/#LogSocketRates). It ends when a transition is pending. The device joins it after `PostRun()` ([Device.cxx](/source/fairmq/Device.cxx/#L384-L395)). | +| Poll threads | The device | In `RUNNING`, with data callbacks on input channels of more than one transport | One thread for each transport. Each thread polls its channels and calls their data callbacks ([Device.cxx](/source/fairmq/Device.cxx/#L509-L523)). | +| ZeroMQ I/O threads | ZeroMQ | While the transport exists | Each transport, also `shmem`, has one ZeroMQ context with [`--io-threads`](/reference/options/#opt-io-threads) I/O threads (default 1) ([zeromq/TransportFactory.h](/source/fairmq/zeromq/TransportFactory.h/#L39), [shmem/TransportFactory.h](/source/fairmq/shmem/TransportFactory.h/#L72-L74)). ZeroMQ moves the data of the sockets in these threads (ZeroMQ behavior). | +| Heartbeat thread | The shmem transport | While the transport exists | Writes the heartbeat for [`fairmq-shmmonitor`](/shmem/monitor/#what-the-daemon-does) every 100 ms ([shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L637-L647)). | +| Ack threads of a region | The shmem transport | While the region exists | The ack sender sends the released blocks to the creator of the region. The ack receiver of the creator calls the region callback. See [Acknowledgements](/shmem/regions/#acknowledgements). | +| Region event thread | The transport | After [`SubscribeToRegionEvents()`](/api/fair/mq/TransportFactory/#SubscribeToRegionEvents) | Calls the region event callback. See [Region events](/shmem/regions/#region-events). | + +The control plugin does not start a controller thread with `--control none`, or when another plugin +has the controller role. The signal handler thread still runs. The C signal handler itself only counts +the signals and stores the last one. A `SIGINT` after a first signal calls `std::abort()` there. See [Signals](/concepts/plugins/#signals). + +Without `DeviceRunner`, the device has no plugins. Then the thread of the state machine is the thread +that calls `RunStateMachine()`, and your code requests the transitions from another thread. See +[Run the device in a thread](/guides/control-from-code/#run-the-device-in-a-thread). One process can +run several devices in this way. In the test `MultipleDevices.TwoInSameProcess`, two devices run in one +process, each with its own thread for `RunStateMachine()` and its own thread for the transitions. +For the limits, see [Several devices in one process](/guides/control-from-code/#several-devices-in-one-process). + +## Which thread runs your code + +| Your code | Thread | Notes | +| --- | --- | --- | +| The hooks `Init()`, `Bind()`, `Connect()`, `InitTask()`, `PreRun()`, `ConditionalRun()`, `Run()`, `PostRun()`, `ResetTask()`, `Reset()` | The thread of the state machine | One hook at a time. The next state starts only after the hook returns. See [The hooks](/concepts/devices/#the-hooks). | +| Data callbacks of [`OnData()`](/api/fair/mq/Device/#OnData) | The thread of the state machine. With input channels of more than one transport: the poll thread of the transport. | In the poll threads, a mutex lets one callback run at a time ([Device.cxx](/source/fairmq/Device.cxx/#L525-L562)). See [Several input channels](/guides/receive-data/#several-input-channels). | +| State change callbacks: [`SubscribeToStateChange()`](/api/fair/mq/Device/#SubscribeToStateChange), [`SubscribeToDeviceStateChange()`](/api/fair/mq/Plugin/#SubscribeToDeviceStateChange) of a plugin | The thread of the state machine | At the start of each state, before the hooks of the state ([StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L191-L219)). | +| New transition callbacks: [`SubscribeToNewTransition()`](/api/fair/mq/Device/#SubscribeToNewTransition) | The thread that calls `ChangeState()` | The state machine holds its lock while it calls the callback ([StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L257-L260)). | +| Property callbacks: [`Subscribe()`](/api/fair/mq/ProgOptions/#Subscribe), [`SubscribeAsString()`](/api/fair/mq/ProgOptions/#SubscribeAsString), [`SubscribeToPropertyChange()`](/api/fair/mq/Plugin/#SubscribeToPropertyChange) | The thread that changes the property, for example with `SetProperty()` | Before the call returns, after the property store releases its lock ([ProgOptions.h](/source/fairmq/ProgOptions.h/#L268-L279)). | +| Region callbacks: [`RegionCallback`](/api/fair/mq/#RegionCallback), [`RegionBulkCallback`](/api/fair/mq/#RegionBulkCallback) | shmem: the ack receiver thread of the region. zeromq: the thread that makes the region message. | The zeromq transport copies the data and calls the callback at once, in `NewMessage()` ([zeromq/Message.h](/source/fairmq/zeromq/Message.h/#L131-L137)). | +| Region event callbacks | The region event thread of the transport | The shmem transport checks for events every 50 ms. | +| Message free functions ([`FreeFn`](/api/fair/mq/#FreeFn)) | shmem: the thread that makes the message. zeromq: a thread that ZeroMQ selects. | The shmem transport copies the buffer and calls the function at once. ZeroMQ calls it when it releases the buffer, also from its own threads (ZeroMQ behavior). See [Your own buffer](/concepts/messages/#your-own-buffer). | +| Your override of `LogSocketRates()` | The rate logger thread | Only in `RUNNING`. | +| Constructors of plugins, hooks of `DeviceRunner` | The main thread | Before the state machine starts. | + +Some rules follow from this table: + +- A state change callback blocks the device. The device calls the hooks of the state only after all + state callbacks return. For long work, start a thread. See + [A controller with its own thread](/guides/control-from-code/#a-controller-with-its-own-thread). +- Do not call `ChangeState()`, `ChangeStateOrThrow()` or `WaitFor()` in a new transition callback. + These functions lock the mutex that the state machine holds during the callback. +- The device itself subscribes to new transitions. Its callback interrupts the transports, in the + thread that requests the transition. The next state resumes the transports in the thread of the + state machine ([Device.cxx](/source/fairmq/Device.cxx/#L96-L104)). +- A zeromq channel that sends a shmem message wraps the message. The free function of the wrapper + destroys the shmem message ([Channel.h](/source/fairmq/Channel.h/#L421-L438)). Thus the shmem + message can be destroyed in a thread of ZeroMQ. +- Both transports call the region event callback while they hold the lock of the subscription + ([shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L582-L616), + [zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L95-L106)). Do not call + `SubscribeToRegionEvents()` or `UnsubscribeFromRegionEvents()` in the callback. With zeromq, also do + not create or destroy a region and do not call `GetRegionInfo()` there. These functions lock the + same mutex. + +## What is thread-safe + +| Object or function | From several threads at the same time | Source | +| --- | --- | --- | +| [`Channel`](/api/fair/mq/Channel/) and its socket | No. The header says: "The class is not thread-safe." Use each channel from one thread at a time. | [Channel.h](/source/fairmq/Channel.h/#L30-L35) | +| Different channels, also of one transport | Yes. Each thread uses its own channels. | Test `PushPullMultipart.MultiThreaded_ipc` | +| [`GetNumberOfConnectedPeers()`](/api/fair/mq/Channel/#GetNumberOfConnectedPeers) of a channel | Safe for distinct channels, not safe for one shared channel. | [Channel.h](/source/fairmq/Channel.h/#L198-L204) | +| [`Message`](/api/fair/mq/Message/), [`Parts`](/api/fair/mq/Parts/), a [`Poller`](/api/fair/mq/Poller/) | No. These classes have no lock. Give each object to one thread at a time. | [Message.h](/source/fairmq/Message.h/), [Parts.h](/source/fairmq/Parts.h/), [Poller.h](/source/fairmq/Poller.h/) | +| [`ChannelResource`](/api/fair/mq/ChannelResource/) | No. Its map of the allocated messages has no lock. See [Use std::pmr memory resources](/guides/pmr/). | [MemoryResources.h](/source/fairmq/MemoryResources.h/#L54-L98) | +| The property functions of [`ProgOptions`](/api/fair/mq/ProgOptions/), for example `GetProperty()` and `SetProperty()` | Yes. Each function locks a mutex. [`GetVarMap()`](/api/fair/mq/ProgOptions/#GetVarMap) returns a reference, and the lock does not protect it. | [ProgOptions.h](/source/fairmq/ProgOptions.h/#L61-L87) | +| [`ChangeState()`](/api/fair/mq/Device/#ChangeState), [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending), [`WaitFor()`](/api/fair/mq/Device/#WaitFor), [`GetCurrentState()`](/api/fair/mq/Device/#GetCurrentState) | Yes. The state machine uses a mutex and atomic values. | [StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L175-L182), [StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L257-L260) | +| Subscribe and unsubscribe for state changes | Yes. A mutex protects the subscriptions. | [StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L312-L329), test `PluginServices.SubscriptionThreadSafety` | +| [`WaitForState()`](/api/fair/mq/Device/#WaitForState), [`WaitForNextState()`](/api/fair/mq/Device/#WaitForNextState) | Call them from one thread only. The queue of states gives each state to one caller. | [StateQueue.h](/source/fairmq/StateQueue.h/#L31-L35) | +| [`Interrupt()`](/api/fair/mq/TransportFactory/#Interrupt), [`Resume()`](/api/fair/mq/TransportFactory/#Resume) of a transport | Yes. They set an atomic flag. | [zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L149-L150), [shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L283-L284), test `InterruptTransfer.Receive` | +| The byte and message counters of a channel, for example [`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) | Yes. The sockets keep them in atomic values. The rate logger thread reads them. | [zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L399-L402), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L459-L462) | + +The device makes its channels in `INITIALIZING DEVICE`, after `Init()` +([Device.cxx](/source/fairmq/Device.cxx/#L153-L171)). It removes them in `RESETTING DEVICE` +([Device.cxx](/source/fairmq/Device.cxx/#L744)). Between these states, the map of the channels does +not change. Thus several threads can call [`GetChannel()`](/api/fair/mq/Device/#GetChannel), +[`Send()`](/api/fair/mq/Device/#Send) and [`Receive()`](/api/fair/mq/Device/#Receive) of the device, +each for its own channels. Register the data callbacks before `RUNNING`, and add the channels in +`Init()` at the latest. Do both in one thread. + +The test `PushPullMultipart.MultiThreaded_ipc` binds and connects two channels of one transport in +the main thread. Then it sends on one channel and receives on the other, each in its own thread: + + + +:::tip +To find data races, build FairMQ with the CMake option `ENABLE_SANITIZER_THREAD`. The option applies to +FairMQ, its tests and its examples, in the build types `Debug` and `RelWithDebInfo` (default). See +[CMake options and variables](/reference/cmake/). +::: + +## Safe patterns + +### One thread for each channel + +Start your thread in `PreRun()`, and join it in `PostRun()`. Give the thread its own channels, and do +not use these channels in the other threads. The sampler of the example +[multiple-transports](/examples/multiple-transports/) sends on `data1` in `ConditionalRun()`. A second +thread receives the acknowledgements on `ack`: + + + + + + + +This pattern works for these reasons: + +- `PostRun()` runs while the transition is pending. The device interrupted the transports, so the + waiting `Receive()` returns `TransferCode::interrupted`, and the loop ends. +- The next state resumes the transports only after `PostRun()` returns. Thus the thread cannot wait + again before the join. +- The channels exist until `RESETTING DEVICE`. The thread ends before this state. + +### Stop your thread with the state machine + +- Check [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) in the loop of your thread. +- For a pause, call [`WaitFor()`](/api/fair/mq/Device/#WaitFor) and not `std::this_thread::sleep_for()`. + `WaitFor()` returns `false` at once when a transition is requested. See + [Wait for a transition in your code](/concepts/states/#wait-for-a-transition-in-your-code). +- Check the return value of each `Send()` and `Receive()`. A negative value ends the loop. +- Catch the exceptions in the function of your thread. An exception that leaves the function of a + `std::thread` calls `std::terminate()`, and the device does not go to `ERROR`. To report the error, + request the transition `ErrorFound`, for example with + [`ChangeStateOrThrow()`](/api/fair/mq/Device/#ChangeStateOrThrow). The state machine accepts it in + all states. + +### Hand messages over by move + +A [`MessagePtr`](/api/fair/mq/#MessagePtr) is a `std::unique_ptr`. To give a message to +another thread, move it into a queue that a mutex protects. Then only one thread owns the message at a +time. In this device, the data callback puts each message into a queue. A second thread takes the +messages out and sends them on its own channel `out`: + +```cpp +#include + +#include +#include +#include +#include +#include + +struct Forwarder : fair::mq::Device +{ + Forwarder() { OnData("in", &Forwarder::HandleData); } + + bool HandleData(fair::mq::MessagePtr& msg, int /*index*/) + { + { + std::lock_guard lock(fMtx); + fQueue.push_back(std::move(msg)); + } + fCV.notify_one(); + return true; + } + + void PreRun() override { fSender = std::thread(&Forwarder::SendLoop, this); } + + void PostRun() override + { + fSender.join(); + fQueue.clear(); // destroy the messages that were not sent + } + + void SendLoop() + { + while (!NewStatePending()) { + fair::mq::MessagePtr msg; + { + std::unique_lock lock(fMtx); + if (!fCV.wait_for(lock, std::chrono::milliseconds(100), [this] { return !fQueue.empty(); })) { + continue; + } + msg = std::move(fQueue.front()); + fQueue.pop_front(); + } + if (Send(msg, "out") < 0) { + break; + } + } + } + + std::mutex fMtx; + std::condition_variable fCV; + std::deque fQueue; + std::thread fSender; +}; +``` + +- The callback uses the channel `in`, in the thread of the state machine. The second thread uses the + channel `out`. No channel is in two threads. +- After the move, the callback does not use `msg` again. +- `PostRun()` destroys the messages that remain in the queue. Destroy all messages before + `RESETTING DEVICE`, because the device then destroys its transports. + +### Protect the data of callbacks + +A region callback, a property callback and the data callbacks of several transports can run in other +threads than your hooks. Protect the data that they share with a mutex or a `std::atomic`. The readout +device of the example [readout](/examples/readout/) counts the acknowledgements in a +`std::atomic`: + + + +The member is `std::atomic fNumUnackedMsgs`. `ConditionalRun()` increments it after each +successful `Send()`, and the callback decrements it in the ack receiver thread. + +The dispatcher of the example [qc](/examples/qc/) uses a `std::atomic` for a flag that a +property callback sets. See [Follow the changes](/guides/control-from-code/#follow-the-changes). + +## Problems that can occur + +- **The device does not leave `RUNNING`:** your thread waits and `PostRun()` waits in `join()`. Make + the thread check `NewStatePending()`, and use `WaitFor()` for pauses. +- **The process ends with `std::terminate()`:** an exception left the function of a thread, or a data + callback threw in a poll thread. Catch the exceptions in the thread. See + [Receive from channels of different transports](/guides/several-transports/#receive-from-channels-of-different-transports). +- **A crash or wrong data in a transfer:** two threads use one channel. Give each channel to one + thread. +- **`WaitForState()` does not return:** another thread took the state from the queue with + `WaitForState()` or `WaitForNextState()`. Wait for the states in one thread only. + +## Related pages + +- [Device states](/concepts/states/): the state machine and the hooks in each state. +- [Receive data with callbacks or loops](/guides/receive-data/): data callbacks and the poll threads. +- [Use several transports](/guides/several-transports/): channels of two transports in one device. +- [Control a device from code](/guides/control-from-code/): controller threads and callbacks. +- [Unmanaged regions](/shmem/regions/): the ack threads and the region callbacks. diff --git a/docs/src/content/docs/concepts/transports.mdx b/docs/src/content/docs/concepts/transports.mdx new file mode 100644 index 00000000..4ba622a4 --- /dev/null +++ b/docs/src/content/docs/concepts/transports.mdx @@ -0,0 +1,238 @@ +--- +title: 'Transports' +description: 'The zeromq and shmem transports, how a device selects the transport of each channel, and how the two transports differ.' +sidebar: + order: 5 +code: [fairmq/TransportFactory.h, fairmq/TransportFactory.cxx, fairmq/Transports.h, fairmq/Device.cxx, fairmq/zeromq/TransportFactory.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +A transport moves the messages of a channel and allocates their buffers. FairMQ has two transports: +`zeromq` sends the data through sockets, and `shmem` keeps the data in shared memory and sends only +metadata. You select the transport for each channel in the configuration, so the code of your device +does not change. + +## The transports and their names + +Each transport is a subclass of [`fair::mq::TransportFactory`](/api/fair/mq/TransportFactory/). A +transport factory makes the messages, the sockets of the channels, the pollers and the unmanaged +regions of one transport. [`Transports.h`](/source/fairmq/Transports.h/) maps the names to the values +of the enum [`fair::mq::Transport`](/api/fair/mq/Transport/): + +| Name | Enum value | Implementation | Use | +| --- | --- | --- | --- | +| `zeromq` | [`Transport::ZMQ`](/api/fair/mq/Transport/#ZMQ) | `fair::mq::zmq::TransportFactory` in `fairmq/zeromq/` | Data through zeromq sockets, in one process, on one host, or between hosts. | +| `shmem` | [`Transport::SHM`](/api/fair/mq/Transport/#SHM) | [`fair::mq::shmem::TransportFactory`](/api/fair/mq/shmem/TransportFactory/) in `fairmq/shmem/` | Data in shared memory, between processes on one host. | +| `default` | [`Transport::DEFAULT`](/api/fair/mq/Transport/#DEFAULT) | none | Channel property only: the channel uses the default transport of the device. | + +[`TransportName()`](/api/fair/mq/#TransportName) converts an enum value to its name. +[`TransportType()`](/api/fair/mq/#TransportType) converts a name to the enum value and throws +`fair::mq::TransportError` for an unknown name. +[`GetEnabledTransports()`](/api/fair/mq/#GetEnabledTransports) returns `Transport::ZMQ` and +`Transport::SHM`. + +### Make a transport factory + +[`TransportFactory::CreateTransportFactory(type, id, config)`](/api/fair/mq/TransportFactory/#CreateTransportFactory) +returns a `std::shared_ptr`. It accepts the names `zeromq` and `shmem` +([TransportFactory.cxx](/source/fairmq/TransportFactory.cxx/#L34-L47)). For all other names, it +logs an error and throws `fair::mq::TransportFactoryError`. + +- `id` is the id of the factory in the topology. A device gives its device id. If `id` is empty, the + function makes a UUID. +- `config` is a [`fair::mq::ProgOptions`](/api/fair/mq/ProgOptions/) pointer. The factory reads its + properties from it, for example `io-threads`. Without `config`, the factory uses the defaults. + +A device makes its factories itself. You call `CreateTransportFactory()` yourself when you +[use channels without a device](/guides/channels-without-device/). + +## How a device selects the transport + +The device selects the transports in the state `INITIALIZING DEVICE` +([Device.cxx](/source/fairmq/Device.cxx/#L158-L183)): + + + +1. The device reads the property `transport`, which is the option `--transport`. The default is + `zeromq`. This is the default transport of the device. + +2. The device makes the factory of the default transport. + [`Transport()`](/api/fair/mq/Device/#Transport) returns it, and `NewMessage()` uses it. + +3. For each sub-channel, the device reads the channel property `transport`. The default is + `default`, which selects the default transport of the device. + +4. The device gets the factory for the transport of the sub-channel with + [`AddTransport()`](/api/fair/mq/Device/#AddTransport). This function makes a factory only if the + device has no factory of this transport yet. + + + +The result: a device has one factory for each transport that it uses. All channels with the same +transport share this factory, and with it one zeromq context or one shared memory session. Each +factory gets the device id and the configuration of the device. + +An unknown name in `--transport` or in a channel property stops the initialization, and the device +goes to the state `ERROR`. + +The sink of the [multiple-transports example](/examples/multiple-transports/) uses `shmem` as the +default transport and `zeromq` for the channel `ack`: + + + +With `--severity debug`, the sink logs its choices between other debug lines. The block shows these +lines without the prefix of time and severity. The order of the channels can change: + +```txt +Setting 'shmem' as default transport for the device +Adding 'shmem' transport +Initializing transport for channel ack[0]: zeromq +Adding 'zeromq' transport +Initializing transport for channel data1[0]: default +Reusing existing 'shmem' transport +Initializing transport for channel data2[0]: shmem +Reusing existing 'shmem' transport +``` + +### The transports during the life of a device + +On each new transition request, the device calls `Interrupt()` on all its factories. A blocking +`Send()` or `Receive()` then returns `TransferCode::interrupted` within about 100 ms. When the next +state starts, the device calls `Resume()`. In the state `RESETTING DEVICE`, the device calls +`Reset()` on all factories and destroys them with the channels. + +## Compare the transports + +| | `zeromq` | `shmem` | +| --- | --- | --- | +| Data path | The data goes through the zeromq socket. | The data stays in a shared memory segment. A small metadata message goes through a zeromq socket. | +| Copies of the data | For `ipc://` and `tcp://`, the receiver gets its own copy. | None. The receiver reads the buffer that the sender allocated. | +| Peers | One process (`inproc://`), one host (`ipc://`, `tcp://`), or other hosts (`tcp://`). | Processes on one host with the same session. | +| Socket types | `push`, `pull`, `pub`, `sub`, `xpub`, `xsub`, `req`, `rep`, `dealer`, `router`, `pair` | The same, without `pub` and `sub`. | +| Required configuration | None. | The same `--session` on all peers, and a segment that is large enough (`--shm-segment-size`, default 2 GiB). | +| Message from your buffer | No copy. The transport calls your deleter after the transfer. | The transport copies the buffer into the segment and calls your deleter at once. | +| Message from an unmanaged region | The transport copies the block and calls the region callback at once. | No copy. The callback runs when the receiver releases the block. | +| [`Copy()`](/api/fair/mq/Message/#Copy) of a message | The messages share the buffer in one process. | The messages share the buffer through a reference count, also between processes. | +| Clean-up | Nothing to clean up. | The last shmem factory of the session removes the shared memory, unless `--shm-no-cleanup` is `true`. After a crash, use the monitor. | +| Tools | none | [`fairmq-shmmonitor`](/tools/shmmonitor/) | + +An `inproc://` address connects only the channels of one factory: each factory has its own zeromq +context, and ZeroMQ connects `inproc://` endpoints only inside one context. Thus both channels must +be in the same process and use the same factory. + +## The zeromq transport + +The zeromq transport ([`fairmq/zeromq/`](/source/fairmq/zeromq/TransportFactory.h/)) uses the +libzmq library: + +- Each factory has one zeromq context with `--io-threads` I/O threads (default 1). The context + accepts up to 10000 sockets ([zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L37-L56)). +- Each sub-channel has one zeromq socket of its type. The socket identity is + `..`. +- A `sub` socket subscribes to all messages. +- A socket waits for 100 ms at most in each call to libzmq. Between the calls, it checks for an + interruption and for the timeout of the transfer. + +## The shmem transport + +The shmem transport ([`fairmq/shmem/`](/source/fairmq/shmem/TransportFactory.h/)) puts the data of +each message into a managed segment of the session. The segment has a default size of 2 GiB. A send +transfers only the metadata of the message through a zeromq socket: 40 bytes for a single message on +a 64-bit platform, or the value of `--shm-metadata-msg-size` if it is larger. The receiver finds the +same buffer in the segment. The factory has its own zeromq context with `--io-threads` I/O threads. + +The devices that exchange shmem messages must run on one host and use the same `--session` (default +`default`). A `pub` or `sub` socket throws `fair::mq::SocketError`. For the details, see +[How shared memory works](/shmem/how-it-works/) and [Sessions and segments](/shmem/sessions/). All devices of a +session must use compatible FairMQ versions: see [Mixed versions](/project/release-notes/#mixed-versions). + +## Tune the zeromq transport + +The zeromq transport has few settings of its own. Most of the tuning is in the channel properties +and in the selection of the transport. Measure each change with +[Run a benchmark](/guides/benchmark/): give the same options to `fairmq-bsampler` and `fairmq-sink`, +and compare the [rate lines](/guides/benchmark/#read-the-rate-lines). + +### I/O threads + +`--io-threads` sets the number of I/O threads of the zeromq context (`ZMQ_IO_THREADS`, default 1). +In code, [`SetNumIoThreads()`](/api/fair/mq/Device/#SetNumIoThreads) sets the same property. The +factory reads the value one time, when it makes its context in `INITIALIZING DEVICE` +([zeromq/TransportFactory.h](/source/fairmq/zeromq/TransportFactory.h/#L30-L44)). All sockets of +the factory share these threads. + +- ZeroMQ needs at least one I/O thread for `tcp://` and `ipc://`. A program that uses only + `inproc://` can set 0 (ZeroMQ behavior). +- If ZeroMQ refuses the value, the zeromq transport throws `ContextError` with + `failed configuring context, reason: ` + ([zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L37-L56)). The shmem transport only logs the + error. +- The shmem transport uses `--io-threads` for its own context, which sends the metadata. + +If one I/O thread does not move the data of all channels fast enough, try 2 or more threads, and +compare the rates. + +### Number of sockets + +FairMQ sets `ZMQ_MAX_SOCKETS` of each context to 10000 +([zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L45-L48)). The ZeroMQ default is 1023. No +option changes this value. Each FairMQ socket also makes a monitor for +[`GetNumberOfConnectedPeers()`](/api/fair/mq/Device/#GetNumberOfConnectedPeers) +([zeromq/Common.h](/source/fairmq/zeromq/Common.h/#L127-L171)). `zmq_socket_monitor()` makes one +`pair` socket in the context (ZeroMQ behavior), and FairMQ makes a second one that reads the events. +Thus one FairMQ socket uses three ZeroMQ sockets of the context. + +### Queues and kernel buffers + +The channel properties set the buffers of each socket. See +[Channel properties](/reference/channel-properties/#sndbufsize-and-rcvbufsize). + +- `sndBufSize` and `rcvBufSize` (default 1000) limit the number of messages in the queues. ZeroMQ + applies the limit to each peer of the socket (ZeroMQ behavior). With the zeromq transport, a + queue holds the messages with their data: 1000 messages of 1 MB in one queue use 1 GB of memory. + Smaller values limit this memory. A `push` socket then waits earlier for a slow receiver. See + [Behavior of each socket type](/concepts/channels/#behavior-of-each-socket-type). +- `sndKernelSize` and `rcvKernelSize` (default 0, the system default) set the kernel buffers of + the `tcp://` connections in bytes. ZeroMQ does not apply them to `ipc://` connections (ZeroMQ + behavior). See + [`sndKernelSize` and `rcvKernelSize`](/reference/channel-properties/#sndkernelsize-and-rcvkernelsize). + Linux limits the values to `net.core.wmem_max` and `net.core.rmem_max` (Linux behavior). + +To send a large buffer without a copy into the message, make the message from your buffer with a +deleter. See [Your own buffer](/concepts/messages/#your-own-buffer). + +### When to use shmem + +Use the shmem transport for large messages between processes on one host. With `ipc://` or +`tcp://`, the zeromq transport moves each byte through the kernel, and the receiver gets its own +copy. The shmem transport sends only the metadata, and the receiver reads the buffer of the sender. + +- The saved copy grows with the size of the message. The cost of each transfer stays: the shmem + transport also sends one ZeroMQ message for each transfer, and it allocates the buffer in the + segment. Measure both transports with the message sizes of your application. +- The shmem transport needs the same session on all peers and a segment that holds all messages + in flight. See [Tune and debug](/shmem/tuning/). +- Between hosts, and for `pub` and `sub`, use the zeromq transport. + +A device can use both transports: shmem for the channels on the host, zeromq for the others. See +[Use several transports](/guides/several-transports/). + +## The removed ofi transport + +FairMQ v1.5.0 removed the experimental `ofi` transport. No transport replaces it. The name `ofi` is +an unknown transport now: `CreateTransportFactory("ofi")` throws `TransportFactoryError`, and a +device with `--transport ofi` goes to the state `ERROR`. `Channel::Validate()` still accepts the +`verbs://` addresses of the `ofi` transport, but the zeromq and shmem transports cannot bind or +connect to them. Use `zeromq` with `tcp://` for transfers between hosts. + +## Related pages + +- [Messages and multipart](/concepts/messages/): what a transport does with your buffers. +- [Use several transports](/guides/several-transports/): one device with zeromq and shmem channels. +- [How shared memory works](/shmem/how-it-works/): the shmem transport in detail. +- [Use channels without a device](/guides/channels-without-device/): make a transport factory in your own program. +- [Command-line options](/reference/options/): `--transport`, `--io-threads` and the `--shm-*` options. +- [Run a benchmark](/guides/benchmark/): measure the two transports and the effect of the settings. +- [Use std::pmr memory resources](/guides/pmr/): fill a container in the message memory of a transport. diff --git a/docs/src/content/docs/examples/1-1.mdx b/docs/src/content/docs/examples/1-1.mdx new file mode 100644 index 00000000..955ad393 --- /dev/null +++ b/docs/src/content/docs/examples/1-1.mdx @@ -0,0 +1,240 @@ +--- +title: '1-1: sampler and sink' +description: 'Two devices: a sampler sends a text message on a push channel, and a sink receives it on a pull channel.' +sidebar: + order: 1 +code: [fairmq/Device.h, fairmq/runDevice.h, fairmq/Message.h, fairmq/ProgOptions.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The 1-1 example has two [devices](/concepts/devices/): a sampler that sends a text message and a sink that +receives it. It shows the minimum code of a device: a class that derives from +[`fair::mq::Device`](/api/fair/mq/Device/), its hooks, one [channel](/concepts/channels/), and the +`main()` function of `fairmq/runDevice.h`. + +The files of the example are in +[`examples/1-1`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/1-1) on GitHub. + +## Topology + +The devices connect through one channel with the name `data`. The sampler binds a `push` socket, and the +sink connects a `pull` socket to it. + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data` | `push` | `bind` | `tcp://*:5555` | +| `sink1` | `data` | `pull` | `connect` | `tcp://localhost:5555` | + +The start script sets `rateLogging=0` on both channels, so the devices do not log the transfer rates. It +also starts the sampler with `--rate 1`, so the sampler sends one message per second. + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON`. `ON` is the +default (see [Install](/start/install/)). The build puts these files into the build directory of the +example: + + + +- build/examples/1-1/ + - fairmq-ex-1-1-sampler the sampler, from sampler.cxx + - fairmq-ex-1-1-sink the sink, from sink.cxx + - fairmq-start-ex-1-1.sh the start script + - test-ex-1-1.sh the test script + + + +The install step copies the two executables and the start script to `/bin/`. The installed start +script calls the installed executables. + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/1-1 + ``` + +2. Run the start script: + + ```sh + ./fairmq-start-ex-1-1.sh + ``` + + + +The script opens one `xterm` window for each device. The windows stay open after a device stops +(`xterm -hold`). The script also sets the environment variable `FAIRMQ_PATH` to `/fairmq`. A device +with `--transport shmem` and `--shm-monitor true` uses this path to find `fairmq-shmmonitor`. + +If you do not use `xterm`, open two terminals in `build/examples/1-1`. Run one command of the script in +each terminal: + +```sh +./fairmq-ex-1-1-sampler --id sampler1 --rate 1 \ + --channel-config "name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0" +``` + +```sh +./fairmq-ex-1-1-sink --id sink1 \ + --channel-config "name=data,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0" +``` + +- `--id` sets the ID of the device. +- `--channel-config` configures one channel with a list of `key=value` pairs. The + [channel properties](/reference/channel-properties/) page lists all keys. +- `--rate` sets the maximum number of `ConditionalRun()` calls per second. The default `0` sets no limit. + +You can start the two devices in any order. Each device goes through its [states](/concepts/states/) to +`RUNNING` without input. Then the default controller (`--control dynamic`) reads keys in the terminal. +Push `q` to stop the device and end the process. Push `h` to see all keys. Ctrl-C also stops the device. + +## The sampler + +The sampler is a `struct` that derives from `fair::mq::Device`. It overrides two hooks and has three +members: `fText`, `fMaxIterations` and `fNumIterations` +([sampler.cxx](https://github.com/FairRootGroup/FairMQ/blob/dev/examples/1-1/sampler.cxx#L16-L57)). + + + +The device calls [`InitTask()`](/api/fair/mq/Device/#InitTask) in the state `INITIALIZING TASK`. The +sampler reads its two custom options there. [`fConfig`](/api/fair/mq/Device/#fConfig) points to the +configuration of the device. [`GetProperty()`](/api/fair/mq/ProgOptions/#GetProperty) returns the value +of an option as the type `T`. + + + +In the state `RUNNING`, the device calls [`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun) again +while the function returns `true` ([Device.cxx](/source/fairmq/Device.cxx/#L412-L427)): + +- [`NewMessage()`](/api/fair/mq/Device/#NewMessage) with a buffer, a size, a free function and a hint + creates a message for an existing buffer. Here the buffer is a new `std::string`, and the free function + deletes it. +- The `zeromq` transport sends the buffer without a copy and calls the free function after the transfer. + The `shmem` transport copies the buffer into shared memory and calls the free function at once. +- [`Send()`](/api/fair/mq/Device/#Send) sends the message on the sub-channel 0 of the channel `data`. It + returns the number of bytes, or a negative [transfer code](/reference/transfer-codes/). +- `LOG(info)` writes a log line with the severity `info` (see [Logging](/tools/logging/)). +- The return value `false` ends the state `RUNNING`, and the device goes to `READY`. The sampler returns + `false` if `Send()` fails or if it reaches `--max-iterations`. + + + + + +The header `fairmq/runDevice.h` contains the `main()` function of the executable. `main()` calls two +functions that your source file must define ([runDevice.h](/source/fairmq/runDevice.h/#L13-L17)): + +- `addCustomOptions()` adds the options of the device to the command line. The sampler adds `--text` + (default `Hello`) and `--max-iterations` (default `0`, no limit). `bpo` is an alias of the namespace + `boost::program_options`. +- `getDevice()` creates the device. + +## The sink + + + +The sink has no `ConditionalRun()`. Its constructor registers the member function `HandleData()` for the +channel `data` with [`OnData()`](/api/fair/mq/Device/#OnData). In the state `RUNNING`, the device receives +the messages of the channel and calls the handler for each message. A device with data handlers does not +call `ConditionalRun()` or `Run()`, and `--rate` has no effect on it +([Device.cxx](/source/fairmq/Device.cxx/#L404-L411)). + + + +The handler gets the message and the index of the sub-channel. +[`GetData()`](/api/fair/mq/Message/#GetData) returns a pointer to the data, and +[`GetSize()`](/api/fair/mq/Message/#GetSize) returns the size in bytes. The handler returns `true` to get +the next message, or `false` to end the state `RUNNING`. The sink also has the option `--max-iterations`. + +## Output + +The listings show the severity and the message of each line. The real lines also have a time at the +start; the option `--verbosity` sets this prefix. Before these lines, each device logs the FairMQ logo and +its states from `IDLE` to `READY`. The interactive controller also prints its list of keys. + +The sampler sends one message per second: + +```txt +[STATE] READY ---> RUNNING +[INFO] fair::mq::Device running... +[INFO] Sending "Hello" +[INFO] Sending "Hello" +[INFO] Sending "Hello" +``` + +The sink logs each message that it receives: + +```txt +[STATE] READY ---> RUNNING +[INFO] fair::mq::Device running... +[INFO] Received: "Hello" +[INFO] Received: "Hello" +[INFO] Received: "Hello" +``` + +With `--max-iterations 3`, each device logs these lines after the third message: + +```txt +[INFO] Configured maximum number of iterations reached. Leaving RUNNING state. +[STATE] RUNNING ---> READY +``` + +## Test the example + +The test script `test-ex-1-1.sh` starts the two devices in the background, in one terminal. Among others, +it adds these options to the commands of the start script: + +| Option | Value in the test | Effect | +| --- | --- | --- | +| `--transport` | the first argument of the script, default `zeromq` | The transport of the devices. | +| `--session` | the output of [`fairmq-uuid-gen -h`](/reference/tools/#fairmq-uuid-gen) | A new session for each run. | +| `--control` | `static` | The process ends when the device leaves `RUNNING`. | +| `--max-iterations` | `1` | Each device stops after one message. | +| `--shm-segment-size` | `100000000` | A 100 MB shared memory segment. | +| `--shm-monitor` | `true` | With `shmem`, starts [`fairmq-shmmonitor`](/tools/shmmonitor/) as a daemon. | + +The test uses an `ipc://` address instead of TCP: `ipc:///tmp/fmq__data_`. At the end, +the script deletes this file. + +CTest runs the script once for each transport. The tests are `Example.1-1.zeromq` and `Example.1-1.shmem`, +each with a timeout of 30 s. CTest has these tests only if you configure with `-DBUILD_TESTING=ON`. The +default is `OFF`. + +```sh +cmake -S FairMQ -B build -DBUILD_TESTING=ON +cmake --build build +cd build +ctest -R '^Example\.1-1\.' --output-on-failure +``` + +You can also run the script directly, for example `./test-ex-1-1.sh shmem` in `build/examples/1-1`. +To write a test of this type for your own devices, see [Test your devices](/guides/test-devices/). To add +an example with its test to FairMQ, see [Add an example](/project/contributing/#add-an-example). + +## Things to try + +- Use shared memory: add `--transport shmem` to both commands. Both devices must use the same session. If + you do not set `--session`, both use the session `default`. +- Change the rate: start the sampler with `--rate 10`. Without `--rate`, the sampler sends as fast as it + can. +- Send another text: start the sampler with `--text "Hello FairMQ"`. +- Stop after five messages: add `--max-iterations 5` to both commands. Also add `--control static` to end + the processes when the devices leave `RUNNING`. To check that no message is lost, see + [Check that no message is lost](/guides/end-of-run/#check-that-no-message-is-lost). +- Show the transfer rates: set `rateLogging=1` in both channel configurations. Each second, the device + logs the messages per second and the MB per second of the channel. +- Swap bind and connect: the sink binds `tcp://*:5555`, and the sampler connects to `tcp://localhost:5555`. +- Show all options of a device, with the custom options: run it with `--help`. + +## Related pages + +- [Your first device](/start/first-device/): write and build a device like this one. +- [Device states](/concepts/states/): the states that the devices go through. +- [Channels and sockets](/concepts/channels/): socket types and methods. +- [Receive data with callbacks or loops](/guides/receive-data/): `OnData()` compared to `ConditionalRun()`. +- [1-n-1: sampler, processors and sink](/examples/1-n-1/): the next example. diff --git a/docs/src/content/docs/examples/1-n-1.mdx b/docs/src/content/docs/examples/1-n-1.mdx new file mode 100644 index 00000000..e7a27bda --- /dev/null +++ b/docs/src/content/docs/examples/1-n-1.mdx @@ -0,0 +1,181 @@ +--- +title: '1-n-1: sampler, processors and sink' +description: 'A sampler sends messages to several processors, and the processors send the results to one sink. A JSON file configures the channels.' +sidebar: + order: 2 +code: [fairmq/Device.h, fairmq/JSONParser.cxx, fairmq/plugins/config/Config.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The 1-n-1 example puts processors between a sampler and a sink. The sampler distributes its messages over +the processors, each processor changes the text, and the sink collects the results. A JSON file configures +the channels of all devices, and the two processors share one entry of this file. + +The files of the example are in +[`examples/1-n-1`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/1-n-1) on GitHub. + +## Topology + +The topology comes from the file `ex-1-n-1.json`: + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data1` | `push` | `bind` | `tcp://*:5555` | +| `processor1`, `processor2` | `data1` | `pull` | `connect` | `tcp://localhost:5555` | +| `processor1`, `processor2` | `data2` | `push` | `connect` | `tcp://localhost:5556` | +| `sink1` | `data2` | `pull` | `bind` | `tcp://*:5556` | + +All sockets have `sndBufSize` 1000, `rcvBufSize` 1000 and `rateLogging` 0. The sampler and the sink bind, +and the processors connect. Thus all processors have the same configuration, and you can add processors +at any time. The `push` socket of the sampler sends each message to one connected processor, in turn +(round-robin). The `pull` socket of the sink receives from all processors. + +## The JSON file + +The file has one entry for each device in `fairMQOptions.devices`. This is the entry of the processors: + + + +A device uses the entry whose `id` is equal to its `--id`. With `--config-key processor`, the device uses +the entry with `"key": "processor"` instead ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L29-L33), +[JSONParser.cxx](/source/fairmq/JSONParser.cxx/#L69)). Thus `processor1` and `processor2` have different +IDs, but the same channels. The [JSON configuration](/reference/json/) page describes the format. + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON` (the default). The +build copies the JSON file to the build directory of the example: + + + +- build/examples/1-n-1/ + - fairmq-ex-1-n-1-sampler + - fairmq-ex-1-n-1-processor + - fairmq-ex-1-n-1-sink + - ex-1-n-1.json + - fairmq-start-ex-1-n-1.sh + - test-ex-1-n-1.sh + + + +The install step copies the JSON file to `/share/fairmq/`. The installed start script uses this +copy. + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/1-n-1 + ``` + +2. Run the start script. It opens four `xterm` windows, one for each device: + + ```sh + ./fairmq-start-ex-1-n-1.sh + ``` + + + +To run the example without `xterm`, run each command in its own terminal in `build/examples/1-n-1`: + +```sh +./fairmq-ex-1-n-1-sampler --id sampler1 --mq-config ex-1-n-1.json +./fairmq-ex-1-n-1-processor --id processor1 --mq-config ex-1-n-1.json --config-key processor +./fairmq-ex-1-n-1-processor --id processor2 --mq-config ex-1-n-1.json --config-key processor +./fairmq-ex-1-n-1-sink --id sink1 --mq-config ex-1-n-1.json +``` + +Push `q` in a terminal to stop the device in it. + +## The code + + + +[`NewStaticMessage()`](/api/fair/mq/Device/#NewStaticMessage) creates a message for the data of `fText` +and does not delete the data after the transfer. The `zeromq` transport does not copy the data, so the data +must stay valid until the transfer is complete. `fText` is a member of the device, so it stays valid. The +`shmem` transport copies the data into shared memory when it creates the message +([shmem/Message.h](/source/fairmq/shmem/Message.h/#L64-L78)). After each message, the sampler waits 1 s. + + + + + +The processor registers `HandleData()` for the channel `data1` with +[`OnData()`](/api/fair/mq/Device/#OnData). For each message, it copies the text into a new string and adds +its device ID [`fId`](/api/fair/mq/Device/#fId). Then it sends the new message on `data2`. The processor has +no custom options, so it runs until you stop it. + +The sink is the sink of the [1-1 example](/examples/1-1/#the-sink), with the channel `data2`. + +## Output + +The listings show the severity and the message of each line, without the time. + +The sampler logs `Sending "Hello"` once per second. Each processor logs one line for each message that it +gets: + +```txt +[INFO] Received data, processing... +``` + +The sink gets the messages of both processors: + +```txt +[INFO] Received: "Hello (modified by processor1)" +[INFO] Received: "Hello (modified by processor2)" +[INFO] Received: "Hello (modified by processor1)" +``` + +## Test the example + +The test script `test-ex-1-n-1.sh` configures the channels with `--channel-config` instead of the JSON file. +It uses `ipc://` addresses in `/tmp`, a new session, and `--control static`. The sampler and the sink stop +after two messages (`--max-iterations 2`). The processors have no such option, so the script stops them +with `SIGINT` after the sampler and the sink end. + +CTest runs the script once for each transport: `Example.1-n-1.zeromq` and `Example.1-n-1.shmem`. The tests +exist if you configure with `-DBUILD_TESTING=ON`. + +```sh +cd build +ctest -R '^Example\.1-n-1\.' --output-on-failure +``` + +## Things to try + +- Add a processor while the other devices run. The sampler then distributes the messages over three + processors: + + ```sh + ./fairmq-ex-1-n-1-processor --id processor3 --mq-config ex-1-n-1.json --config-key processor + ``` + +- Configure a processor without the JSON file, as the test script does. One `--channel-config` option takes + one value for each channel: + + ```sh + ./fairmq-ex-1-n-1-processor --id processor3 \ + --channel-config "name=data1,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0" \ + "name=data2,type=push,method=connect,address=tcp://localhost:5556,rateLogging=0" + ``` + + If you give `--mq-config` and `--channel-config` together, the device uses only `--mq-config` + ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L37-L45)). + +- Send another text: start the sampler with `--text "Hi"`. +- Use shared memory: add `--transport shmem` to all four commands. +- Stop after four messages: add `--max-iterations 4` to the commands of the sampler and the sink. + +## Related pages + +- [JSON configuration](/reference/json/): all keys of the JSON file. +- [Configure channels](/guides/configure-channels/): `--channel-config`, `--mq-config` and code. +- [Channels and sockets](/concepts/channels/): how `push` and `pull` distribute messages. +- [1-1: sampler and sink](/examples/1-1/): the code of the sampler and the sink in detail. +- [Design a topology](/guides/design-topology/#fan-out-and-fan-in): fan-out and fan-in with `push` and `pull`. diff --git a/docs/src/content/docs/examples/builtin-devices.mdx b/docs/src/content/docs/examples/builtin-devices.mdx new file mode 100644 index 00000000..bbb08d99 --- /dev/null +++ b/docs/src/content/docs/examples/builtin-devices.mdx @@ -0,0 +1,150 @@ +--- +title: 'builtin-devices: a topology of built-in devices' +description: 'The built-in devices fairmq-bsampler, fairmq-splitter, fairmq-proxy, fairmq-merger, fairmq-multiplier and fairmq-sink in one topology, without own code.' +sidebar: + order: 10 +code: [fairmq/devices/BenchmarkSampler.h, fairmq/devices/Splitter.h, fairmq/devices/Merger.h, fairmq/devices/Multiplier.h, fairmq/devices/Sink.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree } from '@astrojs/starlight/components'; + +This example has no own code. Its start script connects the [built-in devices](/tools/builtin-devices/) of FairMQ into one topology. The messages go from a benchmark sampler through a splitter, two proxies, a merger and a multiplier to a sink. + +The code is in [`examples/builtin-devices`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/builtin-devices). The example shows how to: + +- configure the built-in devices with command-line options only, +- distribute messages over the [sub-channels](/concepts/channels/) of a channel (splitter), +- collect messages from all sub-channels of a channel (merger), +- send each message to all sub-channels of a channel (multiplier), +- transfer single messages or [multipart messages](/concepts/messages/) with `--multipart`. + +## Topology + +All channels have `sndBufSize=50` and `rcvBufSize=50`. A channel with two addresses has two sub-channels. + +| Device | Executable | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | --- | +| `bsampler1` | `fairmq-bsampler` | `data1` | `push` | `bind` | `tcp://localhost:5555` | +| `splitter` | `fairmq-splitter` | `data1` | `pull` | `connect` | `tcp://localhost:5555` | +| | | `data2` | `push` | `bind` | `tcp://localhost:5556`, `tcp://localhost:5557` | +| `proxy1` | `fairmq-proxy` | `data2` | `pull` | `connect` | `tcp://localhost:5556` | +| | | `data3` | `push` | `connect` | `tcp://localhost:5558` | +| `proxy2` | `fairmq-proxy` | `data2` | `pull` | `connect` | `tcp://localhost:5557` | +| | | `data3` | `push` | `connect` | `tcp://localhost:5559` | +| `merger` | `fairmq-merger` | `data3` | `pull` | `bind` | `tcp://localhost:5558`, `tcp://localhost:5559` | +| | | `data4` | `push` | `connect` | `tcp://localhost:5560` | +| `multiplier` | `fairmq-multiplier` | `data4` | `pull` | `bind` | `tcp://localhost:5560` | +| | | `data5` | `push` | `connect` | `tcp://localhost:5561`, `tcp://localhost:5561` | +| `sink1` | `fairmq-sink` | `data5` | `pull` | `bind` | `tcp://localhost:5561` | + +Each device gets the names of its channels with `--in-channel` and `--out-channel`. Both sub-channels of `data5` connect to the same sink. Thus the sink receives each message two times. + +The sampler sends messages of 100000 bytes, at most 100 messages per second (`--msg-size 100000`, `--msg-rate 100`). The sampler and the sink run without a limit (`--max-iterations 0`). + +## Requirements + +The start script opens one `xterm` window for each device. `xterm` must be installed. + +## Build and run + +The built-in devices are part of the FairMQ build. The example adds only the scripts. The start script uses the executables in `build/fairmq`: + + + +- build/ + - fairmq/ + - fairmq-bsampler + - fairmq-splitter + - fairmq-proxy + - fairmq-merger + - fairmq-multiplier + - fairmq-sink + - examples/builtin-devices/ + - fairmq-start-ex-builtin-devices.sh + - test-ex-builtin-devices.sh + + + +The start script takes three optional arguments: the transport (default `zeromq`), `true` or `false` for `--multipart` (default `false`), and the number of parts (default `1`). + +```sh +cd build/examples/builtin-devices +./fairmq-start-ex-builtin-devices.sh +./fairmq-start-ex-builtin-devices.sh shmem true 4 +``` + +The sampler uses `--control interactive`. The other devices use the default `--control dynamic`, which is the same interactive controller. Type `q` in the window of a device to end it. Type `h` to see all keys. + +## The code + +The code of the devices is in `fairmq/devices/`. This section shows the parts that move the messages. + +### Configure a device + +The start script builds the command line of each device. The splitter gets its input and output channels by name. Its output channel has two addresses: + + + +### Splitter: one sub-channel after the other + +The splitter ([`Splitter.h`](/source/fairmq/devices/Splitter.h/)) registers `HandleData()` with [`OnData()`](/api/fair/mq/Device/#OnData) for its input channel. Each call sends the payload to the next sub-channel of the output channel: + + + +### Merger: poll all sub-channels + +The merger makes a poller for all sub-channels of its input channel. In each loop, it waits up to 100 ms for data. Then it forwards the data from each sub-channel that has input. See [`Merger.h`](/source/fairmq/devices/Merger.h/#L44-L101) and [Poll several channels](/guides/poll-channels/). + +### Multiplier: copy to all outputs + +The multiplier ([`Multiplier.h`](/source/fairmq/devices/Multiplier.h/)) sends a copy to each sub-channel of each output channel. It sends the original message to the last sub-channel of the last output channel: + + + +[`Copy()`](/api/fair/mq/Message/#Copy) shares the data of the message and does not duplicate it. For multipart messages, `HandleMultipartData()` copies each part in the same way. + +## Output + +The sampler logs when it starts and when `RUNNING` ends: + +```txt +Starting the benchmark with message size of 100000 and 0 iterations. +Done iterations in ms. +``` + +The sink logs the same two points: + +```txt +Starting sink and expecting to receive 0 messages. +Received messages in ms. +Leaving RUNNING state. +``` + +The proxies and the merger log `Transfer interrupted` on the severity `debug` when a transfer is interrupted, for example at a state change. The start script sets `--severity debug` only for the sampler and the sink. + +## Test + +`examples/builtin-devices/CMakeLists.txt` adds four tests: `Example.builtin-devices.single_msg.zeromq`, `Example.builtin-devices.multipart.zeromq`, `Example.builtin-devices.single_msg.shmem` and `Example.builtin-devices.multipart.shmem`. Each test runs `test-ex-builtin-devices.sh` with the transport and the variant as arguments. The timeout is 30 s. + +The test script uses `ipc://` addresses, `--control static` and `--msg-rate 1`. The variant `multipart` sets `--multipart true` and sends two parts. The sink stops at `--max-iterations 2`. Then the script stops the other devices with `SIGINT`. + +Configure with `-DBUILD_TESTING=ON` to register the tests. Then run them in the build directory: + +```sh +ctest -R Example.builtin-devices +``` + +## Things to try + +- Write the received data to a file. Add `--out-filename /tmp/sink.bin` to the sink. The sink stops after `--max-file-size` bytes (default 2000000000). +- Remove one of the two addresses of `data5` in the multiplier. Then the sink receives each message once. +- Send more data. Raise `--msg-rate` or set it to `0` (no limit). +- Use the script `startMQBenchmark.sh` in `build/fairmq` for a benchmark with a sampler and a sink. See [Run a benchmark](/guides/benchmark/). + +## Related pages + +- [Built-in devices](/tools/builtin-devices/): all options of each device. +- [Channels and sockets](/concepts/channels/) +- [Poll several channels](/guides/poll-channels/) +- [Messages and multipart](/concepts/messages/) diff --git a/docs/src/content/docs/examples/copypush.mdx b/docs/src/content/docs/examples/copypush.mdx new file mode 100644 index 00000000..f5abffe6 --- /dev/null +++ b/docs/src/content/docs/examples/copypush.mdx @@ -0,0 +1,159 @@ +--- +title: 'copypush: one message to several receivers' +description: 'A sampler sends the same data to two sinks. It makes a copy of each message for each sub-channel of a push channel.' +sidebar: + order: 5 +code: [fairmq/Message.h, fairmq/Device.h, fairmq/SuboptParser.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The copypush example sends the same data to several receivers. The sampler has one channel with two +[sub-channels](/concepts/channels/), and it sends one copy of each message on each sub-channel. +[`Copy()`](/api/fair/mq/Message/#Copy) makes the copy without a copy of the data. + +The files of the example are in +[`examples/copypush`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/copypush) on GitHub. + +## Topology + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data[0]` | `push` | `bind` | `tcp://*:5555` | +| `sampler1` | `data[1]` | `push` | `bind` | `tcp://*:5556` | +| `sink1` | `data` | `pull` | `connect` | `tcp://localhost:5555` | +| `sink2` | `data` | `pull` | `connect` | `tcp://localhost:5556` | + +The channel configuration of the sampler has two `address` keys. Each `address` key makes one sub-channel, +and the sub-channels share the other keys ([SuboptParser.cxx](/source/fairmq/SuboptParser.cxx/#L105-L108)). +Each sub-channel has its own socket, and one sink connects to it. + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON` (the default): + + + +- build/examples/copypush/ + - fairmq-ex-copypush-sampler + - fairmq-ex-copypush-sink + - fairmq-start-ex-copypush.sh + - test-ex-copypush.sh + + + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/copypush + ``` + +2. Run the start script. It opens three `xterm` windows, one for each device: + + ```sh + ./fairmq-start-ex-copypush.sh + ``` + + + +To run the example without `xterm`, run each command in its own terminal in `build/examples/copypush`: + +```sh +./fairmq-ex-copypush-sampler --id sampler1 \ + --channel-config "name=data,type=push,method=bind,rateLogging=0,address=tcp://*:5555,address=tcp://*:5556" +``` + +```sh +./fairmq-ex-copypush-sink --id sink1 \ + --channel-config "name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5555" +``` + +```sh +./fairmq-ex-copypush-sink --id sink2 \ + --channel-config "name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5556" +``` + +## The sampler + + + +[`GetNumSubChannels()`](/api/fair/mq/Device/#GetNumSubChannels) returns the number of sub-channels of a +channel. Here it is 2. + + + +- [`NewSimpleMessage()`](/api/fair/mq/Device/#NewSimpleMessage) creates a message with a copy of the + counter, a `uint64_t`. +- For each sub-channel except the last, the sampler creates an empty message with + [`NewMessage()`](/api/fair/mq/Device/#NewMessage). [`Copy()`](/api/fair/mq/Message/#Copy) makes it a copy + of `msg`. +- The third argument of [`Send()`](/api/fair/mq/Device/#Send) is the index of the sub-channel. The original + message goes to the last sub-channel. +- After each round, the sampler waits 1 s. + +`Copy()` does not copy the data in the sampler. The `zeromq` transport shares the buffer between the two +messages (`zmq_msg_copy()`). The `shmem` transport increments a reference count of the buffer in shared +memory. Do not change the data of a message after a `Copy()`. + +## The sink + + + +The sink registers `HandleData()` for the channel `data` with [`OnData()`](/api/fair/mq/Device/#OnData). +The handler reads the counter from the data of the message. Both sinks run the same executable with +different IDs and addresses. + +## Output + +The listings show the severity and the message of each line, without the time. The sampler logs no line +for each message. Each sink logs every counter value, once per second: + +```txt +[INFO] Received message: "0" +[INFO] Received message: "1" +[INFO] Received message: "2" +``` + +`sink1` and `sink2` get the same values. + +## Push sub-channels compared to pub and sub + +A `pub` socket also sends each message to all receivers. But the `shmem` transport does not support the +socket types `pub` and `sub` ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L59-L62)). With one `push` +sub-channel for each sink, the example runs with both transports. You need one sub-channel, thus one +socket and one address, for each receiver. + +## Test the example + +The test script `test-ex-copypush.sh` starts the sampler and the two sinks with two `ipc://` addresses in +`/tmp`, a new session and `--control static`. All three devices stop after one message +(`--max-iterations 1`). + +CTest runs the script once for each transport: `Example.copypush.zeromq` and `Example.copypush.shmem`. The +tests exist if you configure with `-DBUILD_TESTING=ON`. + +```sh +cd build +ctest -R '^Example\.copypush\.' --output-on-failure +``` + +## Things to try + +- Add a third sink. Add `address=tcp://*:5557` to the channel configuration of the sampler. Then start a + sink with `--id sink3` and `address=tcp://localhost:5557`. `GetNumSubChannels()` returns 3, and the + sampler sends to all three sinks. +- Use shared memory: add `--transport shmem` to all three commands. +- Stop after three messages: add `--max-iterations 3` to all three commands. + +## Related pages + +- [Messages and multipart](/concepts/messages/): message ownership and `Copy()`. +- [Channels and sockets](/concepts/channels/): channels, sub-channels and socket types. +- [1-n-1: sampler, processors and sink](/examples/1-n-1/): distribute messages instead of copying them. +- [multiple-channels: data and broadcast](/examples/multiple-channels/): a `pub` and `sub` channel. +- [Design a topology](/guides/design-topology/#fan-out-and-fan-in): distribute or copy messages to several receivers. diff --git a/docs/src/content/docs/examples/custom-controller.mdx b/docs/src/content/docs/examples/custom-controller.mdx new file mode 100644 index 00000000..ff972c92 --- /dev/null +++ b/docs/src/content/docs/examples/custom-controller.mdx @@ -0,0 +1,156 @@ +--- +title: 'custom-controller: control from code' +description: 'A controller plugin, compiled into the program, moves a device through all states; a state change callback ends the run after 3 s.' +sidebar: + order: 11 +code: [fairmq/Plugin.h, fairmq/PluginServices.h, fairmq/DeviceRunner.h, fairmq/PluginManager.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree } from '@astrojs/starlight/components'; + +This example replaces the built-in controller of a device with an own [plugin](/concepts/plugins/). The plugin is compiled into the program. It takes device control and requests each [transition](/concepts/states/) from a state change callback. + +The code is in [`examples/custom-controller`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/custom-controller). The example shows how to: + +- write a controller plugin that takes device control, +- compile a plugin into the executable and load it with the prefix `s:`, +- start a device with [`DeviceRunner`](/api/fair/mq/DeviceRunner/) and its hooks, without `runDevice.h`, +- end the run through a property that the controller reads. + +For the general procedure, see [Control a device from code](/guides/control-from-code/). + +## Topology + +The example has no channels. `MyDevice` in `MyDevice.h` is an alias of [`fair::mq::Device`](/api/fair/mq/Device/). The device goes through its states without data. + +## Requirements + +The example needs only FairMQ. It has no start script and no install rule. + +## Build and run + +The examples build when the CMake option `BUILD_EXAMPLES` is `ON` (the default). The executable is in the build directory: + + + +- build/examples/custom-controller/ + - fairmq-ex-custom-controller + + + +```sh +cd build/examples/custom-controller +./fairmq-ex-custom-controller +``` + +The program stops by itself about 3 s after the device enters `RUNNING`. Its exit code is 0. + +`CMakeLists.txt` sets the target property `ENABLE_EXPORTS ON`. The executable then exports its symbols, so the plugin manager can find the plugin factory in the program itself. + +## The code + +### The program + +`main.cxx` creates a `DeviceRunner` and adds two hooks: + + + +- `hooks::LoadPlugins` runs after the runner loads the built-in plugin `config` and before it loads the built-in plugin `control`. The hook loads `s:mycontroller`. The prefix `s:` loads a static plugin, a plugin that is part of the executable. The name is the second argument of `REGISTER_FAIRMQ_PLUGIN`. +- `hooks::InstantiateDevice` sets the property `catch-signals` to 0. Thus the built-in control plugin installs no signal handler. The hook also creates the device and subscribes to its state changes with [`SubscribeToStateChange()`](/api/fair/mq/Device/#SubscribeToStateChange). +- In `RUNNING`, the callback waits 3 s with [`WaitFor()`](/api/fair/mq/Device/#WaitFor). Then it sets the property `please-shut-me-down` to `true`. +- [`RunWithExceptionHandlers()`](/api/fair/mq/DeviceRunner/#RunWithExceptionHandlers) runs the device. It returns 1 if an exception reaches it. + +The hooks are declared in [`DeviceRunner.h`](/source/fairmq/DeviceRunner.h/#L84-L89). The order of the steps is in [`DeviceRunner.cxx`](/source/fairmq/DeviceRunner.cxx/#L108-L194). + +### The controller plugin + +`MyController` is a [`fair::mq::Plugin`](/api/fair/mq/Plugin/). The constructor takes device control and subscribes to the state changes of the device: + + + +- The plugin manager creates the plugins in their load order: `config`, `mycontroller`, `control`. Thus [`TakeDeviceControl()`](/api/fair/mq/Plugin/#TakeDeviceControl) of `mycontroller` succeeds first. The built-in control plugin cannot take control. It logs the reason on the severity `debug` and starts no controller. +- For each state, the callback requests the next transition with [`ChangeDeviceState()`](/api/fair/mq/Plugin/#ChangeDeviceState). In `BINDING`, `CONNECTING`, `INITIALIZING TASK`, `RESETTING TASK` and `RESETTING DEVICE`, the device changes state by itself, so the callback requests nothing. +- The callback reads `please-shut-me-down` with [`GetProperty()`](/api/fair/mq/Plugin/#GetProperty-2). The default is `false`. +- In `EXITING`, the plugin calls [`ReleaseDeviceControl()`](/api/fair/mq/Plugin/#ReleaseDeviceControl). `DeviceRunner::Run()` waits until all plugins release device control, and then returns. + +The plugin requests these transitions: + +| State | `please-shut-me-down` is `false` | `please-shut-me-down` is `true` | +| --- | --- | --- | +| `IDLE` | `InitDevice` | `End` | +| `INITIALIZING DEVICE` | `CompleteInit` | `CompleteInit` | +| `INITIALIZED` | `Bind` | `Bind` | +| `BOUND` | `Connect` | `Connect` | +| `DEVICE READY` | `InitTask` | `ResetDevice` | +| `READY` | `Run` | `ResetTask` | +| `RUNNING` | `Stop` | `Stop` | + +The macro `REGISTER_FAIRMQ_PLUGIN` registers the class under the name `mycontroller`: + + + +### The order of the callbacks + +`RunStateMachine()` first calls the state change callbacks with `IDLE`, so the plugin requests `InitDevice`. In each later state, the state machine calls the state change callbacks before the state handler of the device. See [`StateMachine::ProcessWork()`](/source/fairmq/StateMachine.cxx/#L396-L414) and the [loop of the state machine](/source/fairmq/StateMachine.cxx/#L191-L219). + +The state machine calls the callbacks in the order of the number at the start of their key. A key without a number, for example `example` or `mycontroller`, has the number 0. Callbacks with the same number run in the order of subscription. The hook in `main.cxx` subscribes before the plugin manager creates the plugin. Thus, in `RUNNING`, the callback of `main.cxx` runs first: + +1. The callback of `main.cxx` waits 3 s and sets `please-shut-me-down` to `true`. +2. The callback of the plugin requests `Stop`. +3. The state handler of the device logs `fair::mq::Device running...`. The device has no own `Run()` code, and a transition is pending. Thus the device goes to `READY` at once. +4. In `READY`, `DEVICE READY` and `IDLE`, the plugin reads `true`. It requests `ResetTask`, `ResetDevice` and `End`. + +## Output + +The log shows each state change (here without the prefix of the logger): + +```txt +Starting FairMQ state machine --> IDLE +IDLE ---> INITIALIZING DEVICE +INITIALIZING DEVICE ---> INITIALIZED +INITIALIZED ---> BINDING +BINDING ---> BOUND +BOUND ---> CONNECTING +CONNECTING ---> DEVICE READY +DEVICE READY ---> INITIALIZING TASK +INITIALIZING TASK ---> READY +READY ---> RUNNING +fair::mq::Device running... +RUNNING ---> READY +READY ---> RESETTING TASK +RESETTING TASK ---> DEVICE READY +DEVICE READY ---> RESETTING DEVICE +RESETTING DEVICE ---> IDLE +IDLE ---> EXITING +``` + +The 3 s pause is between `READY ---> RUNNING` and `fair::mq::Device running...`. `main.cxx` sets the console severity to `debug`, so the log also shows debug lines. The log also has these warnings: + +- `Signal handling (e.g. Ctrl-C) has been deactivated.`, because `catch-signals` is 0. +- `No device ID or config-key provided for the configuration parser.`, because the program gives no `--id`. +- `No channels created after finishing initialization`, because the device has no channels. + +## Test + +`examples/custom-controller/CMakeLists.txt` adds the test `Example.custom-controller`. It runs the executable and passes when the exit code is 0. The timeout is 30 s. + +Configure with `-DBUILD_TESTING=ON` to register the test. Then run it in the build directory: + +```sh +ctest -R Example.custom-controller +``` + +## Things to try + +- Change the time in `WaitFor(3s)`. +- Set `please-shut-me-down` to `true` in the hook `InstantiateDevice`. Then the plugin requests `End` in the first `IDLE`, and the device never runs. +- Give the plugin its own options. Remove the `//` in front of the function `MyControllerProgramOptions()` in `MyController.h`. Then use `example::MyControllerProgramOptions` as the last argument of `REGISTER_FAIRMQ_PLUGIN`, in place of `fair::mq::Plugin::NoProgramOptions`. The options `--custom-dummy-option` and `--custom-dummy-option2` then show in the output of `--help`. + +## Related pages + +- [Control a device from code](/guides/control-from-code/) +- [Write a plugin](/guides/write-plugin/) +- [Plugins and control](/concepts/plugins/) +- [Device states](/concepts/states/) +- [States and transitions](/reference/states/) diff --git a/docs/src/content/docs/examples/dds.mdx b/docs/src/content/docs/examples/dds.mdx new file mode 100644 index 00000000..06b8f582 --- /dev/null +++ b/docs/src/content/docs/examples/dds.mdx @@ -0,0 +1,198 @@ +--- +title: 'dds: run with DDS' +description: 'A sampler, ten processors and a sink in a DDS topology without channel addresses; the start script needs DDS and a DDS plugin for FairMQ.' +sidebar: + order: 12 +code: [fairmq/Device.h, fairmq/Device.cxx, fairmq/PluginManager.cxx, fairmq/runDevice.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree } from '@astrojs/starlight/components'; + +This example describes a topology for the deployment system DDS. One sampler sends messages to ten processors, and the processors send them to one sink. The topology file gives the [channels](/concepts/channels/) no addresses. The binding channels get [automatic addresses](/concepts/channels/#automatic-ports). A DDS [plugin](/concepts/plugins/) must give the addresses to the connecting channels at run time. + +:::caution +FairMQ alone cannot run this example. The start script needs DDS, a DDS plugin for FairMQ and the tool `fairmq-dds-command-ui`. DDS is not part of FairMQ. FairMQ v1.5.0 and later do not contain the plugin and the tool. See [Requirements](#requirements). +::: + +The code is in [`examples/dds`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/dds). The example shows how to: + +- describe the devices, their channels and their number in a DDS topology file, +- configure channels without addresses, +- request the transitions of all devices from a script, +- send a message that uses a buffer of the device and a function that deletes the buffer. + +## Topology + +The topology file `ex-dds-topology.xml` declares three tasks. Each task starts one device. The group `ProcessorGroup` has `n="10"`, so DDS starts the task `Processor` 10 times. + +| Task | Instances | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | --- | +| `Sampler` | 1 | `data1` | `push` | `bind` | not set | +| `Processor` | 10 | `data1` | `pull` | `connect` | not set | +| | | `data2` | `push` | `connect` | not set | +| `Sink` | 1 | `data2` | `pull` | `bind` | not set | + +Each task configures its channels with `--channel-config` and loads the plugin with `-P dds`. No task sets `--id`. The sampler and the sink stop after 10 messages (`--iterations 10`). + + + +The file declares the properties `fmqchan_data1` and `fmqchan_data2`. The task `Sampler` has write access to `fmqchan_data1`, and the task `Sink` has write access to `fmqchan_data2`. The task `Processor` has read access to both. In DDS, the tasks with read access get the values that the tasks with write access set. The DDS plugin of FairMQ v1.4.56 (`fairmq/plugins/DDS/DDS.cxx` at the tag `v1.4.56`) used these properties: + +- In `BOUND`, it wrote the bound addresses of each binding channel `` to the property `fmqchan_`. +- When it had a value of `fmqchan_` for each sub-channel of a connecting channel ``, it set the properties `chans...address` to these addresses. + +A connecting channel waits for its address. In `CONNECTING`, the device reads `chans...address` again every 50 ms, until all channels connect or `--init-timeout` ends (default 120 s). See [`Device.cxx`](/source/fairmq/Device.cxx/#L235-L276). + +Each task also has a requirement of the type `wnname`, with the value `sampler`, `processor` or `sink`. These values are the first column of `ex-dds-hosts.cfg`. + +In `ex-dds-topology-infinite.xml`, the sampler sends without an end, at most 100 messages per second (`--rate 100 --iterations 0`). The sink has no `--iterations` there, so it uses the default 1000. The start script does not use this file. + +## Requirements + +The three devices build with FairMQ alone. The CMake files of FairMQ do not search for DDS. To run the start script, you need: + +- DDS. The start script calls `dds-session`, `dds-submit`, `dds-info`, `dds-topology`, `dds-agent-cmd` and `dds-user-defaults`. +- A DDS plugin for FairMQ: a library with the name `libfairmq-plugin-dds` or `libFairMQPlugin_dds`. +- The tool `fairmq-dds-command-ui`. + +FairMQ v1.4.56 is the last release that contains the DDS plugin (`fairmq/plugins/DDS`, library `FairMQPlugin_dds`) and `fairmq-dds-command-ui` (`fairmq/sdk`). FairMQ v1.5.0 and later do not contain them. The commit that removes them says that these components moved to the ODC project. It refers to [discussion #392](https://github.com/FairRootGroup/FairMQ/discussions/392). + +The scripts in the build directory add `build/fairmq/sdk` to `PATH`. This is the old directory of `fairmq-dds-command-ui`, and FairMQ does not build it now. Add the directory of your `fairmq-dds-command-ui` to `PATH`. + +### Load the plugin + +`-P dds` loads the plugin from a shared library. The plugin manager searches the directories of `-S` (`--plugin-search-path`) for `libfairmq-plugin-dds` and `libFairMQPlugin_dds`, with the library suffix of the system. Then it tries the system lookup: the system library directories, `RUNPATH` and `LD_LIBRARY_PATH`. See [`PluginManager.cxx`](/source/fairmq/PluginManager.cxx/#L169-L230). + +The plugin manager loads the plugins of `-P` in the constructor of `DeviceRunner`. If it finds no library, the program stops before it creates the device. The exit code is 1, and the log shows: + +```txt +Uncaught exception reached the top of main: Could not load dynamic plugin dds from configured search paths (-S) nor with system lookup (system libdirs, RUNPATH, $LD_LIBRARY_PATH). +``` + +## Build and run + +The examples build when the CMake option `BUILD_EXAMPLES` is `ON` (the default). CMake writes these files to the build directory: + + + +- build/examples/dds/ + - fairmq-ex-dds-sampler + - fairmq-ex-dds-processor + - fairmq-ex-dds-sink + - fairmq-start-ex-dds.sh + - fairmq-ex-dds-env.sh + - ex-dds-topology.xml + - ex-dds-topology-infinite.xml + - ex-dds-hosts.cfg + + + +The install step copies the executables and the two scripts to `bin`, and the topology files and `ex-dds-hosts.cfg` to `share/fairmq` in the install prefix. + +The start script takes one optional argument: the plugin that `dds-submit` uses to start the agents, `localhost` (default) or `ssh`. With `ssh`, the script gives `ex-dds-hosts.cfg` to `dds-submit`. + +```sh +cd build/examples/dds +./fairmq-start-ex-dds.sh +./fairmq-start-ex-dds.sh ssh +``` + +The script does these steps. `set -e` stops it at the first command that fails. + +1. It starts a DDS session and exports `DDS_SESSION_ID`. When the script exits, a trap stops the session. +2. It submits the agents and waits for 12 idle slots. +3. It exports `FAIRMQ_DDS_TOPO_FILE`, activates `ex-dds-topology.xml` and waits for 12 executing slots. +4. It requests the transitions with `fairmq-dds-command-ui`. +5. It stops the topology, gets the log files of the agents and prints `Example successful`. + +Each task has `fairmq-ex-dds-env.sh` as its `env` element. This script adds the directory of the executables to `PATH`. + +### Request the transitions + +Step 4 of the script requests the transitions of all devices: + + + +The script waits until the sampler and the sink go from `RUNNING` to `READY`, after 10 messages. Then it stops all devices. The script uses the options of `fairmq-dds-command-ui` of FairMQ v1.4.56 (`fairmq/sdk/runDDSCommandUI.cxx` at the tag `v1.4.56`). In that version, the tool read the session from `DDS_SESSION_ID` and the topology file from `FAIRMQ_DDS_TOPO_FILE`. Its options had this meaning: + +| Option | Meaning in v1.4.56 | +| --- | --- | +| `-c i`, `-c k`, `-c b`, `-c x`, `-c j`, `-c r` | Request `InitDevice`, `CompleteInit`, `Bind`, `Connect`, `InitTask` or `Run`. | +| `-c s`, `-c t`, `-c d`, `-c q` | Request `Stop`, `ResetTask`, `ResetDevice` or `End`. | +| `-c p` | Set the property `--property-key` to the value `--property-value`. | +| `-w ` | Wait until the devices are in the state. | +| `-w "->"` | Wait until the devices go from `` to ``. | +| `-p ` | Send the command to, or wait for, only the tasks of this topology path. Without `-p`, the tool uses all tasks. | + +For the transitions, see [States and transitions](/reference/states/). + +## The code + +### Sampler + +The sampler sends the string `Data` in each [`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun) call. [`NewSimpleMessage()`](/api/fair/mq/Device/#NewSimpleMessage) copies the data into a new message. + + + +After `--iterations` messages (default 1000, `0` for no limit), `ConditionalRun()` returns `false`. Then the device goes to `READY`. + +### Processor + +The processor registers `HandleData()` for `data1` with [`OnData()`](/api/fair/mq/Device/#OnData). It appends ` (modified by )` to the text, with the device id of the processor. + + + +The new message gets the buffer of the string and a function that deletes the string. See [`CreateMessage()`](/api/fair/mq/TransportFactory/#CreateMessage-5) and [Messages](/concepts/messages/). + +- The zeromq transport, the default, sends the buffer without a copy. It calls the function when it no longer needs the buffer. +- The shmem transport copies the data into the managed segment and calls the function at once. + +### Sink + +The sink registers its `HandleData()` for `data2` and logs each text. After `--iterations` messages (default 1000, `0` for no limit), it returns `false`, and the device goes to `READY`. + +## Output + +The sampler logs each message and the end: + +```txt +Sending "Data" +Sent 10 messages. Finished. +``` + +Each processor logs `Received data, processing...` for each message. The sink logs each text and the end: + +```txt +Received: "Data (modified by )" +Received 10 messages. Finished. +``` + +`` is the id of the processor. When `--id` was empty, the DDS plugin of FairMQ v1.4.56 set the id to the path of the DDS task. At the end, the start script calls `dds-agent-cmd getlog -a`. If this command succeeds, the script prints `AGENT LOG FILES IN: `. + +## Test + +The example has no test. In `CMakeLists.txt`, the test `Example.DDS.localhost` is a comment. It runs `fairmq-start-ex-dds.sh localhost` with a timeout of 15 s and expects the output `Example successful`. + +## Things to try + +- Run the devices without DDS. Remove `-P dds` and give each channel an address. Start each device in its own terminal in `build/examples/dds`: + + ```sh + ./fairmq-ex-dds-sampler --id sampler1 --iterations 10 --channel-config name=data1,type=push,method=bind,address=tcp://127.0.0.1:5555 + ./fairmq-ex-dds-processor --id processor1 --channel-config name=data1,type=pull,method=connect,address=tcp://127.0.0.1:5555 name=data2,type=push,method=connect,address=tcp://127.0.0.1:5556 + ./fairmq-ex-dds-sink --id sink1 --iterations 10 --channel-config name=data2,type=pull,method=bind,address=tcp://127.0.0.1:5556 + ``` + + The devices use the interactive controller. Type `q` in each terminal to end the device. + +- Start the processor without the address of `data1`. It waits in `CONNECTING`. After `--init-timeout` (default 120 s), it logs `could not connect all channels after 120 attempts` on the severity `error` and goes to the state `ERROR`. +- For a topology with many senders and receivers, see [n-m: n senders to m receivers](/examples/n-m/). + +## Related pages + +- [Plugins and control](/concepts/plugins/) +- [Configure channels](/guides/configure-channels/) +- [n-m: n senders to m receivers](/examples/n-m/) +- [qc: quality control on demand](/examples/qc/) +- [Configuration](/concepts/configuration/) diff --git a/docs/src/content/docs/examples/multipart.mdx b/docs/src/content/docs/examples/multipart.mdx new file mode 100644 index 00000000..fd8564f8 --- /dev/null +++ b/docs/src/content/docs/examples/multipart.mdx @@ -0,0 +1,200 @@ +--- +title: 'multipart: several parts in one message' +description: 'A sampler sends a header and six data parts as one multipart message, and a sink receives all parts in one handler call.' +sidebar: + order: 4 +code: [fairmq/Parts.h, fairmq/Device.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The multipart example sends one message that has several parts. The sampler puts a header and six data +parts into a [`fair::mq::Parts`](/api/fair/mq/Parts/) object and sends all parts with one `Send()` call. +The sink gets all seven parts in one call of its data handler. The +[Messages and multipart](/concepts/messages/) page explains the concept. + +The files of the example are in +[`examples/multipart`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/multipart) on GitHub. + +## Topology + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data` | `push` | `connect` | `tcp://127.0.0.1:5555` | +| `sink1` | `data` | `pull` | `bind` | `tcp://127.0.0.1:5555` | + +Here the sink binds and the sampler connects. Both devices use `rateLogging=0`. + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON` (the default): + + + +- build/examples/multipart/ + - fairmq-ex-multipart-sampler + - fairmq-ex-multipart-sink + - fairmq-start-ex-multipart.sh + - test-ex-multipart.sh + + + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/multipart + ``` + +2. Run the start script. It opens two `xterm` windows, one for each device: + + ```sh + ./fairmq-start-ex-multipart.sh + ``` + + + +The first argument of the script sets the transport, for example `./fairmq-start-ex-multipart.sh shmem`. +The default is `zeromq`. The script gives both devices the same session name, from `fairmq-uuid-gen -h`. + +To run the example without `xterm`, run each command in its own terminal in `build/examples/multipart`. +Any session name works if both devices use the same one: + +```sh +./fairmq-ex-multipart-sampler --id sampler1 --transport zeromq --session ex-multipart \ + --channel-config "name=data,type=push,method=connect,rateLogging=0,address=tcp://127.0.0.1:5555" +``` + +```sh +./fairmq-ex-multipart-sink --id sink1 --transport zeromq --session ex-multipart \ + --channel-config "name=data,type=pull,method=bind,rateLogging=0,address=tcp://127.0.0.1:5555" +``` + +## The header + + + +The sampler and the sink include `Header.h`. The first part of each message is a `Header`. The sink stops +when `stopFlag` is `1`. + +## The sampler + + + +- `fair::mq::Parts parts;` creates an empty multipart message. `Parts` holds a vector of + [`MessagePtr`](/api/fair/mq/#MessagePtr). +- [`NewSimpleMessage()`](/api/fair/mq/Device/#NewSimpleMessage) copies the header into a new message. The + transport deletes this copy when it does not need it any more. Use it for small data only. +- [`AddPart()`](/api/fair/mq/Parts/#AddPart-2) adds one message at the end. +- `NewMessage(1000)` creates a message of 1000 bytes. The example does not write data into it. + `NewMessage()` without arguments creates an empty part of 0 bytes. +- The [constructor](/api/fair/mq/Parts/#Parts-4) of `Parts` takes several messages. + [`AddPart()`](/api/fair/mq/Parts/#AddPart-4) with a `Parts` object moves all its parts to the end. +- [`At()`](/api/fair/mq/Parts/#At) returns the part at an index. [`Size()`](/api/fair/mq/Parts/#Size) + returns the number of parts. +- [`Send()`](/api/fair/mq/Device/#Send) sends all seven parts as one message. + +The sampler sets `stopFlag` to `1` in its last message. The option `--max-iterations` of this sampler has +the default `5`, so the sampler stops after five messages. The value `0` sets no limit. + +## The sink + + + + + +The handler takes a `fair::mq::Parts&` instead of a message. With this handler type, +[`OnData()`](/api/fair/mq/Device/#OnData-3) receives multipart messages on the channel. The sink checks the +number of parts and reads the header from the data of part 0. To also check the size of each part, see +[Read the data safely](/guides/send-data-types/#read-the-data-safely). + +- If the message does not have seven parts, the handler throws an exception. The device then goes to the + state `ERROR`. +- If `stopFlag` is `1`, the handler returns `false`. The log line says `going IDLE`, but the device goes to + the state `READY`. + +## Output + +The listings show the severity and the message of each line, without the time. The sampler logs two lines +for each message, once per second. The listing shows the first and the last message: + +```txt +[INFO] Sending header with stopFlag: 0 +[INFO] Sending body of size: 1000 +[INFO] Sending header with stopFlag: 1 +[INFO] Sending body of size: 1000 +[INFO] Configured maximum number of iterations reached. Leaving RUNNING state. +``` + +The sink logs the parts of each message: + +```txt +[INFO] Received message with 7 parts +[INFO] Received part 1 (header) with stopFlag: 0 +[INFO] Received part 2 of size: 1000 +[INFO] Received part 3 of size: 500 +[INFO] Received part 4 of size: 600 +[INFO] Received part 5 of size: 700 +[INFO] Received part 6 of size: 0 +[INFO] Received part 7 of size: 100 +``` + +After the message with `stopFlag` 1, the sink also logs `stopFlag is 1, going IDLE`. + +## Test the example + +The test script `test-ex-multipart.sh` uses a `pair` channel instead of `push` and `pull`. The sampler +connects with `linger=1000`, and the sink binds. The channel uses an `ipc://` address in `/tmp`, and the +devices use `--control static`. The sampler has `--max-iterations 1`, so its first message has the +`stopFlag` 1. Thus both devices stop after one message. + +CTest runs the script once for each transport: `Example.multipart.zeromq` and `Example.multipart.shmem`. The +tests exist if you configure with `-DBUILD_TESTING=ON`. + +```sh +cd build +ctest -R '^Example\.multipart\.' --output-on-failure +``` + +## Things to try + +- Use shared memory: run `./fairmq-start-ex-multipart.sh shmem`. +- Send without a limit: start the sampler with `--max-iterations 0`. `stopFlag` then stays `0`, and the sink + does not stop. +- Send to two sinks: use the JSON file of the next section. + +### Send to two sinks + +The source folder of the example has the file `ex-multipart-multiple-endpoints.json`. The build does not +copy it. In this file, one sampler sends to two sinks. + +The `address` of the sampler has two endpoints, `tcp://localhost:5555,tcp://localhost:5556`. The socket of +the sampler connects to both. The entry of `sink2` has the method `connect`, but the address starts with +`@`: + + + +`@` in front of an endpoint makes the socket bind there, and `+` or `>` makes it connect +([Device.cxx](/source/fairmq/Device.cxx/#L300-L320)). Run each device in its own terminal, with the path of +the file in your source tree: + +```sh +./fairmq-ex-multipart-sink --id sink1 --mq-config /path/to/FairMQ/examples/multipart/ex-multipart-multiple-endpoints.json +./fairmq-ex-multipart-sink --id sink2 --mq-config /path/to/FairMQ/examples/multipart/ex-multipart-multiple-endpoints.json +./fairmq-ex-multipart-sampler --id sampler1 --mq-config /path/to/FairMQ/examples/multipart/ex-multipart-multiple-endpoints.json +``` + +The `push` socket of the sampler distributes the messages over the two sinks. Only the sink that gets the +message with `stopFlag` 1 leaves `RUNNING`. + +## Related pages + +- [Messages and multipart](/concepts/messages/): messages, parts and their memory. +- [Receive data with callbacks or loops](/guides/receive-data/): handlers for messages and for parts. +- [Channel properties](/reference/channel-properties/): the `address` with several endpoints. +- [1-1: sampler and sink](/examples/1-1/): a sampler and a sink with single-part messages. +- [Stop a topology without losing messages](/guides/end-of-run/): end messages, linger and the stop order. diff --git a/docs/src/content/docs/examples/multiple-channels.mdx b/docs/src/content/docs/examples/multiple-channels.mdx new file mode 100644 index 00000000..9e50e419 --- /dev/null +++ b/docs/src/content/docs/examples/multiple-channels.mdx @@ -0,0 +1,193 @@ +--- +title: 'multiple-channels: data and broadcast' +description: 'A sampler and a sink use a data channel and a broadcast channel. The sampler polls both channels, and the sink has one handler for each.' +sidebar: + order: 6 +code: [fairmq/Poller.h, fairmq/Device.h, fairmq/Device.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The multiple-channels example shows devices with more than one channel. The sampler sends data to the sink +on the channel `data`. Both devices also receive the messages of a broadcaster on the channel `broadcast`. +The sampler checks its two channels with a [poller](/guides/poll-channels/), and the sink registers one data +handler for each channel. + +The files of the example are in +[`examples/multiple-channels`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/multiple-channels) +on GitHub. + +## Topology + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data` | `push` | `bind` | `tcp://*:5555` | +| `sampler1` | `broadcast` | `sub` | `connect` | `tcp://localhost:5005` | +| `sink1` | `data` | `pull` | `connect` | `tcp://localhost:5555` | +| `sink1` | `broadcast` | `sub` | `connect` | `tcp://localhost:5005` | +| `broadcaster1` | `broadcast` | `pub` | `bind` | `tcp://*:5005` | + +The `pub` socket of the broadcaster sends each message to all connected `sub` sockets. FairMQ subscribes +each `sub` socket to all messages ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L70-L74)). All +channels use `rateLogging=0`. + +:::caution[zeromq only] +The example needs the `zeromq` transport. The `shmem` transport does not support the socket types `pub` and +`sub`: it throws a `SocketError` when it creates such a socket +([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L59-L62)). Thus CTest runs this example only with +`zeromq`. +::: + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON` (the default): + + + +- build/examples/multiple-channels/ + - fairmq-ex-multiple-channels-sampler + - fairmq-ex-multiple-channels-sink + - fairmq-ex-multiple-channels-broadcaster + - fairmq-start-ex-multiple-channels.sh + - test-ex-multiple-channels.sh + + + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/multiple-channels + ``` + +2. Run the start script. It opens three `xterm` windows, one for each device: + + ```sh + ./fairmq-start-ex-multiple-channels.sh + ``` + + + +To run the example without `xterm`, run each command in its own terminal in +`build/examples/multiple-channels`. One `--channel-config` option takes one value for each channel: + +```sh +./fairmq-ex-multiple-channels-sampler --id sampler1 \ + --channel-config "name=data,type=push,method=bind,rateLogging=0,address=tcp://*:5555" \ + "name=broadcast,type=sub,method=connect,rateLogging=0,address=tcp://localhost:5005" +``` + +```sh +./fairmq-ex-multiple-channels-sink --id sink1 \ + --channel-config "name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5555" \ + "name=broadcast,type=sub,method=connect,rateLogging=0,address=tcp://localhost:5005" +``` + +```sh +./fairmq-ex-multiple-channels-broadcaster --id broadcaster1 \ + --channel-config "name=broadcast,type=pub,method=bind,rateLogging=0,address=tcp://*:5005" +``` + +## The sampler + + + +The sampler overrides [`Run()`](/api/fair/mq/Device/#Run) instead of `ConditionalRun()`. The device calls +`Run()` once in the state `RUNNING`. Thus `Run()` has its own loop, and it must return when +[`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) is `true`. + +- [`NewPoller()`](/api/fair/mq/Device/#NewPoller) creates a poller for the channels `data` and `broadcast`, + with all their sub-channels. +- [`Poll(100)`](/api/fair/mq/Poller/#Poll) waits for max. 100 ms for an event on one of the channels. +- [`CheckInput("broadcast", 0)`](/api/fair/mq/Poller/#CheckInput-2) is `true` if the sub-channel + `broadcast[0]` has a message to receive. +- [`CheckOutput("data", 0)`](/api/fair/mq/Poller/#CheckOutput-2) is `true` if the sub-channel `data[0]` can + send. The `zeromq` poller checks `push` sockets for output and `sub` sockets for input + ([zeromq/Poller.h](/source/fairmq/zeromq/Poller.h/#L111-L123)). +- Before each send, the sampler waits 1 s. [`NewSimpleMessage()`](/api/fair/mq/Device/#NewSimpleMessage) + copies the text into a new message. +- At `--max-iterations`, the loop ends. When `Run()` returns, the device goes to `READY`. + +All channels of one poller must use the same transport. Otherwise `NewPoller()` throws an exception +([Device.h](/source/fairmq/Device.h/#L218-L238)). + +## The sink + + + +The sink calls [`OnData()`](/api/fair/mq/Device/#OnData) once for each channel. With more than one input +channel, the device polls all input channels and calls the handler of the channel that has a message +([Device.cxx](/source/fairmq/Device.cxx/#L449-L507)). + + + +Both handlers return the result of `CheckIterations()`. With `--max-iterations`, the sink leaves `RUNNING` +only after it got messages on both channels. + +## The broadcaster + + + +Once per second, the broadcaster sends the text `OK` on its `pub` channel. It has no custom options, so it +runs until you stop it. + +## Output + +The listings show the severity and the message of each line, without the time. The lines of the two +channels mix, because the messages arrive in any order. + +The sampler: + +```txt +[INFO] Received broadcast: "OK" +[INFO] Sent "Hello" +``` + +The sink: + +```txt +[INFO] Received broadcast: "OK" +[INFO] Received message: "Hello" +``` + +The broadcaster: + +```txt +[INFO] Sending OK +``` + +## Test the example + +The test script `test-ex-multiple-channels.sh` uses `ipc://` addresses in `/tmp`, a new session and +`--control static`. It starts the sink first, waits 1 s, and then starts the sampler and the broadcaster. +The sampler and the sink stop after one iteration (`--max-iterations 1`). Then the script stops the +broadcaster with `SIGINT`. + +The CMake file of the example sets `TRANSPORT zeromq`. Thus CTest has only one test, +`Example.multiple-channels.zeromq`. The test exists if you configure with `-DBUILD_TESTING=ON`. + +```sh +cd build +ctest -R '^Example\.multiple-channels\.' --output-on-failure +``` + +## Things to try + +- Start the broadcaster some seconds after the other devices. The sampler and the sink exchange data + before the first broadcast arrives. +- Stop the broadcaster. The data on the channel `data` continues. +- Send another text: start the sampler with `--text "Hi"`. +- Stop after three iterations: add `--max-iterations 3` to the commands of the sampler and the sink. + +## Related pages + +- [Poll several channels](/guides/poll-channels/): the `Poller` interface in detail. +- [Receive data with callbacks or loops](/guides/receive-data/): `OnData()`, `ConditionalRun()` and `Run()`. +- [Channels and sockets](/concepts/channels/): the socket types `pub` and `sub`. +- [multiple-transports: zeromq and shmem](/examples/multiple-transports/): input channels with two + transports. +- [Design a topology](/guides/design-topology/#broadcast-and-data): a data link and a broadcast link in one topology. diff --git a/docs/src/content/docs/examples/multiple-transports.mdx b/docs/src/content/docs/examples/multiple-transports.mdx new file mode 100644 index 00000000..5e19993c --- /dev/null +++ b/docs/src/content/docs/examples/multiple-transports.mdx @@ -0,0 +1,186 @@ +--- +title: 'multiple-transports: zeromq and shmem' +description: 'Two samplers and a sink use the shmem and the zeromq transport at the same time, with a transport for each channel.' +sidebar: + order: 7 +code: [fairmq/Device.h, fairmq/Device.cxx, fairmq/Channel.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The multiple-transports example uses two [transports](/concepts/transports/) at the same time, in one +topology and in one device. The devices use `shmem` as their default transport, and the channel `ack` uses +`zeromq`. The example also shows [`NewMessageFor()`](/api/fair/mq/Device/#NewMessageFor), which creates a +message with the transport of a channel. + +The files of the example are in +[`examples/multiple-transports`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/multiple-transports) +on GitHub. + +## Topology + +The start script starts all three devices with `--transport shmem`: + +| Device | Channel | Type | Method | Address | Transport | +| --- | --- | --- | --- | --- | --- | +| `sampler1` | `data1` | `push` | `bind` | `tcp://127.0.0.1:5555` | `shmem` (default of the device) | +| `sampler1` | `ack` | `sub` | `bind` | `tcp://127.0.0.1:5557` | `zeromq` | +| `sampler2` | `data2` | `push` | `bind` | `tcp://127.0.0.1:5556` | `shmem` (default of the device) | +| `sink1` | `data1` | `pull` | `connect` | `tcp://127.0.0.1:5555` | `shmem` (default of the device) | +| `sink1` | `data2` | `pull` | `connect` | `tcp://127.0.0.1:5556` | `shmem` | +| `sink1` | `ack` | `pub` | `connect` | `tcp://127.0.0.1:5557` | `zeromq` | + +- `--transport` sets the default transport of a device. Its default is `zeromq`. +- The channel key `transport` sets the transport of one channel. A channel without this key uses the + default transport of the device. +- The device creates its default transport and each other transport that one of its channels uses + ([Device.cxx](/source/fairmq/Device.cxx/#L173-L183)). + +The two ends of a channel must use the same transport. The channel `ack` must use `zeromq`, because the +`shmem` transport does not support `pub` and `sub` sockets. + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON` (the default): + + + +- build/examples/multiple-transports/ + - fairmq-ex-multiple-transports-sampler1 + - fairmq-ex-multiple-transports-sampler2 + - fairmq-ex-multiple-transports-sink + - fairmq-start-ex-multiple-transports.sh + - test-ex-multiple-transports.sh + + + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/multiple-transports + ``` + +2. Run the start script. It opens three `xterm` windows, one for each device: + + ```sh + ./fairmq-start-ex-multiple-transports.sh + ``` + + + +To run the example without `xterm`, run each command in its own terminal in +`build/examples/multiple-transports`: + +```sh +./fairmq-ex-multiple-transports-sampler1 --id sampler1 --severity debug --transport shmem \ + --channel-config "name=data1,type=push,method=bind,address=tcp://127.0.0.1:5555" \ + "name=ack,type=sub,method=bind,address=tcp://127.0.0.1:5557,transport=zeromq" +``` + +```sh +./fairmq-ex-multiple-transports-sampler2 --id sampler2 --severity debug --transport shmem \ + --channel-config "name=data2,type=push,method=bind,address=tcp://127.0.0.1:5556" +``` + +```sh +./fairmq-ex-multiple-transports-sink --id sink1 --severity debug --transport shmem \ + --channel-config "name=data1,type=pull,method=connect,address=tcp://127.0.0.1:5555" \ + "name=data2,type=pull,method=connect,address=tcp://127.0.0.1:5556,transport=shmem" \ + "name=ack,type=pub,method=connect,address=tcp://127.0.0.1:5557,transport=zeromq" +``` + +The three devices use the session `default`, because the commands do not set `--session`. + +## The samplers + + + +`NewMessageFor("data1", 0, 1000000)` creates a message of 1000000 bytes with the transport of the +sub-channel `data1[0]`. Here this is `shmem`. The sampler sends as fast as it can, because it does not wait +and the start script does not set `--rate`. + + + +[`PreRun()`](/api/fair/mq/Device/#PreRun) starts a thread that runs `ListenForAcks()`, and +[`PostRun()`](/api/fair/mq/Device/#PostRun) waits for the end of this thread. The thread receives the +acknowledgements on the channel `ack`, with empty `zeromq` messages from `NewMessageFor("ack", 0)`. A new +state interrupts `Receive()`, and `Receive()` then returns a negative value. Thus the loop ends when the +device leaves `RUNNING`. For the rules of this pattern, see +[One thread for each channel](/concepts/threads/#one-thread-for-each-channel). + +`sampler2` sends messages of 1000 bytes on `data2` with `NewMessage(1000)`. `NewMessage()` uses the default +transport of the device. This is also the transport of `data2`. + +## The sink + + + + + +For each message on `data1`, the sink sends an empty `zeromq` message on `ack`. If `Send()` fails, the +handler throws an exception. With the channels of the start script, the device then goes to the state +`ERROR`. If the input channels use two transports, the handler runs in a separate thread, and the exception +ends the process ([Device.cxx](/source/fairmq/Device.cxx/#L558-L561)). With `--max-iterations`, the sink +leaves `RUNNING` after it got this number of messages on both data channels. + +### Messages and channels with different transports + +If the transport of a message is not the transport of the channel, `Send()` converts the message. It creates +a new message of the channel transport for the same data +([Channel.h](/source/fairmq/Channel.h/#L421-L438)). If the channel uses `shmem`, this step copies the data +into shared memory. `NewMessageFor()` creates the message with the transport of the channel, so `Send()` +does not convert it. + +## Output + +The start script does not set `rateLogging`, so each channel uses the default `1`. Each second, each device +logs one line for each sub-channel: the messages per second and the MB per second, in and out. For example, +the sink logs lines of this form, without the time: + +```txt +[INFO] data1[0]: in: ( MB) out: ( MB) +``` + +With `--severity debug`, the devices also log their transports, for example `Adding 'zeromq' transport`. +When `sampler1` leaves `RUNNING`, it logs the number of acknowledgements: `Acknowledged messages`. + +## Test the example + +The test script `test-ex-multiple-transports.sh` uses `ipc://` addresses in `/tmp`, a new session and +`--control static`. All devices stop after one message (`--max-iterations 1`). To write a script of this +type for your own devices, see [Write the test script](/guides/test-devices/#write-the-test-script). + +The test uses `zeromq` for `data2`: it starts `sampler2` with `--transport zeromq`, and the sink sets +`transport=zeromq` on `data2`. Thus the input channels of the sink use two transports. In this case, the +device polls each transport in its own thread ([Device.cxx](/source/fairmq/Device.cxx/#L509-L523)). + +The CMake file of the example sets `NO_TRANSPORT`, so CTest runs the script only once, without a transport +argument. The name of this test is `Example.multiple-transports.`, with a dot at the end, and its timeout is +30 s. The test exists if you configure with `-DBUILD_TESTING=ON`. + +```sh +cd build +ctest -R '^Example\.multiple-transports' --output-on-failure +``` + +## Things to try + +- Use `zeromq` for `data2`, as the test does. Start `sampler2` with `--transport zeromq`, and set + `transport=zeromq` on `data2` of the sink. +- Remove `transport=zeromq` from the channel `ack` of the sink. The sink then goes to the state `ERROR`, + because the `shmem` transport cannot create a `pub` socket. +- Hide the rate lines: add `rateLogging=0` to each channel configuration. +- Stop after 1000 messages: add `--max-iterations 1000` to all three commands. The devices then wait in + the state `READY`. + +## Related pages + +- [Use several transports](/guides/several-transports/): configure the transport of each channel. +- [Transports](/concepts/transports/): `zeromq` and `shmem` compared. +- [How shared memory works](/shmem/how-it-works/): what the `shmem` transport does with a message. +- [multiple-channels: data and broadcast](/examples/multiple-channels/): devices with several channels. diff --git a/docs/src/content/docs/examples/n-m.mdx b/docs/src/content/docs/examples/n-m.mdx new file mode 100644 index 00000000..27c98d35 --- /dev/null +++ b/docs/src/content/docs/examples/n-m.mdx @@ -0,0 +1,186 @@ +--- +title: 'n-m: n senders to m receivers' +description: 'Three senders send each timeframe to one of four receivers, and the receiver collects the parts of all senders; with push/pull or pair channels.' +sidebar: + order: 13 +code: [fairmq/Device.h, fairmq/Parts.h, fairmq/Channel.h, fairmq/Device.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree } from '@astrojs/starlight/components'; + +In this example, three senders and four receivers exchange timeframes. A synchronizer gives each timeframe an id. Each sender sends its part of the timeframe to the receiver that the id selects, and that receiver collects the parts of all senders. + +The code is in [`examples/n-m`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/n-m). The example shows how to: + +- send one message to all senders on a `pub`/`sub` [channel](/concepts/channels/), +- select the [sub-channel](/concepts/channels/) for each message with the index argument of `Send()`, +- send without a wait (timeout 0 ms), +- collect the [parts](/concepts/messages/) of one timeframe from several senders, +- connect n senders to m receivers with `push`/`pull` channels or with `pair` channels. + +## Topology + +### Push and pull + +`fairmq-start-ex-n-m.sh` starts one synchronizer, three senders and four receivers: + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `Sync` | `sync` | `pub` | `bind` | `tcp://localhost:8010` | +| `Sender1`, `Sender2`, `Sender3` | `sync` | `sub` | `connect` | `tcp://localhost:8010` | +| | `data` | `push` | `connect` | `tcp://localhost:8021`, `tcp://localhost:8022`, `tcp://localhost:8023`, `tcp://localhost:8024` | +| `Receiver1` | `data` | `pull` | `bind` | `tcp://localhost:8021` | +| `Receiver2` | `data` | `pull` | `bind` | `tcp://localhost:8022` | +| `Receiver3` | `data` | `pull` | `bind` | `tcp://localhost:8023` | +| `Receiver4` | `data` | `pull` | `bind` | `tcp://localhost:8024` | + +The `data` channel of a sender has four sub-channels. Sub-channel 0 connects to `Receiver1`, sub-channel 3 to `Receiver4`. + +The devices get these options: + +- `Sync`: `--rate 100`. +- `Sender1`, `Sender2`, `Sender3`: `--sender-index 0`, `1` or `2`, `--subtimeframe-size 1000000` and `--num-receivers 4`. +- The receivers: `--num-senders 3`. + +### Pair + +`fairmq-start-ex-n-m-pair.sh` starts the same devices with the same options. The `data` channels are `pair` channels, and each sub-channel connects one sender to one receiver: + +| Device | Channel | Type | Method | Ports of the sub-channels | +| --- | --- | --- | --- | --- | +| `Sender1` | `data` | `pair` | `connect` | 8021, 8022, 8023, 8024 | +| `Sender2` | `data` | `pair` | `connect` | 8031, 8032, 8033, 8034 | +| `Sender3` | `data` | `pair` | `connect` | 8041, 8042, 8043, 8044 | +| `Receiver1` | `data` | `pair` | `bind` | 8021, 8031, 8041 | +| `Receiver2` | `data` | `pair` | `bind` | 8022, 8032, 8042 | +| `Receiver3` | `data` | `pair` | `bind` | 8023, 8033, 8043 | +| `Receiver4` | `data` | `pair` | `bind` | 8024, 8034, 8044 | + +All addresses are `tcp://localhost:`. The `sync` channels are the same as in the push and pull topology. + +### DDS + +`fairmq-start-ex-n-m-dds.sh` and `fairmq-start-ex-n-m-pair-dds.sh` start the devices with DDS. They use the topology files `ex-n-m-topology.xml` and `ex-n-m-pair-topology.xml`. The channels have no addresses, and each task loads the DDS plugin with `-P dds`. The files set the variables `numSenders` to 3 and `numReceivers` to 4. The table shows these values. DDS starts the task of a group `n` times and replaces `%taskIndex%` with the index of the task. + +| Task | Instances | Channel | Type | Method | Options | +| --- | --- | --- | --- | --- | --- | +| `Synchronizer` | 1 | `sync` | `pub` | `bind` | `--id sync`, `--rate 100` | +| `Sender` | 3 (group `Senders`) | `sync` | `sub` | `connect` | `--id sender%taskIndex%`, `--num-receivers 4` | +| | | `data` | `push` or `pair` | `connect` | `numSockets=4` | +| `Receiver` | 4 (group `Receivers`) | `data` | `pull` or `pair` | `bind` | `--id receiver%taskIndex%`, `--num-senders 3`, `--max-timeframes 10` | + +In the pair topology, the `data` channel of a receiver has `numSockets=3`. Each sender also gets `--dds-i data:%taskIndex%`. With this option, the DDS plugin of FairMQ v1.4.56 took address number `%taskIndex%` from the addresses that each receiver published for `data`. + +The topology files give the senders `--timeframe-size 100000`. The sender has no such option. The device logs it as an unregistered option on the severity `debug` and ignores it. Thus the senders use the default `--subtimeframe-size` of 1000 bytes. The files also give no `--sender-index`, so all senders use the index 0. + +## Requirements + +- `fairmq-start-ex-n-m.sh` and `fairmq-start-ex-n-m-pair.sh` open one `xterm` window for each device. `xterm` must be installed. These scripts do not need DDS. +- The two DDS scripts need DDS, a DDS plugin for FairMQ and `fairmq-dds-command-ui`. DDS is not part of FairMQ. FairMQ v1.5.0 and later do not contain the plugin and the tool. See [dds: run with DDS](/examples/dds/#requirements). + +## Build and run + +The examples build when the CMake option `BUILD_EXAMPLES` is `ON` (the default). CMake writes these files to the build directory: + + + +- build/examples/n-m/ + - fairmq-ex-n-m-synchronizer + - fairmq-ex-n-m-sender + - fairmq-ex-n-m-receiver + - fairmq-start-ex-n-m.sh + - fairmq-start-ex-n-m-pair.sh + - fairmq-start-ex-n-m-dds.sh + - fairmq-start-ex-n-m-pair-dds.sh + - fairmq-ex-n-m-env.sh + - ex-n-m-topology.xml + - ex-n-m-pair-topology.xml + + + +The scripts take no arguments: + +```sh +cd build/examples/n-m +./fairmq-start-ex-n-m.sh +./fairmq-start-ex-n-m-pair.sh +``` + +The devices use the interactive controller. Type `q` in a window to end its device. + +The DDS scripts call `dds-submit -r localhost --slots 8`. They request the transitions with `fairmq-dds-command-ui`, in the same sequence as the [dds example](/examples/dds/). They wait until all receivers go from `RUNNING` to `READY`, and then they stop all devices. + +The install step copies the executables and the scripts to `bin`, and the topology files to `share/fairmq` in the install prefix. + +## The code + +### Synchronizer: one id for each timeframe + +[`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun) sends a 2-byte id on the `pub` channel `sync`. All senders receive it. With `--rate 100`, the synchronizer sends at most 100 ids per second. + + + +After the id 65533, the next id is 0. If a send fails, `ConditionalRun()` returns `false`, and the device goes to `READY`. + +### Sender: select the receiver + +The parts of a timeframe start with this header: + + + +The sender has its own `Run()` loop. It receives an id from `sync` with [`Channel::Receive()`](/api/fair/mq/Channel/#Receive). Then it sends a multipart message: the header, and a message of `--subtimeframe-size` bytes (default 1000). + + + +- The id modulo `--num-receivers` selects the sub-channel of `data`. Thus all senders send the parts of one id to the same receiver. +- The last argument of [`Send()`](/api/fair/mq/Device/#Send-2) is a timeout of 0 ms, so `Send()` does not wait. If the queue of the sub-channel is full, `Send()` returns a negative value. The sender then logs `Failed to queue Subtimeframe # to Receiver[]` on the severity `debug` and drops the parts. +- `--num-receivers` has no default. The device does not start without it. + +### Receiver: collect the parts + +The receiver registers `HandleData()` for the multipart messages of `data` with [`OnData()`](/api/fair/mq/Device/#OnData-3). It moves part 1 into a buffer for the id of the header. When the buffer has `--num-senders` parts, the timeframe is complete. + + + +- With `--max-timeframes` greater than 0, the receiver leaves `RUNNING` after that number of complete timeframes. The default is 0 (no limit). +- `--num-senders` has no default. The device does not start without it. +- In the pair topology, the `data` channel of a receiver has three sub-channels. The device then polls all sub-channels and calls `HandleData()` with the index of the sub-channel. See [Poll several channels](/guides/poll-channels/). + +`DiscardIncompleteTimeframes()` removes the timeframes that are older than `--buffer-timeout` (default 1000 ms). The example never calls this function. Thus `--buffer-timeout` has no effect, and an incomplete timeframe stays in the buffer. + +## Output + +Each receiver logs each complete timeframe: + +```txt +Successfully completed timeframe # +``` + +With `--max-timeframes`, the receiver logs this line when it leaves `RUNNING`: + +```txt +Reached configured maximum number of timeframes (10). Exiting RUNNING state. +``` + +The synchronizer and the senders log no lines of their own on the severity `info`. In `RUNNING`, each device logs the message rate and the data rate of each sub-channel every second, in the form `data[0]: in: ( MB) out: ( MB)`. The channel property `rateLogging` sets the interval in seconds (default 1, `0` turns it off). + +## Test + +The example has no test. In `CMakeLists.txt`, the tests `Example.N-M.localhost` and `Example.N-M-pair.localhost` are comments. They run the two DDS scripts with a timeout of 15 s and expect the output `Example successful`. + +## Things to try + +- Add `--max-timeframes 10` to the receivers in `fairmq-start-ex-n-m.sh`. Each receiver then goes to `READY` after 10 complete timeframes. +- End one sender with `q`. The receivers then get only two parts for each id, so no timeframe is complete. The buffers of the receivers grow, because the example does not discard incomplete timeframes. +- Add `--severity debug` to the senders and end one receiver with `q`. When the queue of that sub-channel is full, the senders log `Failed to queue Subtimeframe # to Receiver[]`. +- Change `--subtimeframe-size` or the `--rate` of the synchronizer, and look at the rates of the `data` sub-channels. + +## Related pages + +- [Channels and sockets](/concepts/channels/) +- [Messages and multipart](/concepts/messages/) +- [Poll several channels](/guides/poll-channels/) +- [dds: run with DDS](/examples/dds/) +- [Errors and timeouts](/guides/errors-timeouts/) +- [Design a topology](/guides/design-topology/#n-senders-to-m-receivers) diff --git a/docs/src/content/docs/examples/qc.mdx b/docs/src/content/docs/examples/qc.mdx new file mode 100644 index 00000000..b447dcc7 --- /dev/null +++ b/docs/src/content/docs/examples/qc.mdx @@ -0,0 +1,144 @@ +--- +title: 'qc: quality control on demand' +description: 'A dispatcher forwards data from a sampler to a sink, and also to a QC task when a controller sets the property qc to active; the start script needs DDS.' +sidebar: + order: 14 +code: [fairmq/ProgOptions.h, fairmq/Device.h, fairmq/Message.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree } from '@astrojs/starlight/components'; + +This example sends data from a sampler through a dispatcher to a sink. When a controller sets the [property](/concepts/configuration/) `qc` of the dispatcher to `active`, the dispatcher also sends the data to a QC task. In this example, the QC task only logs that it received data. + +:::caution +FairMQ alone cannot run the start script of this example. It needs DDS, a DDS plugin for FairMQ and the tool `fairmq-dds-command-ui`. DDS is not part of FairMQ. FairMQ v1.5.0 and later do not contain the plugin and the tool. See [dds: run with DDS](/examples/dds/#requirements). +::: + +The code is in [`examples/qc`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/qc). The example shows how to: + +- subscribe to the changes of a property with `Subscribe()`, +- change the behavior of a running device through a property, +- start the devices of a topology in a specified order. + +## Topology + +The topology file `ex-qc-topology.xml` lists each task once in `main`, so DDS starts one instance of each task. Each task loads the DDS plugin with `-P dds`. No channel has an address. + +| Task | Executable | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | --- | +| `Sampler` | `fairmq-ex-qc-sampler` | `data1` | `push` | `bind` | not set | +| `QCDispatcher` | `fairmq-ex-qc-dispatcher` | `data1` | `pull` | `connect` | not set | +| | | `data2` | `push` | `connect` | not set | +| | | `qc` | `push` | `connect` | not set | +| `QCTask` | `fairmq-ex-qc-task` | `qc` | `pull` | `bind` | not set | +| `Sink` | `fairmq-ex-qc-sink` | `data2` | `pull` | `bind` | not set | + +The tasks with a binding channel have write access to the properties `fmqchan_data1`, `fmqchan_qc` and `fmqchan_data2`. The dispatcher has read access to all three. The [dds example](/examples/dds/) explains how the DDS plugin of FairMQ v1.4.56 used these properties. + +The file gives `--max-iterations 1000` to the sampler and the sink. These devices have no such option. They log it as an unregistered option on the severity `debug` and ignore it. + +## Requirements + +The start script needs DDS, a DDS plugin for FairMQ and `fairmq-dds-command-ui`. The [dds example](/examples/dds/#requirements) describes these requirements and the error when the plugin is missing. + +The four devices build with FairMQ alone. Without DDS, you can start them by hand. See [Things to try](#things-to-try). + +## Build and run + +The examples build when the CMake option `BUILD_EXAMPLES` is `ON` (the default). CMake writes these files to the build directory: + + + +- build/examples/qc/ + - fairmq-ex-qc-sampler + - fairmq-ex-qc-dispatcher + - fairmq-ex-qc-task + - fairmq-ex-qc-sink + - fairmq-start-ex-qc.sh + - fairmq-ex-qc-env.sh + - ex-qc-topology.xml + + + +`fairmq-ex-qc-dispatcher` comes from `qCDispatcher.cxx`, and `fairmq-ex-qc-task` from `qCTask.cxx`. The install step copies the executables and the scripts to `bin`, and `ex-qc-topology.xml` to `share/fairmq` in the install prefix. + +The start script takes no arguments: + +```sh +cd build/examples/qc +./fairmq-start-ex-qc.sh +``` + +The script does the same steps as the start script of the [dds example](/examples/dds/), with `dds-submit -r localhost --slots 4`. It requests the transitions in a specified order: + + + +1. All devices go to `READY`. +2. The sampler, the dispatcher and the sink go to `RUNNING`. +3. The script sets the property `qc` of the dispatcher to `active` (`-c p`). +4. The QC task goes to `RUNNING`. +5. The script waits until the QC task goes from `RUNNING` to `READY`. Then it stops all devices and prints `Example successful :)`. + +For the options of `fairmq-dds-command-ui`, see [Request the transitions](/examples/dds/#request-the-transitions). + +## The code + +### Dispatcher: subscribe to a property + +In `InitTask()`, the dispatcher subscribes to the changes of all properties of the type `std::string` with [`Subscribe()`](/api/fair/mq/ProgOptions/#Subscribe). The callback looks only at the key `qc`. The value `active` turns the sends to `qc` on, and `inactive` turns them off. + + + +The callback runs in the thread that changes the property. Thus `fDoQC` is a `std::atomic`. [`ResetTask()`](/api/fair/mq/Device/#ResetTask) ends the subscription with [`Unsubscribe()`](/api/fair/mq/ProgOptions/#Unsubscribe). + +### Dispatcher: forward the data + +The dispatcher registers `HandleData()` for `data1` with [`OnData()`](/api/fair/mq/Device/#OnData): + + + +When `fDoQC` is `true`, the dispatcher makes a copy of the message with [`Copy()`](/api/fair/mq/Message/#Copy). But it sends `msg` to `qc`, and then the same `msg` to `data2`. The code does not use `msgCopy`. On the zeromq transport, the first `Send()` empties `msg`, so the sink gets empty messages while `qc` is `active`. + +### Sampler, QC task and sink + +- The sampler sends a message of 1000 bytes on `data1` in each `ConditionalRun()` call. Then it waits 10 ms. It has no limit. +- The QC task registers a lambda for `qc` with [`OnData()`](/api/fair/mq/Device/#OnData-2). The lambda logs `received data` and returns `false`. Thus the QC task goes to `READY` after its first message. +- The sink registers `HandleData()` for `data2`. The function does nothing with the messages and returns `true`. + +## Output + +The QC task logs one line when it gets the first message on `qc`: + +```txt +received data +``` + +The sampler, the dispatcher and the sink log no lines of their own. + +## Test + +The example has no test. In `CMakeLists.txt`, the test `Example.QC.localhost` is a comment. It runs `fairmq-start-ex-qc.sh localhost` with a timeout of 15 s and expects the output `Example successful`. + +## Things to try + +- Send `msgCopy` to `qc` in `qCDispatcher.cxx`. Then the QC task and the sink both get the data. The built-in multiplier uses the same method, see [builtin-devices](/examples/builtin-devices/). +- Start the devices without DDS. Remove `-P dds` and give each channel an address. Start each device in its own terminal in `build/examples/qc`: + + ```sh + ./fairmq-ex-qc-sampler --id sampler1 --channel-config name=data1,type=push,method=bind,address=tcp://127.0.0.1:5555 + ./fairmq-ex-qc-task --id qctask1 --channel-config name=qc,type=pull,method=bind,address=tcp://127.0.0.1:5556 + ./fairmq-ex-qc-sink --id sink1 --channel-config name=data2,type=pull,method=bind,address=tcp://127.0.0.1:5557 + ./fairmq-ex-qc-dispatcher --id dispatcher1 --channel-config name=data1,type=pull,method=connect,address=tcp://127.0.0.1:5555 name=data2,type=push,method=connect,address=tcp://127.0.0.1:5557 name=qc,type=push,method=connect,address=tcp://127.0.0.1:5556 + ``` + + No controller sets `qc` here, so the dispatcher sends nothing to the QC task. + +- Set the property from code. When the dispatcher is in `READY` or `RUNNING`, a plugin can call [`SetProperty()`](/api/fair/mq/Plugin/#SetProperty) as `SetProperty("qc", "active")`. The value must be a `std::string`, because the dispatcher subscribes to `std::string` properties. See [Write a plugin](/guides/write-plugin/) and [custom-controller](/examples/custom-controller/). + +## Related pages + +- [Configuration and properties](/concepts/configuration/) +- [dds: run with DDS](/examples/dds/) +- [Plugins and control](/concepts/plugins/) +- [builtin-devices: a topology of built-in devices](/examples/builtin-devices/) diff --git a/docs/src/content/docs/examples/readout.mdx b/docs/src/content/docs/examples/readout.mdx new file mode 100644 index 00000000..482aaa81 --- /dev/null +++ b/docs/src/content/docs/examples/readout.mdx @@ -0,0 +1,138 @@ +--- +title: 'readout: a readout chain' +description: 'A readout node passes region messages over shmem channels and sends them to a receiver over zeromq, with or without a processor.' +sidebar: + order: 9 +code: [fairmq/UnmanagedRegion.h, fairmq/Device.h, fairmq/Channel.h, fairmq/shmem/Message.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree } from '@astrojs/starlight/components'; + +This example models a readout node and a processing node. On the readout node, messages from an [unmanaged region](/shmem/regions/) go through several devices on shmem channels without a copy. A sender forwards the data to the processing node on a zeromq channel. + +The code is in [`examples/readout`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/readout). The example shows how to: + +- create a region in one device and send messages from it, +- forward region messages through other devices, +- send a shmem message on a zeromq channel ([several transports](/guides/several-transports/) in one device), +- make new data in the managed segment from a region message, and release the region block. + +## Topology + +The devices do not set `--transport`, so the default transport of each device is `zeromq`. Each channel selects its transport with the [channel property](/reference/channel-properties/) `transport`. All channels are `pair` channels. + +`fairmq-start-ex-readout.sh` starts four devices: readout, builder, sender and receiver. + +| Device | Channel | Type | Method | Address | Transport | +| --- | --- | --- | --- | --- | --- | +| `readout1` | `rb` | `pair` | `bind` | `tcp://localhost:7777` | `shmem` | +| `builder1` | `rb` | `pair` | `connect` | `tcp://localhost:7777` | `shmem` | +| | `bs` | `pair` | `connect` | `tcp://localhost:7778` | `shmem` | +| `sender1` | `bs` | `pair` | `bind` | `tcp://localhost:7778` | `shmem` | +| | `sr` | `pair` | `connect` | `tcp://localhost:7779` | `zeromq` | +| `receiver1` | `sr` | `pair` | `bind` | `tcp://localhost:7779` | `zeromq` | + +`fairmq-start-ex-readout-processing.sh` adds a processor between the builder and the sender. The builder gets `--output-name bp` and the sender gets `--input-name ps`. + +| Device | Channel | Type | Method | Address | Transport | +| --- | --- | --- | --- | --- | --- | +| `readout1` | `rb` | `pair` | `bind` | `tcp://localhost:7777` | `shmem` | +| `builder1` | `rb` | `pair` | `connect` | `tcp://localhost:7777` | `shmem` | +| | `bp` | `pair` | `connect` | `tcp://localhost:7778` | `shmem` | +| `processor1` | `bp` | `pair` | `bind` | `tcp://localhost:7778` | `shmem` | +| | `ps` | `pair` | `connect` | `tcp://localhost:7779` | `shmem` | +| `sender1` | `ps` | `pair` | `bind` | `tcp://localhost:7779` | `shmem` | +| | `sr` | `pair` | `connect` | `tcp://localhost:7780` | `zeromq` | +| `receiver1` | `sr` | `pair` | `bind` | `tcp://localhost:7780` | `zeromq` | + +## Requirements + +The start scripts open one `xterm` window for each device. `xterm` must be installed. + +## Build and run + +The examples build when the CMake option `BUILD_EXAMPLES` is `ON` (the default). The executables and the start scripts are in the build directory: + + + +- build/examples/readout/ + - fairmq-ex-readout-readout + - fairmq-ex-readout-builder + - fairmq-ex-readout-processor + - fairmq-ex-readout-sender + - fairmq-ex-readout-receiver + - fairmq-start-ex-readout.sh + - fairmq-start-ex-readout-processing.sh + + + +Both scripts take one optional argument: the message size in bytes (default `1000000`). + +```sh +cd build/examples/readout +./fairmq-start-ex-readout.sh +./fairmq-start-ex-readout-processing.sh 4096 +``` + +## The code + +### Readout: create the region and send + +The readout device creates a region of 10000000 bytes with the transport of the channel `rb`. It gives no [`RegionConfig`](/api/fair/mq/RegionConfig/), so the region uses the defaults. The callback counts the acknowledgements. + + + +[`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun) sends one message for each call. The message points to the start of the region and has the size `--msg-size`. + + + +In `ResetTask()`, the readout device waits 500 ms once if messages are not acknowledged. Then it destroys the region. + +### Builder and sender: forward the messages + +The builder and the sender register a data callback with [`OnData()`](/api/fair/mq/Device/#OnData) and send each message on. The builder forwards from `rb` to the channel of `--output-name` (default `bs`): + + + +The sender forwards from the channel of `--input-name` (default `bs`) to `sr`. The message is a shmem message, but `sr` is a zeromq channel. [`Channel::Send()`](/api/fair/mq/Channel/#Send) compares the transports. If they differ, the channel puts the data of the message into a new message of its own transport. It does not copy the data. The new message deletes the original message when the zeromq transport releases the data. See [`Channel.h`](/source/fairmq/Channel.h/#L421-L438). + +Thus the readout device gets the acknowledgement for a block after the zeromq transport releases the data. + +### Processor: make new data + +The processor receives a region message and makes a new message of the same size for the channel `ps`. It does not copy the data. On the shmem transport, this message is in the managed segment, not in the region. + + + +The device destroys the received message when `HandleData()` returns (see [`Device.cxx`](/source/fairmq/Device.cxx/#L564-L573)). Then the transport releases the region block, and the readout device gets the acknowledgement. The new message is not part of the region. + +## Output + +The devices log little. With `--max-iterations` greater than 0, the readout device and the receiver leave the state `RUNNING` after that number of messages. The readout device logs: + +```txt +Configured maximum number of iterations reached. Leaving RUNNING state. +``` + +The receiver logs `Configured max number of iterations reached. Leaving RUNNING state.` With `--severity debug` and `--max-iterations`, the readout device also logs each bulk callback as `Received acks`. When messages are not acknowledged in `ResetTask()`, it logs `waiting for all acknowledgements... ()` and `done, still unacked: ` on the severity `debug`. + +## Test + +The example has no test. Its `CMakeLists.txt` uses `NO_TEST`. + +## Things to try + +- Add `--max-iterations 1000 --severity debug` to the readout device in the start script. The log then shows the acknowledgements. +- Limit the rate of the readout device with `--rate 100` (in Hz). The option controls the `ConditionalRun()` loop. +- Run the receiver on a second computer. Change the address of `sr` in the sender and in the receiver to an address of that computer. +- Look at the segment and the region with [fairmq-shmmonitor](/tools/shmmonitor/) while the devices run. + +## Related pages + +- [Unmanaged regions](/shmem/regions/) +- [How shared memory works](/shmem/how-it-works/) +- [Use several transports](/guides/several-transports/) +- [region: unmanaged regions](/examples/region/): acknowledgements, region events and shared copies. +- [Transports](/concepts/transports/) +- [Design a topology](/guides/design-topology/#a-readout-chain) diff --git a/docs/src/content/docs/examples/region.mdx b/docs/src/content/docs/examples/region.mdx new file mode 100644 index 00000000..58b9b708 --- /dev/null +++ b/docs/src/content/docs/examples/region.mdx @@ -0,0 +1,207 @@ +--- +title: 'region: unmanaged regions' +description: 'A sampler sends messages from an unmanaged region and counts the acknowledgements; a larger topology shares the region data with four sinks.' +sidebar: + order: 8 +code: [fairmq/UnmanagedRegion.h, fairmq/Device.h, fairmq/TransportFactory.h, fairmq/shmem/UnmanagedRegion.h, fairmq/shmem/Message.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { FileTree, Steps } from '@astrojs/starlight/components'; + +The sampler of this example creates an [unmanaged region](/shmem/regions/) and sends messages that point into it. The transport tells the sampler, through a callback, when the receivers no longer use a message. The sampler counts these acknowledgements. + +The code is in [`examples/region`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/region). The example shows how to: + +- create a region with [`NewUnmanagedRegionFor()`](/api/fair/mq/Device/#NewUnmanagedRegionFor) and a [`RegionConfig`](/api/fair/mq/RegionConfig/), +- make messages in the region with [`NewMessageFor()`](/api/fair/mq/Device/#NewMessageFor) and send 64 of them as one multipart message, +- receive the acknowledgements in a bulk callback, +- log region events with [`SubscribeToRegionEvents()`](/api/fair/mq/TransportFactory/#SubscribeToRegionEvents), +- share region messages between two outputs with [`Copy()`](/api/fair/mq/Message/#Copy), +- use a region that another process created. + +## Topology + +The example has three start scripts. `fairmq-start-ex-region.sh` connects one sampler to one sink: + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data` | `push` | `bind` | `tcp://127.0.0.1:7777` | +| `sink1` | `data` | `pull` | `connect` | `tcp://127.0.0.1:7777` | + +The script also sets `sndKernelSize=212992` on the channel of the sampler and `rcvKernelSize=212992` on the channel of the sink. + +`fairmq-start-ex-region-advanced.sh` starts one sampler, two processors and four sinks. The `push` channel of the sampler distributes the messages over the two processors. Each processor sends each part to two sinks. The sampler and the sinks select their channel with `--chan-name`. + +| Device | `--shm-segment-id` | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | --- | +| `sampler1` | `0` (default) | `data1` | `push` | `bind` | `tcp://127.0.0.1:7777` | +| `processor1` | `1` | `data1` | `pull` | `connect` | `tcp://127.0.0.1:7777` | +| | | `data2` | `push` | `bind` | `tcp://127.0.0.1:7778` | +| | | `data3` | `push` | `bind` | `tcp://127.0.0.1:7779` | +| `processor2` | `2` | `data1` | `pull` | `connect` | `tcp://127.0.0.1:7777` | +| | | `data2` | `push` | `bind` | `tcp://127.0.0.1:7788` | +| | | `data3` | `push` | `bind` | `tcp://127.0.0.1:7789` | +| `sink1_1` | `1` | `data2` | `pull` | `connect` | `tcp://127.0.0.1:7778` | +| `sink1_2` | `1` | `data3` | `pull` | `connect` | `tcp://127.0.0.1:7779` | +| `sink2_1` | `2` | `data2` | `pull` | `connect` | `tcp://127.0.0.1:7788` | +| `sink2_2` | `2` | `data3` | `pull` | `connect` | `tcp://127.0.0.1:7789` | + +`fairmq-start-ex-region-advanced-external.sh` starts the same topology with these changes: + +- All devices use `--shmid 1`, `--shm-no-cleanup true` and `--shm-monitor false`. +- The sampler uses `--external-region true` and `--rc-segment-size 200000000`. + +With `--external-region true`, the sampler uses a region that another process created. See [Use a region of another process](#use-a-region-of-another-process). + +## Requirements + +- The start scripts open one `xterm` window for each device. `xterm` must be installed. +- The advanced scripts use options of the shmem transport (`--shm-segment-id`, `--shmid`). Use them with the shmem transport, the default of the scripts. +- `fairmq-ex-region-keep-alive` uses the shared memory classes of FairMQ directly. It works only with shared memory. + +## Build and run + +The examples build when the CMake option `BUILD_EXAMPLES` is `ON` (the default). The executables and the start scripts are in the build directory: + + + +- build/examples/region/ + - fairmq-ex-region-sampler + - fairmq-ex-region-processor + - fairmq-ex-region-sink + - fairmq-ex-region-keep-alive + - fairmq-start-ex-region.sh + - fairmq-start-ex-region-advanced.sh + - fairmq-start-ex-region-advanced-external.sh + - test-ex-region.sh + + + +Each start script takes two arguments: the transport (default `shmem`) and the size of one part in bytes (default `1000000`). + +```sh +cd build/examples/region +./fairmq-start-ex-region.sh +./fairmq-start-ex-region.sh zeromq 4096 +./fairmq-start-ex-region-advanced.sh +``` + +The scripts set `FAIRMQ_PATH` to `build/fairmq`. A device with `--shm-monitor true` finds `fairmq-shmmonitor` there. The install step copies the executables and the scripts to `bin` in the install prefix. The installed scripts start the installed executables. + +## The code + +### Create the region + +The sampler creates the region in `InitTask()`. The region is 10000000 bytes. The sampler creates it with the transport of sub-channel 0 of its output channel. + + + +- The lambda is the bulk callback. The transport calls it with the blocks that it no longer needs. Each [`RegionBlock`](/api/fair/mq/RegionBlock/) has the pointer, the size and the hint of one message. +- `linger` comes from `--region-linger` (default 100). On the shmem transport, the region receives outstanding acknowledgements for this time in ms when it is destroyed. The zeromq transport ignores it. +- `rcSegmentSize` comes from `--rc-segment-size` (default 10000000 in this example). It sets the size of the segment that keeps the reference counts of copied region messages. +- `lock` and `zero` lock the pages of the region in memory and fill the region with zeros. The sampler sets them only for a region that it creates itself. + +### Send messages from the region + +`Run()` makes 64 messages and sends them as one [`Parts`](/api/fair/mq/Parts/) object. All 64 messages point to the start of the region and have the size `--msg-size`. The counter of unacknowledged messages goes up by the number of parts. + + + +After the send loop, `Run()` waits until the counter is zero, or until a new state is pending. `ResetTask()` destroys the region and ends the subscription to region events. + +### Log the region events + +The sampler, the processor and the sink all subscribe to the region events of their transport: + + + +On the shmem transport, the events cover all managed segments and unmanaged regions of the [session](/shmem/sessions/). Thus the sink also logs the region of the sampler. On the zeromq transport, the events come only from the regions of the own process. There, the first event is `local_only`. + +### Share a region message + +The processor sends each received part to two channels. It makes both outgoing messages with `Copy()`: + + + +On the shmem transport, `Copy()` of a region message copies no data. It adds a reference count. The transport releases the block, and the sampler gets the acknowledgement, after the last copy is destroyed. See [`shmem/Message.h`](/source/fairmq/shmem/Message.h/#L273-L330) and [How shared memory works](/shmem/how-it-works/). On the zeromq transport, the copy shares the buffer of the original message. + +### Keep segments and regions alive + +`fairmq-ex-region-keep-alive` is not a device. At start, it removes all shared memory of the given `--shmid`. Then it creates managed segments and unmanaged regions for this `--shmid`, locks them in memory and fills them with zeros: + + + +The program checks every 500 ms that the segments and regions are present. It stops and cleans up if one is missing. On `SIGUSR1`, it resets the content of the segments and regions. On `SIGINT` or `SIGTERM`, it removes all shared memory of the `--shmid`. + +:::note +`--segments` and `--regions` need three comma-separated values for each entry, for example `1,10000000,0`. The program uses the first two values (id and size) and ignores the third. The help text of `--regions` shows only `,` for the first entry. +::: + +## Output + +The sampler, the processors and the sinks log each region event: + +```txt +Region event: created: unmanaged, id: , ptr:
    , size: 10000000, flags: 0 +``` + +With `--max-iterations` greater than 0, the sampler stops after that number of multipart messages. It also logs each bulk callback: + +```txt +Configured maximum number of iterations reached. Stopping sending. +Received 64 acks +All acknowledgements received. +``` + +The acknowledgements can arrive in more than one callback. Then `Received acks` shows more than once. If a new state is pending before all acknowledgements arrive, the sampler logs `Done, still not acknowledged: ` instead of the last line. With `--max-iterations`, the sink and the processor log `Configured max number of iterations reached. Leaving RUNNING state.` + +## Test + +`examples/region/CMakeLists.txt` adds the tests `Example.region.zeromq` and `Example.region.shmem`. Each test runs `test-ex-region.sh` with the transport as argument. The script starts one sampler and one sink with `--max-iterations 1`, `--control static` and an `ipc://` address. The timeout is 30 s. To write a script of this type for your own devices, see [Write the test script](/guides/test-devices/#write-the-test-script). + +Configure with `-DBUILD_TESTING=ON` to register the tests. Then run them in the build directory: + +```sh +ctest -R Example.region +``` + +## Things to try + +- Limit the send rate of the sampler with `--sampling-rate 10` (in Hz). The default `0` sends as fast as possible. +- Start the advanced topology with `--rc-segment-size 0` on the sampler (the script has it as a comment). Then the transport keeps the reference counts of the copies in the managed segment. +- Look at the shared memory while the topology runs. Run `fairmq-shmmonitor --list-all` from `build/fairmq`. See [fairmq-shmmonitor](/tools/shmmonitor/). + +### Use a region of another process + +The external variant needs a region with id 1 and a size of 10000000 bytes, the size that the sampler requests. Create it with the keep-alive program: + + + +1. In a terminal, start the keep-alive program in `build/examples/region`: + + ```sh + ./fairmq-ex-region-keep-alive --shmid 1 --regions 1,10000000,0 + ``` + +2. In a second terminal, start the topology: + + ```sh + ./fairmq-start-ex-region-advanced-external.sh + ``` + +3. Stop the devices. Then stop the keep-alive program with `Ctrl-C`. It removes the shared memory of `--shmid 1`. + + + +The opened region uses the `rcSegmentSize` of its creator. The keep-alive program creates the region with `rcSegmentSize` 0. Thus `--rc-segment-size 200000000` of the sampler has no effect, and the transport keeps the reference counts of the copies in the managed segment. + +The devices of this variant use `--shm-no-cleanup true`. Thus their shared memory stays after they stop. Without the keep-alive program, remove it with `fairmq-shmmonitor --cleanup --shmid 00000001`. The shmem transport writes `--shmid 1` as the hexadecimal string `00000001`. + +## Related pages + +- [Unmanaged regions](/shmem/regions/): the region API and the acknowledgements in detail. +- [How shared memory works](/shmem/how-it-works/) +- [Sessions and segments](/shmem/sessions/) +- [readout: a readout chain](/examples/readout/): a region in a chain of devices. +- [Monitor and clean up](/shmem/monitor/) diff --git a/docs/src/content/docs/examples/req-rep.mdx b/docs/src/content/docs/examples/req-rep.mdx new file mode 100644 index 00000000..dd91f162 --- /dev/null +++ b/docs/src/content/docs/examples/req-rep.mdx @@ -0,0 +1,149 @@ +--- +title: 'req-rep: request and reply' +description: 'A client sends a request on a req socket and waits for the reply. A server answers on a rep socket of the same channel.' +sidebar: + order: 3 +code: [fairmq/Device.h, fairmq/Channel.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, FileTree } from '@astrojs/starlight/components'; + +The req-rep example shows messages in two directions on one channel. The client sends a request and waits +for the reply. The server receives the request in a data handler and sends the reply on the same channel. + +The files of the example are in +[`examples/req-rep`](https://github.com/FairRootGroup/FairMQ/tree/dev/examples/req-rep) on GitHub. + +## Topology + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `client` | `data` | `req` | `connect` | `tcp://127.0.0.1:5005` | +| `server` | `data` | `rep` | `bind` | `tcp://127.0.0.1:5005` | + +A `req` socket must send and receive in turn: one request, then one reply. A `rep` socket receives a request +and sends the reply to the client of this request. The [Channels and sockets](/concepts/channels/) page +describes all socket types. + +## Build the example + +The examples build together with FairMQ when the CMake option `BUILD_EXAMPLES` is `ON` (the default): + + + +- build/examples/req-rep/ + - fairmq-ex-req-rep-client + - fairmq-ex-req-rep-server + - fairmq-start-ex-req-rep.sh + - test-ex-req-rep.sh + + + +## Run the example + + + +1. Go to the directory of the example in the build tree: + + ```sh + cd build/examples/req-rep + ``` + +2. Run the start script. It opens two `xterm` windows, one for each device: + + ```sh + ./fairmq-start-ex-req-rep.sh + ``` + + + +To run the example without `xterm`, run each command in its own terminal in `build/examples/req-rep`: + +```sh +./fairmq-ex-req-rep-client --id client \ + --channel-config "name=data,type=req,method=connect,rateLogging=0,address=tcp://127.0.0.1:5005" +``` + +```sh +./fairmq-ex-req-rep-server --id server \ + --channel-config "name=data,type=rep,method=bind,rateLogging=0,address=tcp://127.0.0.1:5005" +``` + +Push `q` in a terminal to stop the device in it. + +## The client + + + +- The request is a message for a new `std::string`, with a free function that deletes the string. The + [1-1 example](/examples/1-1/#the-sampler) explains this form of + [`NewMessage()`](/api/fair/mq/Device/#NewMessage). +- `NewMessage()` without arguments creates an empty message for the reply. +- [`Send()`](/api/fair/mq/Device/#Send) sends the request. Then + [`Receive()`](/api/fair/mq/Device/#Receive) waits for the reply on the same channel and puts it into + `rep`. +- The default receive timeout of a channel is `-1`. Thus `Receive()` waits until the reply arrives or the + device gets a new state. If the server ends before it replies, see + [A peer ends while the device sends or receives](/guides/errors-timeouts/#a-peer-ends-while-the-device-sends-or-receives). +- `ConditionalRun()` returns `false` if `Send()` returns `0` or less, or if `Receive()` returns a negative + value. Then the device goes to `READY`. +- After each reply, the client waits 1 s. + +The client has the custom options `--text` (default `Hello`) and `--max-iterations` (default `0`, no limit). + +## The server + + + + + +The server registers `HandleData()` for the channel `data` with [`OnData()`](/api/fair/mq/Device/#OnData). +The device calls the handler for each request. The handler puts the text of the request into the reply and +sends the reply with `Send()` on the same channel. The server has the option `--max-iterations`. + +## Output + +The listings show the severity and the message of each line, without the time. The client logs two lines +for each request: + +```txt +[INFO] Sending "Hello" to server. +[INFO] Received reply from server: "Thank you for the "Hello"!" +``` + +The server logs two lines for each request: + +```txt +[INFO] Received request from client: "Hello" +[INFO] Sending reply to client. +``` + +## Test the example + +The test script `test-ex-req-rep.sh` starts the client and the server in the background. It uses an +`ipc://` address in `/tmp`, a new session, and `--control static`. Both devices stop after one request +(`--max-iterations 1`). + +CTest runs the script once for each transport: `Example.req-rep.zeromq` and `Example.req-rep.shmem`. The +tests exist if you configure with `-DBUILD_TESTING=ON`. + +```sh +cd build +ctest -R '^Example\.req-rep\.' --output-on-failure +``` + +## Things to try + +- Send another text: start the client with `--text "Ping"`. +- Use shared memory: add `--transport shmem` to both commands. +- Stop after three requests: add `--max-iterations 3` to both commands. +- Start a second client with the same channel configuration and `--id client2`. The server receives the + requests of both clients, and each client gets its own replies. + +## Related pages + +- [Channels and sockets](/concepts/channels/): the socket types `req` and `rep`. +- [Receive data with callbacks or loops](/guides/receive-data/): `OnData()` and `Receive()`. +- [Handle errors and timeouts](/guides/errors-timeouts/): the return values of `Send()` and `Receive()`. +- [Transfer codes and errors](/reference/transfer-codes/): the negative return values. diff --git a/docs/src/content/docs/guides/benchmark.mdx b/docs/src/content/docs/guides/benchmark.mdx new file mode 100644 index 00000000..949f8b27 --- /dev/null +++ b/docs/src/content/docs/guides/benchmark.mdx @@ -0,0 +1,253 @@ +--- +title: 'Run a benchmark' +description: 'Measure the throughput of the zeromq and shmem transports with fairmq-bsampler and fairmq-sink, and read the rate lines that the devices log.' +sidebar: + order: 10 +code: [fairmq/devices/BenchmarkSampler.h, fairmq/devices/Sink.h, fairmq/Device.cxx, fairmq/shmem/Manager.h] +--- + +import { Steps } from '@astrojs/starlight/components'; +import Snippet from '../../../components/Snippet.astro'; + +This guide measures the throughput between two devices on one host. `fairmq-bsampler` sends messages of a fixed size as fast as the channel accepts them. `fairmq-sink` receives the messages and discards them. Each device logs the message rate and the data rate of its channel every second. The options of the two devices are on [Built-in devices](/tools/builtin-devices/). + +## Before you start + +- Use an optimized build of FairMQ. If you give no `CMAKE_BUILD_TYPE`, FairMQ uses `RelWithDebInfo`. +- Keep the CMake option `FAIRMQ_DEBUG_MODE` at its default `OFF`. In debug mode, the `shmem` transport records each message in the shared memory under a lock. +- Find the executables. In a build directory, they are in `/fairmq/`. In an installation, they are in the `bin` directory. The commands on this page expect them in `$PATH`. +- Open two terminals on the same host. + +## Measure the zeromq transport + + + +1. In the first terminal, start the sink: + + ```sh + fairmq-sink --id sink1 \ + --channel-config name=data,type=pair,method=connect,address=tcp://127.0.0.1:5555 + ``` + +2. In the second terminal, start the sampler with messages of 1 MB: + + ```sh + fairmq-bsampler --id bsampler1 --msg-size 1000000 \ + --channel-config name=data,type=pair,method=bind,address=tcp://127.0.0.1:5555 + ``` + +3. Wait some seconds. Then read the rate lines in the two terminals. See [Read the rate lines](#read-the-rate-lines). + +4. Stop each device. Push `q` in its terminal, or push Ctrl+C. + + + +The two devices connect with a `pair` channel. The [start script](#use-the-start-script) uses the same channel. The default of `--msg-size` is `1000000` bytes. The command gives the option only to show the value. + +## Measure the shmem transport + +With `--transport shmem`, the sampler makes each message in a shared memory segment. The socket sends only a small metadata message with the location of the buffer. The receiver finds the buffer in the same segment. + + + +1. In the first terminal, start the sink: + + ```sh + fairmq-sink --id sink1 --transport shmem \ + --channel-config name=data,type=pair,method=connect,address=tcp://127.0.0.1:5555 + ``` + +2. In the second terminal, start the sampler: + + ```sh + fairmq-bsampler --id bsampler1 --transport shmem --msg-size 1000000 \ + --shm-throw-bad-alloc false \ + --channel-config name=data,type=pair,method=bind,address=tcp://127.0.0.1:5555 + ``` + +3. Read the rate lines. Then stop the two devices. + + + +The two devices must use the same shared memory: + +- They must run on the same host. +- They must use the same `--session`. The default is `default`. +- They must run with the same effective user ID. The name of the segment comes from the session name and the user ID. + +The default segment size is 2147483648 bytes (2 GiB, option `--shm-segment-size`). Messages that wait in the queues of the channel use memory in the segment. With `--shm-throw-bad-alloc false`, the sampler waits for free memory when the segment is full. Without this option, the sampler goes to the state `ERROR`. See [Problems that can occur](#problems-that-can-occur). + +## Send a fixed number of messages + +To measure the time for a number of messages, give the same `--max-iterations` to the two devices. Also give `--control static`, so that each process ends after the run. + + + +1. Start the sink: + + ```sh + fairmq-sink --id sink1 --control static --max-iterations 100000 \ + --channel-config name=data,type=pair,method=connect,address=tcp://127.0.0.1:5555 + ``` + +2. Start the sampler: + + ```sh + fairmq-bsampler --id bsampler1 --control static --max-iterations 100000 \ + --channel-config name=data,type=pair,method=bind,address=tcp://127.0.0.1:5555 + ``` + +3. Read the last lines of each device: + + ```txt + Done 100000 iterations in ms. + ``` + + ```txt + Received 100000 messages in ms. + ``` + + + +Each device sends or receives one more message than the value of `--max-iterations`. The log line shows the value. See [the note on fairmq-bsampler](/tools/builtin-devices/#fairmq-bsampler). + +Each time starts when the device enters the state `RUNNING`. So the time includes the wait for the other device. Use the time of the device that you start last. The mean data rate is the number of messages multiplied by `--msg-size`, divided by the time. + +With the default `--control dynamic`, the device does not end after the last message. It goes back to the state `READY` and waits for a key. + +## Change the load + +Give these options to the sampler. Give `--multipart` with the same value to the sink. + +| Option | Effect | +| --- | --- | +| `--msg-size ` | Size of each message, or of each part. Small messages show the cost of each message. Large messages show the maximum data rate. | +| `--multipart true --num-parts ` | Send multipart messages of `n` parts. The rate lines count a multipart message as one message. | +| `--msg-rate ` | Send at most `n` messages per second. Use it to measure a fixed load. | +| `--memset true` | Write zeros into each buffer before the send. Without it, no device writes or reads the data. | +| `--msg-alignment ` | Alignment of each buffer. `0` is the default alignment of the transport. | + +To keep the two devices on different CPU cores, start them with `taskset`: + +```sh +taskset -c 1 fairmq-sink --id sink1 \ + --channel-config name=data,type=pair,method=connect,address=tcp://127.0.0.1:5555 +``` + +```sh +taskset -c 0 fairmq-bsampler --id bsampler1 \ + --channel-config name=data,type=pair,method=bind,address=tcp://127.0.0.1:5555 +``` + +## Use the start script + +The build directory has the script `startMQBenchmark.sh`. It starts the sampler and the sink in two `xterm` windows, with the channel of this page. It needs `xterm` and a display. + + + +1. Go to the directory of the script: + + ```sh + cd build/fairmq + ``` + +2. Start the benchmark. The parameters are the message size, the number of iterations and the transport: + + ```sh + ./startMQBenchmark.sh 1000000 0 shmem + ``` + +3. Read the rate lines in the two windows. + + + +The script also takes the parameters affinity, multipart and number of parts. It does not give `--control static`. See [The script startMQBenchmark.sh](/tools/builtin-devices/#the-script-startmqbenchmarksh). + +## Read the rate lines + +During the state `RUNNING`, a thread of each device logs one line for each sub-channel every second. These lines have the severity `info`: + +```txt +data[0]: in: ( MB) out: ( MB) +``` + +- `data[0]` is the name of the sub-channel. The device pads the names on the left to the length of the longest name. +- `in` is the receive rate. `out` is the send rate. +- The first number is the number of messages per second. +- The number in parentheses is the data rate in megabytes per second. One MB is 1000000 bytes. A multipart message counts once, with the sum of the sizes of its parts. +- The device divides the counts by the measured time since the last line. + +The device computes the values in [`Device::LogSocketRates()`](/source/fairmq/Device.cxx/#L613-L705): + + + +The `in` values of the sampler and the `out` values of the sink are 0. The numbers in this example are not a measurement: + +```txt +data[0]: in: 0 (0 MB) out: 2840.16 (2840.16 MB) +``` + +```txt +data[0]: in: 2840.16 (2840.16 MB) out: 0 (0 MB) +``` + +The channel property `rateLogging` sets the interval in seconds. The default is `1`. `0` turns the lines off for the sub-channel. Give the property in the channel configuration, for example `name=data,type=pair,method=bind,address=tcp://127.0.0.1:5555,rateLogging=0`. See [Channel properties](/reference/channel-properties/). + +:::caution[Keep rateLogging at 1 for measurements] +With a value `n` above 1, the device adds up the counts of `n` seconds, but it divides them by the time of the last second. So the logged rates are about `n` times too high. +::: + +With `--severity state`, `warn` or a higher severity, the device does not log the rate lines. + +## Understand the numbers + +- Compare the `out` rate of the sampler with the `in` rate of the sink. After some seconds, they are almost equal. +- Do not use the first lines. They include the time until the other device connects, and the time to fill the queues. +- The data rate is the message rate multiplied by the message size. +- With `shmem`, the data does not go through the socket. The data rate shows how fast the devices pass buffers, not how fast data moves in memory. +- Without `--memset true`, the measurement does not include the time to write or read the data. A real device writes and reads its data. +- Run each measurement more than one time. Other processes on the host change the result. + +## Measure between two hosts + +Only the `zeromq` transport connects devices on two hosts. The `shmem` transport works only on one host. + + + +1. On the first host, start the sampler. It binds on all interfaces: + + ```sh + fairmq-bsampler --id bsampler1 \ + --channel-config name=data,type=pair,method=bind,address=tcp://*:5555 + ``` + +2. On the second host, start the sink. Replace `` with the name or the IP address of the first host: + + ```sh + fairmq-sink --id sink1 \ + --channel-config name=data,type=pair,method=connect,address=tcp://:5555 + ``` + + + +The firewall of the first host must accept connections on port 5555. + +## Problems that can occur + +| Problem | Cause | Solution | +| --- | --- | --- | +| The sampler goes to `ERROR` with `Requested message size () exceeds segment size ()`. | With `shmem`, a message and its header must fit into the segment. | Give a larger `--shm-segment-size` to the two devices, or use a smaller `--msg-size`. | +| The sampler goes to `ERROR` with `shmem: could not create a message of size , …, free memory: `. | The segment is full. By default, the device tries one time. | Give `--shm-throw-bad-alloc false` to the sampler. It then tries again every `--bad-alloc-attempt-interval` ms (default 50) and logs no line. Or give `--bad-alloc-max-attempts `. | +| The rate lines show `in: 0` on the sink. | The devices do not use the same address, transport, session or user. | Check the options of the two devices. | +| The rates of the sink do not agree with the sampler, or the sink logs errors. | The devices use different `--multipart` values. With `shmem`, single messages and multipart messages have different metadata. | Give the same `--multipart` value to the two devices. | +| Shared memory of an old run stays after a crash. | A device that crashes does not remove the shared memory. | Remove it with `fairmq-shmmonitor --cleanup --session default`. See [Monitor and clean up](/shmem/monitor/). | +| The rates change a lot between runs. | Other processes use the same CPU cores. | Pin the devices to different cores with `taskset`. | + +## Related pages + +- [Built-in devices](/tools/builtin-devices/): all options of `fairmq-bsampler` and `fairmq-sink`, and the start script. +- [Channel properties](/reference/channel-properties/): `rateLogging`, `sndBufSize`, `rcvBufSize` and the other properties. +- [Sessions and segments](/shmem/sessions/): the names of the shared memory objects. +- [Tune and debug](/shmem/tuning/): segment size and bad allocations. +- [fairmq-shmmonitor](/tools/shmmonitor/): look at and remove shared memory. +- [Transports](/concepts/transports/#tune-the-zeromq-transport): the I/O threads, queues and kernel buffers of the zeromq transport. diff --git a/docs/src/content/docs/guides/channels-without-device.mdx b/docs/src/content/docs/guides/channels-without-device.mdx new file mode 100644 index 00000000..276fd72f --- /dev/null +++ b/docs/src/content/docs/guides/channels-without-device.mdx @@ -0,0 +1,282 @@ +--- +title: 'Use channels without a device' +description: 'Make a transport factory and channels in your own program, send and receive messages, and close the channels, without fair::mq::Device.' +sidebar: + order: 6 +code: [fairmq/TransportFactory.h, fairmq/TransportFactory.cxx, fairmq/Channel.h, fairmq/Channel.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +You can use the FairMQ transports and channels without +[`fair::mq::Device`](/api/fair/mq/Device/), for example +[in a test](/guides/test-devices/#test-without-a-device), or in a tool with its own main +loop. You make the transport factory and the channels yourself, bind and connect them, +and send and receive messages. You do not get the state machine, the plugins and the command-line +options of a device. + +## Make and use channels + + + +1. Make a [`fair::mq::ProgOptions`](/api/fair/mq/ProgOptions/) object. Set the properties that the + transport reads. + +2. Make the transport factory with + [`TransportFactory::CreateTransportFactory()`](/api/fair/mq/TransportFactory/#CreateTransportFactory). + +3. Make each channel with a constructor that takes the factory. + +4. Bind or connect each channel. Make sure that the call returns `true`. + +5. Make messages with the channel, and send and receive them with a timeout. + +6. At the end, destroy the messages first, then the channels, and then the factory. + + + +This program does all steps with the zeromq transport. It sends one message from a `push` channel +to a `pull` channel in the same program: + +```cpp title="main.cxx" +#include +#include +#include + +#include +#include + +int main() +{ + fair::mq::ProgOptions config; + config.SetProperty("io-threads", 1); + + auto factory = fair::mq::TransportFactory::CreateTransportFactory("zeromq", "my-program", &config); + + fair::mq::Channel pull("data-in", "pull", factory); + fair::mq::Channel push("data-out", "push", factory); + + if (!pull.Bind("tcp://127.0.0.1:5555") || !push.Connect("tcp://127.0.0.1:5555")) { + return 1; + } + + auto out(push.NewSimpleMessage("hello")); + if (push.Send(out, 1000) < 0) { + return 1; + } + + auto in(pull.NewMessage()); + if (pull.Receive(in, 1000) < 0) { + return 1; + } + + std::cout << std::string(static_cast(in->GetData()), in->GetSize()) << '\n'; + return 0; +} +``` + +Link the program with the CMake target `FairMQ::FairMQ`, as in +[Use FairMQ in a CMake project](/start/cmake/). The program writes `hello`. + +## Make the transport factory + +`CreateTransportFactory(type, id, config)` returns a `std::shared_ptr`: + +- `type` is `zeromq` or `shmem`. For other values, the function throws + [`fair::mq::TransportFactoryError`](/api/fair/mq/TransportFactoryError/). +- `id` names the factory. The zeromq sockets get the identity `..`. If `id` + is empty, the function makes a UUID. +- `config` is a pointer to a `ProgOptions` object. The factory reads its properties when you make + it. With `nullptr`, the factory uses the defaults. + +A new `ProgOptions` object has only the log options and `help`, `version` and `print-options`. The +factory reads each other property with a default value, so set only the properties that you change. +The most important properties: + +| Property | C++ type | Default | Transport | +| --- | --- | --- | --- | +| `io-threads` | `int` | `1` | both | +| `session` | `std::string` | `default` | shmem | +| `shm-segment-size` | `std::size_t` | 2 GiB | shmem | +| `shm-monitor` | `bool` | `false` | shmem | +| `shm-no-cleanup` | `bool` | `false` | shmem | +| `shm-metadata-msg-size` | `std::size_t` | `0` | shmem | + +The shmem transport reads more properties, for example `shm-allocation`, `shm-segment-id` and +`shm-throw-bad-alloc`. Set each property with the C++ type that the transport reads. For another +type, the factory throws `boost::bad_any_cast`. For all properties, see +[Command-line options](/reference/options/). The test +helper of FairMQ sets the properties for the shmem transport: + + + +Each factory has its own zeromq context, and ZeroMQ connects `inproc://` endpoints only inside one +context. Thus an `inproc://` address connects only channels of the same factory. For the shmem transport, all factories with the same session share the shared memory. +See [Sessions and segments](/shmem/sessions/). + +## Make the channels + +[`fair::mq::Channel`](/api/fair/mq/Channel/) has two constructors that take a factory. Both make the +socket at once: + +| Constructor | What it stores | +| --- | --- | +| [`Channel(name, type, factory)`](/api/fair/mq/Channel/#Channel-4) | The name and the socket type. | +| [`Channel(name, type, method, address, factory)`](/api/fair/mq/Channel/#Channel-5) | Also the method (`bind` or `connect`) and the address, for `Validate()`. | + +The socket types are `push`, `pull`, `pub`, `sub`, `xpub`, `xsub`, `req`, `rep`, `dealer`, `router` +and `pair`. An unknown type throws an exception. The shmem transport throws +[`fair::mq::SocketError`](/api/fair/mq/SocketError/) for `pub` and `sub`. + +The other constructors make a channel without a factory and without a socket. The device gives such +channels their factory. Your program cannot do this, because the function for it is private. + +A copy of a channel has no factory and no socket. Move a channel, or make it in place, for example +with `emplace_back()`. Use each channel from one thread at a time, because the class is not +[thread-safe](/concepts/threads/#what-is-thread-safe). Different threads can use different channels. + +## Bind and connect + +| Function | What it does | +| --- | --- | +| [`Bind(address)`](/api/fair/mq/Channel/#Bind) | Sets the method `bind` and the address of the channel, and binds the socket. | +| [`Connect(address)`](/api/fair/mq/Channel/#Connect) | Sets the method `connect` and the address of the channel, and connects the socket. | +| [`BindEndpoint(endpoint)`](/api/fair/mq/Channel/#BindEndpoint) | Binds the socket. If the bind fails for a `tcp://` endpoint, it tries random ports. | +| [`ConnectEndpoint(endpoint)`](/api/fair/mq/Channel/#ConnectEndpoint) | Connects the socket. | + +All four functions return `false` if the transport cannot bind or connect. Each call takes one +endpoint, for example `tcp://127.0.0.1:5555`, `ipc:///tmp/data` or `inproc://data`. + +`BindEndpoint()` changes its argument. If the bind fails, the endpoint is a `tcp://` endpoint, and +the property `autoBind` is `true` (default), it tries up to 1000 random ports. The ports are in the +range from `portRangeMin` to `portRangeMax` (default 22000 to 23000). Then the string holds the +endpoint with the new port ([Channel.cxx](/source/fairmq/Channel.cxx/#L346-L386)). The tests use +the port 1, which a normal user cannot bind: + + + +### Apply the channel properties + +A socket from the constructor has the defaults of the transport, for example a linger time of +1000 ms. The functions `UpdateLinger()`, `UpdateSndBufSize()`, `UpdateRcvBufSize()`, +`UpdateSndKernelSize()` and `UpdateRcvKernelSize()` change only the values in the channel object. +To apply them, do the steps of a device: + + + +1. Make the channel with the method and the address. + +2. Call [`Validate()`](/api/fair/mq/Channel/#Validate). It returns `false` for a wrong name or + address. It throws [`ChannelConfigurationError`](/api/fair/mq/Channel/ChannelConfigurationError/) + for a wrong type or method, and for a negative size or rate logging interval. It logs the cause. + +3. Call [`Init()`](/api/fair/mq/Channel/#Init). It makes a new socket with the linger time, the + buffer sizes and the kernel sizes of the channel. + +4. Call `BindEndpoint()` or `ConnectEndpoint()` with the address. + + + +Call `Init()` before you bind or connect, because it replaces the socket. To change one option of a +bound socket, use the socket directly, for example +[`GetSocket().SetLinger(500)`](/api/fair/mq/Socket/#SetLinger). + +Other properties apply at once: `Send()` and `Receive()` read the timeouts of +[`UpdateSndTimeout()`](/api/fair/mq/Channel/#UpdateSndTimeout) and +[`UpdateRcvTimeout()`](/api/fair/mq/Channel/#UpdateRcvTimeout). `BindEndpoint()` reads the values of +[`UpdateAutoBind()`](/api/fair/mq/Channel/#UpdateAutoBind) and of the port range. + +## Send and receive + +[`Send(msg, timeout)`](/api/fair/mq/Channel/#Send) and +[`Receive(msg, timeout)`](/api/fair/mq/Channel/#Receive) take a `MessagePtr`, a +[`fair::mq::Parts`](/api/fair/mq/Parts/) object or a `std::vector`, and a +timeout in milliseconds. They return the number of bytes, or a negative +[transfer code](/reference/transfer-codes/): `-1` error, `-2` timeout, `-3` interrupted. + +Without a timeout, they use the channel properties `sndTimeoutMs` and `rcvTimeoutMs`. The default +is `-1`, which waits without a limit. A timeout of `0` returns at once. + +The sockets wait in steps of 100 ms. Thus the transports round a positive timeout up to a multiple +of 100 ms. + +Make messages with the channel, with [`NewMessage()`](/api/fair/mq/Channel/#NewMessage) or +[`NewSimpleMessage()`](/api/fair/mq/Channel/#NewSimpleMessage). Then the message has the transport +of the channel. A `pair` channel sends and receives: + + + +The test uses this function to receive a string: + + + +To wait for messages on several channels, use a poller from +[`CreatePoller()`](/api/fair/mq/TransportFactory/#CreatePoller-2) of the factory. See +[Poll several channels](/guides/poll-channels/). + +## Stop a blocking call + +[`Interrupt()`](/api/fair/mq/TransportFactory/#Interrupt) of the factory stops the waiting +`Send()` and `Receive()` calls of all channels of this factory. They return `-3` +(`TransferCode::interrupted`) within about 100 ms. Until you call +[`Resume()`](/api/fair/mq/TransportFactory/#Resume), each call that has to wait also returns `-3`. +A device calls `Interrupt()` on each transition request, and `Resume()` when the next state starts. + +In your program, call `Interrupt()` from another thread. In this test, the function +`delayedInterruptor()` waits 100 ms and then calls `Interrupt()`: + + + +The test `Factory.ResumeAfterInterrupt` in +[`test/transport/_factory.cxx`](https://github.com/FairRootGroup/FairMQ/blob/dev/test/transport/_factory.cxx) +shows that the channels transfer messages again after `Resume()`. + +## Close the channels + +A channel has no close function. Its destructor closes the socket. `Socket::Close()` is deprecated. + + + +1. Destroy the messages and the unmanaged regions, because they keep a pointer to the factory. + Destroy the pollers, because they keep the sockets of the channels. + +2. Destroy the channels. Each channel keeps a `std::shared_ptr` to the factory. + +3. Destroy your last `std::shared_ptr` to the factory. + + + +C++ destroys local objects in the reverse order of their declaration. Thus declare the factory +first, then the channels, then the messages, as in the program above. + +The destructor of the factory calls `zmq_ctx_term()`. In ZeroMQ, this call waits until the closed +sockets sent the messages in their queues, for the linger time of each socket at most. + +For the shmem transport, the last factory of the session removes the shared memory, unless +`shm-no-cleanup` is `true`. If your program ends without this step, for example after a crash, +remove the shared memory with [`fairmq-shmmonitor`](/tools/shmmonitor/): + +```sh +fairmq-shmmonitor --cleanup --session default +``` + +## What you do not get without a device + +| Topic | With a device | Without a device | +| --- | --- | --- | +| [States](/concepts/states/) | The state machine calls your hooks, for example `InitTask()` and `Run()`. | Your program has its own main loop. | +| Interruptions | The device calls `Interrupt()` and `Resume()` on each transition. | Call them yourself. | +| [Options](/reference/options/) | A device program parses `--id`, `--transport`, `--channel-config`, `--mq-config`, `--session` and the other options. | `ProgOptions` knows only the log options and `help`, `version` and `print-options`. Set the properties with `SetProperty()`. | +| Channels | The device makes the channels from the configuration, and gives each channel the factory of its transport. | Make the factories and the channels yourself. | +| Addresses | The device accepts a list of endpoints, the modifiers `@`, `+` and `>`, and host names. It takes a bind address from `--network-interface`, and waits up to `--init-timeout` for the addresses of connecting channels. | One endpoint for each call. | +| Data | `OnData()` callbacks, `ConditionalRun()` with `--rate`, and the rate log of each channel. | Your own loop. | +| [Plugins](/concepts/plugins/) | Controllers and other plugins, for example `--control static`. | None. | +| [Logging](/tools/logging/) | The device runner applies `--severity` and the other log options. | Call `fair::Logger::SetConsoleSeverity()` yourself. | + +## Related pages + +- [Transports](/concepts/transports/): the transport factories and their properties. +- [Channels and sockets](/concepts/channels/): the socket types and the channel properties. +- [Messages and multipart](/concepts/messages/): how to make, send and receive messages. +- [Handle errors and timeouts](/guides/errors-timeouts/): the transfer codes and what to do. diff --git a/docs/src/content/docs/guides/configure-channels.mdx b/docs/src/content/docs/guides/configure-channels.mdx new file mode 100644 index 00000000..115c054b --- /dev/null +++ b/docs/src/content/docs/guides/configure-channels.mdx @@ -0,0 +1,237 @@ +--- +title: 'Configure channels' +description: 'Give a device its channels with --channel-config, a JSON file or properties from code, on one host or on several hosts.' +sidebar: + order: 2 +code: [fairmq/SuboptParser.cxx, fairmq/JSONParser.cxx, fairmq/Device.cxx, fairmq/tools/Network.cxx, fairmq/plugins/config/Config.cxx] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, Tabs, TabItem } from '@astrojs/starlight/components'; + +This guide shows how to give a device its channels: with `--channel-config`, with a JSON file, or as properties from code. The result is a topology in which each device binds or connects its sub-channels on the addresses that you select. + +## Before you start + +- You have a device made with `runDevice.h`, for example from [Your first device](/start/first-device/). +- You know the channel names that your code uses, for example `"data"` in [`Send(msg, "data")`](/api/fair/mq/Device/#Send) or in [`OnData("data", ...)`](/api/fair/mq/Device/#OnData). The configuration must give channels with the same names. + +## Steps + + + +1. Select the socket type of each channel, for example `push` for the sender and `pull` for the receiver. Refer to [Socket types and patterns](/concepts/channels/#socket-types-and-patterns) and [Select the socket pattern](/guides/design-topology/#select-the-socket-pattern). + +2. Select the [device that binds](/guides/design-topology/#select-the-device-that-binds). Usually this is the device with a fixed place in the topology, for example the sink. Give it the method `bind` and an address such as `tcp://*:5555`. + +3. Give the peers the method `connect` and the address of the binding device, for example `tcp://host1:5555`. + +4. Give the configuration to the devices in one of the [three ways](#three-ways-to-give-the-configuration). + +5. Start the devices, and [check the result](#check-the-result). + + + +## Three ways to give the configuration + + + + +Give one value for each channel. A value is a list of `key=value` pairs, separated by `,`, without spaces. Put the value in quotes if it contains `*`, so that the shell does not change it. + +```sh +fairmq-ex-1-n-1-processor --id processor1 \ + --channel-config 'name=data1,type=pull,method=connect,address=tcp://localhost:5555' \ + 'name=data2,type=push,method=connect,address=tcp://localhost:5556' +``` + +- Give all channels as values after one `--channel-config`, as the examples do. +- `name=data1,...` and `data1:...` give the same name ([SuboptParser.cxx](/source/fairmq/SuboptParser.cxx/#L91-L98)). +- Each `address=` key makes one sub-channel. All other keys apply to all sub-channels of the channel, at each position in the list ([SuboptParser.cxx](/source/fairmq/SuboptParser.cxx/#L100-L110)). +- The parser logs `Ignoring unknown argument in --channel-config` for an unknown key. +- Because `,` separates the keys, an address with several endpoints is not possible here. + + + + +Write one file for all devices of the topology, with one entry for each device. Give the file with `--mq-config`. The device reads the entry that matches `--config-key`, or `--id` if there is no `--config-key`. An entry matches by its `key`, or by its `id` if it has no `key`. + +```sh +fairmq-ex-1-n-1-processor --id processor1 --mq-config ex-1-n-1.json --config-key processor +``` + +- The values of a channel are the defaults for its `sockets`. Each socket object makes one sub-channel. +- Several devices can use one entry with `--config-key`, for example the two processors of the 1-n-1 example. +- If you give `--mq-config` and `--channel-config`, the device reads only the JSON file. + +[JSON configuration](/reference/json/) describes the format and the errors. The [complete example](#a-complete-example) below shows a file. + + + + +Set the properties `chans...` before the controller requests the transition `COMPLETE INIT`. Use the exact types: `std::string`, `int` or `bool`. Each sub-channel needs a `type` property, otherwise the device does not see it. For a plugin, set them when the device goes into `INITIALIZING DEVICE`: + +```cpp +#include + +#include +#include + +struct ChannelSetup : fair::mq::Plugin +{ + template + ChannelSetup(Args&&... args) + : Plugin(std::forward(args)...) + { + SubscribeToDeviceStateChange([this](DeviceState state) { + if (state == DeviceState::InitializingDevice) { + SetProperty("chans.data.0.type", "push"); + SetProperty("chans.data.0.method", "bind"); + SetProperty("chans.data.0.address", "tcp://*:5555"); + SetProperty("chans.data.0.rateLogging", 0); + } + }); + } + + ~ChannelSetup() override { UnsubscribeFromDeviceStateChange(); } +}; +``` + +Register and load the plugin as [Write a plugin](/guides/write-plugin/) describes. The device runner makes the plugins of `-P` before the config plugin. If `--mq-config` or `--channel-config` also gives the channel `data`, the config plugin replaces these values. + +In the device, use the hook [`Init()`](/api/fair/mq/Device/#Init). It runs after the request of `COMPLETE INIT`, before the device reads the channel properties: + +```cpp +void Init() override +{ + fair::mq::Channel channel("push", "bind", "tcp://*:5555"); + channel.UpdateRateLogging(0); + AddChannel("data", std::move(channel)); +} +``` + +A device without `runDevice.h` can add its channels before it starts, as this test helper does: + + + +:::caution +- [`AddChannel()`](/api/fair/mq/Device/#AddChannel) adds a sub-channel at the next free index, also when the channel exists. After `RESET DEVICE`, `Init()` runs again and adds one more sub-channel. If your device can go through `INITIALIZING DEVICE` again, set the properties with `fConfig->SetProperty()` instead. +- `AddChannel()` does not copy `sndTimeoutMs` and `rcvTimeoutMs`. Set them as properties. +- Do not set channels in the constructor of a device that uses `Device()`. With `runDevice.h`, the device runner replaces the store of the device after the constructor. +::: + + + + +## Several sub-channels + +| Method | Several sub-channels | +| --- | --- | +| `--channel-config` | Give one `address=` key for each sub-channel: `name=data,type=push,method=bind,address=tcp://*:5555,address=tcp://*:5556`. Or give `numSockets=3` for sub-channels without an address. | +| JSON file | Give one object for each sub-channel in `sockets`, or give `numSockets` in the channel. | +| Properties | Set the properties of the indexes 0, 1, 2 and so on, without gaps. | + +The [copypush example](/examples/copypush/) has a channel with two sub-channels. [Channel properties](/reference/channel-properties/#numsockets) describes `numSockets`. + +## Addresses on one host + +- `tcp://localhost:5555` or `tcp://127.0.0.1:5555` on the connecting side, and `tcp://*:5555` or `tcp://127.0.0.1:5555` on the binding side. +- `ipc:///tmp/fmq_data` gives a Unix domain socket file. The test scripts of the examples use `ipc://` addresses. +- `inproc://data` connects two sub-channels of the same device with the same transport. + +The `shmem` transport uses the same addresses. It sends the metadata of the messages through its ZeroMQ socket on this address, and the data through the shared memory. + +## Addresses on several hosts + +- On the binding host, bind to `tcp://*:5555` (all interfaces) or to the IPv4 address of one interface. +- On the connecting hosts, give the host name or the IPv4 address of the binding host. The device uses the first IPv4 address of a host name ([Network.cxx](/source/fairmq/tools/Network.cxx/#L160-L177)). + +A binding sub-channel without an address binds to the IPv4 address of the interface that `--network-interface` names, for example `eth0` ([Device.cxx](/source/fairmq/Device.cxx/#L185-L198)). With the default `default`, the device uses the interface of the default route. On Linux, it reads `/proc/net/route` and then the output of `ip route`. On macOS, it uses `route -n get default` ([Network.cxx](/source/fairmq/tools/Network.cxx/#L95-L158)). If it finds no interface, it binds to `tcp://*:1`. Without root rights, the bind to port 1 fails, and autobind selects a port. For the functions that find the interface and the addresses, see [Network.h](/reference/tools/#networkh). + +The peers must then get the address. After the bind, the device writes the address to the property `chans...address`. A plugin can read it and give it to the peers. A connecting device reads its address property again every 50 ms in `CONNECTING`, until the time of `--init-timeout` is over. + +## Automatic ports + +By default, a binding sub-channel takes a random port from 22000 to 23000 when its TCP bind fails. For fixed ports, switch this off: + +```sh +fairmq-ex-1-n-1-sink --id sink1 \ + --channel-config 'name=data2,type=pull,method=bind,address=tcp://*:5556,autoBind=false' +``` + +In a JSON file, write `"autoBind": false`. The keys `portRangeMin` and `portRangeMax` change the range. Refer to [Channel properties](/reference/channel-properties/#portrangemin-portrangemax-and-autobind). + +## A complete example + +The [1-n-1 example](/examples/1-n-1/) has one sampler, two processors and one sink: + +| Device | Channel | Type | Method | Address | +| --- | --- | --- | --- | --- | +| `sampler1` | `data1` | `push` | `bind` | `tcp://*:5555` | +| `processor1`, `processor2` | `data1` | `pull` | `connect` | `tcp://localhost:5555` | +| `processor1`, `processor2` | `data2` | `push` | `connect` | `tcp://localhost:5556` | +| `sink1` | `data2` | `pull` | `bind` | `tcp://*:5556` | + +The JSON file has one entry for each device. The two processors use the entry with the key `processor`: + + + +The start script gives the file to all devices, and `--config-key processor` to the processors. The build writes it to `examples/1-n-1/fairmq-start-ex-1-n-1.sh` in the build directory, with the paths filled in: + + + +The same topology with `--channel-config`, in four terminals in the directory `examples/1-n-1` of the build directory: + +```sh +./fairmq-ex-1-n-1-sampler --id sampler1 \ + --channel-config 'name=data1,type=push,method=bind,address=tcp://*:5555,rateLogging=0' +./fairmq-ex-1-n-1-processor --id processor1 \ + --channel-config 'name=data1,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0' \ + 'name=data2,type=push,method=connect,address=tcp://localhost:5556,rateLogging=0' +./fairmq-ex-1-n-1-processor --id processor2 \ + --channel-config 'name=data1,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0' \ + 'name=data2,type=push,method=connect,address=tcp://localhost:5556,rateLogging=0' +./fairmq-ex-1-n-1-sink --id sink1 \ + --channel-config 'name=data2,type=pull,method=bind,address=tcp://*:5556,rateLogging=0' +``` + +## Check the result + +Start the devices with `--severity debug`. For each endpoint, the device logs the address and the method: + +```txt +Attached channel data1[0] to tcp://*:5555 (bind) (push) +``` + +```txt +Attached channel data1[0] to tcp://127.0.0.1:5555 (connect) (pull) +``` + +The connecting device shows the resolved IPv4 address of `localhost`. In the interactive controller (the default `--control dynamic`), press `p`. The device logs the number of peers of each sub-channel, for example in `sampler1` with two processors: + +```txt +data1[0]: 2 peers connected +``` + +## Problems + +| Message or symptom | Cause | Fix | +| --- | --- | --- | +| `GetChannel(): 'data[0]' does not exist.` | The configuration has no channel with the name that the code uses, or the device did not read the configuration. | Compare the names. Look for parser errors at the start of the log. | +| `fair::mq::plugins::Config: no channels configuration provided via --mq-config or --channel-config` | The device has no channel configuration. A misspelled option, for example `--chanel-config`, has the same effect, because the device ignores unknown options. | Give `--channel-config` or `--mq-config`. For a misspelled option, the debug log shows `detected unregistered option`. | +| `No device ID or config-key provided for the configuration parser.` | `--id` and `--config-key` are empty. | Give `--id`. | +| `missing channel name in argument of option --channel-config` | A value of `--channel-config` has no `name`. | Add `name=`. | +| `Invalid channel type: 'unspecified'` | A sub-channel has no `type`. | Give `type`. | +| `Cannot update configuration. Socket method (bind/connect) for channel 'data[0]' not specified.` | A sub-channel has no `method` and no modifier. | Give `method=bind` or `method=connect`. | +| `1 of the binding channels could not initialize` | A bind failed, for example because the port is in use and `autoBind` is `false`. | Free the port, or select another port. | +| `could not connect all channels after 120 attempts` | A connecting sub-channel has no valid address, or its host name does not resolve. | Correct the address. | +| The peers do not find the binding device. | The port was in use, and autobind selected a random port. | Set `autoBind=false`. | + +## Related pages + +- [Channels and sockets](/concepts/channels/): sub-channels, socket types, methods and addresses. +- [Channel properties](/reference/channel-properties/): all keys, with their defaults. +- [JSON configuration](/reference/json/): the format of the file for `--mq-config`. +- [Configuration and properties](/concepts/configuration/): how the device reads its configuration. +- [1-n-1 example](/examples/1-n-1/): the example of this guide. +- [Design a topology](/guides/design-topology/): the patterns, the binding devices and the transports of a topology. diff --git a/docs/src/content/docs/guides/control-from-code.mdx b/docs/src/content/docs/guides/control-from-code.mdx new file mode 100644 index 00000000..3e02d785 --- /dev/null +++ b/docs/src/content/docs/guides/control-from-code.mdx @@ -0,0 +1,540 @@ +--- +title: 'Control a device from code' +description: 'Change the state of a device and read its properties from your program or a plugin.' +sidebar: + order: 8 +code: [fairmq/Device.h, fairmq/PluginServices.h, fairmq/StateMachine.h, fairmq/StateQueue.h, fairmq/ProgOptions.h, fairmq/PluginManager.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +A controller requests the transitions of a device. This guide shows the ways to write your own controller, also +without `DeviceRunner`. It also shows how to read and change properties while the device runs. + +## Choose a way + +| Way | Use it when | +| --- | --- | +| [A controller plugin](#control-the-device-from-a-plugin) | The device starts with `runDevice.h` or `DeviceRunner`, and no mode of `--control` fits. | +| [A plugin in your program](#put-the-controller-in-your-program) | You want one executable that contains the device and its controller. | +| [A device in a thread](#run-the-device-in-a-thread) | Your program creates the device without `DeviceRunner`, for example in a test. | +| [Your own `main()` with plugins](#load-plugins-without-devicerunner) | You want the plugins and the command line of a device, but not `DeviceRunner`. | + +All ways use the same states and transitions. See [Device states](/concepts/states/) and +[States and transitions](/reference/states/). + +## Control the device from a plugin + +A plugin requests a transition with [`ChangeDeviceState()`](/api/fair/mq/Plugin/#ChangeDeviceState). Only the plugin +with the controller role can do this. See [The controller role](/concepts/plugins/#the-controller-role). + + + +1. Write a plugin. See [Write a plugin](/guides/write-plugin/). + +2. In the constructor, call [`TakeDeviceControl()`](/api/fair/mq/Plugin/#TakeDeviceControl). The plugins of `-P` are + created before the control plugin. Thus your plugin gets the role first. + +3. In the constructor, subscribe to the state changes with + [`SubscribeToDeviceStateChange()`](/api/fair/mq/Plugin/#SubscribeToDeviceStateChange). + +4. In the callback, request the next transition in each idling state. In `INITIALIZING DEVICE`, request + `CompleteInit`. + +5. In `EXITING`, call [`ReleaseDeviceControl()`](/api/fair/mq/Plugin/#ReleaseDeviceControl). `DeviceRunner::Run()` + returns only after the controller releases the role. + +6. Call `ReleaseDeviceControl()` in the destructor too. Without the role, the call does nothing. + + + +The plugin of the [custom-controller](/examples/custom-controller/) example does these steps: + + + +The control plugin then cannot take the role. It logs the reason with the severity `debug` and starts no controller. +Its signal handling still works. + +### Rules for the state callback + +- The callback runs in the thread of the state machine, at the start of each state. The device calls the hooks of + the state after all state callbacks return. See [Threads in a device](/concepts/threads/#which-thread-runs-your-code). +- Request no transition in `BINDING`, `CONNECTING`, `INITIALIZING TASK`, `RESETTING TASK` and `RESETTING DEVICE`. The + device ends these states by itself with the transition `Auto`. +- `INITIALIZING DEVICE` waits until the controller requests `CompleteInit`. Set the configuration of the device before + this request. +- The device ends `RUNNING` by itself when its work ends: it requests `Stop`. A `Stop` from the callback of `RUNNING` + is pending before the work starts. Then `ConditionalRun()` and the data callbacks do not run. `PreRun()` and + `PostRun()` still run. `Run()` also runs, but only in a device without data callbacks. +- `ChangeDeviceState()` returns `false` when the state machine refuses the transition. +- `ChangeDeviceState()` throws `fair::mq::PluginServices::DeviceControlError` when another plugin has the role. If no + plugin has the role, the call gives the role to the calling plugin. +- An exception that leaves the callback moves the device to `ERROR`. Catch the exceptions in the callback. + +### A controller with its own thread + +The device waits until the state callback returns. For a controller that waits, for example for a timer or for input, +use a thread. The built-in control plugin works so: + +1. Its state callback puts each new state into a [`fair::mq::StateQueue`](/api/fair/mq/StateQueue/). +2. Its controller thread requests a transition. Then it waits in the queue for the next state. + + + + + +- [`WaitForState(state)`](/api/fair/mq/StateQueue/#WaitForState) takes states from the queue until it gets `state`. +- [`WaitForStateOrCustom(state, predicate)`](/api/fair/mq/StateQueue/#WaitForStateOrCustom) also returns when the + predicate is `true`. The queue checks the predicate after each `Push()` and `Notify()`. +- [`WaitForNext()`](/api/fair/mq/StateQueue/#WaitForNext) returns the next state of the queue. +- When the next state of the queue is `ERROR`, these functions throw + [`fair::mq::DeviceErrorState`](/api/fair/mq/DeviceErrorState/). + +## Put the controller in your program + +A plugin can be part of the executable. The [custom-controller](/examples/custom-controller/) example works so. + + + +1. Put the plugin class and the macro `REGISTER_FAIRMQ_PLUGIN` into the code of your program. + +2. In `main()`, create a [`fair::mq::DeviceRunner`](/api/fair/mq/DeviceRunner/) with `argc` and `argv`. + +3. In the hook `hooks::LoadPlugins`, load the plugin with the prefix `s:` and its name, for example `s:mycontroller`. + +4. In the hook `hooks::InstantiateDevice`, create the device with `r.fConfig` and put it into `r.fDevice`. + +5. Return the result of [`RunWithExceptionHandlers()`](/api/fair/mq/DeviceRunner/#RunWithExceptionHandlers). + +6. In CMake, set the target property `ENABLE_EXPORTS` to `ON`. The plugin manager finds the plugin in the symbols of the + executable. + + + + + + + +`DeviceRunner` keeps one function for each type of hook. A second `AddHook()` of the same type replaces the first. +The order of the hooks is in [How a device starts](/concepts/plugins/#how-a-device-starts). + +## Run the device in a thread + +Without `DeviceRunner`, the device has no config plugin and no control plugin. Your program sets the configuration +and requests all transitions. + + + +1. Create the device: a `fair::mq::Device` or an object of your device class. + +2. Configure the device, for example with `SetTransport()` and `AddChannel()`. + +3. Start [`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine) in a thread. It returns when the device reaches + `EXITING`. + +4. Request each transition with [`ChangeStateOrThrow()`](/api/fair/mq/Device/#ChangeStateOrThrow). + +5. Wait for the next idling state with [`WaitForState()`](/api/fair/mq/Device/#WaitForState). + +6. In `IDLE`, request `End`. Then join the thread. + + + +The test `Config.SetTransport` does these steps: + + + +The test helper `Control()` requests the transitions of a full cycle. The device of the test has no own `Run()` code. +It goes back to `READY` by itself, so `Control()` waits for `READY` after `RUNNING`. + + + +### The configuration of the device + +- Without a `ProgOptions` object, the device uses its own internal object. +- To use your object, give it to the constructor `Device(ProgOptions&)` or to + [`SetConfig()`](/api/fair/mq/Device/#SetConfig). `SetConfig()` deletes the internal object. Thus call it before the + other setters. +- Set the device ID with the property `id`. [`SetId()`](/api/fair/mq/Device/#SetId) has no effect on a device that + you initialize, because `INITIALIZING DEVICE` reads the property `id`. + +### The functions of the device + +| Function | What it does | +| --- | --- | +| [`ChangeState(transition)`](/api/fair/mq/Device/#ChangeState) | Requests a transition. Returns `false` when the current state does not accept it, or when another transition is pending. [`ChangeState(name)`](/api/fair/mq/Device/#ChangeState-2) takes the name, for example `"INIT DEVICE"`. | +| `ChangeStateOrThrow()` | Requests a transition. Throws `std::system_error` when `ChangeState()` returns `false`. The text starts with the name of the transition, for example `Invalid transition: CONNECT`. The error code is `ErrorCode::DeviceChangeStateFailed`. | +| `WaitForState(state)` | Waits until the device enters `state`. [`WaitForState(name)`](/api/fair/mq/Device/#WaitForState-2) takes the name, for example `"READY"`. | +| [`WaitForNextState()`](/api/fair/mq/Device/#WaitForNextState) | Waits for the next state and returns it. | +| [`GetCurrentState()`](/api/fair/mq/Device/#GetCurrentState), [`GetCurrentStateName()`](/api/fair/mq/Device/#GetCurrentStateName) | Return the current state. | +| [`SubscribeToStateChange(key, callback)`](/api/fair/mq/Device/#SubscribeToStateChange) | Calls `callback` at the start of each state, in the thread of the state machine. `UnsubscribeFromStateChange(key)` removes it. | +| [`SubscribeToNewTransition(key, callback)`](/api/fair/mq/Device/#SubscribeToNewTransition) | Calls `callback` when the state machine accepts a transition, in the thread that requests the transition. | +| [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) | Returns `true` when a transition is requested and the next state has not started yet. | + +`ChangeState()` is `[[nodiscard]]`. A name that does not exist makes `ChangeState(name)` and `WaitForState(name)` +throw `std::out_of_range`. The names are in [States and transitions](/reference/states/). + +### How WaitForState() works + +The device puts each new state into a queue. `WaitForState()` takes states from the queue until it finds the given +state. Thus it returns at once for a state that is in the queue already. + +- The first `IDLE` is not in the queue. Do not wait for it. +- After the transition `ErrorFound`, the queue gets `ERROR`. Then `WaitForState()` and `WaitForNextState()` throw + `fair::mq::DeviceErrorState` with the text `Controlled device transitioned to error state.` +- After an exception in a hook, the queue gets no `ERROR`. Then `WaitForState()` does not return. + +`RunStateMachine()` lets the exception of a hook pass to its caller. Catch it in the thread: an exception that leaves +the function of a `std::thread` calls `std::terminate()`. To see `ERROR` in all cases, use `SubscribeToStateChange()`. The +state machine calls the subscribers with `ERROR` also after an exception. + +### The class StateMachine + +Each device has a private [`fair::mq::StateMachine`](/api/fair/mq/StateMachine/). Use the functions of the device for +it. The class also works without a device. The tests in `test/state_machine/_state_machine.cxx` use it so. + +| Function | What it does | +| --- | --- | +| [`Start()`](/api/fair/mq/StateMachine/#Start) | Starts the state machine in `IDLE`. Call it before the first transition. | +| [`ProcessWork()`](/api/fair/mq/StateMachine/#ProcessWork) | Runs the loop. It first calls the subscribers with `IDLE`. For each new state, it calls the `PrepareState()` function, the subscribers and the `HandleStates()` function. It returns in `EXITING`. | +| [`PrepareState(f)`](/api/fair/mq/StateMachine/#PrepareState), [`HandleStates(f)`](/api/fair/mq/StateMachine/#HandleStates) | Set the functions for each new state. Each takes one function. A second call logs an error. `StopHandlingStates()` removes both. | +| [`WaitForPendingState()`](/api/fair/mq/StateMachine/#WaitForPendingState), [`WaitForPendingStateFor(ms)`](/api/fair/mq/StateMachine/#WaitForPendingStateFor) | Wait until a transition is requested. `WaitForPendingStateFor()` returns `false` after the timeout. | +| `ChangeState()`, `SubscribeToStateChange()`, `SubscribeToNewTransition()`, `NewStatePending()`, `GetCurrentState()` | Work as the functions of the device. | + +In `ERROR`, `ProcessWork()` throws [`StateMachine::ErrorStateException`](/api/fair/mq/StateMachine/ErrorStateException/). +When a function of the loop throws, `ProcessWork()` sets `ERROR`, calls the subscribers with `ERROR`, and passes the +exception on. + +## Parse options without DeviceRunner + +Without `DeviceRunner`, no code reads the command line. Your program can parse it with a +[`fair::mq::ProgOptions`](/api/fair/mq/ProgOptions/) object and give this object to the device. + + + +1. Create a `ProgOptions` object. It knows only the general options: `--help`, `--version`, `--severity`, + `--file-severity`, `--verbosity`, `--color`, `--log-to-file` and `--print-options` + ([ProgOptions.cxx](/source/fairmq/ProgOptions.cxx/#L69-L83)). + +2. Add your options with [`AddToCmdLineOptions()`](/api/fair/mq/ProgOptions/#AddToCmdLineOptions). It takes a + `boost::program_options::options_description`. Add all options before the parse. + +3. Call [`ParseAll(argc, argv, true)`](/api/fair/mq/ProgOptions/#ParseAll-2). + +4. To apply the log options, call + [`DeviceRunner::HandleGeneralOptions(config, false)`](/api/fair/mq/DeviceRunner/#HandleGeneralOptions). It is + static. For `--help` and `--print-options`, it prints the options and returns `false`. The second argument + `true` prints the FairMQ logo. + +5. Call [`Notify()`](/api/fair/mq/ProgOptions/#Notify). It calls `boost::program_options::notify()`. `DeviceRunner` + calls it after `HandleGeneralOptions()` too. + +6. Give the object to the device: use the constructor `Device(ProgOptions&)` or + [`SetConfig()`](/api/fair/mq/Device/#SetConfig). See [The configuration of the device](#the-configuration-of-the-device). + +7. Request the transitions as in [Run the device in a thread](#run-the-device-in-a-thread). + + + +The test `Config.SetConfig` parses two options and gives the object to the device: + + + +- `ParseAll()` first removes all properties, also the values of `SetProperty()` + ([ProgOptions.cxx](/source/fairmq/ProgOptions.cxx/#L108-L132)). Then it stores the values of the command line and + the defaults of the registered options. Call `SetProperty()` after `ParseAll()`, as the test does. +- The last argument `true` accepts options that are not registered. `ParseAll()` does not store them as + properties. [`PrintOptions()`](/api/fair/mq/ProgOptions/#PrintOptions) logs each of them at the severity `debug`: + `detected unregistered option: …`. In the test above, `--id` is not registered, so the device ID stays empty. +- With `false`, an option that is not registered throws `boost::program_options::unknown_option`. The test in + `test/properties/_properties.cxx` checks this. +- The first element of `argv`, or of the vector of the other overload, is the name of the program. The parser skips + it (Boost behavior). + +### The device options and the channels + +The device options, for example `--id`, `--transport`, `--session`, `--mq-config` and `--channel-config`, are the +options of the config plugin ([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L56-L87)). In +`INITIALIZING DEVICE`, the config plugin also turns `--mq-config` or `--channel-config` into channel properties +([Config.cxx](/source/fairmq/plugins/config/Config.cxx/#L22-L53)). A program without `DeviceRunner` has two ways to get +them: + +- Load the config plugin with a plugin manager, and add its options before the parse. See + [Load plugins without DeviceRunner](#load-plugins-without-devicerunner). The test `Config.SetConfigWithPlugins` + does this: + + + +- Register only the options that you need, and make the channel properties yourself. + [`SuboptParser()`](/api/fair/mq/#SuboptParser) turns the values of `--channel-config` into channel properties. + [`JSONParser()`](/api/fair/mq/#JSONParser) reads them from a JSON file. + [`SetProperties()`](/api/fair/mq/ProgOptions/#SetProperties) stores them. Store them before you request + `CompleteInit`, because the device reads the channel properties after this request. + +This function does the second way for the options `--id` and `--channel-config`: + +```cpp +#include +#include + +#include + +#include +#include + +void Configure(fair::mq::ProgOptions& config, int argc, char* argv[]) +{ + namespace bpo = boost::program_options; + bpo::options_description options("My device"); + options.add_options() + ("id", bpo::value()->default_value("sampler1"), "Device ID") + ("channel-config", bpo::value>()->multitoken()->composing(), "Channels"); + config.AddToCmdLineOptions(options); + + config.ParseAll(argc, argv, true); + config.Notify(); + + if (config.Count("channel-config")) { + auto const id = config.GetProperty("id"); + auto const channels = config.GetProperty>("channel-config"); + config.SetProperties(fair::mq::SuboptParser(channels, id)); + } +} +``` + +For a value without `name`, `SuboptParser()` throws `boost::property_tree::ptree_bad_path`. For an empty device ID, +it throws [`fair::mq::ParserError`](/api/fair/mq/ParserError/). The test `SuboptParser.Errors` checks both. The +device options that you do not register, for example `transport` and `rate`, have the defaults of the device. + +## Load plugins without DeviceRunner + +A [`fair::mq::PluginManager`](/api/fair/mq/PluginManager/) loads, creates and owns the plugins of a device. Without +`DeviceRunner`, your program must call its functions in the sequence of +[`DeviceRunner::Run()`](/source/fairmq/DeviceRunner.cxx/#L108-L194): + +| Step | Call | Notes | +| --- | --- | --- | +| 1 | [`LoadPlugin(name)`](/api/fair/mq/PluginManager/#LoadPlugin) or [`LoadPlugins(names)`](/api/fair/mq/PluginManager/#LoadPlugins) | Finds the plugin and its options. It does not create the plugin. `DeviceRunner` loads the plugins of `-P` (in the constructor of the plugin manager), then `s:config`, then the plugins of the hook `LoadPlugins`, then `s:control`. For the prefixes, see [Load a plugin](/concepts/plugins/#load-a-plugin). | +| 2 | [`ForEachPluginProgOptions()`](/api/fair/mq/PluginManager/#ForEachPluginProgOptions) with `AddToCmdLineOptions()` | Adds the options of the loaded plugins. `DeviceRunner` also adds [`PluginManager::ProgramOptions()`](/api/fair/mq/PluginManager/#ProgramOptions) (`-P` and `-S`). | +| 3 | `ParseAll()`, `HandleGeneralOptions()`, `Notify()` | See [Parse options without DeviceRunner](#parse-options-without-devicerunner). | +| 4 | `SetConfig()` of the device | Give the device the `ProgOptions` object of the plugins. Otherwise the device does not see the properties that the plugins set, for example the channels of the config plugin. | +| 5 | [`EmplacePluginServices(config, device)`](/api/fair/mq/PluginManager/#EmplacePluginServices) | Makes the [`PluginServices`](/api/fair/mq/PluginServices/) object, which connects the plugins to the device and to the properties. | +| 6 | [`InstantiatePlugins()`](/api/fair/mq/PluginManager/#InstantiatePlugins) | Creates the plugins in the load sequence. The constructors run now, and a controller takes its role. | +| 7 | [`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine) of the device | Returns in `EXITING`. | +| 8 | [`WaitForPluginsToReleaseDeviceControl()`](/api/fair/mq/PluginManager/#WaitForPluginsToReleaseDeviceControl) | Waits until no plugin has the controller role. | + +This `main()` has the minimum sequence for the built-in plugins. `MyDevice` is your device class: + +```cpp +#include +#include // DeviceRunner::HandleGeneralOptions() +#include +#include +#include // tools::ToStrVector() + +#include + +int main(int argc, char* argv[]) +{ + // Declare the configuration and the device before the plugin manager. + // Then the plugin manager and its plugins are destroyed first. + fair::mq::ProgOptions config; + MyDevice device; + fair::mq::PluginManager mgr(fair::mq::tools::ToStrVector(argc, argv, false)); // reads -S and -P + + mgr.LoadPlugin("s:config"); + mgr.LoadPlugin("s:control"); + mgr.ForEachPluginProgOptions([&](boost::program_options::options_description options) { + config.AddToCmdLineOptions(options); + }); + config.AddToCmdLineOptions(fair::mq::PluginManager::ProgramOptions()); + + config.ParseAll(argc, argv, true); + if (!fair::mq::DeviceRunner::HandleGeneralOptions(config, false)) { + return 0; // --help or --print-options + } + config.Notify(); + + device.SetConfig(config); + mgr.EmplacePluginServices(config, device); + mgr.InstantiatePlugins(); + + device.RunStateMachine(); + mgr.WaitForPluginsToReleaseDeviceControl(); + return 0; +} +``` + +The test `PluginManager.LoadPluginStatic` uses the control plugin without a parse. It sets the two options of the +control plugin with `SetProperty()` before `InstantiatePlugins()`: + + + +Rules for the sequence: + +- Call `EmplacePluginServices()` before `InstantiatePlugins()` and before `WaitForPluginsToReleaseDeviceControl()`. + Both use the `PluginServices` object, and the plugin manager does not check that it exists. +- The plugins read their options in their constructors. The control plugin reads `control` and `catch-signals`. If a + property is missing, `InstantiatePlugins()` throws + [`PluginManager::PluginInstantiationError`](/api/fair/mq/PluginManager/PluginInstantiationError/), for example + `An error occurred while instantiating plugin control: Config has no key: control`. +- The plugins unsubscribe from the device in their destructors. Thus the device must exist until the plugin manager is + destroyed. +- The constructor `PluginManager(args)` reads `-S` and `-P` from `args` and loads the plugins of `-P`. It throws + [`PluginManager::ProgramOptionsParseError`](/api/fair/mq/PluginManager/ProgramOptionsParseError/) for an option + value that it cannot parse. The default constructor reads nothing. +- With the default `--control dynamic`, the control plugin reads keys from the terminal. For a program without a + terminal, use `--control static`. See [Control modes](/concepts/plugins/#control-modes). + +## Several devices in one process + +One process can run more than one device. The test `MultipleDevices.TwoInSameProcess` runs a sender and a receiver +in one process. Each device runs `RunStateMachine()` in its own thread, and its controller requests the transitions +from another thread: + + + +Each device has its own objects: + +- **A state machine.** Each `Device` object has a private `StateMachine`. The transitions of one device do not change + the other devices. +- **A property store.** Without `SetConfig()`, each device uses its own internal `ProgOptions` object. If you give + your own object, give each device its own. The device reads `id` and the `chans.` properties from it, and it writes + the bound addresses back. +- **Transports.** In `INITIALIZING DEVICE`, [`AddTransport()`](/api/fair/mq/Device/#AddTransport) makes one transport + factory for each transport type of the device, from the property store of the device + ([Device.cxx](/source/fairmq/Device.cxx/#L586-L605)). All channels of the device with this type use it. + +Two devices do not share a transport factory. No constructor of `Device` takes a factory, and +[`SetTransport()`](/api/fair/mq/Device/#SetTransport) only sets the property `transport` (the name). The public API +has no function that gives a device an existing factory. Only a derived class has access to the protected member +`fTransports`, in which `AddTransport()` looks for an existing factory. No test or example uses this, and +`RESETTING DEVICE` clears the member. For channels that share one factory, use channels without a +device. See [Use channels without a device](/guides/channels-without-device/). + +What this means for each transport: + +- **zeromq:** Each factory has its own ZeroMQ context, with its own I/O threads + ([zeromq/TransportFactory.h](/source/fairmq/zeromq/TransportFactory.h/#L30-L45)). An `inproc://` address connects only + sockets of one context (ZeroMQ behavior). Thus use `ipc://` or `tcp://` between two devices of one process. The + test above uses `ipc://`. +- **shmem:** Each factory opens the segments of its session and increments the device counter. Devices in one + process with the same session (the property `session`) exchange messages in the same way as devices in different processes. The test + `ShmMessages.ZeroCopyFromUnmanaged` (`test/message/_message.cxx`) makes two shmem factories with one session in one + process and sends messages between them. + +The limits are in the parts of FairMQ that exist once per process: + +- **The logger is global.** FairLogger keeps its settings in static members. A change of the severity, the verbosity + or the log file applies to all devices of the process. The prefix of a log line does not contain the device ID. + See [Logging](/tools/logging/). +- **The signal handling of the control plugin is global.** The control plugin installs its handlers for `SIGINT` and + `SIGTERM` with `signal()`. It counts the signals in global variables, and no code resets them + ([Control.cxx](/source/fairmq/plugins/control/Control.cxx/#L25-L45)). One signal starts the shutdown of each device + with a control plugin in the process. The next `SIGINT` ends the process with `std::abort()`. A control plugin that + starts after a signal, with `--catch-signals 1`, shuts down its device at once. +- **The interactive mode reads the standard input** ([Control.cxx](/source/fairmq/plugins/control/Control.cxx/#L157-L180)). + Two interactive controllers in one process read the same keys. +- **One `DeviceRunner` for each process.** `DeviceRunner` sets the global logger, and it loads the control plugin. + FairMQ has no test with two `DeviceRunner` objects in one process. Run the other devices without `DeviceRunner`, + and control them from your code, as the test above does. + +For the threads of each device, see [Threads in a device](/concepts/threads/). + +## Read and change properties at run time + +The device, the plugins and the hooks of `DeviceRunner` share one +[`fair::mq::ProgOptions`](/api/fair/mq/ProgOptions/) object. Each option of the command line is a property in it. See +[Configuration and properties](/concepts/configuration/). + +| Code | Access to the properties | +| --- | --- | +| A plugin | The property functions of [`Plugin`](/api/fair/mq/Plugin/#GetProperty), for example `GetProperty()` and `SetProperty()`. | +| A device | [`GetConfig()`](/api/fair/mq/Device/#GetConfig) returns a pointer to the `ProgOptions` object. | +| A hook of `DeviceRunner` | The member `fConfig` of the runner. | +| A program without `DeviceRunner` | Your `ProgOptions` object, or `GetConfig()` of the device. | + +### Read and set a property + +- [`GetProperty(key)`](/api/fair/mq/ProgOptions/#GetProperty) throws + [`fair::mq::PropertyNotFoundError`](/api/fair/mq/PropertyNotFoundError/) when the key does not exist. The text is + `Config has no key: `. +- [`GetProperty(key, fallback)`](/api/fair/mq/ProgOptions/#GetProperty-2) returns `fallback` when the key does not + exist. +- `T` must be the type of the stored value, for example `float` for `rate` and `int` for `io-threads`. For another + type, both functions throw an exception. +- [`GetPropertyAsString(key)`](/api/fair/mq/ProgOptions/#GetPropertyAsString) returns the value as text. For a type + that [`PropertyHelper`](/api/fair/mq/PropertyHelper/) does not know, the text is `[unidentified_type]`. +- [`SetProperty(key, value)`](/api/fair/mq/ProgOptions/#SetProperty) adds or changes a property. + [`UpdateProperty()`](/api/fair/mq/ProgOptions/#UpdateProperty) changes only a property that exists. It returns + `false` otherwise. +- The type of the value is the type of the property. `SetProperty("key", "text")` stores a `const char*`. Use + `SetProperty("key", "text")` for a text property. + +### Follow the changes + +[`Subscribe(subscriber, callback)`](/api/fair/mq/ProgOptions/#Subscribe) calls `callback` with the key and the new +value of each change. A plugin uses [`SubscribeToPropertyChange()`](/api/fair/mq/Plugin/#SubscribeToPropertyChange). + +- The callback runs in the thread that changes the property, before `SetProperty()` returns ([Threads in a device](/concepts/threads/#which-thread-runs-your-code)). Protect the data that the + callback changes, for example with `std::atomic`. +- The callback gets only the changes with a value of the type `T`. A subscription for `std::string` gets no call for a + `const char*` value. +- [`SubscribeAsString()`](/api/fair/mq/ProgOptions/#SubscribeAsString) gets the changes of all types, with the value + as text. +- `SetProperty()`, `UpdateProperty()`, `SetProperties()` and `UpdateProperties()` call the subscribers. + `DeleteProperty()` and `AddChannel()` do not. +- A subscriber name has one subscription for each type. A second subscription with the same name and type replaces the + first. +- [`Unsubscribe(subscriber)`](/api/fair/mq/ProgOptions/#Unsubscribe) throws `std::out_of_range` when the + subscription does not exist. + +The dispatcher of the [qc](/examples/qc/) example subscribes in `InitTask()` and unsubscribes in `ResetTask()`. The +value `active` of the property `qc` sets the flag `fDoQC`. The value `inactive` clears it. + + + +A plugin can set the flag with `SetProperty("qc", "active")`. The callback runs in the thread that calls +`SetProperty()`. Thus `fDoQC` is a `std::atomic`. + +### When a change has an effect + +| Property | The device uses a new value | +| --- | --- | +| `severity`, `file-severity`, `verbosity`, `log-to-file` (type `std::string`), `color` (type `bool`) | At once. `DeviceRunner` subscribes to these keys after it parses the command line. See [Logging](/tools/logging/). | +| `id`, `rate`, `init-timeout`, `transport`, `network-interface`, `chans...` | In `INITIALIZING DEVICE`, after the request of `CompleteInit`. | +| `io-threads`, `session`, the options of shared memory | In `INITIALIZING DEVICE`, when the device creates the transport. | +| `chans...address` of a channel that is not connected yet | In `CONNECTING`. The device reads the address again every 50 ms, until the time of `init-timeout` ends. | +| Your own properties | When your code reads them, or in your subscription callback. | + +[When the device reads a property](/concepts/configuration/#when-the-device-reads-a-property) has the details for +each property. + +- In its state callback of `INITIALIZING DEVICE`, the config plugin writes the channel properties of `--mq-config` or + `--channel-config`. The device reads the properties after all state callbacks return and after the request of + `CompleteInit`. +- The state callbacks of the plugins run in the sequence in which the plugin manager creates the plugins. The plugins + of `-P` come first, then `config`, the plugins of the hook `LoadPlugins`, and `control`. +- After `BINDING`, `chans...address` holds the address that the channel bound to. +- To use new values of the `INITIALIZING DEVICE` properties, request `ResetDevice` and initialize the device again. + `RESETTING DEVICE` removes the channels and the transports. + +## Problems + +| Problem | Cause and solution | +| --- | --- | +| `ChangeState()` or `ChangeDeviceState()` returns `false`. | The log shows the cause. `No transition from state … on transition …`: the current state does not accept the transition. `Transition … incoming, but another state transition is already ongoing.`: wait for the next state first. | +| The device stays in `INITIALIZING DEVICE`. | The device waits for `CompleteInit`. Request it. | +| `WaitForState()` does not return. | The state does not come. Check the transition that you requested, and check the log for an exception in a hook. | +| `DeviceRunner::Run()` does not return after `EXITING`. | A plugin has the controller role. Call `ReleaseDeviceControl()` in `EXITING`. | +| `RUNNING` ends at once. | The controller requested `Stop` in the callback of `RUNNING`, or the work of the device ended. | +| A subscription callback gets no call. | The type of the new value is not the type of the subscription. Give the type to `SetProperty()`. | +| `could not connect all channels after 120 attempts` | A channel did not connect in the time of `init-timeout`. The number in the text is the value of `init-timeout` in seconds. | + +## Related pages + +- [Plugins and control](/concepts/plugins/): the control plugin, its modes and the controller role. +- [Write a plugin](/guides/write-plugin/): build and load your own plugin. +- [custom-controller](/examples/custom-controller/): the complete controller example. +- [Device states](/concepts/states/): the states, the hooks and the state `ERROR`. diff --git a/docs/src/content/docs/guides/design-topology.mdx b/docs/src/content/docs/guides/design-topology.mdx new file mode 100644 index 00000000..6912a4d9 --- /dev/null +++ b/docs/src/content/docs/guides/design-topology.mdx @@ -0,0 +1,284 @@ +--- +title: Design a topology +description: 'Select the patterns, the binding devices, the channels and the transports of a topology: fan-out, fan-in, n to m, broadcast, one host and several hosts.' +sidebar: + order: 2.5 +code: [fairmq/Channel.h, fairmq/Device.cxx, fairmq/devices/Splitter.h, fairmq/devices/Merger.h, fairmq/devices/Multiplier.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +A topology is a set of devices and the channels that connect them. This guide shows how to select the +socket type, the binding side, the channels and the transport of each link, and how to plan the +addresses. Each decision refers to an example of the repository that uses it. + +## Before you start + +- Read [Channels and sockets](/concepts/channels/). This guide uses its terms and does not repeat its + tables. +- Draw your devices and the direction of the data between them. Each arrow is a link. + +## Steps + + + +1. For each link, [select the socket pattern](#select-the-socket-pattern). + +2. For each link, [select the device that binds](#select-the-device-that-binds). + +3. Decide where you need [sub-channels or several channels](#sub-channels-or-several-channels). + +4. [Select the transport](#select-the-transport-of-each-link) of each link. + +5. Write the [address plan](#plan-the-addresses). + +6. Write the configuration as [Configure channels](/guides/configure-channels/) shows, and + [check the result](#check-the-result). + + + +## Select the socket pattern + +The [socket types](/concepts/channels/#socket-types-and-patterns) give four patterns. Select the +pattern from what the link must do: + +| What the link must do | Pattern | Transports | Example | +| --- | --- | --- | --- | +| Give each message to one of several workers | `push` to `pull` | `zeromq`, `shmem` | [1-n-1](/examples/1-n-1/) | +| Collect the messages of several senders | `push` to `pull` | `zeromq`, `shmem` | [1-n-1](/examples/1-n-1/), [n-m](/examples/n-m/) | +| Send each message to all receivers | `pub` to `sub` | `zeromq` only | [multiple-channels](/examples/multiple-channels/) | +| Send the same data to all receivers with `shmem` | `push` sub-channels and `Copy()` | `zeromq`, `shmem` | [copypush](/examples/copypush/) | +| Send a request and wait for the reply | `req` to `rep` | `zeromq`, `shmem` | [req-rep](/examples/req-rep/) | +| Connect exactly two devices | `pair` | `zeromq`, `shmem` | [readout](/examples/readout/) | + +Know these properties of the patterns before you select one. For the details, see +[Behavior of each socket type](/concepts/channels/#behavior-of-each-socket-type). + +- A `push` socket with several peers gives each message to one peer, in turn. A `pull` socket + receives from all its peers. When the queues of all peers are full, `Send()` waits (ZeroMQ + behavior). Thus the receivers slow down the sender when they cannot keep up. +- The channel properties `sndBufSize` and `rcvBufSize` (default 1000 messages) set the size of the + send queue and the receive queue. FairMQ gives them to ZeroMQ as `ZMQ_SNDHWM` and `ZMQ_RCVHWM` + ([Channel.cxx](/source/fairmq/Channel.cxx/#L328-L330)). +- A `pub` socket does not wait for slow `sub` peers. For a peer with a full queue, it drops the + messages. A `sub` socket that connects late misses the earlier messages (ZeroMQ behavior). Do not + use `pub` and `sub` for data that must arrive. +- The `zeromq` transport subscribes each `sub` socket to all messages + ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L70-L74)). FairMQ has no option for a topic + filter ([zeromq/Common.h](/source/fairmq/zeromq/Common.h/#L91-L123)). +- The `shmem` transport throws `SocketError` for `pub` and `sub`. Give such a channel + `transport=zeromq`, as the channel `ack` of the + [multiple-transports example](/examples/multiple-transports/) does. +- A `req` socket must send and receive in turn. One `rep` server can answer several `req` clients + (ZeroMQ behavior). +- A `pair` socket has one peer (ZeroMQ behavior). For n peers, the device needs n sub-channels. + +## Patterns of the examples + +### Fan-out and fan-in + +In the [1-n-1 example](/examples/1-n-1/), the sampler binds a `push` channel, and the processors +connect to it. The processors also connect to the `pull` channel of the sink. The `push` socket +distributes the messages, and the `pull` socket of the sink collects them. All processors have the +same configuration. A binding socket accepts new peers at any time (ZeroMQ behavior), so you can add a +processor while the other devices run. + +You can also distribute the messages in your code. Give the output channel one sub-channel for each +receiver, and select the index in `Send()`. The built-in devices do this: + +- [`fairmq-splitter`](/tools/builtin-devices/#fairmq-splitter) sends each message on the next + sub-channel of its output channel, in turn. +- [`fairmq-merger`](/tools/builtin-devices/#fairmq-merger) polls all sub-channels of its input channel + and sends on one output. +- [`fairmq-multiplier`](/tools/builtin-devices/#fairmq-multiplier) sends each message to all + sub-channels of all output channels, with `Copy()` for all except the last. + + + +The [copypush example](/examples/copypush/) sends a copy of each message on each sub-channel. +`Copy()` does not copy the data. Use this form for a broadcast with `shmem`. + +### n senders to m receivers + +In the [n-m example](/examples/n-m/), each of the three senders connects to all four receivers. The +`data` channel of a sender has one sub-channel for each receiver: + + + +- A synchronizer sends an id on a `pub` channel. All senders get the same id. +- Each sender selects the sub-channel from the id: the id modulo `--num-receivers`. Thus all parts of + one id go to the same receiver. +- Each receiver binds one `pull` channel and collects the parts of all senders. +- The senders send with a timeout of 0 ms. If the queue of one receiver is full, the sender drops the + parts and continues with the other receivers. See + [Timeout for one call](/guides/errors-timeouts/#timeout-for-one-call). + +The pair variant of the example uses `pair` channels. Each receiver then binds one sub-channel for +each sender. The push and pull variant needs 4 ports for the data, and the pair variant needs 12 (3 +senders × 4 receivers). + +### Broadcast and data + +In the [multiple-channels example](/examples/multiple-channels/), the sampler sends data to the sink +on `data` (`push` to `pull`). A broadcaster binds a `pub` channel, and the sampler and the sink connect +a `sub` channel to it. The two links have different socket types, so each device has two channels. The +sampler polls both channels in its `Run()` loop. The sink registers one data callback for each channel. + +### A readout chain + +In the [readout example](/examples/readout/), the readout device creates an +[unmanaged region](/shmem/regions/) with the transport of its output channel and sends messages that +point into it. The start script gives each channel its transport: + + + +- The links on the readout host use `shmem`. The messages go from the readout device through the + builder to the sender without a copy. +- The sender forwards the messages to the receiver on a `zeromq` channel. The receiver can run on + another host. +- The readout device gets the acknowledgement for a block of the region when the last device releases + it. For the link to the other host, this is after the zeromq transport releases the data. + +## Select the device that binds + +Bind on the device with a stable place in the topology. Connect on the devices that you add, remove or +start several times: + +| Link | Binds | Connects | Example | +| --- | --- | --- | --- | +| One source, n workers, one sink | Source and sink | Workers | [1-n-1](/examples/1-n-1/) | +| n senders, m receivers | Receivers | Senders | [n-m](/examples/n-m/) | +| One broadcaster, n listeners | Broadcaster | Listeners | [multiple-channels](/examples/multiple-channels/) | +| One server, n clients | Server | Clients | [req-rep](/examples/req-rep/) | +| A chain of devices | `readout1`, `sender1`, `receiver1` | `builder1`, `sender1` | [readout](/examples/readout/) | + +- The method does not depend on the socket type. In the [multipart example](/examples/multipart/), the + `pull` side binds. In the multiple-transports example, the `sub` channel `ack` binds and the `pub` + channel connects. +- The connecting devices need the address of the binding device. With one binding device, all + connecting devices can use one configuration. The processors of the 1-n-1 example share one entry of + the JSON file with `--config-key processor`. +- You can start the devices in any sequence. See [Bind and connect](/concepts/channels/#bind-and-connect). + +## Sub-channels or several channels + +| Use | When | Example | +| --- | --- | --- | +| One sub-channel with several peers | The socket distributes the messages, and all peers are equal. You can add peers without a change in the binding device. | [1-n-1](/examples/1-n-1/) | +| Several sub-channels of one channel | All links have the same role, socket type and transport, and your code selects the peer with the index. | [copypush](/examples/copypush/), [n-m](/examples/n-m/) | +| Several channels | The links have different roles, socket types or transports. | [multiple-channels](/examples/multiple-channels/), [multiple-transports](/examples/multiple-transports/) | + +- In `--channel-config`, each `address=` key makes one sub-channel. See + [Several sub-channels](/guides/configure-channels/#several-sub-channels). +- Give all sub-channels of one channel the same transport. The pollers and the data callbacks use the + transport of the sub-channel 0 for all sub-channels ([Device.cxx](/source/fairmq/Device.cxx/#L452-L481)). +- A data callback gets the index of the sub-channel. With more than one input sub-channel, the device + polls all of them. See [Several input channels](/guides/receive-data/#several-input-channels). + +## Select the transport of each link + +- Use `shmem` for the links inside one host. The receiver finds the data in the shared memory, and + only the metadata goes through the socket. Both peers must use the same `--session`. See + [Transports](/concepts/transports/). +- Use `zeromq` for the links between hosts, and for `pub` and `sub`. +- A device on the border of a host has channels of both transports. Make its messages with + `NewMessageFor()`. A shmem message goes out on a zeromq channel without a copy. A zeromq message on + a shmem channel is copied. See [Use several transports](/guides/several-transports/). +- If a device receives with data callbacks from channels of two transports, the device polls each + transport in its own thread. See [Threads in a device](/concepts/threads/). +- Create a region in the first device of a chain, with the transport of its output channel. See + [Unmanaged regions](/shmem/regions/). +- To run two topologies on one host, give them different sessions. See + [Keep two topologies apart](/shmem/sessions/#keep-two-topologies-apart). + +## Plan the addresses + +### Fixed ports + +Give each binding sub-channel its own port. The examples use fixed ports, for example 5555 and +5556 in 1-n-1, and 8010 and 8021 to 8024 in n-m. + +- Set `autoBind=false` on the binding sub-channels. Otherwise a port in use gives a random port, and + the peers do not find the device. See [Automatic ports](/concepts/channels/#automatic-ports). +- Bind to `tcp://*:` for all interfaces (ZeroMQ behavior). The start scripts of n-m and + readout bind to `tcp://localhost:`. This works only on one host. +- On the connecting side, give the host name or the IPv4 address of the binding host. See + [Addresses on several hosts](/guides/configure-channels/#addresses-on-several-hosts). + +### Automatic ports + +A binding sub-channel without an address binds to port 1 of the interface of `--network-interface`. +Without root rights, this bind fails. Then autobind (`autoBind`, default `true`) selects a random port +from `portRangeMin` to `portRangeMax` (default 22000 to 23000). After the bind, the device writes the +address to the property `chans...address`. Your code, for example a plugin, must give this +address to the connecting devices. A connecting device reads its +address property again every 50 ms in `CONNECTING`, until `--init-timeout` (default 120 s) ends. See +[Addresses on several hosts](/guides/configure-channels/#addresses-on-several-hosts). + +The topologies of the [dds](/examples/dds/) and [qc](/examples/qc/) examples have no addresses. The DDS +plugin of FairMQ v1.4.56 gave the addresses to the peers. This repository has no such plugin. + +### ipc on one host + +On one host, `ipc://` endpoints need no ports. The test scripts of the examples use one file for each +sub-channel, with the session in the name. The channels then get the address `ipc://$chan1Addr`: + + + +Both transports work with `ipc://`. The shmem transport sends the metadata of the messages on this +endpoint. Use `inproc://` only between channels of one transport in one device. An `inproc://` +endpoint works only inside one ZeroMQ context (ZeroMQ behavior), and each transport of a device has +its own context. + +## Example for each need + +| Need | Example | +| --- | --- | +| Two devices, one direction | [1-1](/examples/1-1/) | +| Distribute work and collect the results | [1-n-1](/examples/1-n-1/) | +| Request and reply | [req-rep](/examples/req-rep/) | +| Several parts in one message | [multipart](/examples/multipart/) | +| The same data to each receiver, also with `shmem` | [copypush](/examples/copypush/) | +| Data and a broadcast in one device | [multiple-channels](/examples/multiple-channels/) | +| `shmem` and `zeromq` in one device | [multiple-transports](/examples/multiple-transports/) | +| Messages from your own shared memory, with acknowledgements | [region](/examples/region/) | +| A readout chain from one host to another | [readout](/examples/readout/) | +| Split, merge and copy without your own code | [builtin-devices](/examples/builtin-devices/) | +| n senders to m receivers | [n-m](/examples/n-m/) | +| A topology without addresses, started by DDS | [dds](/examples/dds/), [qc](/examples/qc/) | +| Your own controller | [custom-controller](/examples/custom-controller/) | + +## Check the result + + + +1. Start the devices with `--severity debug`. + +2. Find the line `Attached channel [] to
    () ()` for each + sub-channel. See [Check the result](/guides/configure-channels/#check-the-result). + +3. In the interactive controller, press `p`. Each sub-channel must show the number of peers of your + plan. + +4. Look at the rate lines of each sub-channel. The device logs them only for sub-channels with + `rateLogging` above 0 (default 1). A sub-channel with 0 messages per second has no traffic. + + + +## Problems that can occur + +| Symptom | Cause | Fix | +| --- | --- | --- | +| `PUB/SUB socket type is not supported for shared memory transport` | A `pub` or `sub` channel uses `shmem`. | Add `transport=zeromq` to both ends. | +| A sender stops when one receiver stops. | The sender selects the sub-channel, and the queue of that sub-channel is full. `Send()` waits. | Send with a timeout, as the n-m sender does, or let one `push` socket distribute. It waits only when the queues of all peers are full (ZeroMQ behavior). | +| The `sub` peers miss messages. | `pub` drops messages for slow peers, and a late `sub` misses the earlier messages (ZeroMQ behavior). | Use `push` and `pull`, or `push` sub-channels with `Copy()`. | +| The peers do not find the binding device. | The port was in use, and autobind selected a random port. | Set `autoBind=false`, and select a free port. | +| Two topologies on one host disturb each other. | They use the same ports, `ipc://` files or session. | Give each topology its own ports or files, and its own `--session`. | + +## Related pages + +- [Channels and sockets](/concepts/channels/): socket types, methods, addresses and automatic ports. +- [Configure channels](/guides/configure-channels/): write the plan as `--channel-config` or JSON. +- [Use several transports](/guides/several-transports/): a device with `shmem` and `zeromq` channels. +- [Built-in devices](/tools/builtin-devices/): splitter, merger, multiplier and proxy. diff --git a/docs/src/content/docs/guides/end-of-run.mdx b/docs/src/content/docs/guides/end-of-run.mdx new file mode 100644 index 00000000..1947bda6 --- /dev/null +++ b/docs/src/content/docs/guides/end-of-run.mdx @@ -0,0 +1,344 @@ +--- +title: Stop a topology without losing messages +description: 'End a run so that each sent message arrives: what the transitions do to queued messages, linger, end-of-stream messages, the stop order and the checks.' +sidebar: + order: 9.5 +code: [fairmq/Device.cxx, fairmq/Channel.h, fairmq/Channel.cxx, fairmq/plugins/control/Control.cxx, fairmq/zeromq/Context.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +At the end of a run, messages can still wait in the queues of the sockets. A device that resets its +channels too early loses them. This guide shows what each transition does to these messages, and +how each receiver learns that it has all data. It also gives the order in which the devices must +stop, and shows how you check that no message is lost. + +## What the transitions do to the messages + +Each transition that the state machine accepts interrupts the transports of the device. This is also +true for `Stop` and `Auto`, which the device requests itself +([Device.cxx](/source/fairmq/Device.cxx/#L96-L99)). When the next state starts, the device resumes +the transports ([Device.cxx](/source/fairmq/Device.cxx/#L101-L104)). While the transports are +interrupted, a `Send()` or `Receive()` that must wait returns `TransferCode::interrupted` (-3). A +transfer that is possible at once still completes, because the socket tries the transfer before it +checks the interruption ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L124)). + +| Transition or state | What happens to the messages | +| --- | --- | +| `Stop` (end of `RUNNING`) | The device does not call `ConditionalRun()` or the data callbacks again. A `Send()` that waits returns `interrupted`. This message is not sent, and your `MessagePtr` keeps it. The messages in the queues of the sockets stay there. | +| `READY`, `RESETTING TASK`, `DEVICE READY` | The channels and their queues still exist. After a new `Run`, the device receives the queued messages. | +| `RESETTING DEVICE` | The device resets its transports, calls `Reset()`, and destroys all channels and transports ([Device.cxx](/source/fairmq/Device.cxx/#L732-L749)). The sockets close. The messages in a send queue get the linger time, see [Linger](#linger). The messages in a receive queue are lost (ZeroMQ behavior). | +| `ERROR` | The control plugin requests no more transitions. The device does not call `ResetTask()` and `Reset()`. With `runDevice.h`, the process ends with the exit code 1, and the messages in its receive queues are lost. | + +Thus a device must have all its data before it goes to `RESETTING DEVICE`. The transitions are in +[Device states](/concepts/states/#transitions). + +## Linger + +The channel property `linger` is a time in ms. The default is 500 +([Channel.h](/source/fairmq/Channel.h/#L378)). [`Channel::Init()`](/api/fair/mq/Channel/#Init) sets +it as the ZeroMQ option `ZMQ_LINGER` on the socket ([Channel.cxx](/source/fairmq/Channel.cxx/#L325-L326)). +The shmem transport sets it on the ZeroMQ socket that carries the metadata of its messages. + +In `RESETTING DEVICE`, the device destroys its transports. The destructor of a transport calls +`zmq_ctx_term()` ([zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L156-L175)). This call waits +until the closed sockets sent the messages in their send queues, for the linger time at most. Then +ZeroMQ discards the remaining messages. This is ZeroMQ behavior. Thus: + +- A device can stay up to `linger` ms in `RESETTING DEVICE`. +- Linger helps only if the peer still exists and takes the messages (ZeroMQ behavior). It does not + help the messages in the receive queue of a device that resets. +- With `-1`, ZeroMQ waits without a time limit. If the peer does not take the messages, the device + does not leave `RESETTING DEVICE`. +- With `0`, ZeroMQ discards the queued messages at once. + +The test script of the [multipart example](/examples/multipart/#test-the-example) gives the sampler +`linger=1000`. The sampler resets at once after its only message. The longer linger time gives +ZeroMQ more time to deliver this message. Set the value in the channel configuration, for +example `--channel-config name=data,type=push,method=connect,address=tcp://localhost:5555,linger=2000`, +or with `"linger": 2000` in a JSON file. See [Channel properties](/reference/channel-properties/#linger). + +With shmem, the data of a message stays in the managed segment, and the linger time applies to the +metadata. After a successful `Send()`, the sender does not free the block any more. If ZeroMQ +discards the metadata, no process frees the block. It stays in the segment until the shared memory of +the session is removed (see [Sessions and segments](/shmem/sessions/#the-device-counter-and-cleanup)). + +## Tell each receiver that the data ends + +A receiver cannot see if more messages come. The sender must tell it with an end message after its +last data message. Send the end message on the same sub-channel as the data. ZeroMQ delivers the +messages of one connection in the order of the `Send()` calls (ZeroMQ behavior). Messages on +different channels or sub-channels have no fixed order. + +The [multipart example](/examples/multipart/) puts a flag into its header. The sampler sets the flag +in its last message: + + + +After the last message, `ConditionalRun()` returns `false`. The device then requests `Stop` itself: + + + +The sink leaves `RUNNING` when it gets the flag. The callback returns `false`, and the device goes to +`READY`: + + + +The sampler ignores the return value of `Send()`. Your source must check it. If the end message is +not sent, the receiver does not stop. + +### Several receivers and several senders + +- **One sender, several receivers.** A `push` socket gives each message to one of its peers + (ZeroMQ behavior). Thus one end message reaches one receiver only. The page of the multipart + example shows this with [two sinks](/examples/multipart/#send-to-two-sinks). Give each receiver its own sub-channel, and send an end message on each sub-channel. The + sender of the [n-m example](/examples/n-m/#sender-select-the-receiver) has one sub-channel for each + receiver. It selects the sub-channel with the index argument of `Send()`. See + [Several sub-channels](/guides/configure-channels/#several-sub-channels). +- **Several senders, one receiver.** The receiver needs one end message from each sender. It must + know the number of senders. The receiver of the n-m example gets this number from its option + `--num-senders`. +- **Processors.** A processor between the senders and the receivers waits for the end messages of + all its inputs. Then it sends an end message on each output and returns `false`. + +This sink receives the multipart messages of the example from several senders. It leaves `RUNNING` +after the end message of the last sender: + +```cpp +#include "Header.h" // example_multipart::Header + +#include +#include + +#include +#include +#include + +namespace bpo = boost::program_options; + +struct Sink : fair::mq::Device +{ + Sink() { OnData("data", &Sink::HandleData); } + + void InitTask() override { fNumSenders = fConfig->GetProperty("num-senders"); } + + bool HandleData(fair::mq::Parts& parts, int /*index*/) + { + if (parts.Size() < 1 || parts.At(0)->GetSize() != sizeof(example_multipart::Header)) { + throw std::runtime_error("unexpected message format"); + } + example_multipart::Header header; + std::memcpy(&header, parts.At(0)->GetData(), sizeof(header)); + + if (header.stopFlag == 1) { + ++fNumEnded; + LOG(info) << "End message " << fNumEnded << " of " << fNumSenders; + return fNumEnded < fNumSenders; // false ends RUNNING + } + ++fNumReceived; + return true; + } + + void PostRun() override { LOG(info) << "Received " << fNumReceived << " data messages"; } + + private: + int fNumSenders = 1; + int fNumEnded = 0; + std::uint64_t fNumReceived = 0; +}; + +void addCustomOptions(bpo::options_description& options) +{ + options.add_options() + ("num-senders", bpo::value()->default_value(1), "Number of senders"); +} + +std::unique_ptr getDevice(fair::mq::ProgOptions& /*config*/) +{ + return std::make_unique(); +} +``` + +The checks of the size come from [Send your own data types](/guides/send-data-types/#read-the-data-safely). + +## Stop the devices in the right order + +The data flows from the sources through the processors to the sinks. End `RUNNING` in the same order: + + + +1. End `RUNNING` of the sources. A source that ends by itself sends its end messages and returns + `false`. + +2. Let each processor and each sink end `RUNNING` by itself, after its end messages. + +3. Wait until all sinks are in `READY`. The log line of each sink contains `RUNNING ---> READY`. + +4. Then request `ResetTask`, `ResetDevice` and `End` for all devices. + + + +If a controller stops a sink first, the sink does not read its queue any more. New messages fill +the receive queue of the sink and then the send queue of the sender (ZeroMQ behavior). Then +`Send()` of the sender waits until its timeout ends or a transition interrupts it. When the sink +resets, the messages in its queue are lost. + +A signal starts the shutdown sequence of the control plugin: `Stop`, `ResetTask`, `ResetDevice` +and `End`. Thus a signal to all devices at the same time also resets the sinks while data is on the +way. Send the signal to the sources first. Signal the other devices after the sinks left `RUNNING`. +The test script of the [1-n-1 example](/examples/1-n-1/#test-the-example) waits for the sampler and +the sink, which end by themselves. Then it stops the processors with `SIGINT`: + + + +### A source that a controller stops + +A controller can request `Stop` for a source, for example with the key `s` or with a signal. Then +the source cannot send the end message in `RUNNING`. In `PostRun()`, `Stop` is pending and the +transports are interrupted, so a `Send()` that must wait returns `interrupted`. Send the end message +in [`ResetTask()`](/api/fair/mq/Device/#ResetTask) instead. In `RESETTING TASK`, the transports are +not interrupted, and the state machine accepts only `Auto` and `ErrorFound`. Give the `Send()` a +timeout: + +```cpp +void ResetTask() override +{ + if (fEndSent) { + return; // ConditionalRun() sent the end message already + } + example_multipart::Header header; + header.stopFlag = 1; + fair::mq::Parts parts; + parts.AddPart(NewSimpleMessage(header)); + if (Send(parts, "data", 0, 1000) < 0) { + LOG(error) << "Could not send the end message in 1 s"; + } + fEndSent = true; +} +``` + +The sink of the previous section accepts this end message with one part. The sink of the multipart +example expects seven parts and throws an exception for it. + +## Wait in PostRun() or ResetTask() + +A sink that a controller stops can still read the messages that arrived. The two hooks after +`RUNNING` behave differently: + +- **[`PostRun()`](/api/fair/mq/Device/#PostRun):** `Stop` is pending, and the transports are + interrupted. A `Receive()` returns the messages that are already in the receive queue. When the + queue is empty, it returns `interrupted`: at once for the timeout 0, otherwise within 100 ms. Thus + `PostRun()` can empty the queue, but it cannot wait for more messages. +- **[`ResetTask()`](/api/fair/mq/Device/#ResetTask):** the transports are not interrupted. A + `Receive()` with a timeout waits for more messages. Always give a timeout. In `RESETTING TASK`, + the state machine accepts only `Auto` and `ErrorFound`, and the control plugin requests neither. + Thus a `Receive()` without a timeout can block the device. + +This `ResetTask()` reads messages until no message arrives for 1 s: + +```cpp +void ResetTask() override +{ + while (true) { + auto msg(NewMessage()); + if (Receive(msg, "data", 0, 1000) < 0) { + break; // no message in 1 s, or an error + } + ++fNumReceived; + } + LOG(info) << "Received " << fNumReceived << " messages in total"; +} +``` + +Receive into a [`fair::mq::Parts`](/api/fair/mq/Parts/) object if the sender sends multipart +messages. The four-argument form of [`Receive()`](/api/fair/mq/Device/#Receive-2) takes the +timeout in ms. A wait in `ResetTask()` does not replace the end message: it cannot know whether +the senders sent everything. + +## What the controllers do + +The built-in control plugin handles the end of `RUNNING` in a different way in each mode +([interactive](/source/fairmq/plugins/control/Control.cxx/#L274-L290), +[static and gui](/source/fairmq/plugins/control/Control.cxx/#L403-L437)): + +| `--control` | When `RUNNING` ends | What this means for the end of the run | +| --- | --- | --- | +| `static` | When the device goes to `READY`, the plugin runs the shutdown sequence at once. | The device resets right after its last message. Its linger time must be long enough for its send queue. Use this mode with end messages. | +| `dynamic` (default), `interactive`, `external` | The device stays in `READY`. The plugin waits for keys: `s` requests `Stop`, `q` runs the shutdown sequence. | You select the order. Press `s` for the sources, wait for the sinks, then press `q` in each device. | +| `gui` | The device stays in `READY` until a signal. | Send the signals in the order of this guide. | +| `none` | The plugin requests no transitions. A signal still starts its shutdown sequence. | Your controller must request the transitions in the order of this guide. | + +With `--catch-signals 1` (default), the first `SIGINT` or `SIGTERM` runs the shutdown sequence +from the current state. A second `SIGINT` ends the process at once with `std::abort()`, and all +queued messages are lost. After `ERROR`, the plugin runs no shutdown sequence. For the details, see +[Control modes](/concepts/plugins/#control-modes) and +[Startup and shutdown sequences](/reference/states/#startup-and-shutdown-sequences). + +## Check that no message is lost + + + +1. Count the successful transfers in each device: each `Send()` that returns 0 or more, and each + received message. + +2. Log the counters in `PostRun()` or `ResetTask()`, and compare the numbers of the senders with + the numbers of the receivers. + +3. Put the number of data messages into the end message. The receiver then compares it with its own + count. A sequence number in each header also shows which message is missing. + +4. Test with a fixed number of messages, and let the receiver stop after this number. + + + +Each channel also counts its transfers. +[`GetMessagesTx()`](/api/fair/mq/Channel/#GetMessagesTx), +[`GetMessagesRx()`](/api/fair/mq/Channel/#GetMessagesRx), +[`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) and +[`GetBytesRx()`](/api/fair/mq/Channel/#GetBytesRx) return the counters of the socket. The socket +increments them after each successful transfer. A multipart message counts as one message. The +counters start when the device makes the socket, and they include all runs since then. Read them +before `RESETTING DEVICE`, because the device destroys the channels there: + +```cpp +void ResetTask() override +{ + auto& channel = GetChannel("data"); + LOG(info) << "data: " << channel.GetMessagesTx() << " messages, " << channel.GetBytesTx() << " bytes sent"; +} +``` + +The tests of the examples use a fixed number. In the test script of the [1-1 example](/examples/1-1/#test-the-example), +the sampler and the sink both have `--max-iterations 1` and `--control static`. The sink ends only +after it received the message. If the message is lost, the sink stays in `RUNNING`, and CTest stops +the test after its timeout of 30 s (`examples/CMakeLists.txt`). See +[Test your devices](/guides/test-devices/). + +## Problems that can occur + +- **The sink gets fewer messages than the source sent, with `--control static`:** the source reset + before ZeroMQ sent its queue. Increase `linger` on the output channel of the source. +- **A device does not leave `RESETTING DEVICE`:** its `linger` is `-1`, and the peer does not take + the messages. Use a time limit. +- **Only one of several sinks leaves `RUNNING`:** the `push` socket gave the end message to one + peer only. Send an end message on a sub-channel for each receiver. +- **The sink does not leave `RUNNING`:** an end message did not arrive, or the sink expects too many + senders. Check the log of the senders and the number of senders of the sink. +- **`Send()` returns -3 in `PostRun()`:** the transports are interrupted. Send the end message + before `RUNNING` ends, or in `ResetTask()`. +- **Messages are lost after Ctrl-C in all terminals:** each device stopped and reset at once. Stop + the sources first. +- **A device does not leave `RESETTING TASK`:** your `ResetTask()` calls `Receive()` without a + timeout. Give a timeout. + +## Related pages + +- [Device states](/concepts/states/): the transitions, `PostRun()` and the interruption of the + transports. +- [Plugins and control](/concepts/plugins/#control-modes): the control modes and the signals. +- [Channel properties](/reference/channel-properties/#linger): `linger` and the queue sizes. +- [Handle errors and timeouts](/guides/errors-timeouts/): transfer codes and timeouts. +- [When a peer stops or restarts](/guides/errors-timeouts/#when-a-peer-stops-or-restarts): the queues + and the shared memory of a peer that ends. +- [multipart: several parts in one message](/examples/multipart/): the example with the stop flag. diff --git a/docs/src/content/docs/guides/errors-timeouts.mdx b/docs/src/content/docs/guides/errors-timeouts.mdx new file mode 100644 index 00000000..1e993a64 --- /dev/null +++ b/docs/src/content/docs/guides/errors-timeouts.mdx @@ -0,0 +1,421 @@ +--- +title: 'Handle errors and timeouts' +description: 'Check the return values of Send() and Receive(), set timeouts, handle interrupted transfers and exceptions, and know what happens in ERROR.' +sidebar: + order: 9 +code: [fairmq/Socket.h, fairmq/Channel.h, fairmq/Device.cxx, fairmq/Error.h, fairmq/shmem/Manager.h, fairmq/shmem/Message.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +This guide shows how your device detects failed transfers, uses timeouts and reacts to errors. When +you complete it, your device continues after a timeout, stops cleanly after an interruption, and +goes to `ERROR` only for a real error. + +## Check the return value of a transfer + +`Send()` and `Receive()` return an `int64_t`. A value of 0 or more is the number of bytes. A negative +value is a [`TransferCode`](/api/fair/mq/TransferCode/): + +| Return value | Meaning | Typical reaction | +| --- | --- | --- | +| 0 or more | The transfer is complete. For `Send()`, the message is in the queue of the socket. 0 is the size of an empty message. | Continue. | +| `TransferCode::timeout` (-2) | The timeout ended before the transfer was possible. | Try again, or do other work. | +| `TransferCode::interrupted` (-3) | A transition is pending, and the device interrupted its transports. | Return from the hook. | +| `TransferCode::error` (-1) | The transfer failed. The transport logs the reason. | End `RUNNING`, or throw an exception. | + + + +1. Store the return value of each `Send()` and `Receive()`. + +2. Compare a negative value with the codes. Use `static_cast(fair::mq::TransferCode::timeout)`. + +3. Select the reaction from the table above. + + + +Many examples only check for a negative value. The sampler of the example [1-1](/examples/1-1/) +ends `RUNNING` for each failed transfer: + + + +This hook handles each code in a different way. It waits up to 1000 ms for a message: + +```cpp +bool ConditionalRun() override +{ + auto msg(NewMessage()); + auto const result = Receive(msg, "data", 0, 1000); + + if (result >= 0) { + LOG(info) << "Received " << result << " bytes"; + return true; + } + if (result == static_cast(fair::mq::TransferCode::timeout)) { + LOG(warn) << "No message in 1 s"; + return true; // try again in the next call + } + if (result == static_cast(fair::mq::TransferCode::interrupted)) { + return false; // a transition is pending + } + throw std::runtime_error("Receive on channel data failed"); // the device goes to ERROR +} +``` + +For all codes, see [Transfer codes and errors](/reference/transfer-codes/). + +## Set a timeout + +A timeout is a value in ms: + +- `-1` (default): wait until the transfer is possible, or until a transition interrupts the transfer. +- `0`: do not wait. If the transfer is not possible at once, return `TransferCode::timeout`. While + the transports are interrupted, return `TransferCode::interrupted`. +- A positive value: wait up to this time. + +You can give the timeout for one call or for all calls on a channel. + +### Timeout for one call + +Give the timeout as the fourth argument of +[`Send()`](/api/fair/mq/Device/#Send-2) or [`Receive()`](/api/fair/mq/Device/#Receive-2). On a +[`Channel`](/api/fair/mq/Channel/), it is the second argument. The test device `TransferTimeout` +sends and receives on channels without a peer, with 200 ms and with 0 ms: + + + +### Timeout for a channel + +The channel properties `sndTimeoutMs` and `rcvTimeoutMs` (default `-1`) set the timeout for all +calls without a timeout argument. Give them in the channel configuration: + +```sh +./my-device --id device1 --channel-config name=data,type=pull,method=connect,address=tcp://localhost:5555,rcvTimeoutMs=1000 +``` + +In a JSON file, use the same keys. See [Channel properties](/reference/channel-properties/). +[`Channel::UpdateSndTimeout()`](/api/fair/mq/Channel/#UpdateSndTimeout) and +[`UpdateRcvTimeout()`](/api/fair/mq/Channel/#UpdateRcvTimeout) change the values of a `Channel` +object. + +:::caution[Known defect] +[`Device::AddChannel()`](/api/fair/mq/Device/#AddChannel) does not copy `sndTimeoutMs` and +`rcvTimeoutMs` into the configuration. A channel that you add in this way has the timeouts `-1`. +Give the timeout as an argument of each call instead. +::: + +### Steps of 100 ms + +The zeromq and shmem sockets wait in steps of 100 ms. After each step, the socket checks for an +interruption and for the end of the timeout. Thus: + +- The real timeout is the value rounded up to a multiple of 100 ms. A timeout of 150 ms waits + 200 ms. +- A transfer that waits returns `TransferCode::interrupted` not more than 100 ms after the + interruption. + +## Handle interrupted transfers + +When a controller or the device requests a transition, the device calls `Interrupt()` of all its +transports. From then on, a `Send()` or `Receive()` that must wait returns `TransferCode::interrupted`. A transfer +that is possible at once can still complete. When the next state starts, the device resumes the +transports. + +Thus: + +- Treat `interrupted` as a normal end of `RUNNING`. Return from `ConditionalRun()` with `false`, or + go back to the check of `NewStatePending()` in your `Run()` loop. +- In `PostRun()`, the transports are still interrupted. Do not wait for transfers there. See + [Wait in PostRun() or ResetTask()](/guides/end-of-run/#wait-in-postrun-or-resettask). +- With shmem, a `NewMessage()` that waits for free memory throws `MessageBadAlloc` after an + interruption (see below). + +The test `InterruptTransfer.Receive` interrupts a transport while a `Receive()` waits. +`Factory.ResumeAfterInterrupt` shows that transfers work again after `Resume()`. + +## Exceptions and the ERROR state + +An exception in a hook or in a data callback moves the device to `ERROR`. With input channels on more +than one transport, an exception in a data callback ends the process with `std::terminate()` +instead. Your code can also request the transition `ErrorFound`. The test device `StateAction` does +both: + + + +After an exception, the device does these steps: + +1. The state machine logs `Exception caught in ProcessWork(), going to Error state` (severity + `debug`), and changes to `ERROR`. +2. The device does not call the other hooks of the state. After an exception in `RUNNING`, it does + not call `PostRun()`. +3. [`RunStateMachine()`](/api/fair/mq/Device/#RunStateMachine) throws the exception again. +4. With `fairmq/runDevice.h`, `main()` logs `Uncaught exception reached the top of main:` and the + text of the exception. The exit code is 1. + +After the transition `ErrorFound`, the current hook continues until it returns. In `RUNNING`, the +device also calls the remaining hooks, for example `PostRun()`. Then the state machine changes to +`ERROR`. `RunStateMachine()` throws `StateMachine::ErrorStateException` with the text +`Device transitioned to error state`, and the exit code is also 1. + +The tests `Exceptions.Throw` and `ErrorState.ChangeState` check the exit code 1 for each hook, with +`--control static` and `interactive`. + +### What the control plugin does in ERROR + +In `ERROR`, the controller of the control plugin stops. It does not run the shutdown sequence. Thus +the device does not call `ResetTask()` and `Reset()` after an error. Free your resources also in the +destructor of your device, or use objects that free them automatically. + +With `--catch-signals 1` (default), a signal is not an error. A `SIGINT` in any hook starts the +shutdown sequence, and the exit code is 0. The test `Signals.RaiseSIGINT` checks this for each hook. + +## Error codes + +[`ChangeStateOrThrow()`](/api/fair/mq/Device/#ChangeStateOrThrow) throws `std::system_error` when the +state machine refuses the transition. The code is +[`ErrorCode::DeviceChangeStateFailed`](/api/fair/mq/ErrorCode/#DeviceChangeStateFailed) (13) in the +category `fairmq`. Compare the value and the name of the category: + +```cpp +try { + device.ChangeStateOrThrow(fair::mq::Transition::Run); +} catch (std::system_error const& e) { + if (e.code().value() == static_cast(fair::mq::ErrorCode::DeviceChangeStateFailed) + && std::string_view(e.code().category().name()) == "fairmq") { + LOG(error) << e.what(); // Invalid transition: RUN: failed to change state of a fairmq device + } +} +``` + +:::caution +Do not compare `e.code()` with [`fair::mq::MakeErrorCode()`](/api/fair/mq/#MakeErrorCode). `fairmq/Error.h` defines the category +object as `static`, so each translation unit has its own object. Then the comparison can return +`false` for the same error. +::: + +The text of `what()` comes from the standard library. The example shows the text of libstdc++. + +## Shared memory allocation + +With shmem, `NewMessage(size)` allocates the message in the shared memory segment. If the segment +does not have enough free memory, the transport throws +[`MessageBadAlloc`](/api/fair/mq/MessageBadAlloc/). These options change the behavior: + +| Option | Default | Effect | +| --- | --- | --- | +| `--shm-throw-bad-alloc` | `true` | With `false`, the transport tries again without a limit. `--bad-alloc-max-attempts` then has no effect. | +| `--bad-alloc-max-attempts` | Not set (1 attempt) | The number of attempts before the exception. `-1` means no limit. `0` has the same effect as `1`. | +| `--bad-alloc-attempt-interval` | `50` | The time between two attempts, in ms. | +| `--shm-segment-size` | `2147483648` (2 GiB) | A message larger than the segment always throws `MessageBadAlloc` at once. | + +An attempt that waits ends with `MessageBadAlloc` when a transition interrupts the transport. The +test `ShmAllocation.MaxAttempts` fills a segment and expects the exception after four attempts: + + + +For the size of the segment, see [Tune shared memory](/shmem/tuning/). + +## Connect timeout + +In `CONNECTING`, the device tries to connect each channel with the method `connect`. If a connect +fails, the device waits 50 ms, reads the address property again and tries again. After +`--init-timeout` seconds (default 120), the device throws `std::runtime_error` and goes to `ERROR`: + +```txt +could not connect all channels after 120 attempts +following channels are still invalid: +``` + +The number in the first line is the value of `init-timeout` in seconds, not the number of attempts. +A zeromq or shmem connect succeeds also when the peer does not exist yet. Thus the retries help +when the address is not valid yet, for example when a controller sets it later. + +In `BINDING`, the device tries each channel once. With the channel property `autoBind` (default +`true`), a tcp channel that cannot bind to its port tries random ports. If a channel cannot bind, +the device throws an exception with the text +`… of the binding channels could not initialize. Initial configuration incomplete.` + +## When a peer stops or restarts + +FairMQ does not watch the peers of a channel. When a peer process ends, FairMQ does not report it +to your device. The zeromq and the shmem transport both send through ZeroMQ sockets, so this section +applies to both. A statement marked "ZeroMQ behavior" comes from the ZeroMQ documentation, not from +the code of FairMQ. + +### A peer ends while the device sends or receives + +`Send()` and `Receive()` return `TransferCode::error` when the ZeroMQ socket reports an error other +than `EAGAIN` or `EINTR`, for example after the end of its context +([zeromq/Common.h](/source/fairmq/zeromq/Common.h/#L79-L88)). A peer that ends does not cause such an +error (ZeroMQ behavior). +The socket waits in steps of 100 ms, and after each step it checks only for an interruption and for +the end of the timeout ([zeromq/Common.h](/source/fairmq/zeromq/Common.h/#L64-L77)). Thus a peer that +ends looks like a peer that is slow: + +| Timeout | `Send()` | `Receive()` | +| --- | --- | --- | +| `-1` | Returns the size when ZeroMQ puts the message into a queue. If no queue has space, it waits until a queue has space or a transition interrupts it. | Waits until a message arrives, or until a transition interrupts it. | +| `0` or more | Returns `TransferCode::timeout` when no queue has space before the timeout ends. | Returns `TransferCode::timeout` when no message arrives before the timeout ends. | + +The test device `TransferTimeout` (see [Timeout for one call](#timeout-for-one-call)) shows the +second row for channels without a peer. + +A successful `Send()` does not tell you that the peer received the message. ZeroMQ put it into a +queue. These messages can be lost when a peer ends: + +- The messages in the queues of the process that ends. The queues are in the memory of the process. +- The messages in the queue of a socket that binds, for the peer that disconnects. ZeroMQ removes + this queue (ZeroMQ behavior). +- The messages that a `pub` socket sends while no `sub` socket is connected. ZeroMQ drops them + (ZeroMQ behavior). Only the zeromq transport has `pub` and `sub`. + +A socket that connects keeps its queue while the peer is away. It sends the messages when the +connection comes back (ZeroMQ behavior). A `push` socket that binds sends new messages only to the +peers that remain (ZeroMQ behavior). A `push` socket that connects to several peers continues to put messages into the +queue of the peer that ended, until this queue is full (ZeroMQ behavior). FairMQ does not set the +ZeroMQ option `ZMQ_IMMEDIATE`, which changes this. + +With `req` and `rep` and the timeout `-1`, a request can wait forever. If the `rep` peer ends before it replies, +`Receive()` on the `req` channel waits or returns `TransferCode::timeout`. After that, ZeroMQ refuses +the next `Send()` on the `req` socket, because the socket waits for the reply (ZeroMQ behavior). This +`Send()` returns `TransferCode::error`, and the log shows `Failed transfer on socket …`. The device +makes its sockets only in `BINDING` and `CONNECTING`. Thus the controller must reset the device and +take it through `INITIALIZING DEVICE`, `BINDING` and `CONNECTING` again. + +### Find out if a peer is connected + +[`GetNumberOfConnectedPeers()`](/api/fair/mq/Channel/#GetNumberOfConnectedPeers) of a channel returns +the number of connections of its socket. The socket counts the ZeroMQ events "connected", +"accepted" and "disconnected" when you call the function +([zeromq/Common.h](/source/fairmq/zeromq/Common.h/#L238-L264)). The test `ConnectedPeers.Pair` shows +that the count goes back to 0 when the peer closes its channel: + + + +Call the function in the thread that uses the channel. See +[What is thread-safe](/concepts/threads/#what-is-thread-safe). + +### The peer starts again + +- **Your device connects, and the peer binds.** ZeroMQ connects again by itself (ZeroMQ behavior). + Your device stays in its state. For a `tcp://` address, the device resolves the host name once, in + `CONNECTING`, and gives the IP address to ZeroMQ + ([Device.cxx](/source/fairmq/Device.cxx/#L321-L331)). Thus the peer must start again on the same + host and port. +- **Your device binds, and the peer connects.** ZeroMQ accepts the new connection (ZeroMQ + behavior). Your device does nothing. +- **The peer binds to another port.** If the port is not free and `autoBind` is `true`, the peer + binds to a random port ([Channel.cxx](/source/fairmq/Channel.cxx/#L346-L386)). The connecting + device does not find it there. Set `autoBind=false` for a peer that can start again. Then its bind + fails, and it goes to `ERROR`. +- **The shmem transport.** The new peer must use the same `--session`. Then it opens the segments and + regions that exist. The transport does not check the session of a message. See + [Keep two topologies apart](/shmem/sessions/#keep-two-topologies-apart). + +### The binding peer starts after the connecting device + +The connecting device does not wait for the peer. In `CONNECTING`, a zeromq or shmem connect +succeeds also when no socket binds at the address (ZeroMQ behavior, see [Connect timeout](#connect-timeout)). The +device goes on to `RUNNING`. ZeroMQ connects when the peer binds (ZeroMQ behavior). Until then: + +- `Send()` puts messages into the queue of the socket, up to the limit of `sndBufSize` (default + 1000). Then it waits or returns `TransferCode::timeout` (ZeroMQ behavior). +- `Receive()` waits, or returns `TransferCode::timeout`. + +Thus the start order of the processes does not matter, if the addresses are fixed. The test +`MultipleDevices.TwoInSameProcess` starts a connecting sender and a binding receiver at the same +time, in no fixed order. If the connecting device closes its socket before the peer binds, ZeroMQ +keeps the queued messages for the time of the channel property `linger` (default 500 ms) and then +drops them (ZeroMQ behavior). See [Stop a topology without losing messages](/guides/end-of-run/). + +### Shared memory after a peer ends + +With shmem, the data of a message is a block in a segment. After a successful `Send()`, the message +of the sender no longer owns the block. Its destructor does not free it +([shmem/Message.h](/source/fairmq/shmem/Message.h/#L372-L411)). The receiver frees the block when it +destroys or rebuilds the received message and the reference count was 1. Only the process that holds +the last message of a block frees the block. Thus: + +| Case | What happens to the block | +| --- | --- | +| The receiver crashes while it holds the message. | The block stays allocated. | +| The receiver ends before it receives the message. | If the metadata message is lost with a queue (see above), the block stays allocated. If the connecting socket of the sender keeps the message, the next receiver gets it and frees the block. | +| The sender ends after `Send()`, and the receiver gets the message. | The data is valid. The segment does not belong to the sender. The receiver frees the block. | +| A process crashes while it holds one of several copies (`Copy()`). | The reference count does not get to 1. The block stays allocated after the other copies are destroyed. | +| A block of an unmanaged region stays allocated in one of these cases. | The creator of the region gets no callback for this block. | + +A block that stays allocated stays until the segment is removed, or until +`fairmq-shmmonitor --reset-content` (experimental) resets the segment while no device uses it. If +peers crash often, the segment fills, and `NewMessage()` throws `MessageBadAlloc`. See +[Shared memory allocation](#shared-memory-allocation). + +The segments belong to the session, not to the process that created them. Each shmem transport +increments the device counter in the management segment when it starts +([shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L144-L153)). Its destructor decrements the +counter. When the counter is 0, this transport removes all objects of the session, unless +`--shm-no-cleanup` is `true` ([shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L773-L798)). Thus: + +- When the creator of a segment ends normally and other devices run, the segment stays. The other + devices continue. +- A process that ends without the destructor, for example after a crash or `kill -9`, does not + decrement the counter. The topology continues, but the last device does not remove the memory at + the end. See [The device counter and cleanup](/shmem/sessions/#the-device-counter-and-cleanup). +- A peer that starts again with the same session opens the segments and increments the counter + again. + +### Rules for peers that can stop + + + +1. Give a timeout to `Send()` and `Receive()` on a channel whose peer can stop. With `-1`, only a + transition ends the wait. + +2. Check the return value of each transfer. Decide in your code when a peer is lost, for example + after a number of timeouts. FairMQ does not decide it. + +3. Do not take a successful `Send()` as a delivery. If the data must arrive, let the receiver + confirm it, with `req`/`rep` or with an acknowledgement on a second channel. The example + [multiple-transports](/examples/multiple-transports/) sends acknowledgements on its channel `ack`. + +4. Give fixed addresses to the peers that can start again. + +5. With shmem, start the new process with the same `--session` as the other devices. + +6. After a crash, start the peer again, or stop the topology. When all devices of the session have + stopped, look for the memory that stays and remove it. See [Monitor and clean up](/shmem/monitor/). + With `--shm-monitor true`, a daemon removes it when the heartbeats of the session stop. + + + +## Problems that can occur + +- **The device stops slowly after Ctrl-C:** a hook waits in `std::this_thread::sleep_for()` or in a + long computation. Use `WaitFor()` for pauses, and check `NewStatePending()` in long loops. +- **A timeout is longer than the value:** the sockets wait in steps of 100 ms. Use multiples of + 100 ms. +- **The device goes to `ERROR` in `INITIALIZING TASK` with `Config has no key: …`:** the option does + not exist. `GetProperty(key)` throws `PropertyNotFoundError`. Register the option in + `addCustomOptions()`, or use `GetProperty(key, default)`. +- **`boost::bad_any_cast` in a hook:** the type in `GetProperty()` is not the type of the option. + Use the type from the option definition. +- **The device ignores the timeout of a channel:** the channel came from `AddChannel()`. See the + caution above. +- **The device has no channels, and the log shows an error at the start of `INITIALIZING DEVICE`:** + the configuration parser failed. The config plugin logs the error and continues. Correct the file + of `--mq-config` or the values of `--channel-config`. +- **A device waits forever after its peer crashed:** the transfers use the timeout `-1`. Give a + timeout. See [When a peer stops or restarts](#when-a-peer-stops-or-restarts). +- **The free memory of the shmem segment gets smaller after each crash of a peer:** the blocks of + the crashed process stay allocated. Stop the topology, and remove the shared memory. See + [Shared memory after a peer ends](#shared-memory-after-a-peer-ends). + +## Related pages + +- [Transfer codes and errors](/reference/transfer-codes/): all codes and all exceptions of FairMQ. +- [Behavior of each socket type](/concepts/channels/#behavior-of-each-socket-type): full queues, `pub` drops and `req` errors. +- [Device states](/concepts/states/): `ERROR` and the transitions. +- [Receive data with callbacks or loops](/guides/receive-data/): the end of `RUNNING`. +- [Channel properties](/reference/channel-properties/): `sndTimeoutMs`, `rcvTimeoutMs` and the other + properties. +- [Tune shared memory](/shmem/tuning/): segment size and allocation. diff --git a/docs/src/content/docs/guides/fairmq-tidy.mdx b/docs/src/content/docs/guides/fairmq-tidy.mdx new file mode 100644 index 00000000..4605d722 --- /dev/null +++ b/docs/src/content/docs/guides/fairmq-tidy.mdx @@ -0,0 +1,207 @@ +--- +title: 'Check code with fairmq-tidy' +description: 'Find the deprecated FairMQ* type names in your project with fairmq-tidy, fix them, and run the check at each build and in CI.' +sidebar: + order: 11 +code: [fairmq/tidy/ModernizeNonNamespacedTypes.h, fairmq/tidy/Tool.h] +--- + +import { Steps } from '@astrojs/starlight/components'; + +This guide runs `fairmq-tidy` on a CMake project that uses FairMQ. The result is a list of all places that use a deprecated `FairMQ*` type name. A CMake target then checks the code at each build. The reference of the tool is on [fairmq-tidy](/tools/fairmq-tidy/). + +## Before you start + +- You need a FairMQ installation with the tool. Build FairMQ with `-DBUILD_TIDY_TOOL=ON`, see [Build fairmq-tidy](/tools/fairmq-tidy/#build-fairmq-tidy). +- Your project must use the Makefile or the Ninja generator of CMake. The other generators do not write a compilation database. + +Make sure that the tool runs: + +```sh +fairmq-tidy --help +``` + +## Make a compilation database + +The tool reads the compile command of each file, with the include paths and flags, from the file `compile_commands.json`. + + + +1. Configure your project with `CMAKE_EXPORT_COMPILE_COMMANDS`: + + ```sh + cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + ``` + +2. Make sure that the file `build/compile_commands.json` exists. + + + +The database has an entry for each source file. A header file has no entry. The tool checks a header when it checks a source file that includes the header. + +## Run the check + + + +1. Go to the source directory of your project. The tool finds a relative file name from the current directory. + +2. Check one file: + + ```sh + fairmq-tidy -p build src/mydevice.cxx + ``` + +3. Check all source files. Give several file names: + + ```sh + fairmq-tidy -p build src/*.cxx + ``` + + With more than one file, the tool prints a line before each file. An example is `[1/3] Processing file /home/me/myproject/src/mydevice.cxx.` + +4. Write the output to a file. The tool writes to the standard error stream: + + ```sh + fairmq-tidy -p build src/*.cxx 2> tidy.log + ``` + + + +## Read the output + +Each finding has a warning line, the source line with a marker under the old name, and a fix-it hint with the new name: + +```txt +/home/me/myproject/src/mydevice.cxx:3:25: warning: Modernize non-namespaced type 'FairMQDevice' with 'fair::mq::Device'. [fairmq-modernize-nonnamespaced-types] + 3 | class MyDevice : public FairMQDevice + | ^~~~~~~~~~~~ + | fair::mq::Device +/home/me/myproject/src/mydevice.cxx:5:21: warning: Modernize non-namespaced type 'FairMQMessagePtr' with 'fair::mq::MessagePtr' (aka 'unique_ptr'). [fairmq-modernize-nonnamespaced-types] + 5 | bool HandleData(FairMQMessagePtr& msg, int); + | ^~~~~~~~~~~~~~~~ + | fair::mq::MessagePtr +``` + +- `/home/me/myproject/src/mydevice.cxx:3:25` is the file, the line and the column of the old name. The file name is the name in the compilation database. CMake writes absolute paths. +- `'FairMQDevice'` is the old name. `'fair::mq::Device'` is the new name. For some names, `(aka …)` shows the full type. +- `[fairmq-modernize-nonnamespaced-types]` is the name of the check. Use it to search the log. +- With Clang 18, most findings appear two times at the same location. The example shows one copy. Fix each finding one time. +- After each file, the tool prints the number of warnings, for example `4 warnings generated.` This number includes the second copies. +- A finding in a header appears for each source file that includes the header. + +A finding in `runFairMQDevice.h` of FairMQ means that your code includes this old header. Do not change the FairMQ header. Move your code to `runDevice.h`, see [Replace runFairMQDevice.h](/guides/migrate-names/#replace-runfairmqdeviceh). + +The tool does not find all old names. For example, it does not find `fairmq_free_fn`, `InputMsgCallback` and the old headers. See [Names that the check does not find](/tools/fairmq-tidy/#names-that-the-check-does-not-find). + +## Apply the fixes + +`fairmq-tidy` does not change your files. Do these steps for each finding: + + + +1. Open the file at the line and the column of the warning. + +2. Replace the old name with the text of the fix-it hint, for example `FairMQDevice` with `fair::mq::Device`. + +3. Replace the old `#include` lines. Use the table [Headers](/guides/migrate-names/#headers). + +4. Run `fairmq-tidy` again. Continue until it prints no warning. + +5. Build your project with `-Werror=deprecated-declarations`. The compiler then stops at the old names that the tool does not find. + + + +To get a list of all fixes, add the Clang option `-fdiagnostics-parseable-fixits`: + +```sh +fairmq-tidy -p build --extra-arg=-fdiagnostics-parseable-fixits src/*.cxx 2>&1 | grep '^fix-it:' | sort -u +``` + +```txt +fix-it:"/home/me/myproject/src/mydevice.cxx":{3:25-3:37}:"fair::mq::Device" +fix-it:"/home/me/myproject/src/mydevice.cxx":{5:21-5:37}:"fair::mq::MessagePtr" +``` + +Each line gives the file, the range of the old name (`line:column-line:column`) and the new text. `sort -u` removes the second copy of each finding. + +## Check the code at each build + +The CMake module `FairMQTidy.cmake` adds the check to a target. The build then runs the tool after it builds the target. The check includes only the source files of the target that end in `.cpp` or `.cxx`. + + + +1. Find FairMQ with the component `tidy_tool`. CMake stops if FairMQ has no `fairmq-tidy`: + + ```cmake + find_package(FairMQ REQUIRED COMPONENTS tidy_tool) + ``` + +2. Turn on the compilation database. Do this before you add the targets: + + ```cmake + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + ``` + +3. Include the module and call `fairmq_target_tidy()` for each target: + + ```cmake + include(FairMQTidy) + + add_executable(mydevice src/mydevice.cxx) + target_link_libraries(mydevice PRIVATE FairMQ::FairMQ) + fairmq_target_tidy(TARGET mydevice) + ``` + +4. Build the project: + + ```sh + cmake --build build + ``` + + + +For each source file, the build prints a line like this one and then the findings: + +```txt +fairmq-tidy: Analyzing source file 'src/mydevice.cxx' of target 'mydevice' +``` + +To build one target and run its check, build the target `fairmq-tidy-`: + +```sh +cmake --build build --target fairmq-tidy-mydevice +``` + +The build runs the check again each time the target changes. Findings do not stop the build. If the tool fails on a file, the build fails. + +## Fail a CI job on findings + +The exit code of `fairmq-tidy` is `0` also when it finds old names. To fail a CI job on findings, search the build log for the name of the check: + +```sh +set -eo pipefail +cmake --build build 2>&1 | tee build.log +if grep -q "fairmq-modernize-nonnamespaced-types" build.log; then + echo "fairmq-tidy found deprecated FairMQ names" + exit 1 +fi +``` + +`set -eo pipefail` stops the script with the exit code of `cmake --build`, so that a failed build also fails the job. + +## Problems that can occur + +| Message | Cause | Solution | +| --- | --- | --- | +| `CMAKE_EXPORT_COMPILE_COMMANDS is not enabled. Skipping.` | The variable is off when `fairmq_target_tidy()` runs. | Set `CMAKE_EXPORT_COMPILE_COMMANDS` to `ON` before the call. | +| `Skipping . Compile command not found.` (exit code 2) | The file has no entry in the compilation database. | Check the `-p` directory. Give source files of the project, not headers. | +| `error: no such file or directory: '-Wno-everything'` | The compilation database has no entry for the file, for example a header. Clang 18 takes the compile command of a similar file. The tool checks the file, but it also shows the compiler warnings. | Give the source files that the database lists. | +| `fatal error: '
    ' file not found`, then `Error while processing .` (exit code 1) | Clang does not find a header. | Add the include path with `--extra-arg=-I`. For the headers of Clang itself, add `--extra-arg-before=-I$(clang -print-resource-dir)/include`. | +| `Error while trying to load a compilation database` and `Running without flags.` | The tool did not find `compile_commands.json`. | Give the build directory with `-p`. | +| `no such file or directory: '…$<1:…'` in the CMake build | `fairmq_target_tidy()` breaks the command line when its list of extra arguments has two or more items. With GCC, the function always adds one item. | Do not use `EXTRA_ARGS` with GCC. With other compilers, give at most one argument. See [The CMake function](/tools/fairmq-tidy/#the-cmake-function-fairmq_target_tidy). | + +## Related pages + +- [fairmq-tidy](/tools/fairmq-tidy/): the check, the command line, the exit codes and the CMake function. +- [Move from the FairMQ* names](/guides/migrate-names/): all old names and their replacements. +- [Use FairMQ in a CMake project](/start/cmake/): `find_package(FairMQ)` and the targets. diff --git a/docs/src/content/docs/guides/migrate-names.mdx b/docs/src/content/docs/guides/migrate-names.mdx new file mode 100644 index 00000000..45bfffdc --- /dev/null +++ b/docs/src/content/docs/guides/migrate-names.mdx @@ -0,0 +1,195 @@ +--- +title: 'Move from the FairMQ* names' +description: 'Replace the deprecated FairMQ* headers, type names and members with the fair::mq names. The complete list of old names and their replacements.' +sidebar: + order: 12 +code: [fairmq/FwdDecls.h, fairmq/Device.h, fairmq/Message.h, fairmq/UnmanagedRegion.h, fairmq/runFairMQDevice.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps, Tabs, TabItem } from '@astrojs/starlight/components'; + +The API of FairMQ is in the namespace `fair::mq`, and its headers are in the directory `fairmq/`. The old global names like `FairMQDevice` and the old headers like `` still compile, but the compiler warns. This guide moves your code to the new names and lists each old name with its replacement. + +## Before and after + +```cpp title="mydevice.cxx (old)" +#include + +class MyDevice : public FairMQDevice +{ + bool HandleData(FairMQMessagePtr& msg, int); +}; +``` + +```cpp title="mydevice.cxx (new)" +#include + +class MyDevice : public fair::mq::Device +{ + bool HandleData(fair::mq::MessagePtr& msg, int); +}; +``` + +## Move your code + + + +1. Replace the old `#include` lines. Use the table [Headers](#headers). + +2. Replace the old type names. Use the table [Type names](#type-names). [fairmq-tidy](/guides/fairmq-tidy/) finds most of them for you. + +3. If your `main()` comes from `runFairMQDevice.h`, move to `runDevice.h`. See [Replace runFairMQDevice.h](#replace-runfairmqdeviceh). + +4. Replace the deprecated functions and members. Use the table [Functions and members](#functions-and-members). + +5. Build with `-Werror=deprecated-declarations`. The compiler then stops at each remaining use of a deprecated name: + + ```sh + cmake -S . -B build -DCMAKE_CXX_FLAGS="-Werror=deprecated-declarations" + cmake --build build + ``` + + + +## How the compiler warns + +An old header contains a `#pragma GCC warning`. An old type name or member has the attribute `[[deprecated("…")]]`, and the compiler prints the text of the attribute. For the old code above, GCC and Clang print these warnings (the paths are shorter here): + + + + +```txt +FairMQDevice.h:13:21: warning: Deprecated header: Use instead +mydevice.cxx:5:47: warning: 'using FairMQMessagePtr = using fair::mq::MessagePtr = class std::unique_ptr' is deprecated: Use fair::mq::MessagePtr [-Wdeprecated-declarations] +``` + + + + +```txt +FairMQDevice.h:13:13: warning: Deprecated header: Use instead [-W#pragma-messages] +mydevice.cxx:3:25: warning: 'FairMQDevice' is deprecated: Use fair::mq::Device [-Wdeprecated-declarations] +mydevice.cxx:5:21: warning: 'FairMQMessagePtr' is deprecated: Use fair::mq::MessagePtr [-Wdeprecated-declarations] +``` + + + + +The compiler does not show all uses: + +- GCC 13 does not warn for a deprecated alias in a list of base classes, for example `class MyDevice : public FairMQDevice`. Clang and fairmq-tidy find it. +- [``](/source/fairmq/FwdDecls.h/#L29-L43) declares twelve of the old names again, without the attribute. A file that includes only this header gets no warning for these names. +- An old header warns only if the file did not include the new header before. `FairMQLogger.h` always warns. `runFairMQDevice.h` does not warn. +- `FairMQDevicePtr` of `runFairMQDevice.h` has no attribute. + +## Headers + +Each old header includes the new header, so the old `#include` lines still work. The include directories of an installed `FairMQ::FairMQ` are `include` and `include/fairmq`, so the old headers also work with the prefix `fairmq/`, for example ``. + +| Old header | New header | Warning | +| --- | --- | --- | +| [``](/source/fairmq/FairMQChannel.h/) | `` | yes | +| [``](/source/fairmq/FairMQDevice.h/) | `` | yes | +| [``](/source/fairmq/FairMQLogger.h/) | `` (FairLogger) | yes, always | +| [``](/source/fairmq/FairMQMessage.h/) | `` | yes | +| [``](/source/fairmq/FairMQParts.h/) | `` | yes | +| [``](/source/fairmq/FairMQPoller.h/) | `` | yes | +| [``](/source/fairmq/FairMQSocket.h/) | `` | yes | +| [``](/source/fairmq/FairMQTransportFactory.h/) | `` | yes | +| [``](/source/fairmq/FairMQUnmanagedRegion.h/) | `` | yes | +| [``](/source/fairmq/options/FairMQProgOptions.h/) | `` | yes | +| [``](/source/fairmq/runFairMQDevice.h/) | `` | no | + +## Type names + +The table is in the order of the headers that declare the deprecated alias. The column fairmq-tidy shows if [the check](/tools/fairmq-tidy/#names-that-the-check-finds) finds the name (with Clang 18). + +| Old name | New name | Declared in | fairmq-tidy | +| --- | --- | --- | --- | +| `FairMQChannel` | [`fair::mq::Channel`](/api/fair/mq/Channel/) | `Channel.h` | yes | +| `FairMQChannelMap` | [`fair::mq::ChannelMap`](/api/fair/mq/#ChannelMap) | `Device.h` | yes | +| `InputMsgCallback` | [`fair::mq::InputMsgCallback`](/api/fair/mq/#InputMsgCallback) | `Device.h` | no | +| `InputMultipartCallback` | [`fair::mq::InputMultipartCallback`](/api/fair/mq/#InputMultipartCallback) | `Device.h` | no | +| `FairMQDevice` | [`fair::mq::Device`](/api/fair/mq/Device/) | `Device.h` | yes | +| `fair::mq::FairMQMemoryResource` | [`fair::mq::MemoryResource`](/api/fair/mq/MemoryResource/) | `MemoryResources.h` | no | +| `fairmq_free_fn` | [`fair::mq::FreeFn`](/api/fair/mq/#FreeFn) | `Message.h` | no | +| `FairMQMessage` | [`fair::mq::Message`](/api/fair/mq/Message/) | `Message.h` | yes | +| `FairMQMessagePtr` | [`fair::mq::MessagePtr`](/api/fair/mq/#MessagePtr) | `Message.h` | yes | +| `FairMQParts` | [`fair::mq::Parts`](/api/fair/mq/Parts/) | `Parts.h` | yes | +| `FairMQPoller` | [`fair::mq::Poller`](/api/fair/mq/Poller/) | `Poller.h` | yes | +| `FairMQPollerPtr` | [`fair::mq::PollerPtr`](/api/fair/mq/#PollerPtr) | `Poller.h` | yes | +| `FairMQProgOptions` | [`fair::mq::ProgOptions`](/api/fair/mq/ProgOptions/) | `ProgOptionsFwd.h` | yes | +| `FairMQSocket` | [`fair::mq::Socket`](/api/fair/mq/Socket/) | `Socket.h` | yes | +| `FairMQSocketPtr` | [`fair::mq::SocketPtr`](/api/fair/mq/#SocketPtr) | `Socket.h` | yes | +| `FairMQTransportFactory` | [`fair::mq::TransportFactory`](/api/fair/mq/TransportFactory/) | `TransportFactory.h` | yes | +| `FairMQTransportFactoryError` | [`fair::mq::TransportFactoryError`](/api/fair/mq/TransportFactoryError/) | `TransportFactory.h` | yes | +| `FairMQRegionEvent` | [`fair::mq::RegionEvent`](/api/fair/mq/RegionEvent/) | `UnmanagedRegion.h` | yes | +| `FairMQRegionInfo` | [`fair::mq::RegionInfo`](/api/fair/mq/RegionInfo/) | `UnmanagedRegion.h` | yes | +| `FairMQRegionBlock` | [`fair::mq::RegionBlock`](/api/fair/mq/RegionBlock/) | `UnmanagedRegion.h` | yes | +| `FairMQRegionCallback` | [`fair::mq::RegionCallback`](/api/fair/mq/#RegionCallback) | `UnmanagedRegion.h` | yes | +| `FairMQRegionBulkCallback` | [`fair::mq::RegionBulkCallback`](/api/fair/mq/#RegionBulkCallback) | `UnmanagedRegion.h` | yes | +| `FairMQRegionEventCallback` | [`fair::mq::RegionEventCallback`](/api/fair/mq/#RegionEventCallback) | `UnmanagedRegion.h` | yes | +| `FairMQUnmanagedRegion` | [`fair::mq::UnmanagedRegion`](/api/fair/mq/UnmanagedRegion/) | `UnmanagedRegion.h` | yes | +| `FairMQUnmanagedRegionPtr` | [`fair::mq::UnmanagedRegionPtr`](/api/fair/mq/#UnmanagedRegionPtr) | `UnmanagedRegion.h` | yes | +| `FairMQRegionConfig` | [`fair::mq::RegionConfig`](/api/fair/mq/RegionConfig/) | `UnmanagedRegion.h` | yes | +| `FairMQDevicePtr` | `std::unique_ptr` as the return type of `getDevice()` | `runFairMQDevice.h` | yes, as `fair::mq::Device *` | + +All old names are global, except `fair::mq::FairMQMemoryResource`. All names in the table except `FairMQDevicePtr` have the attribute `[[deprecated]]`. + +## Replace runFairMQDevice.h + +[`runFairMQDevice.h`](/source/fairmq/runFairMQDevice.h/) and [`runDevice.h`](/source/fairmq/runDevice.h/) both contain a `main()` function. Your code gives the two functions `getDevice()` and `addCustomOptions()`. The signature of `getDevice()` is different: + +| Header | Declaration of `getDevice()` | +| --- | --- | +| `runFairMQDevice.h` | `FairMQDevicePtr getDevice(const fair::mq::ProgOptions& config);` with `FairMQDevicePtr` = `fair::mq::Device*` | +| `runDevice.h` | `std::unique_ptr getDevice(fair::mq::ProgOptions& config);` | + +`addCustomOptions(boost::program_options::options_description&)` is the same in both headers. + +```cpp title="Old code" +#include + +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) +{ + return new MyDevice(); +} +``` + +The new code returns a `std::unique_ptr`, and the parameter is not `const`. The example 1-1 uses the new header: + + + + + +## Functions and members + +The compiler warns for these members too. The column "Declared in" names the header in `fairmq/`. + +| Old | New | Declared in | +| --- | --- | --- | +| [`Device::fChannels`](/api/fair/mq/Device/#fChannels) | [`GetChannels()`](/api/fair/mq/Device/#GetChannels) | `Device.h` | +| [`Device::GetStateName(state)`](/api/fair/mq/Device/#GetStateName) | [`fair::mq::GetStateName(state)`](/api/fair/mq/#GetStateName) of `` | `Device.h` | +| [`Device::GetTransitionName(transition)`](/api/fair/mq/Device/#GetTransitionName) | [`fair::mq::GetTransitionName(transition)`](/api/fair/mq/#GetTransitionName) of `` | `Device.h` | +| [`Device::Serialize(msg, data, args...)`](/api/fair/mq/Device/#Serialize) | `S().Serialize(msg, data, args...)` | `Device.h` | +| [`Device::Deserialize(msg, data, args...)`](/api/fair/mq/Device/#Deserialize) | `D().Deserialize(msg, data, args...)` | `Device.h` | +| [`Parts::AddPart(Message* msg)`](/api/fair/mq/Parts/#AddPart) | [`Parts::AddPart(MessagePtr msg)`](/api/fair/mq/Parts/#AddPart-2) | `Parts.h` | +| [`Parts::AtRef(index)`](/api/fair/mq/Parts/#AtRef) | `*(parts.At(index))` with [`At()`](/api/fair/mq/Parts/#At) | `Parts.h` | +| [`Socket::Close()`](/api/fair/mq/Socket/#Close) | Destroy the socket. Its destructor closes it. | `Socket.h` | +| [`shmem::Socket::GetConstant()`](/api/fair/mq/shmem/Socket/#GetConstant) and `zmq::Socket::GetConstant()` | `fair::mq::zmq::getConstant()` of `` | `shmem/Socket.h`, `zeromq/Socket.h` | + +## CMake names + +The CMake package is `FairMQ`. Link your targets with `FairMQ::FairMQ`. The executables of FairMQ are imported targets with the same prefix, for example `FairMQ::fairmq-bsampler`. See [Use FairMQ in a CMake project](/start/cmake/). + +## Automate the search with fairmq-tidy + +`fairmq-tidy` finds the uses of most old type names and shows the new name for each one. It does not look at the `#include` lines and the members, and it does not change your files. See [Check code with fairmq-tidy](/guides/fairmq-tidy/). + +## Related pages + +- [Check code with fairmq-tidy](/guides/fairmq-tidy/): find the old type names in a project. +- [fairmq-tidy](/tools/fairmq-tidy/): the check, the command line and the CMake function. +- [Your first device](/start/first-device/): a device with the current API. +- [Use FairMQ in a CMake project](/start/cmake/): the package and its targets. diff --git a/docs/src/content/docs/guides/pmr.mdx b/docs/src/content/docs/guides/pmr.mdx new file mode 100644 index 00000000..7de70d84 --- /dev/null +++ b/docs/src/content/docs/guides/pmr.mdx @@ -0,0 +1,173 @@ +--- +title: 'Use std::pmr memory resources' +description: 'Fill a container in the message memory of a transport with a std::pmr allocator, and send it as a message without a copy.' +sidebar: + order: 5 +code: [fairmq/MemoryResources.h, fairmq/MemoryResources.cxx, fairmq/MemoryResourceTools.h, fairmq/TransportFactory.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +Each transport factory has a memory resource of the C++17 type `std::pmr::memory_resource`. A +container that allocates from this resource keeps its data in a message buffer of the transport. +[`fair::mq::getMessage()`](/api/fair/mq/#getMessage) then makes a message from the container +without a copy, and you send it as a normal message. + +## The names in FairMQ + +[`MemoryResources.h`](/source/fairmq/MemoryResources.h/) declares `namespace pmr = std::pmr;` in +`fair::mq`. Thus `fair::mq::pmr::polymorphic_allocator` is `std::pmr::polymorphic_allocator`, +and `fair::mq::pmr::vector` is `std::pmr::vector`. Before v1.10.0, `fair::mq::pmr` was +`boost::container::pmr`. Code that uses `boost::container::pmr` types with the FairMQ resources does +not compile with v1.10.0 and later. Use the `std::pmr` types. + +| Name | Header | What it is | +| --- | --- | --- | +| [`fair::mq::MemoryResource`](/api/fair/mq/MemoryResource/) | `MemoryResources.h` | Interface. A `pmr::memory_resource` that can give the message of a buffer. | +| [`fair::mq::ChannelResource`](/api/fair/mq/ChannelResource/) | `MemoryResources.h` | The memory resource of a transport factory. Each allocation is one message of this transport. | +| [`FairMQMemoryResource`](/api/fair/mq/#FairMQMemoryResource) | `MemoryResources.h` | Deprecated name of `fair::mq::MemoryResource`. | +| [`fair::mq::BytePmrAllocator`](/api/fair/mq/#BytePmrAllocator) | `MemoryResourceTools.h` | `pmr::polymorphic_allocator`, where [`fair::mq::byte`](/api/fair/mq/#byte) is `unsigned char`. | +| [`fair::mq::getMessage()`](/api/fair/mq/#getMessage) | `MemoryResourceTools.h` | Makes a message from a container. | + +`TransportFactory.h` includes `MemoryResources.h`. For `getMessage()` and `BytePmrAllocator`, +include ``. For the deprecated names, see +[Move from the FairMQ\* names](/guides/migrate-names/). + +## The memory resource of a transport + +[`TransportFactory::GetMemoryResource()`](/api/fair/mq/TransportFactory/#GetMemoryResource) returns +a pointer to the `ChannelResource` of the factory. Each factory has its own resource, and each call +returns the same pointer. The test `MemoryResources.transportAllocatorMap` checks this: + + + +The [conversion operator](/api/fair/mq/TransportFactory/#operator-ChannelResource2a) of the factory +gives the same pointer. Thus a factory reference can replace the pointer, for example in +`getMessage(std::move(v), *factory)`. + +In a device, `Transport()->GetMemoryResource()` returns the resource of the default transport. For +the transport of one channel, use `GetChannel("data").Transport()->GetMemoryResource()`. + +The `ChannelResource` gives each allocation to the transport +([MemoryResources.cxx](/source/fairmq/MemoryResources.cxx/#L18-L21)): + +- An allocation of `n` bytes makes a message of `n` bytes with the requested alignment. The + resource keeps the message, with the address of its data as the key. +- A deallocation destroys the message of this address. +- Two resources are equal only if they are the same object. +- [`getNumberOfMessages()`](/api/fair/mq/ChannelResource/#getNumberOfMessages) returns the number of + messages that the resource keeps. + +## Send a container without a copy + + + +1. Include ``. + +2. Get the memory resource of the transport of the channel that sends the data. With the resource + of another transport, `Send()` converts the message. See + [Send a message of another transport](/guides/several-transports/#send-a-message-of-another-transport). + +3. Make a container with a pmr allocator on this resource, for example a `fair::mq::pmr::vector`. + +4. Reserve the full size with `reserve()` before you add the elements. + +5. Add the elements. + +6. Call `getMessage(std::move(container))`. Do not use the container after this call. + +7. Send the message. + + + +The test `PmrMessage.FromContainerWithoutCopy` does these steps for each transport. Then it sends +the message on a channel and receives it: + + + +After `getMessage()`, the message has the address of the container data. For one exception of the +shmem transport, see the unused capacity in [Limits](#limits). The size of the message is `size()` +multiplied by the size of one element, and the resource keeps no message. + +In a device, the same steps look like this: + +```cpp +#include +#include + +#include +#include + +struct Sampler : fair::mq::Device +{ + bool ConditionalRun() override + { + auto* resource = GetChannel("data").Transport()->GetMemoryResource(); + + fair::mq::pmr::vector values(resource); + values.reserve(1000); + for (int i = 0; i < 1000; ++i) { + values.push_back(0.5f * i); + } + + fair::mq::MessagePtr msg(fair::mq::getMessage(std::move(values))); + return Send(msg, "data") >= 0; + } +}; +``` + +## What `getMessage()` does + +`getMessage(container, target)` moves the container into the function, and finds the resource of +its allocator ([MemoryResourceTools.h](/source/fairmq/MemoryResourceTools.h/#L25-L63)). Give the +container as an rvalue, for example `std::move(v)`. A call with an lvalue does not compile, because +the function uses `ContainerT::value_type` and `ContainerT` is then a reference type. The +optional `target` is a `fair::mq::MemoryResource*`. The result depends on the two resources: + +| Resource of the container | `target` | Result | +| --- | --- | --- | +| A FairMQ resource | none, or the same resource | No copy. The message of the container buffer, with the size of the elements in the container. | +| A FairMQ resource | another FairMQ resource | A new message of the target transport with a copy of the data. The container frees its buffer. | +| Another `std::pmr` resource | a FairMQ resource | A new message of the target transport with a copy of the data. | +| Another `std::pmr` resource | none | Throws `std::runtime_error` with `Neither the container or target resource specified`. | + +If the resource has no message for the container data, `getMessage()` copies the data into a new +message. This occurs for a container without a buffer. Examples are an empty vector without `reserve()`, and +a short `std::pmr::string` that keeps its characters in the string object. + +The test `MemoryResources.getMessage` shows both results. The first message has the address of the +vector data. The second message, with the shmem factory as target, has a new address: + + + +## Limits + +- **Allocator.** The container must use a `pmr::polymorphic_allocator`, because `getMessage()` + calls `get_allocator().resource()`. +- **Contiguous data.** `getMessage()` uses `data()` and `size()` of the container. The buffer must + start at `data()`, as in `std::vector`. +- **Element type.** Use types that you can copy as bytes, for example numbers and structs of + numbers. `getMessage()` destroys the container, and with it the elements. The message keeps their + bytes. A receiver in another process also gets only the bytes. +- **Growth.** Each allocation makes a message. If the vector grows past its capacity, it allocates + a new message, copies the elements, and destroys the old message. Use `reserve()`. +- **Unused capacity.** `getMessage()` makes the message smaller with + [`SetUsedSize()`](/api/fair/mq/Message/#SetUsedSize). The zeromq transport keeps the unused memory + until it destroys the message. The shmem transport tries to give the unused memory back to the + segment. If this fails, it keeps the memory, or it copies the data into a new buffer if 1000000 + bytes or more are unused. +- **Threads.** `ChannelResource` has no lock. All channels of one transport in a device share one + resource. Allocate and call `getMessage()` from one thread at a time. +- **Lifetime.** The resource is a member of the transport factory. Destroy the containers before the + factory. A device destroys its factories in the state `RESETTING DEVICE`. +- **Receive.** `getMessage()` is for the sender only. A received message is a normal message: read + it with `GetData()` and `GetSize()`. + +## Related pages + +- [Messages and multipart](/concepts/messages/): how to make, send and receive messages. +- [Transports](/concepts/transports/): the transport factories that own the memory resources. +- [How shared memory works](/shmem/how-it-works/): where the shmem transport keeps the message data. +- [Use channels without a device](/guides/channels-without-device/): the channels of the tests in this guide. +- [Send your own data types](/guides/send-data-types/): structs, arrays and serialized objects in messages. diff --git a/docs/src/content/docs/guides/poll-channels.mdx b/docs/src/content/docs/guides/poll-channels.mdx new file mode 100644 index 00000000..bdc4a0b7 --- /dev/null +++ b/docs/src/content/docs/guides/poll-channels.mdx @@ -0,0 +1,187 @@ +--- +title: 'Poll several channels' +description: 'Wait with a poller until one of several channels can receive or send a message, and then serve the channels that are ready.' +sidebar: + order: 4 +code: [fairmq/Poller.h, fairmq/Device.h, fairmq/TransportFactory.h, fairmq/zeromq/Poller.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +A poller waits until at least one of several channels can receive or send a message. With a poller, +one thread of your device serves several channels in `Run()`. It receives where a message waits, +and it sends where a peer can take a message. + +If your device only receives, register data callbacks with [`OnData()`](/api/fair/mq/Device/#OnData) +instead. Then the device polls the channels itself. See +[Receive data with callbacks or loops](/guides/receive-data/). + +## Poll channels in `Run()` + + + +1. In `Run()`, make the poller with [`NewPoller()`](/api/fair/mq/Device/#NewPoller) and the names + of the channels. Make it once, before the loop. + +2. In a loop, call [`Poll(timeout)`](/api/fair/mq/Poller/#Poll). The timeout is in milliseconds, for + example 100 ms. + +3. After each `Poll()`, call [`CheckInput()`](/api/fair/mq/Poller/#CheckInput-2) for each channel + that receives. Call [`CheckOutput()`](/api/fair/mq/Poller/#CheckOutput-2) for each channel that + sends. + +4. If a check returns `true`, call `Receive()` or `Send()` on this sub-channel. + +5. Stop the loop when [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) returns `true`. + + + +The sampler of the [multiple-channels example](/examples/multiple-channels/) sends on the channel +`data` and receives on the channel `broadcast` in one loop: + + + +`data` is a `push` socket, and `broadcast` is a `sub` socket. The start script gives the sampler +these channels: + + + +The example uses the zeromq transport only, because shmem has no `pub` and `sub` sockets. The +sampler logs `Received broadcast: "OK"` for each message of the broadcaster, and `Sent "Hello"` for +each message on `data`. + +## Make a poller + +The device has two functions. Both return a [`fair::mq::PollerPtr`](/api/fair/mq/#PollerPtr), which +is a `std::unique_ptr`. + +| Function | The poller polls | Check a channel with | +| --- | --- | --- | +| [`NewPoller("data", "broadcast")`](/api/fair/mq/Device/#NewPoller) | All sub-channels of the named channels. | `CheckInput("data", index)`, with the sub-channel index. | +| [`NewPoller(channels)`](/api/fair/mq/Device/#NewPoller-2), with a `std::vector` | The sub-channels in the vector. | `CheckInput(i)`, with the position `i` in the vector. | + +`CheckOutput()` takes the same arguments as `CheckInput()`. The poller of `NewPoller(channels)` has +no channel names. On this poller, `CheckInput("data", 0)` throws +[`fair::mq::PollerError`](/api/fair/mq/PollerError/). + +The poller of `NewPoller("data", "broadcast")` also accepts a position. It keeps the sub-channels in +the order of the names, and in each channel in the order of the index. With one +sub-channel in each channel, `CheckInput(0)` checks `data[0]` and `CheckInput(1)` checks +`broadcast[0]`. + +The built-in merger device polls all sub-channels of its input channel with a vector: + + + +`NewPoller(fInChannelName)` polls the same sub-channels. Then check them with +`CheckInput(fInChannelName, i)`. + +Make the poller in `InitTask()`, `PreRun()` or `Run()`. Before the states `BINDING` and +`CONNECTING`, the channels have no sockets. The poller keeps the zeromq sockets of the channels. If +you keep the poller as a member of your device, destroy it in `ResetTask()`. + +### The functions of the transport factory + +`NewPoller()` calls a function of the [transport factory](/api/fair/mq/TransportFactory/) of the +channels. You can call these functions directly, for example +[without a device](/guides/channels-without-device/): + +| Function | The poller polls | Check a channel with | +| --- | --- | --- | +| [`CreatePoller(subChannels)`](/api/fair/mq/TransportFactory/#CreatePoller), with a `std::vector` | The sub-channels of one channel, for example `GetChannels().at("data")`. | `CheckInput(index)`, with the sub-channel index. | +| [`CreatePoller(channels)`](/api/fair/mq/TransportFactory/#CreatePoller-2), with a `std::vector` | The sub-channels in the vector. | `CheckInput(i)`, with the position `i`. | +| [`CreatePoller(channelMap, names)`](/api/fair/mq/TransportFactory/#CreatePoller-3) | All sub-channels of the named channels in the map. | `CheckInput(name, index)` or `CheckInput(i)`. | + +An unknown name in `CreatePoller(channelMap, names)` throws `PollerError`. These functions do not +compare the transports of the channels. Give them only channels of the transport of this factory. + +## What the poller checks + +The socket type of each sub-channel selects the events that the poller waits for +([zeromq/Poller.h](/source/fairmq/zeromq/Poller.h/#L111-L123)): + +| Socket type | The poller waits until | `CheckInput()` | `CheckOutput()` | +| --- | --- | --- | --- | +| `pull`, `sub`, `xsub` | a message arrived | `true` or `false` | always `false` | +| `push`, `pub`, `xpub` | the socket can send | always `false` | `true` or `false` | +| `req`, `rep`, `pair`, `dealer`, `router` | a message arrived, or the socket can send | `true` or `false` | `true` or `false` | + +`CheckInput()` returns `true` if `zmq_poll()` set the event `ZMQ_POLLIN` for the socket, and +`CheckOutput()` returns `true` for `ZMQ_POLLOUT`. In ZeroMQ, `ZMQ_POLLIN` means that at least one +message waits, and `ZMQ_POLLOUT` means that the socket can take at least one message without a wait. +Both functions give the result of the last `Poll()`. The shmem transport polls the sockets that carry the metadata of its messages, +with the same rules. + +:::caution[Sockets in both directions] +For the types `req`, `rep`, `pair`, `dealer` and `router`, the poller also waits for output. +ZeroMQ sets `ZMQ_POLLOUT` while one of these sockets can send. Then `Poll()` returns at once, also if +no message arrived. A loop +that does not send on such a socket then does not wait in `Poll()`, and it uses the CPU all the +time. +::: + +The poller does not check the index. For a position outside the poller, or for a sub-channel index +that the channel does not have, `CheckInput()` and `CheckOutput()` read the item of another +sub-channel or memory outside the poller. The result is undefined. + +## Select the timeout + +`Poll(timeout)` waits until a socket is ready or the timeout ends. The poller gives the timeout in +milliseconds to `zmq_poll()` without a change. In ZeroMQ, the values have this effect: + +- `0` returns at once. +- `-1` waits until a socket is ready. +- A positive value waits for this number of milliseconds at most. + +`Poll()` returns no value. Check the channels after each call. + +A transition request does not stop `Poll()`. On a request, the device calls `Interrupt()` on its +transports, and this stops only `Send()` and `Receive()`. Thus use a timeout of about 100 ms, and +check `NewStatePending()` after each `Poll()`. The device uses 200 ms for its own poller of the data +callbacks, and 500 ms if the callbacks use several transports. + +`Poll()` tries again if a signal interrupts the system call. It returns when the zeromq context +ends. For all other errors, it logs `polling failed, reason: ` and throws `PollerError`. + +## Use one transport for each poller + +All channels of one poller must use the same transport. Both `NewPoller()` functions compare the +transports before they make the poller ([Device.h](/source/fairmq/Device.h/#L218-L257)). For the +channel names, they compare the sub-channel 0 of each channel. If the transports are different, +they log an error and throw `std::runtime_error`. If your `Run()` does not catch the exception, the +device goes to the state `ERROR`. + +For channels of two transports, use one thread and one poller for each transport. Or register data +callbacks with `OnData()`: then the device makes one thread for each transport. See +[Receive from channels of different transports](/guides/several-transports/#receive-from-channels-of-different-transports). + +## Check the result + +The poller tests in [`test/poller/_poller.cxx`](https://github.com/FairRootGroup/FairMQ/blob/dev/test/poller/_poller.cxx) +run two devices for each transport. One device sends one message on each of `data1` and `data2`. +The other device polls the two channels until a message arrived on each. It uses `NewPoller()` with +a vector or with the names: + + + +To test your own loop, send messages on one channel only, and make sure that the device receives +them. Then request the transition `STOP`, and make sure that the device leaves the state `RUNNING` +within your timeout. + +## Problems that can occur + +| Problem | Cause | Fix | +| --- | --- | --- | +| `GetChannel(): '[0]' does not exist.`, then `std::out_of_range` | `NewPoller()` got the name of a channel that the device does not have. | Use the names of the channel configuration. | +| `invalid channel key: ''`, then `PollerError` | `CheckInput(name, index)` on a poller from a vector, or a name that the poller does not have. | Check with the position, or make the poller with the names. | +| `poller failed: different transports within same poller are not yet supported` | The channels of one poller use different transports. | Make one poller for each transport. | +| The device does not stop. | `Poll(-1)`, or a long timeout, waits for a message. | Use a timeout of about 100 ms. Check `NewStatePending()` after each `Poll()`. | +| The loop uses the CPU all the time. | A `req`, `rep`, `pair`, `dealer` or `router` socket can send, and the loop does not send on it. | Poll these sockets only in a loop that also sends on them. To only receive, call `Receive()` with a timeout. | + +## Related pages + +- [Receive data with callbacks or loops](/guides/receive-data/): `OnData()`, `ConditionalRun()` and `Run()`. +- [Channels and sockets](/concepts/channels/): the socket types and their patterns. +- [Use several transports](/guides/several-transports/): channels of zeromq and shmem in one device. +- [Example: multiple channels](/examples/multiple-channels/): the example of this guide, step by step. diff --git a/docs/src/content/docs/guides/receive-data.mdx b/docs/src/content/docs/guides/receive-data.mdx new file mode 100644 index 00000000..f20e1972 --- /dev/null +++ b/docs/src/content/docs/guides/receive-data.mdx @@ -0,0 +1,235 @@ +--- +title: 'Receive data with callbacks or loops' +description: 'Process messages in RUNNING with OnData() callbacks, with ConditionalRun() and the option --rate, or with your own Run() loop.' +sidebar: + order: 1 +code: [fairmq/Device.h, fairmq/Device.cxx, fairmq/tools/RateLimit.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +This guide shows the three ways to do the work of a device in the state `RUNNING`: data callbacks, +`ConditionalRun()` and `Run()`. When you complete it, your device processes messages and leaves +`RUNNING` when its work ends or when a controller requests `Stop`. + +## Choose a way + +| | `OnData()` callbacks | `ConditionalRun()` | `Run()` | +| --- | --- | --- | --- | +| Who receives the messages | The device | Your code | Your code | +| How often the device calls your code | Once for each message | Again and again | Once | +| How your code ends `RUNNING` | The callback returns `false` | The function returns `false` | The function returns | +| What happens on `Stop` | The device does not call the callbacks again | The device does not call the function again | Your loop must check `NewStatePending()` | +| Rate limit | No | The option `--rate` | Your code | +| Typical device | Sink, processor | Sampler, client of a request and reply | Device with a poller or with its own order of transfers | + +Use `OnData()` when your device reacts to messages. Use `ConditionalRun()` when your device creates +data or does a sequence of transfers. Use `Run()` only when you need full control of the loop. + +## Receive with OnData() + + + +1. In the constructor of your device, call [`OnData()`](/api/fair/mq/Device/#OnData) with the name + of the input channel and your callback. + +2. Write the callback. It receives the message and the index of the sub-channel. + +3. Return `true` from the callback to receive the next message. Return `false` to end `RUNNING`. + + + +The processor of the example [1-n-1](/examples/1-n-1/) receives a message on the channel `data1` and +sends a new message on the channel `data2`: + + + +The message belongs to the callback. You can change it, send it, or keep it. + +### Callback forms + +`OnData()` has four overloads. Two take a member function, and two take a `std::function`: + +| Overload | Signature of the callback | Receives | +| --- | --- | --- | +| [`OnData(name, &T::f)`](/api/fair/mq/Device/#OnData) | `bool f(fair::mq::MessagePtr& msg, int index)` | One message | +| [`OnData(name, callback)`](/api/fair/mq/Device/#OnData-2) | [`InputMsgCallback`](/api/fair/mq/#InputMsgCallback) | One message | +| [`OnData(name, &T::f)`](/api/fair/mq/Device/#OnData-3) | `bool f(fair::mq::Parts& parts, int index)` | One multipart message | +| [`OnData(name, callback)`](/api/fair/mq/Device/#OnData-4) | [`InputMultipartCallback`](/api/fair/mq/#InputMultipartCallback) | One multipart message | + +A multipart callback receives all parts of a message that the sender sent as `Parts`. This is the +start of the callback of the sink in the example [multipart](/examples/multipart/). It checks the +number of parts and reads the header from the first part: + + + +A lambda is also a callback. The device of the example [qc](/examples/qc/) leaves `RUNNING` after the +first message: + + + +### Several input channels + +Call `OnData()` once for each input channel. The sink of the example +[multiple-channels](/examples/multiple-channels/) has two callbacks: + + + +The device selects the method from the input channels: + +- **One channel with one sub-channel:** the device calls `Receive()` in a loop, without a poller. +- **More channels or sub-channels, one transport:** the device polls all input channels with a + timeout of 200 ms. Then it calls the callbacks of the channels with data, in the order of the + `OnData()` calls. +- **More than one transport:** the device polls each transport in + [its own thread](/concepts/threads/#the-threads-of-a-device-process), with a timeout of 500 ms. A + mutex makes sure that only one callback runs at a time. + +The index argument tells the callback which sub-channel received the message. + +### Rules for callbacks + +- Register the callbacks before `RUNNING` starts, for example in the constructor. +- Register one callback for each channel. A second `OnData()` of the same form for the same channel + has no effect. +- With callbacks, the device does not call `ConditionalRun()` and `Run()`. It calls `PreRun()` and + `PostRun()`. +- The device checks for a pending transition between two callbacks. A callback that does not return + delays the transition. +- If `Receive()` returns a negative [transfer code](/reference/transfer-codes/), the device does not + call the callback and ends `RUNNING`. + +## Use ConditionalRun() + + + +1. Override [`ConditionalRun()`](/api/fair/mq/Device/#ConditionalRun). Do one step of the work in + each call. + +2. Check the return value of each `Send()` and `Receive()`. Return `false` when it is negative. + +3. Return `true` to get the next call. Return `false` to end `RUNNING`. + +4. To limit the number of calls per second, start the device with the option `--rate`. + + + +The client of the example [req-rep](/examples/req-rep/) sends a request and waits for the reply in +each call: + + + +The device calls `ConditionalRun()` while it returns `true` and no transition is pending. After the +last call, the device calls `Run()` once. + +The option `--rate` gives the maximum rate of the calls in Hz. The default is 0, which means no +limit. The device reads the value in `INITIALIZING DEVICE`. A +[`tools::RateLimiter`](/api/fair/mq/tools/RateLimiter/) measures the time between the calls +and sleeps when the calls come too fast. Values of 0.001 or less give no limit. To limit a loop of +your own, see [RateLimit.h](/reference/tools/#ratelimith). + +```sh +fairmq-ex-1-1-sampler --id sampler1 --rate 10 --channel-config name=data,type=push,method=bind,address=tcp://*:5555 +``` + +## Write a Run() loop + + + +1. Override [`Run()`](/api/fair/mq/Device/#Run). + +2. Write a loop that continues while [`NewStatePending()`](/api/fair/mq/Device/#NewStatePending) + returns `false`. + +3. In the loop, check the return value of each `Send()` and `Receive()`. + +4. For a pause, call [`WaitFor()`](/api/fair/mq/Device/#WaitFor) and not `std::this_thread::sleep_for()`. + A pending transition ends `WaitFor()` at once. + +5. Return from `Run()` to end `RUNNING`. + + + +The sender of the example [n-m](/examples/n-m/) receives an id on the channel `sync` and sends a +multipart message to one of the receivers: + + + +When a controller requests `Stop`, the device interrupts its transports. The waiting `Receive()` +returns `TransferCode::interrupted`. The loop continues, and `NewStatePending()` ends it. + +For a loop that also waits for output channels, see [Poll several channels](/guides/poll-channels/). + +## What the tests show + +The tests in `test/device/_data_callbacks.cxx` check these properties. The `DataCallbacks` tests run +for each transport: + +| Test | Result | +| --- | --- | +| `DataCallbacks.SingleMessage` | The callback receives three messages with the index 0. It returns `false` after the third, and the device goes to `READY`. | +| `DataCallbacks.Multipart` | The multipart callback receives the parts `a` and `bc` in one call. | +| `DataCallbacks.TwoChannels` | A message callback and a multipart callback on two channels receive their messages. | +| `MultipleTransports.OneInputEach` | A zeromq channel and a shmem channel in one device receive their messages. | +| `ConditionalRun.EndsRunWhenItReturnsFalse` | `ConditionalRun()` returns `false` in the fifth call. The device makes no more calls and goes to `READY`. | +| `ConditionalRun.Rate` | With `rate` 100, the 21 calls take 140 ms or more. | + +## Check the result + +Start the sampler and the sink of the example [1-1](/examples/1-1/) in two terminals: + +```sh +fairmq-ex-1-1-sampler --id sampler1 --rate 1 --max-iterations 3 --control static --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0 +``` + +```sh +fairmq-ex-1-1-sink --id sink1 --max-iterations 3 --control static --channel-config name=data,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0 +``` + +The log of the sink shows these lines (without the prefix of the logger): + +```txt +READY ---> RUNNING +fair::mq::Device running... +Received: "Hello" +Received: "Hello" +Received: "Hello" +Configured maximum number of iterations reached. Leaving RUNNING state. +RUNNING ---> READY +``` + +The line `RUNNING ---> READY` tells you that the device left `RUNNING`. With `--control static`, the +device then resets and exits. + +## Problems that can occur + +- **The device goes to `ERROR` at the start of `RUNNING`:** the channel name in `OnData()` does not + exist. The device throws `std::out_of_range`. Make sure that the name is the same as in the + channel configuration. +- **`RUNNING` ends without a reason in the log:** a `Receive()` for a callback returned a negative + value. For example, the input channel has the property `rcvTimeoutMs`, and no message arrived in + time. Remove the timeout, or use a `Run()` loop. +- **The device does not leave `RUNNING`:** your `Run()` loop does not check `NewStatePending()`, or a + callback does not return. Add the check, and return from the callbacks. A second Ctrl-C aborts a + device that does not stop. +- **`ConditionalRun()` is not called:** the device has data callbacks. Remove the `OnData()` calls, or + move the work into the callbacks. +- **A multipart callback receives wrong parts:** the sender sends single messages. With shmem, a + multipart `Receive()` of a single message reads wrong metadata. See the disabled test + `PartsTransfer.SingleSendMultipartReceive`. Use the same form on both sides. + +:::caution[Known defect] +With input channels on more than one transport, the device calls the callbacks in +[other threads](/concepts/threads/#which-thread-runs-your-code). If +a callback throws an exception there, the process ends with `std::terminate()`. The device does not +go to `ERROR`. +::: + +## Related pages + +- [Device states](/concepts/states/): what happens in `RUNNING`, and what ends it. +- [Devices](/concepts/devices/): the hooks and the helper functions of a device. +- [Handle errors and timeouts](/guides/errors-timeouts/): transfer codes, timeouts and exceptions. +- [Poll several channels](/guides/poll-channels/): a `Run()` loop with a poller. +- [Messages and parts](/concepts/messages/): `MessagePtr` and `Parts`. diff --git a/docs/src/content/docs/guides/send-data-types.mdx b/docs/src/content/docs/guides/send-data-types.mdx new file mode 100644 index 00000000..efe67923 --- /dev/null +++ b/docs/src/content/docs/guides/send-data-types.mdx @@ -0,0 +1,357 @@ +--- +title: Send your own data types +description: Put structs, arrays and serialized objects into messages, keep the data valid until the transport is done, and read it safely in the receiver. +sidebar: + order: 1.5 +code: [fairmq/TransportFactory.h, fairmq/Message.h, fairmq/Device.h, fairmq/Parts.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +A message holds bytes. FairMQ copies and sends these bytes, but it does not serialize your objects +and it does not check their type. This guide shows how to put structs, arrays and serialized objects +into messages. It also shows how long your data must stay valid, and how a receiver reads the +bytes safely. + +[Messages and multipart](/concepts/messages/) explains the message functions. This page uses them +for your own data types. + +## Choose a way + +| Your data | Make the message with | Copies that FairMQ makes | +| --- | --- | --- | +| A small trivially copyable struct or number | [`NewSimpleMessage(value)`](/api/fair/mq/Device/#NewSimpleMessage) | One copy on the heap. The shmem transport copies it again into the segment. | +| An array or a struct that you can write in place | [`NewMessage(size, alignment)`](/api/fair/mq/Device/#NewMessage), then write into [`GetData()`](/api/fair/mq/Message/#GetData) | None. | +| Data in a buffer of your own, for example a `std::vector` | `NewMessage(data, size, ffn, hint)` | zeromq: none. shmem: one copy into the segment. | +| A serialized object | Your serializer, then `NewMessage(size)` or a buffer of your own | See [Serialized objects](#serialized-objects). | +| A `std::pmr` container | [`fair::mq::getMessage()`](/api/fair/mq/#getMessage) | None, if the container uses the memory resource of the transport. Otherwise one copy ([MemoryResourceTools.h](/source/fairmq/MemoryResourceTools.h/#L42-L62)). See [Use std::pmr memory resources](/guides/pmr/). | +| A header and a payload | [`fair::mq::Parts`](/api/fair/mq/Parts/) with one part for each | The same as for each part. See [A header and a payload](#a-header-and-a-payload). | + +The data types on this page are examples. This struct is the type of one element. The samples are +member functions of a device class, and they also need the headers ``, ``, +`` and ``. + +```cpp +#include +#include + +struct Hit +{ + float x; + float y; + float energy; + std::uint32_t detectorId; +}; + +// FairMQ does not check this. Check it yourself. +static_assert(std::is_trivially_copyable_v, "Hit must be trivially copyable"); +``` + +## Plain structs with NewSimpleMessage() + +`NewSimpleMessage(value)` copies `value` into a new heap object with `new T(value)`. Then it makes a +message of `sizeof(T)` bytes for this object, with a deleter that deletes it +([TransportFactory.h](/source/fairmq/TransportFactory.h/#L195-L203)). You can change or destroy +`value` at once after the call. + +```cpp +bool ConditionalRun() override +{ + Hit const hit{1.5f, 2.5f, 0.3f, 7}; + fair::mq::MessagePtr msg(NewSimpleMessage(hit)); + return Send(msg, "data") >= 0; +} +``` + +The [copypush example](/examples/copypush/) sends a `uint64_t` counter in the same way, and the +sampler of the [multipart example](/examples/multipart/) sends its header struct. + +### Limits of NewSimpleMessage() + +The type must be trivially copyable, because the receiver gets only the bytes of the object. The +check for this is a comment in the code +([TransportFactory.h](/source/fairmq/TransportFactory.h/#L198-L200)). Thus a wrong type compiles and +sends wrong bytes: + +| Argument | What the message contains | +| --- | --- | +| A trivially copyable struct, a number, `std::array` | The bytes of the object. This is correct. | +| A `std::vector`, or a struct with a `std::string` member or a pointer member | The bytes of the object itself: sizes and addresses in the memory of the sender. The receiver cannot use them. | +| A pointer, for example a `const char*` variable | The bytes of the pointer itself, not the data that it points to. | +| A `char` array or a string literal | The characters up to the first zero byte, without the zero byte (overload for `const char (&)[N]`). Binary data in a `char` array is cut. For a `char` array without a zero byte, the copy reads past the end of the array. | +| A `std::string` | The characters of the string, without the terminating zero. | +| A C array of another element type, for example `float values[16]` | Does not compile, because `new T(value)` cannot copy an array. Use `std::array`. | + +More rules: + +- The receiver must use the same definition of the struct. FairMQ copies the bytes and does not + convert them, for example for another byte order or another padding. +- Use `NewSimpleMessage()` for small data only, because of the additional copy. The comment in the + multipart sampler says the same. With shmem, the data is copied two times. +- `NewSimpleMessage()` uses the default transport of the device. For a channel with another + transport, use `NewSimpleMessageFor(channel, index, value)`. + +## Write in place with NewMessage(size) + +`NewMessage(size)` allocates a buffer of `size` bytes in the transport. The zeromq transport +allocates it in the memory of the process. The shmem transport allocates it in the managed segment, +and the receiver reads this block without a copy. Write your data into the buffer before you send +the message. + + + +1. Calculate the size in bytes, for example `numHits * sizeof(Hit)`. + +2. Call `NewMessage(size, fair::mq::Alignment{alignof(Hit)})`. The alignment makes sure that the + pointer to the buffer is correct for the type. + +3. Cast [`GetData()`](/api/fair/mq/Message/#GetData) to a pointer to your type and write the + elements. + +4. If you wrote fewer bytes than you allocated, call + [`SetUsedSize(bytes)`](/api/fair/mq/Message/#SetUsedSize). + +5. Send the message. After a successful `Send()`, do not read or write the buffer. + + + +```cpp +bool ConditionalRun() override +{ + std::size_t const numHits = 1000; + fair::mq::MessagePtr msg(NewMessage(numHits * sizeof(Hit), fair::mq::Alignment{alignof(Hit)})); + + auto* hits = static_cast(msg->GetData()); + for (std::size_t i = 0; i < numHits; ++i) { + hits[i] = Hit{0.1f * i, 0.2f * i, 1.0f, static_cast(i)}; + } + + return Send(msg, "data") >= 0; +} +``` + +[`fair::mq::Alignment`](/api/fair/mq/Alignment/) has one `size_t` member. The test +`Messages.Alignment` makes messages with an alignment of 64 bytes and checks the addresses for both +transports. Without an alignment, the zeromq transport uses the buffer of `zmq_msg_init_size()`, +and FairMQ does not check its alignment. +[Change the size](/concepts/messages/#change-the-size) explains `SetUsedSize()`. By default, a full +shmem segment makes `NewMessage()` throw `MessageBadAlloc`, see +[Shared memory allocation](/guides/errors-timeouts/#shared-memory-allocation). + +## Send a buffer of your own + +`NewMessage(data, size, ffn, hint)` makes a message for a buffer that you allocated. `ffn` is a +function of the type [`fair::mq::FreeFn`](/api/fair/mq/#FreeFn), `void(void* data, void* hint)`. +The transport calls `ffn(data, hint)` when it does not need the buffer any more. The `hint` can +point to the object that owns the buffer. The [1-1 example](/examples/1-1/) sends a `std::string` +this way. A `std::vector` works in the same way: + +```cpp +bool ConditionalRun() override +{ + auto* hits = new std::vector(1000); + // Write the elements of *hits here. + + fair::mq::MessagePtr msg(NewMessage(hits->data(), + hits->size() * sizeof(Hit), + [](void* /*data*/, void* hint) { delete static_cast*>(hint); }, + hits)); + return Send(msg, "data") >= 0; +} +``` + +- The zeromq transport sends your buffer without a copy. ZeroMQ calls `ffn` after the transfer, + and it can call it from one of its own threads (ZeroMQ behavior). +- The shmem transport copies the buffer into the segment when it makes the message. Then it calls + `ffn` at once ([shmem/Message.h](/source/fairmq/shmem/Message.h/#L64-L78)). +- For the size 0, the shmem transport does not call `ffn`. The object of the `hint` then stays + allocated. Send an empty message with `NewMessage()` instead. +- If the shmem transport cannot allocate the block, `NewMessage()` throws before it calls `ffn`. + Then you must free the buffer yourself. + +Write data that you send with shmem directly into a message from `NewMessage(size)`. Then the +transport does not copy it. + +## Serialized objects + +FairMQ has no serializer. Use the library of your choice, for example to serialize an object into a +`std::string` or a `std::vector`. Then put the bytes into a message in one of these ways: + +- **The serializer gives a buffer.** Move the buffer to the heap. Give it to + `NewMessage(data, size, ffn, hint)`, as in [Send a buffer of your own](#send-a-buffer-of-your-own). +- **You know the size before you serialize.** Make the message with `NewMessage(maxSize)`, and let + the serializer write into `GetData()`. Then call `SetUsedSize()` with the real size. The zeromq + transport does not copy the data. The shmem transport shrinks the block in place. Only if this + fails and at least 1000000 bytes are unused, it copies the data into a new block + ([shmem/Message.h](/source/fairmq/shmem/Message.h/#L208-L235)). +- **The serializer writes into a container with an allocator.** Use a `std::pmr` container on the + memory resource of the transport. See [Use std::pmr memory resources](/guides/pmr/). + +In this sample, `MySerialize()` stands for the function of your library: + +```cpp +bool ConditionalRun() override +{ + auto* buffer = new std::string(MySerialize(fEvent)); + fair::mq::MessagePtr msg(NewMessage(buffer->data(), + buffer->size(), + [](void* /*data*/, void* hint) { delete static_cast(hint); }, + buffer)); + return Send(msg, "data") >= 0; +} +``` + +The receiver gives `GetData()` and `GetSize()` to the deserializer. The deserializer must not read +more than `GetSize()` bytes. + +### The deprecated Serialize() and Deserialize() + +[`Device::Serialize(msg, data, args…)`](/api/fair/mq/Device/#Serialize) and +[`Device::Deserialize(msg, data, args…)`](/api/fair/mq/Device/#Deserialize) are +deprecated ([Device.h](/source/fairmq/Device.h/#L78-L88)). They make a temporary `Serializer` or +`Deserializer` object and call its member function `Serialize(msg, data, args…)` or +`Deserialize(msg, data, args…)`. They add nothing else. Call your class directly instead: + +```cpp +// Old, gives a deprecation warning: +Serialize(*msg, fEvent); +// New: +MySerializer().Serialize(*msg, fEvent); +``` + +## A header and a payload + +Put the header and the payload into two parts of one multipart message. Each part keeps its own +buffer, so FairMQ does not copy the payload to join it with the header. The receiver gets all parts +in one call. The [multipart example](/examples/multipart/) uses this header: + + + +The sampler copies the header with `NewSimpleMessage()` into part 0, and allocates the payload +with `NewMessage(1000)` as part 1: + + + +The sink reads the header from part 0: + + + +The sink checks the number of parts, but not the size of part 0. A receiver must also check the +size before it reads the header. See [Read the data safely](#read-the-data-safely). For the rules of +multipart messages, see [Multipart messages](/concepts/messages/#multipart-messages). + +## How long the data must stay valid + +The rules depend on the function that makes the message and on the transport. The default +transport of a device comes from `--transport`, and each channel can have its own transport. To +support both transports, follow the stricter rule of the two columns. + +| Message from | zeromq | shmem | +| --- | --- | --- | +| `NewSimpleMessage()` | The message owns a copy. You can change your object at once. | The same. | +| `NewMessage(size)` | The transport owns the buffer. Write it before `Send()`. After a successful `Send()`, do not use it. | The same. The receiver reads the same block in shared memory. | +| `NewMessage(data, size, ffn, hint)` | Your buffer must stay valid and unchanged until ZeroMQ calls `ffn`. | The transport copies the buffer and calls `ffn` before `NewMessage()` returns. | +| [`NewStaticMessage(str)`](/api/fair/mq/Device/#NewStaticMessage), or a buffer with [`NoCleanup`](/api/fair/mq/TransportFactory/#NoCleanup) | The transport tells you nothing when the transfer ends. Use only data that does not change and that lives longer than the transport, for example the member `fText` of the [1-n-1 sampler](/examples/1-n-1/#the-code). | The transport copies the data when it makes the message. | +| [`Copy()`](/api/fair/mq/Message/#Copy) of a message | Do not change the buffer after `Copy()`. Both messages can use the same buffer ([Message.h](/source/fairmq/Message.h/#L55-L59)). | The same. | +| A block of an unmanaged region | See [Unmanaged regions](/shmem/regions/). | See [Unmanaged regions](/shmem/regions/). | + +If `Send()` returns a negative value, the message keeps its buffer. You can send it again or +destroy it. + +A received message owns its buffer. The data is valid while the message exists. Do not keep the +pointer from `GetData()` after you destroy or rebuild the message. To keep the data longer, keep the +`MessagePtr`. The receiver of the [n-m example](/examples/n-m/#receiver-collect-the-parts) moves +a part out of the `Parts` object and stores it, with +`fBuffer[h.id].parts.AddPart(std::move(parts.At(1)))`. With shmem, destroy all messages before the +device destroys its transports, see +[Rules for your code](/shmem/how-it-works/#rules-for-your-code). + +## Read the data safely + +A message can have another size than you expect, for example from a sender with another version of +your struct. A read past `GetSize()` reads memory that does not belong to the message. + + + +1. For a multipart message, check the number of parts with `parts.Size()`. + +2. Check `GetSize()` of each part before you read it. A struct needs `GetSize() == sizeof(T)`. An + array needs `GetSize() % sizeof(T) == 0`. + +3. Copy a struct out of the buffer with `std::memcpy()`. Then the alignment of the buffer has no + effect. + +4. Read an array in place only from a message that you received with an alignment. + + + +The test `Factory.SimpleAndStaticMessages` checks the size and copies a number out of the buffer: + + + +A data callback of [`OnData()`](/api/fair/mq/Device/#OnData) gets a message that the device made +without an alignment ([Device.cxx](/source/fairmq/Device.cxx/#L564-L584)). This multipart callback +uses the `Header` of the multipart example. It checks the sizes and copies each element: + +```cpp +bool HandleData(fair::mq::Parts& parts, int /*index*/) +{ + if (parts.Size() != 2 || parts[0].GetSize() != sizeof(example_multipart::Header)) { + throw std::runtime_error("unexpected message format"); + } + + example_multipart::Header header; + std::memcpy(&header, parts[0].GetData(), sizeof(header)); + + auto const& payload = parts[1]; + if (payload.GetSize() % sizeof(Hit) != 0) { + throw std::runtime_error("payload size is not a multiple of sizeof(Hit)"); + } + + auto const* bytes = static_cast(payload.GetData()); + std::size_t const numHits = payload.GetSize() / sizeof(Hit); + for (std::size_t i = 0; i < numHits; ++i) { + Hit hit; + std::memcpy(&hit, bytes + i * sizeof(Hit), sizeof(hit)); + fSumEnergy += hit.energy; + } + + return header.stopFlag == 0; +} +``` + +An exception in the callback moves the device to `ERROR`. To continue instead, log the error and +return `true`. See [Handle errors and timeouts](/guides/errors-timeouts/#exceptions-and-the-error-state). + +To read an array in place, receive the message yourself, for example in `ConditionalRun()`. Make +the empty message with `NewMessage(fair::mq::Alignment{alignof(Hit)})`. If the received buffer of +the zeromq transport is not aligned, the transport copies it into an aligned buffer +([zeromq/Message.h](/source/fairmq/zeromq/Message.h/#L241-L256)). The shmem transport ignores this +alignment, because the receiver gets the block of the sender. The shmem transport aligns each block +of the managed segment to at least `alignof(std::max_align_t)` +([shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L694-L696)). + +## Problems that can occur + +- **The receiver gets a few bytes instead of the data:** you gave a `std::vector` to + `NewSimpleMessage()`. The message has `sizeof(std::vector)` bytes, for example 24. Use + `NewMessage(data, size, ffn, hint)` or `NewMessage(size)`. +- **A binary `char` array arrives shorter:** `NewSimpleMessage()` treats a `char` array as a C + string. Use `NewMessage(size)` and `std::memcpy()`. +- **The receiver reads wrong values after an update of the sender:** the two devices use different + definitions of the struct. Put a version number into the header, and check the size. +- **The data of a zeromq message changes during the transfer:** your code changed the buffer too + early. With `NewStaticMessage()` or `NewMessage(data, size, ffn, hint)`, ZeroMQ uses your buffer + until the transfer ends (ZeroMQ behavior). +- **The shared memory segment becomes full:** the receiver keeps the messages, or the sender sends + faster than the receiver reads. See [Tune and debug](/shmem/tuning/). + +## Related pages + +- [Messages and multipart](/concepts/messages/): the functions that make, send and receive messages. +- [Use std::pmr memory resources](/guides/pmr/): fill a container in message memory and send it + without a copy. +- [multipart: several parts in one message](/examples/multipart/): the header and payload example. +- [How shared memory works](/shmem/how-it-works/): where the shmem transport keeps the data. +- [Unmanaged regions](/shmem/regions/): messages for blocks of your own shared memory. diff --git a/docs/src/content/docs/guides/several-transports.mdx b/docs/src/content/docs/guides/several-transports.mdx new file mode 100644 index 00000000..e73c17f5 --- /dev/null +++ b/docs/src/content/docs/guides/several-transports.mdx @@ -0,0 +1,199 @@ +--- +title: 'Use several transports' +description: 'Give each channel of one device its own transport, make messages for the right transport, and receive from channels of different transports.' +sidebar: + order: 3 +code: [fairmq/Device.h, fairmq/Device.cxx, fairmq/Channel.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +One device can use the shmem transport for some channels and the zeromq transport for others. For +example, it uses shmem to a process on the same host and zeromq to another host. This guide shows +how to configure the transport of each channel and how to make messages without a conversion. It +also shows how to receive from channels of different transports. + +The device makes one transport factory for each transport that its channels use. For the rules, see +[How a device selects the transport](/concepts/transports/#how-a-device-selects-the-transport). + +## Configure the channels + + + +1. Select the default transport of the device with `--transport`. The value is `zeromq` (default) or + `shmem`. All channels without a transport property use it. + +2. Add the [channel property](/reference/channel-properties/) `transport` to each channel that uses + the other transport. In `--channel-config`, add `transport=zeromq` or `transport=shmem`. + +3. Give the peer channel in the other device the same transport. + +4. For each shmem channel, run both devices on the same host with the same `--session`. Do not use + the socket types `pub` and `sub`. + + + +The [multiple-transports example](/examples/multiple-transports/) starts `sampler1` with `shmem` as +the default transport. Its channel `ack` is a `sub` socket, thus it uses `zeromq`: + + + +The example has no JSON file. In a [JSON file](/reference/json/) for `--mq-config`, set `transport` +for the channel or for one socket of the channel. A socket without `transport` uses the value of its channel. This file +gives `sampler1` the same channels: + +```json +{ + "fairMQOptions": { + "devices": [ + { + "id": "sampler1", + "channels": [ + { + "name": "data1", + "sockets": [ + { "type": "push", "method": "bind", "address": "tcp://127.0.0.1:5555" } + ] + }, + { + "name": "ack", + "transport": "zeromq", + "sockets": [ + { "type": "sub", "method": "bind", "address": "tcp://127.0.0.1:5557" } + ] + } + ] + } + ] + } +} +``` + +Give all sub-channels of one channel the same transport. The pollers and the data callbacks of the +device use the transport of the sub-channel 0 for all sub-channels. + +## Make messages for the right transport + +[`NewMessage()`](/api/fair/mq/Device/#NewMessage) uses the default transport of the device. To make +a message with the transport of a channel, use +[`NewMessageFor(channel, index, args…)`](/api/fair/mq/Device/#NewMessageFor). It takes the same +arguments as `NewMessage()` after the channel name and the sub-channel index. `sampler1` makes its +data messages with the transport of `data1`: + + + +The device has more functions of this kind: +[`NewSimpleMessageFor()`](/api/fair/mq/Device/#NewSimpleMessageFor), +[`NewStaticMessageFor()`](/api/fair/mq/Device/#NewStaticMessageFor) and +[`NewUnmanagedRegionFor()`](/api/fair/mq/Device/#NewUnmanagedRegionFor). If you have a reference to +the channel, call [`NewMessage()`](/api/fair/mq/Channel/#NewMessage) on the channel. +[`AddTransport(Transport::SHM)`](/api/fair/mq/Device/#AddTransport) returns the factory of a +transport, and makes it if the device has none. + +## Send a message of another transport + +You can send a message on a channel of another transport. `Channel::Send()` then converts the +message ([Channel.h](/source/fairmq/Channel.h/#L421-L480)): + +| Message | Channel | What the channel does | +| --- | --- | --- | +| `shmem` | `zeromq` | Makes a zeromq message that points to the shared memory buffer. No copy. The shared memory buffer stays allocated until zeromq releases the message. | +| `zeromq` | `shmem` | Copies the data into the shared memory segment, and destroys the zeromq message. | +| empty | either | Replaces the message with an empty message of the channel transport. | + +After the call, your `MessagePtr` points to the new message. `Receive()` replaces a message object of +another transport with an empty message of the channel transport. The sender of the +[readout example](/examples/readout/) receives shmem messages and sends them on its zeromq channel +`sr`: + + + +The copy from zeromq to shmem costs time and memory for large messages. Use `NewMessageFor()` to +prevent it. + +## Receive from channels of different transports + +If you register data callbacks with [`OnData()`](/api/fair/mq/Device/#OnData) on channels of +different transports, the device polls each transport in its own thread. The callbacks run in +[these threads](/concepts/threads/#which-thread-runs-your-code). A mutex lets only one callback run at a time +([Device.cxx](/source/fairmq/Device.cxx/#L509-L562)). The sink of the example registers callbacks +for `data1` and `data2`: + + + +:::caution[Exceptions in the threads of the transports] +In this mode, an exception in a poll thread, for example in a data callback, does not move the +device to the state `ERROR`. +The device logs `fair::mq::Device::PollForTransport() failed: , going to ERROR state.` and +throws again ([Device.cxx](/source/fairmq/Device.cxx/#L558-L561)). The exception leaves the thread, +and C++ calls `std::terminate()`. Catch the exceptions in your callbacks. +::: + +The start script gives `data1` and `data2` of the sink the same transport, `shmem`. The test script +of the example gives `data2` the transport `zeromq`. Then the sink polls `shmem` and `zeromq` in two +threads: + + + +One [poller](/guides/poll-channels/) can poll channels of one transport only. +[`NewPoller()`](/api/fair/mq/Device/#NewPoller) throws `std::runtime_error` for channels of +different transports. Use one thread for each transport, with its own poller or a blocking +`Receive()`. `sampler1` receives the acknowledgements with a blocking `Receive()` in a second +thread: + + + +## Check the result + + + +1. Start the devices with `--severity debug`. + +2. Find the line `Initializing transport for channel []: ` for each + sub-channel. The value `default` means the default transport of the device. + +3. Find the line `Adding '' transport` once for each transport of the device. + + + +In the code, [`GetChannel(name, index).GetTransportName()`](/api/fair/mq/Channel/#GetTransportName) +returns the transport of a sub-channel, and [`msg->GetType()`](/api/fair/mq/Message/#GetType) +returns the transport of a message. + +To run the example, start `fairmq-start-ex-multiple-transports.sh` in the directory +`examples/multiple-transports` of the build directory. The script opens one `xterm` window for each +device. When `sampler1` leaves the state `RUNNING`, it logs `Acknowledged messages`. + +## Problems that can occur + +| Message in the log | Cause | Fix | +| --- | --- | --- | +| `Received message is not a valid FairMQ shared memory message` | A shmem channel received a message from a zeromq peer. | Give both ends of the channel the same transport. | +| `poller failed: different transports within same poller are not yet supported` | `NewPoller()` got channels of different transports. | Make one poller for each transport. | +| `PUB/SUB socket type is not supported for shared memory transport` | A shmem channel has the type `pub` or `sub`. | Add `transport=zeromq` to the channel. | +| `Unknown transport provided: ` | A channel property `transport` has an unknown value. | Use `default`, `zeromq` or `shmem`. | +| `invalid transport type provided: ` | `--transport` has an unknown value. | Use `zeromq` or `shmem`. | + +A shmem receiver detects a zeromq message only if the message is smaller than the shmem metadata. A +larger zeromq message goes into the receiver as shmem metadata. A zeromq receiver gets the shmem +metadata as data and reports no error. Thus a wrong transport on one end of a channel does not +always cause an error message. + +## Checklist + +- The default transport of the device is the transport of most channels. +- Each other channel has the property `transport`. +- Both ends of each channel use the same transport. +- All sub-channels of one channel use the same transport. +- Each shmem channel connects devices on one host with the same `--session`, and is not `pub` or `sub`. +- The device makes messages with `NewMessageFor()`, or with `NewMessage()` of the channel. +- Each poller polls channels of one transport only. + +## Related pages + +- [Transports](/concepts/transports/): the two transports and how a device selects them. +- [Messages and multipart](/concepts/messages/): what `Send()` does with a message. +- [Poll several channels](/guides/poll-channels/): wait for messages on several channels. +- [Example: multiple transports](/examples/multiple-transports/): the example of this guide, step by step. +- [Design a topology](/guides/design-topology/#select-the-transport-of-each-link): select the transport of each link. diff --git a/docs/src/content/docs/guides/test-devices.mdx b/docs/src/content/docs/guides/test-devices.mdx new file mode 100644 index 00000000..f5dcddd1 --- /dev/null +++ b/docs/src/content/docs/guides/test-devices.mdx @@ -0,0 +1,415 @@ +--- +title: Test your devices +description: 'Run a topology as CTest tests: a script with a unique session, the static controller, ipc addresses and the cleanup of shared memory, for each transport.' +sidebar: + order: 9.7 +code: [fairmq/tools/runUuidGenerator.cxx, fairmq/plugins/control/Control.cxx, fairmq/shmem/Manager.cxx, fairmq/shmem/runMonitor.cxx, fairmq/TransportFactory.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +This guide makes CTest tests for your devices. A shell script starts the devices of the topology, +waits until they stop, and removes what they leave behind. CMake adds the script once for each +transport. For code that does not need a device, a GoogleTest program in one process is enough. + +The examples of FairMQ use the same method. See [Test the example](/examples/1-1/#test-the-example) +on the page of the 1-1 example. + +## What a test needs + +| Need | How | Why | +| --- | --- | --- | +| A new session for each run | `--session` with the output of `fairmq-uuid-gen -h` | Tests that run at the same time do not share shared memory. See [Keep two topologies apart](/shmem/sessions/#keep-two-topologies-apart). | +| Devices that stop by themselves | `--control static`, and an end condition in the devices | With `static`, the process ends when the device leaves `RUNNING`. The default `dynamic` waits for the key `q`. See [Control modes](/concepts/plugins/#control-modes). | +| Unique addresses | `ipc:///tmp/fmq___` | No port collisions, and no connections to the devices of another test. | +| A small segment | `--shm-segment-size 100000000` | The default is 2 GiB. The tests of FairMQ use 100000000 bytes (100 MB). | +| Cleanup after a crash | `--shm-monitor true` and `FAIRMQ_PATH` | When all devices of the session stopped, also after a crash, a daemon removes the shared memory. See [Automatic cleanup](/shmem/monitor/#automatic-cleanup-with---shm-monitor). | +| Cleanup after a failure | A trap in the script | The script stops the other devices and removes the shared memory and the socket files. | +| A limit for the time | The test property `TIMEOUT` | CTest stops a test that hangs, and the test fails (CMake behavior). | + +`--max-iterations` is not an option of every device. Many example devices add it with +`addCustomOptions()` and return `false` from `ConditionalRun()` or from their data callback after +this number of messages. The built-in devices `fairmq-bsampler` and `fairmq-sink` also have it. +See [The sampler](/examples/1-1/#the-sampler) and +[Stop a topology without losing messages](/guides/end-of-run/). Give your +devices an end condition of this type, or stop them with a signal. + +## Write the test script + + + +1. Read the transport from the first argument. + +2. Make a new session name with `fairmq-uuid-gen -h`. Write it to the output. + +3. Make an `ipc://` address for each channel from the session, the channel name and the transport. + +4. Set a trap for `EXIT` that stops the remaining devices and removes the shared memory and the + socket files. + +5. Start each device in the background with the same session and `--control static`. + +6. Wait for the devices with an end condition. + +7. Stop the other devices with `SIGTERM` or `SIGINT`, and wait for them. + + + +This script tests a topology `my-sampler` → `my-processor` → `my-sink`. The sampler and the sink have +an option `--max-iterations` like the examples. The processor has no end condition: + +```sh title="test-topology.sh" +#!/bin/bash +# Usage: test-topology.sh +# FAIRMQ_PATH must be the directory of fairmq-uuid-gen and fairmq-shmmonitor. +set -eu + +transport="$1" +bin="$2" + +session="$("$FAIRMQ_PATH/fairmq-uuid-gen" -h)" +echo "session: $session" +dataAddr="/tmp/fmq_${session}_data_${transport}" +resultAddr="/tmp/fmq_${session}_result_${transport}" + +cleanup() { + set +e + local running + running="$(jobs -p)" + if [[ -n $running ]]; then + kill -TERM $running + wait + fi + "$FAIRMQ_PATH/fairmq-shmmonitor" --cleanup --session "$session" + rm -f "$dataAddr" "$resultAddr" +} +trap cleanup EXIT +trap 'exit 1' TERM INT + +common=(--transport "$transport" --session "$session" --control static --color false + --shm-segment-size 100000000 --shm-monitor true) + +"$bin/my-sampler" --id sampler1 "${common[@]}" --max-iterations 10 \ + --channel-config "name=data,type=push,method=bind,address=ipc://$dataAddr,rateLogging=0" & +samplerPid=$! + +"$bin/my-processor" --id processor1 "${common[@]}" \ + --channel-config "name=data,type=pull,method=connect,address=ipc://$dataAddr,rateLogging=0" \ + "name=result,type=push,method=connect,address=ipc://$resultAddr,rateLogging=0" & +processorPid=$! + +"$bin/my-sink" --id sink1 "${common[@]}" --max-iterations 10 \ + --channel-config "name=result,type=pull,method=bind,address=ipc://$resultAddr,rateLogging=0" & +sinkPid=$! + +wait "$samplerPid" +wait "$sinkPid" + +kill -TERM "$processorPid" +wait "$processorPid" +``` + +How the script works: + +- `set -e` ends the script when a command fails. `wait "$pid"` returns the exit code of the device, + so a device that stops with an error ends the script with this code. The test then fails. +- The script waits for the devices in a fixed order. If the sink fails before the sampler stops, + the script finds the error when the sampler stops. +- `set -u` stops the script at a variable that has no value, for example a misspelled name. +- The trap for `EXIT` runs at each end of the script: after success, after a failed device, and + after `SIGTERM` or `SIGINT`. `jobs -p` lists the devices that still run. The trap stops them, + waits for them, and removes the shared memory of the session and the socket files. +- The exit code of the script does not change in the trap. After a signal, `trap 'exit 1' TERM INT` + ends the script with the code 1. +- After a signal, the control plugin of each device runs the shutdown sequence, and the device + exits with the code 0. See [Signals](/concepts/plugins/#signals). +- A device that goes to the state `ERROR` exits with the code 1. See + [When the device goes to ERROR](/concepts/plugins/#when-the-device-goes-to-error). +- The script writes the session name. If the test fails, the output of CTest shows it, and you can + remove the shared memory of this session. + +The test script of the 1-1 example starts the sampler in the same way: + + + +The script of the [1-n-1 example](/examples/1-n-1/) stops its two processors with `SIGINT` after +the sampler and the sink stop. + +:::caution[Errors in the example scripts] +Do not copy the example scripts without changes: + +- Their traps run only on `TERM`. If a device fails, `set -e` ends the script, and the other + devices continue to run. +- Their traps end with `exit 0`. +- In `test-ex-multiple-transports.sh.in` and `test-ex-region.sh.in`, the trap calls + `fairmq-shmmonitor --cleanup --session $SESSION`. The variable of the script is `session`, so the + option `--session` gets no value. `set -u` finds this type of error. +- `test-ex-builtin-devices.sh.in` gives each device `--session $SESSION`, with the same error. +::: + +## Add one CTest test for each transport + +Register the script once for each transport. This `CMakeLists.txt` uses the package variable +`FairMQ_BINDIR`, the directory of `fairmq-uuid-gen` and `fairmq-shmmonitor` (see +[Package variables](/start/cmake/#package-variables)): + +```cmake title="CMakeLists.txt" +enable_testing() # in the top-level CMakeLists.txt + +foreach(transport IN ITEMS zeromq shmem) + set(test "MyTopology.${transport}") + add_test(NAME ${test} + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-topology.sh + ${transport} $) + set_tests_properties(${test} PROPERTIES + TIMEOUT 30 + ENVIRONMENT "FAIRMQ_PATH=${FairMQ_BINDIR}") +endforeach() +``` + +- `FAIRMQ_PATH` has two uses. The script finds the two tools there, and the shmem transport looks + there first for `fairmq-shmmonitor`, then in `PATH` + ([Manager.cxx](/source/fairmq/shmem/Manager.cxx/#L26-L53)). +- `$` gives the directory of your devices. The script expects all three + devices in this directory. +- `TIMEOUT 30` is the timeout of the example tests. Give your test enough time for a slow machine, + for example a build with sanitizers. + +On a timeout, CTest stops the test process (CMake behavior). The trap of the script does not run +then. With CMake 3.27 or later, the test properties `TIMEOUT_SIGNAL_NAME` and +`TIMEOUT_SIGNAL_GRACE_PERIOD` make CTest send a signal first and wait before it stops the process +(CMake behavior, see the +[CMake documentation](https://cmake.org/cmake/help/latest/prop_test/TIMEOUT_SIGNAL_NAME.html)). +Then the trap can stop the devices: + +```cmake +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) + set_tests_properties(${test} PROPERTIES + TIMEOUT_SIGNAL_NAME SIGTERM + TIMEOUT_SIGNAL_GRACE_PERIOD 10) +endif() +``` + +Put this block in the loop, after `set_tests_properties()`. + +### How the examples register their tests + +The function `add_example()` in +[`examples/CMakeLists.txt`](https://github.com/FairRootGroup/FairMQ/blob/dev/examples/CMakeLists.txt) +copies `test-ex-.sh.in` with `configure_file()` into the build directory. Then it adds the test +`Example..` (or `Example...`) for each transport, with a +timeout of 30 s. `env_mods` holds the changes of the environment for the leak sanitizer and for +`FAIRMQ_TEST_LD_LIBRARY_PATH`: + + + +`configure_file()` replaces `@CMAKE_BINARY_DIR@`, `@CMAKE_CURRENT_BINARY_DIR@` and `@FAIRMQ_BIN_DIR@` +in the script with the paths of the build tree. Thus the example scripts find `fairmq-uuid-gen` in +`/fairmq`. + +:::caution[`${…}` in a configured script] +`add_example()` calls `configure_file()` for the test scripts without the option `@ONLY`. Then CMake +also replaces each `${variable}` in the script with the value of a CMake variable, which is often +empty (CMake behavior). The example scripts use only the form `$variable`. If you configure your +script, use `@ONLY`, or do not use `${…}` in it. +::: + +## Test without a device + +To test the code that sends and receives, and not the state machine, make the transport factory +and the channels in the test program. See +[Use channels without a device](/guides/channels-without-device/). The tests of FairMQ in +[`test/transport/`](https://github.com/FairRootGroup/FairMQ/tree/dev/test/transport) and +[`test/channel/`](https://github.com/FairRootGroup/FairMQ/tree/dev/test/channel) do this. Many of +these tests run once for each transport. + +This GoogleTest program sends one message from a `push` channel to a `pull` channel: + +```cpp title="test_channels.cxx" +#include +#include +#include +#include + +#include + +#include +#include + +namespace +{ + +class PushPull : public testing::TestWithParam +{}; + +TEST_P(PushPull, OneMessage) +{ + fair::mq::ProgOptions config; + config.SetProperty("session", fair::mq::tools::Uuid()); + config.SetProperty("shm-segment-size", 100000000); + config.SetProperty("shm-monitor", true); + + auto factory = fair::mq::TransportFactory::CreateTransportFactory(GetParam(), "", &config); + + fair::mq::Channel pull("data-in", "pull", factory); + fair::mq::Channel push("data-out", "push", factory); + ASSERT_TRUE(pull.Bind("inproc://data")); + ASSERT_TRUE(push.Connect("inproc://data")); + + auto out(push.NewSimpleMessage("hello")); + ASSERT_EQ(push.Send(out, 1000), 5); + + auto in(pull.NewMessage()); + ASSERT_EQ(pull.Receive(in, 1000), 5); + EXPECT_EQ(std::string(static_cast(in->GetData()), in->GetSize()), "hello"); +} + +INSTANTIATE_TEST_SUITE_P(, PushPull, testing::Values("zeromq", "shmem"), + [](testing::TestParamInfo const& info) { return info.param; }); + +} // namespace +``` + +- [`tools::Uuid()`](/api/fair/mq/tools/#Uuid) gives each test its own session. Without the property + `session`, all tests use the session `default` and share its shared memory. +- An `inproc://` address connects only channels of the same factory: each factory has its own + ZeroMQ context (ZeroMQ behavior). Thus the tests of two processes cannot connect to each other. + For channels of different factories, use an `ipc://` address with a unique path. +- The name generator puts the transport at the end of the test name. With the CMake file below, + the CTest names are `MyProject.PushPull.OneMessage/zeromq` and + `MyProject.PushPull.OneMessage/shmem`. + +Register the tests with the module `GoogleTest` of CMake. FairMQ does the same in +`add_testsuite()` of `cmake/GTestHelper.cmake`: + +```cmake title="CMakeLists.txt" +find_package(GTest REQUIRED) +include(GoogleTest) + +add_executable(test-channels test_channels.cxx) +target_link_libraries(test-channels PRIVATE FairMQ::FairMQ GTest::gtest_main) +gtest_discover_tests(test-channels + TEST_PREFIX MyProject. + NO_PRETTY_VALUES + PROPERTIES TIMEOUT 20 ENVIRONMENT "FAIRMQ_PATH=${FairMQ_BINDIR}") +``` + +Without `NO_PRETTY_VALUES`, `gtest_discover_tests()` adds the parameter value to each CTest name, +for example `MyProject.PushPull.OneMessage/zeromq # GetParam() = "zeromq"` (CMake behavior, seen +with CMake 3.28). + +The test helpers of FairMQ in `test/` are not installed. An installed FairMQ does not contain them, +so your project cannot include them from there. Copy them into your project if they help: + +- `Configure()` in [`test/helper/Transport.h`](https://github.com/FairRootGroup/FairMQ/blob/dev/test/helper/Transport.h) + sets the session, the segment size and the monitor. See + [Make the transport factory](/guides/channels-without-device/#make-the-transport-factory). +- `IpcAddress` makes a unique `ipc://` address and removes the socket file in its destructor: + + + +- `TransportParam`, `AllTransports()` and the name generator `TransportParamName` in + [`test/helper/TransportParam.h`](https://github.com/FairRootGroup/FairMQ/blob/dev/test/helper/TransportParam.h) + run a test for `zeromq`, `shmem`, and `shmem` with expanded metadata. `BasicTransports()` and + `ShmTransports()` select fewer transports. +- The `main()` of the test suites sets `FAIRMQ_PATH` if the environment does not have it + ([`test/runner.cxx.in`](https://github.com/FairRootGroup/FairMQ/blob/dev/test/runner.cxx.in)). + The value is the directory `fairmq` of the build tree (`FAIRMQ_TEST_ENVIRONMENT` in + `test/TestEnvironment.h.in`). + +To test a device class in the test process, run its state machine in a thread. See +[Run the device in a thread](/guides/control-from-code/#run-the-device-in-a-thread). + +To start device processes from C++, use [`tools::execute()`](/reference/tools/#processh). The helper +`RunDevices()` in [`test/helper/Devices.h`](https://github.com/FairRootGroup/FairMQ/blob/dev/test/helper/Devices.h) +starts the test program `testhelper_runTestDevice` of the FairMQ build tree, once for each device. +It calls `execute()` for each device in its own thread, with a default timeout of 15 s. Thus you +cannot copy this helper without the test devices of FairMQ. The session is a new `UuidHash()` as a decimal +number, like the output of `fairmq-uuid-gen -h`. Each device gets the same options as in the script above: + + + +## Clean up shared memory after a failed test + +A device that crashes or that CTest stops does not remove its shared memory. Three things remove +it: + +1. **The monitor daemon.** With `--shm-monitor true`, a shmem device starts `fairmq-shmmonitor` as + a daemon if no monitor runs for the session. The daemon removes the memory of the session + 2000 ms after the last heartbeat of the devices. The daemon forks and calls `setsid()`, so it + continues after the devices stop. If the transport cannot find + `fairmq-shmmonitor`, it logs `could not find fairmq-shmmonitor in "$FAIRMQ_PATH:$PATH"` and runs + without a daemon. + +2. **The trap of the script.** `fairmq-shmmonitor --cleanup --session ` removes the + segments, the regions and the monitor mutex of the session. For a session without shared memory, + for example with `zeromq`, it writes a message and removes nothing. Also then, its exit code + is 0. + +3. **You.** Find the sessions with `fairmq-shmmonitor --list-all`. Remove one session with its + name from the test output: + + ```sh + fairmq-shmmonitor --list-all + fairmq-shmmonitor --cleanup --session 1234567890 + ``` + + The files are in `/dev/shm`. All names start with `fmq_` or `sem.fmq_`: + + ```sh + ls -l /dev/shm/ | grep fmq_ + ``` + +See [Monitor and clean up](/shmem/monitor/) and [fairmq-shmmonitor](/tools/shmmonitor/) for the +details. A file-backed region keeps its file. Remove it at its path. + +## Run the tests + +```sh +ctest --test-dir build -R '^MyTopology\.' --output-on-failure +ctest --test-dir build -R '^MyTopology\.' --parallel 4 +``` + +The second command runs the tests at the same time. This is a good check for collisions: each test +must use its own session and its own addresses. After the tests, `ls /dev/shm/ | grep fmq_` must +show no file of your sessions. + +You can also run the script directly. Set `FAIRMQ_PATH` first: + +```sh +FAIRMQ_PATH=/bin bash test-topology.sh shmem build/bin +``` + +## Problems that can occur + +- **A test fails only when tests run in parallel.** Two tests use the same TCP port, the same + `ipc://` path or the same session. With a fixed port in use, `autoBind` binds to a random port, + and the peers do not find the device (see [Automatic ports](/concepts/channels/#automatic-ports)). + They can also connect to the device of the other test. Put the session and the transport in each + `ipc://` path, as above. +- **A test hangs until the timeout.** A device has no end condition, or it does not use + `--control static`. Or a device failed, and its peer waits for messages. Use `set -e` and a trap + for `EXIT`, so that the script stops the others when `wait` returns the error. Set + `TIMEOUT_SIGNAL_NAME`, so that the trap also runs on a timeout. Stop the devices without an end + condition with a signal. +- **A device stops slowly after the signal.** A hook waits in `std::this_thread::sleep_for()` or in + a long loop. See [Handle errors and timeouts](/guides/errors-timeouts/#problems-that-can-occur). +- **The log shows `could not find fairmq-shmmonitor`.** `FAIRMQ_PATH` is not set, and + `fairmq-shmmonitor` is not in `PATH`. Set the environment of the test. +- **`/dev/shm` fills up.** Earlier tests crashed without `--shm-monitor true`. Remove their sessions + with `fairmq-shmmonitor --cleanup`. +- **The test passes, but a device failed.** The script does not wait for each device, or the trap + ends with `exit 0`. Wait for each device, and let a signal end the script with a code other than 0. + +## Related pages + +- [1-1: sampler and sink](/examples/1-1/#test-the-example): the test script of the simplest example. +- [Use channels without a device](/guides/channels-without-device/): factories and channels in one process. +- [Monitor and clean up](/shmem/monitor/): when shared memory stays and how to remove it. +- [Helpers in fair::mq::tools](/reference/tools/#fairmq-uuid-gen): `fairmq-uuid-gen` and `execute()`. +- [Contributing](/project/contributing/#build-and-test): build and run the tests of FairMQ, and + [Tests with device processes](/project/contributing/#tests-with-device-processes) in FairMQ itself. +- [A CTest cleanup test](/shmem/monitor/#a-ctest-cleanup-test): remove the shared memory after the other tests. +- [When a peer stops or restarts](/guides/errors-timeouts/#when-a-peer-stops-or-restarts): what a test of a restart can check. +- [Parse options without DeviceRunner](/guides/control-from-code/#parse-options-without-devicerunner): configure a device in a test program. diff --git a/docs/src/content/docs/guides/write-plugin.mdx b/docs/src/content/docs/guides/write-plugin.mdx new file mode 100644 index 00000000..26063fcd --- /dev/null +++ b/docs/src/content/docs/guides/write-plugin.mdx @@ -0,0 +1,226 @@ +--- +title: 'Write a plugin' +description: 'Write a plugin with its own options, build it as a shared library, load it into a device with -P, and use the plugin API in it.' +sidebar: + order: 7 +code: [fairmq/Plugin.h, fairmq/PluginManager.cxx, fairmq/PluginServices.h] +--- + +import Snippet from '../../../components/Snippet.astro'; +import { Steps } from '@astrojs/starlight/components'; + +This guide shows how to write a plugin, build it as a shared library and load it into a device with `-P`. The result +is a device that loads your plugin at startup and accepts the options of the plugin on its command line. + +## Before you start + +- Install FairMQ. See [Install](/start/install/). +- Have a device that starts with `runDevice.h`, for example `fairmq-sink` or a device of the examples. +- Read [Plugins and control](/concepts/plugins/) for the plugin system and the controller role. + +A plugin has four parts: + +1. A class that derives from [`fair::mq::Plugin`](/api/fair/mq/Plugin/). +2. A function that declares the options of the plugin. This part is optional. +3. The macro `REGISTER_FAIRMQ_PLUGIN`. It exports the plugin from the library. +4. A shared library with the name `libfairmq-plugin-.so`. + +A plugin can also be part of the executable. See +[Put the controller in your program](/guides/control-from-code/#put-the-controller-in-your-program). + +The code samples on this page come from the test plugin `test_dummy` (`test/helper/plugins/dummy.h.in`) and from the +built-in control plugin. + +## Write the plugin class + + + +1. Include ``. Derive your class from `fair::mq::Plugin`. + +2. Give the class a constructor with the five parameters of the + [`Plugin` constructor](/api/fair/mq/Plugin/#Plugin-2). These are the name, the version, the maintainer, the + homepage and a pointer to `PluginServices`. Pass them to the base class. The macro `REGISTER_FAIRMQ_PLUGIN` calls + this constructor. + +3. In the constructor, read your options. Then subscribe to the events that you need, for example to the state + changes. + +4. Remove your subscriptions before the plugin goes away. `DeviceRunner` destroys the plugins before the device. The + test plugin unsubscribes in the state `EXITING`. The built-in plugins unsubscribe in their destructors. + + + + + +The base class gives the plugin API: the state, the controller role, the properties and the log settings. The list is +in [What a plugin can do](/concepts/plugins/#what-a-plugin-can-do). + +## Add options + + + +1. Write a function without parameters that returns `fair::mq::Plugin::ProgOptions`. This type is + `boost::optional`. + +2. Fill an `options_description` with your options and return it. The caption of the description is the heading of + the group in the output of `--help`. + +3. For a plugin without options, use `fair::mq::Plugin::NoProgramOptions` in the macro. + + + + + +The device adds these options to its command line. After the parsing, each option is a property with the same name. +Read it in the constructor of the plugin: + +```cpp +// An option without a default value is a property only if the command line gives it. +auto const value = GetProperty("custom-dummy-option", "nothing"); +``` + +[`GetProperty(key)`](/api/fair/mq/Plugin/#GetProperty) without a fallback value throws +`fair::mq::PropertyNotFoundError` when the property does not exist. The type `T` must be the type of the option, for +example `float` for `--rate`. + +## Register the plugin + +Write the macro `REGISTER_FAIRMQ_PLUGIN` once, at namespace scope. The built-in control plugin registers itself so: + + + +| Argument | Meaning | +| --- | --- | +| `KLASS` | The plugin class. | +| `NAME` | The name of the plugin, without quotes. Give this name to `-P`. The file name of the library ends with it: `libfairmq-plugin-NAME.so`. The macro makes function names from it, so use lower-case letters and `_`, for example `test_dummy`. | +| `VERSION` | A [`fair::mq::tools::Version`](/api/fair/mq/tools/Version/) with the major, minor and patch number. Put it in parentheses, `(fair::mq::Plugin::Version{1, 0, 0})`: the commas in the braces otherwise separate macro arguments. See [Version.h](/reference/tools/#versionh). | +| `MAINTAINER` | A string, for example a name and an e-mail address. | +| `HOMEPAGE` | A string with a URL. | +| `PROGOPTIONS` | The function that declares the options, or `fair::mq::Plugin::NoProgramOptions`. | + +The macro defines a factory function and exports two symbols: `make_NAME_plugin` and `get_NAME_plugin_progoptions`. +The plugin manager looks for these symbols when it loads the plugin +([Plugin.h](/source/fairmq/Plugin.h/#L145-L151)). + +## Build the plugin + +Build the plugin as a shared library. The name of the CMake target is `fairmq-plugin-` and the plugin name. CMake +then makes the file `libfairmq-plugin-.so`. + +```cmake title="CMakeLists.txt" +cmake_minimum_required(VERSION 3.15) +project(MyPlugin CXX) + +find_package(FairMQ REQUIRED) +# FairMQConfig.cmake does not find the dependencies of FairMQ. Find them here. +foreach(dep IN LISTS FairMQ_PACKAGE_DEPENDENCIES) + find_package(${dep} ${FairMQ_${dep}_VERSION} REQUIRED COMPONENTS ${FairMQ_${dep}_COMPONENTS}) +endforeach() + +add_library(fairmq-plugin-myplugin SHARED myplugin.cxx) +target_link_libraries(fairmq-plugin-myplugin PRIVATE FairMQ::FairMQ) +``` + +In this sample, `myplugin.cxx` contains the class, the options function and the macro with the name `myplugin`. The +target `FairMQ::FairMQ` gives the include paths, the dependencies and C++17. Without the loop over +`FairMQ_PACKAGE_DEPENDENCIES`, CMake does not find the targets of the dependencies. The prefix `FairMQPlugin_` also works: +the tests of FairMQ build `FairMQPlugin_test_dummy` and `fairmq-plugin-test_dummy2`. See +[Use FairMQ in a CMake project](/start/cmake/) for `find_package()`. + +```sh +cmake -S . -B build +cmake --build build +``` + +## Load the plugin + + + +1. Give the name of the plugin to `-P`. Give `-P` once for each plugin. + +2. Give the directory of the library to `-S`, or put it in `LD_LIBRARY_PATH`. + +3. Start the device. This command uses the built-in device `fairmq-sink`: + + ```sh + fairmq-sink --id sink1 \ + --channel-config name=data,type=pull,method=bind,address=tcp://*:5555 \ + --control static --severity debug \ + -P myplugin -S ./build + ``` + +4. Stop the device with Ctrl-C. + + + +To load a plugin from your own `main()`, call `LoadPlugin()` in the runner hook `hooks::LoadPlugins`. The +[custom-controller](/examples/custom-controller/) example does this for a plugin that the executable contains. +To load plugins without `DeviceRunner`, see +[Load plugins without DeviceRunner](/guides/control-from-code/#load-plugins-without-devicerunner). + +## Check the result + +- `--help` with `-P myplugin -S ./build` prints the options of the plugin, under the caption of its options group. + The device does not start with `--help`. +- With `--severity debug`, the device logs a line for each plugin that it creates, and a line when it destroys the + plugin: + + ```txt + Loaded plugin: 'myplugin', version '1.0.0', maintainer 'Jane Doe ', homepage 'https://example.org/myplugin' + ``` + +- With `--severity debug`, the table `Configuration:` lists the options of the plugin that have a value. + +## Use the plugin API + +### Read and change properties + +- [`SetProperty()`](/api/fair/mq/Plugin/#SetProperty) adds or changes a property. It notifies all subscribers. +- [`UpdateProperty()`](/api/fair/mq/Plugin/#UpdateProperty) changes only a property that exists. It returns + `false` otherwise. +- Give the type for text values: `SetProperty("key", "value")`. Without it, the property gets the type + `const char*`, and `GetProperty()` throws an exception. + +The time when a change has an effect depends on the property. See +[Control a device from code](/guides/control-from-code/#read-and-change-properties-at-run-time). + +### Follow the state of the device + +[`SubscribeToDeviceStateChange()`](/api/fair/mq/Plugin/#SubscribeToDeviceStateChange) calls your function at the +start of each new state, in the thread of the state machine. The device waits until your function returns. For long +work, start a thread in the plugin and stop it in the destructor. The control plugin runs its controller in this way. + +:::caution +An exception that leaves a state callback moves the device to `ERROR`. Catch the exceptions in the callback. +::: + +### Control the device + +A plugin that calls [`TakeDeviceControl()`](/api/fair/mq/Plugin/#TakeDeviceControl) in its constructor gets the +controller role before the control plugin. The plugins of `-P` are created first. See +[Control a device from code](/guides/control-from-code/#control-the-device-from-a-plugin). + +### Change the log settings + +[`CycleLogConsoleSeverityUp()`](/api/fair/mq/Plugin/#CycleLogConsoleSeverityUp) and the other `CycleLog` functions +change the console severity and the verbosity in steps. To set a value, change the property, for example +`SetProperty("severity", "debug")`. See [Logging](/tools/logging/). + +## Problems + +| Problem | Cause and solution | +| --- | --- | +| `Could not load dynamic plugin myplugin from configured search paths (-S) nor with system lookup …` | The plugin manager found no file, or the file does not load. Check the file name `libfairmq-plugin-myplugin.so`, the directory in `-S` or `LD_LIBRARY_PATH`, and the name in `REGISTER_FAIRMQ_PLUGIN`. | +| `… is not a directory.` | A path of `-S` is a file. Give the directory. | +| `An error occurred while instantiating plugin myplugin: …` | The constructor of the plugin throws, for example `Config has no key: …` from `GetProperty()`. Give a fallback value, or check with `PropertyExists()` first. | +| `Plugin 'myplugin' is not allowed to change device states. Currently, plugin 'control' has taken control.` | The control plugin has the controller role. Take the role in the constructor, or start the device with `--control none`. | +| The device does not end after `EXITING`. | The plugin has the controller role. Call `ReleaseDeviceControl()` in `EXITING`. | +| The options of the plugin do nothing. | The device ignores unknown options. With `--severity debug`, it logs `detected unregistered option: …`. Check that the plugin loads. | +| An unsubscribe function throws `std::out_of_range`. | `UnsubscribeFromPropertyChange()` and `UnsubscribeFromPropertyChangeAsString()` need an existing subscription. Call them only after the subscription. | + +## Related pages + +- [Plugins and control](/concepts/plugins/): how plugins load, and the controller role. +- [Control a device from code](/guides/control-from-code/): a controller plugin step by step. +- [custom-controller](/examples/custom-controller/): a complete controller plugin. +- [Configuration and properties](/concepts/configuration/): the properties that a plugin reads and sets. diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx new file mode 100644 index 00000000..5f350ec9 --- /dev/null +++ b/docs/src/content/docs/index.mdx @@ -0,0 +1,24 @@ +--- +title: FairMQ +description: FairMQ is a C++17 message queuing library and framework for large-scale data processing. It connects processes through channels and moves data without a copy on one host. +template: splash +editUrl: false +lastUpdated: false +hero: + title: Message queuing for large-scale data processing + tagline: FairMQ connects processes through channels. Each process is a device with a state machine. On one host, the shared memory transport moves data without a copy. + actions: + - text: Get started + link: /FairMQ/start/first-device/ + variant: primary + - text: Read the concepts + link: /FairMQ/concepts/devices/ + variant: secondary +--- + +import HomePaths from '../../components/home/HomePaths.astro'; +import HomeCode from '../../components/home/HomeCode.astro'; + + + + diff --git a/docs/src/content/docs/project/contributing.mdx b/docs/src/content/docs/project/contributing.mdx new file mode 100644 index 00000000..5844db08 --- /dev/null +++ b/docs/src/content/docs/project/contributing.mdx @@ -0,0 +1,407 @@ +--- +title: 'Contributing' +description: 'Get the code, build and test FairMQ, follow the code style and the commit rules, send a pull request, and work on this documentation.' +sidebar: + order: 1 +--- + +import { Steps, FileTree } from '@astrojs/starlight/components'; +import Snippet from '../../../components/Snippet.astro'; + +FairMQ is developed on GitHub. This page tells you how to get the code, how to build and test it, and which rules your changes must follow. It also tells you how to report a problem and how to work on this documentation. + +## Repository and branches + +The repository is [FairRootGroup/FairMQ](https://github.com/FairRootGroup/FairMQ) on GitHub. + +| Branch or tag | Content | +| --- | --- | +| `dev` | The development branch. Send your pull requests to `dev`. | +| `master` | The latest release. It is the default branch on GitHub. | +| `v1.11.0`, `v1.10.1`, … | The releases. The release tags are on commits of `dev`. | + +The [release notes](/project/release-notes/) list the changes of each release and the changes on `dev` that are not released yet. + +## Get the code + +```sh +git clone -b dev https://github.com/FairRootGroup/FairMQ fairmq_source +``` + +Do not make a shallow clone. The build reads the version of FairMQ from the Git tags (see [Version](/reference/cmake/#version)). + +The bundled packages GoogleTest, PicoSHA2 and FairCMakeModules are Git submodules in `extern/`. The configure step gets the submodules that it needs with `git submodule update --init`. + +## Build and test + + + +1. Install the dependencies. See [Install](/start/install/). To install them with Spack, use the file `spack.yaml` of the repository: + + ```sh + spack --env fairmq_source install + spack env activate fairmq_source + ``` + +2. Configure a debug build with the tests: + + ```sh + cmake -S fairmq_source -B fairmq_build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON + ``` + +3. Build: + + ```sh + cmake --build fairmq_build + ``` + +4. Run all tests: + + ```sh + ctest --test-dir fairmq_build --output-on-failure --parallel "$(nproc)" + ``` + + + +The debug build compiles with `-Wshadow -Wall -Wextra -Wpedantic`. Your change must compile without warnings, because the CI job `static-analysis` fails on each warning. + +### Select tests + +The test suites are GoogleTest programs in `test/`: `Channel`, `Device`, `EventManager`, `MemoryResources`, `Message`, `Parts`, `Plugins`, `PluginServices`, `PluginsPrelinked`, `Poller`, `Properties`, `Protocols`, `Region`, `StateMachine`, `Tools` and `Transport`. CTest gives each test the name `.`, for example `Channel.ConnectedPeers.Pair/zeromq`. Many tests run once for each transport and have the transport in the name. The suite `Tools` tests the [helpers in fair::mq::tools](/reference/tools/). To test your own devices in your project, see [Test your devices](/guides/test-devices/). + +The examples add tests with names like `Example.1-1.zeromq` and `Example.builtin-devices.multipart.shmem`. + +The tests have no CTest labels. Select tests with a regular expression on the name: + +```sh +ctest --test-dir fairmq_build -R '^Channel\.' +ctest --test-dir fairmq_build -R 'shmem' +ctest --test-dir fairmq_build -R '^Example\.' +``` + +The first command runs the suite `Channel`. The second command runs all tests with `shmem` in the name. The third command runs the tests of the examples. + +Each suite is a program `test/testsuite_` in the build directory. CTest runs it in the build directory. To run some tests of a suite without CTest, give a GoogleTest filter: + +```sh +cd fairmq_build +test/testsuite_Channel --gtest_filter='ConnectedPeers.*' +``` + +CTest stops a test after its timeout: 20 s for most suites, 5 s for `Tools`, and 30 s for the tests of the examples. + +:::caution[Locked memory] +Some shared memory tests lock memory in RAM. For example, `Region.PreallocateInsideSession.shmem` locks two segments and two regions, 60 MB in total. If the limit for locked memory is lower, the test fails with `Could not lock the managed segment memory`. Show the limit with `ulimit -l`. The CI sets the limit to `unlimited` before it runs the tests. +::: + +### Sanitizers and static analysis + +The CI also builds FairMQ with sanitizers and with static analysis. Use the same settings to find problems before you send a change: + +- Address, leak and undefined behavior sanitizers, as the CI job `asan+lsan+ubsan`: + + ```sh + cmake -S fairmq_source -B build_asan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON \ + -DENABLE_SANITIZER_ADDRESS=ON -DENABLE_SANITIZER_LEAK=ON \ + -DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON -DFAIRMQ_DEBUG_MODE=ON \ + -DCMAKE_CXX_FLAGS="-O1 -fno-omit-frame-pointer" + ``` + +- Static analysis, as the CI job `static-analysis`. The build runs `clang-tidy` and `cpplint` on each file that it compiles, if CMake finds these programs. + + ```sh + cmake -S fairmq_source -B build_tidy -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON \ + -DRUN_STATIC_ANALYSIS=ON + ``` + +[CMake options and variables](/reference/cmake/) describes all sanitizer options and the static analysis options. + +## Add a test + +The tests are GoogleTest programs. `test/CMakeLists.txt` makes one program for each suite with the function `add_testsuite()` of [`cmake/GTestHelper.cmake`](https://github.com/FairRootGroup/FairMQ/blob/dev/cmake/GTestHelper.cmake). + + + +1. Write the tests in a source file in the folder of the suite, for example `test/poller/_poller.cxx`. Start the file with the license header. + +2. Add the file to the `SOURCES` of the suite in `test/CMakeLists.txt`. For a new suite, make a new folder and add a call of `add_testsuite()`. + +3. Configure with `-DBUILD_TESTING=ON`, and build. After the build, CMake runs the suite program and registers each of its tests in CTest (`gtest_discover_tests()`). + +4. Run the new tests with `ctest -R`. See [Run the new test](#run-the-new-test). + + + +This is the suite `Poller` in `test/CMakeLists.txt`: + + + +`${definitions}` and `${environment}` add the compile definitions and the test environment that `test/CMakeLists.txt` sets at the top of the file. + +### The arguments of add_testsuite() + +| Argument | What it does | +| --- | --- | +| `` | The name of the suite. The program is `test/testsuite_` in the build directory. CTest puts `.` in front of each test name. | +| `SOURCES …` | The source files. Add `${CMAKE_CURRENT_BINARY_DIR}/runner.cxx`. It contains the `main()` of the suite. | +| `LINKS …` | The libraries. The function adds `GTest::GTest`. The suites link `FairMQ`, the library target of the build. | +| `DEPENDS …` | Targets that CMake must build before the suite, for example `testhelper_runTestDevice`. | +| `INCLUDES …` | The include directories. The suites need `${CMAKE_CURRENT_SOURCE_DIR}` for `runner.h` and the headers in `test/helper/`, and `${CMAKE_CURRENT_BINARY_DIR}` for the generated `TestEnvironment.h`. | +| `DEFINITIONS …` | Compile definitions. | +| `ENVIRONMENT =:…` | Changes to the environment of each test, in the format of the CTest property `ENVIRONMENT_MODIFICATION`. CMake older than 3.22 ignores this argument. | +| `TIMEOUT ` | The CTest timeout of each test. The default is 10 s. Most suites set 20 s. | +| `RUN_SERIAL ` | `ON`: CTest runs no other test at the same time as a test of this suite. The default is `OFF`. No suite sets it at the moment. | + +`add_testhelper( …)` makes the program `testhelper_`, which is not a test. It takes `SOURCES`, `LINKS`, `DEPENDS`, `INCLUDES` and `DEFINITIONS`. `add_testlib( …)` makes a shared library. It takes the same arguments, and also `HIDDEN` (hidden symbol visibility) and `VERSION`. The suite `Plugins` uses two of these libraries as plugins. + +### Run a test for each transport + +The header `test/helper/TransportParam.h` makes a GoogleTest test run once for each transport. Write the test with `TEST_P()` for the fixture `TransportTest`. Then give the transports to `INSTANTIATE_TEST_SUITE_P()`: + + + +| Values | Transports | Test name suffix | +| --- | --- | --- | +| `AllTransports()` | `zeromq`, `shmem`, and `shmem` with `--shm-metadata-msg-size 2048` | `/zeromq`, `/shmem`, `/shmem_expanded_metadata` | +| `BasicTransports()` | `zeromq` and `shmem` | `/zeromq`, `/shmem` | +| `ShmTransports()` | `shmem`, and `shmem` with `--shm-metadata-msg-size 2048` | `/shmem`, `/shmem_expanded_metadata` | +| `testing::Values(TransportParam("zeromq"))` | `zeromq` only | `/zeromq` | + +`TransportParamName()` gives the suffix. `GetParam().transport` is the name of the transport. `GetParam().DeviceArgs()` gives the extra command-line options of a device process for this parameter. For example, the suite `Poller` has the tests `Poller.Poller.Subchannel/zeromq` and `Poller.Poller.Channel/shmem_expanded_metadata`. + +### Tests with device processes + +`RunDevices()` of `test/helper/Devices.h` starts one process of `testhelper_runTestDevice` for each `DeviceSpec`. All processes get the same new session and the transport of `RunOptions`. The default control mode is `static`. The function waits for all processes. It kills a process that runs longer than `RunOptions::timeout`, by default 15 s. + +The prefix of the device ID selects the device class, in `getDevice()` of `test/helper/runTestDevice.cxx`. For example, `push_zeromq` starts the class `Push`. A test device derives from `TestDevice` (`test/helper/devices/TestDevice.h`). At the end of its test, it calls `Succeed()`, which logs `test device succeeded, transport: ` and the transport name. `Succeeded()` checks the exit code 0 and this log line. + +To add a test device: + + + +1. Write a header `test/helper/devices/Test.h` with a class that derives from `TestDevice`. + +2. Include the header in `test/helper/runTestDevice.cxx`. In `getDevice()`, return your class for a new ID prefix. + +3. Add the header to the `SOURCES` of `add_testhelper(runTestDevice …)` in `test/CMakeLists.txt`. + +4. Give your suite the argument `DEPENDS testhelper_runTestDevice`. + + + +### Run the new test + +Build, and run the suite with CTest: + +```sh +cmake --build fairmq_build +ctest --test-dir fairmq_build -R '^Poller\.' --output-on-failure +``` + +To see the test names without running the tests, add `-N`. To run the tests of one transport, select the suffix, for example `-R '^Poller\..*/shmem$'`. To run the program directly, see [Select tests](#select-tests). + +## Add an example + +Each example is a folder in `examples/`. Most examples use the function `add_example()` of [`examples/CMakeLists.txt`](https://github.com/FairRootGroup/FairMQ/blob/dev/examples/CMakeLists.txt). It builds the devices, writes the scripts, registers the tests, and installs the programs and the start scripts. The examples `custom-controller`, `dds`, `n-m` and `qc` have their own CMake code. + +Example 1-1 has these files: + + + +- examples/ + - CMakeLists.txt calls add_subdirectory(1-1) + - 1-1/ + - CMakeLists.txt + - sampler.cxx + - sink.cxx + - fairmq-start-ex-1-1.sh.in the start script + - test-ex-1-1.sh.in the test script + - README.md + + + + + +1. Make a folder `examples//`. + +2. Write a file `.cxx` for each device, with `fairmq/runDevice.h`. See `examples/1-1/sampler.cxx`. The test script needs devices that stop by themselves. The devices of example 1-1 have the option `--max-iterations` for this. + +3. Write `examples//CMakeLists.txt` with a call of `add_example()`. Example 1-1 has this call: + + + +4. Write the start script `fairmq-start-ex-.sh.in` and the test script `test-ex-.sh.in`. See [The scripts](#the-scripts). + +5. Add `add_subdirectory()` to `examples/CMakeLists.txt`. + +6. Configure with `-DBUILD_TESTING=ON`. `BUILD_EXAMPLES` is `ON` by default. Build, and run the tests of the example: + + ```sh + ctest --test-dir fairmq_build -R '^Example\.\.' --output-on-failure + ``` + + + +### The arguments of add_example() + +| Argument | What it does | +| --- | --- | +| `NAME ` | Required. The name of the example. Without it, CMake stops with `NAME arg is required`. | +| `DEVICE …` | For each device, the program `fairmq-ex--` from the file `.cxx`, linked to `FairMQ`. | +| `SCRIPT diff --git a/docs/src/pages/api/[...slug].astro b/docs/src/pages/api/[...slug].astro new file mode 100644 index 00000000..9d26f6a6 --- /dev/null +++ b/docs/src/pages/api/[...slug].astro @@ -0,0 +1,365 @@ +--- +// API pages: one page for each public class, struct, union, namespace and namespace enum. +import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; +import { getCollection } from 'astro:content'; +import Member from '../../components/api/Member.astro'; +import CopyButton from '../../components/CopyButton.astro'; +import { model, base, apiSidebar, githubUrl, guidesForFile, noBase } from '../../lib/model.mjs'; +import { family, FAMILY_ORDER } from '../../lib/families.mjs'; +import '../../styles/api.css'; + +export function getStaticPaths() { + const m = model(); + const slug = (url: string) => noBase(url).replace(/^\/api\//, '').replace(/\/$/, ''); + return [ + ...m.types().map((t: any) => ({ params: { slug: slug(t.url) }, props: { kind: 'type', id: t.id } })), + ...m.namespaces().map((ns: any) => ({ params: { slug: slug(ns.url) }, props: { kind: 'namespace', id: ns.id } })), + ...m.namespaceEnums().map(({ e }: any) => ({ params: { slug: slug(e.page) }, props: { kind: 'enum', id: e.id } })), + ]; +} + +const { kind, id } = Astro.props; +const m = model(); +const docs = await getCollection('docs'); +const strip = (html: string) => html.replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim(); + +const SECTION_ORDER: [string, string][] = [ + ['public-type', 'Types'], + ['public-func', 'Functions'], + ['public-static-func', 'Static functions'], + ['public-static-attrib', 'Static data members'], + ['public-attrib', 'Data members'], + ['protected-type', 'Protected types'], + ['protected-func', 'Protected functions'], + ['protected-static-func', 'Protected static functions'], + ['protected-static-attrib', 'Protected static data members'], + ['protected-attrib', 'Protected data members'], + ['friend', 'Friends'], + ['related', 'Related functions'], +]; +const NS_SECTIONS: [string, string][] = [ + ['typedef', 'Type aliases'], + ['func', 'Functions'], + ['var', 'Variables'], +]; + +const slugify = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, ''); + +let page: any; +if (kind === 'type') { + const rec = m.compounds.get(id); + const sections = SECTION_ORDER.map(([key, label]) => ({ + id: slugify(label), + label, + members: rec.visible.filter((x: any) => x.section === key), + })).filter((s) => s.members.length > 0); + const known = new Set(SECTION_ORDER.map(([k]) => k)); + const otherMembers = rec.visible.filter((x: any) => !known.has(x.section)); + if (otherMembers.length) sections.push({ id: 'other-members', label: 'Other members', members: otherMembers }); + const nested = rec.inner.map((i: string) => m.compounds.get(i)).filter((c: any) => c && c.public); + const headings: any[] = []; + if (nested.length) headings.push({ depth: 2, slug: 'nested-types', text: 'Nested types' }); + for (const s of sections) { + headings.push({ depth: 2, slug: s.id, text: s.label }); + for (const x of s.members) if (x.overload === 1) headings.push({ depth: 3, slug: x.anchor, text: x.name }); + } + const families = new Map(); + for (const x of rec.visible) { + const f = family(x, rec); + families.set(f, (families.get(f) ?? 0) + 1); + } + page = { + rec, + title: rec.short, + titleKind: rec.templ ? `${rec.kind} template` : rec.kind, + eyebrow: `API · ${rec.scope}`, + searchTitle: rec.name, + file: rec.file, + line: rec.line, + include: rec.include, + sections, + nested, + headings, + families: FAMILY_ORDER.filter((f) => families.has(f)).map((f) => [f, families.get(f)]), + total: rec.visible.length, + }; +} else if (kind === 'namespace') { + const rec = m.compounds.get(id); + const types = m + .types() + .filter((t: any) => t.scope === rec.name) + .sort((a: any, b: any) => a.short.localeCompare(b.short, 'en', { sensitivity: 'base' })); + const enums = rec.visible.filter((x: any) => x.kind === 'enum'); + const sections = NS_SECTIONS.map(([key, label]) => ({ + id: slugify(label), + label, + members: rec.visible.filter((x: any) => x.section === key && x.kind !== 'enum'), + })).filter((s) => s.members.length > 0); + const subs = rec.innerNamespaces.map((i: string) => m.compounds.get(i)).filter((c: any) => c && c.public); + const headings: any[] = []; + if (subs.length) headings.push({ depth: 2, slug: 'namespaces', text: 'Namespaces' }); + if (types.length) headings.push({ depth: 2, slug: 'types', text: 'Classes and structs' }); + if (enums.length) headings.push({ depth: 2, slug: 'enums', text: 'Enums' }); + for (const s of sections) { + headings.push({ depth: 2, slug: s.id, text: s.label }); + for (const x of s.members) if (x.overload === 1) headings.push({ depth: 3, slug: x.anchor, text: x.name }); + } + page = { rec, title: rec.name, titleKind: 'namespace', eyebrow: 'API', searchTitle: rec.name, types, enums, sections, subs, headings }; +} else { + const e = m.members.get(id); + const ns = m.compounds.get(e.owner); + page = { + e, + ns, + title: e.name, + titleKind: e.strong ? 'enum class' : 'enum', + eyebrow: `API · ${ns.name}`, + searchTitle: e.qualified, + file: e.file, + line: e.line, + include: m.publicHeaders.has(e.file) ? e.file : null, + headings: [{ depth: 2, slug: 'values', text: 'Values' }], + }; +} + +const descRec = page.rec ?? page.e; +const description = strip(descRec.brief || '') || `${page.titleKind} ${page.searchTitle}`; +const guides = page.file ? guidesForFile(docs, page.file) : []; +const srcHref = page.file ? `${base}/source/${page.file}/#L${page.line}` : null; +--- + + + { + page.file && ( +
    + {page.include && ( + + #include <{page.include}> + `} label="Copy the include line" /> + + )} + + {page.file}:{page.line} + + GitHub ↗ +
    + ) + } + + { + kind === 'type' && ( + <> + {page.rec.templ && ( +
    +            ${page.rec.kind} ${page.rec.short}`} />
    +          
    + )} + {(page.rec.bases.length > 0 || page.rec.derived.length > 0) && ( +
    + {page.rec.bases.length > 0 && ( + <> +
    Inherits from
    +
    `${b.html}`).join(', ')} /> + + )} + {page.rec.derived.length > 0 && ( + <> +
    Inherited by
    +
    `${b.html}`).join(', ')} /> + + )} +
    + )} + {page.rec.brief &&

    } + {page.rec.detail &&

    } + {!page.rec.documented &&

    No comment in the header yet.

    } + + {page.nested.length > 0 && ( + <> +

    Nested types

    +
      + {page.nested.map((c: any) => ( +
    • + + {c.short} + + {c.kind} + {c.brief && } +
    • + ))} +
    + + )} + + {page.total > 10 && ( +
    + +
    + + {page.families.map(([f, n]: any) => ( + + ))} +
    +

    +

    + )} + + {page.sections.map((s: any) => ( +
    +

    {s.label}

    + {s.members.map((x: any) => ( + + ))} +
    + ))} + + ) + } + + { + kind === 'namespace' && ( + <> + {page.rec.brief &&

    } + {page.rec.detail &&

    } + {page.subs.length > 0 && ( + <> +

    Namespaces

    + + + )} + {page.types.length > 0 && ( + <> +

    Classes and structs

    +
      + {page.types.map((c: any) => ( +
    • + + {c.short} + + {c.kind} + {c.brief && } +
    • + ))} +
    + + )} + {page.enums.length > 0 && ( + <> +

    Enums

    +
      + {page.enums.map((e: any) => ( +
    • + + {e.name} + + {e.strong ? 'enum class' : 'enum'} + {e.brief && } +
    • + ))} +
    + + )} + {page.sections.map((s: any) => ( +
    +

    {s.label}

    + {s.members.map((x: any) => ( + + ))} +
    + ))} + + ) + } + + { + kind === 'enum' && ( + <> +
    +          
    +        
    + {page.e.brief &&

    } + {page.e.detail &&

    } +

    Values

    +
    + + + + + + + + + + {page.e.values.map((v: any) => ( + + + + + ))} + +
    EnumeratorValueDescription
    + {v.name} + {v.init ? {v.init} : —}—'} /> +
    +
    + + ) + } + + + diff --git a/docs/src/pages/api/index.astro b/docs/src/pages/api/index.astro new file mode 100644 index 00000000..a34d5ec4 --- /dev/null +++ b/docs/src/pages/api/index.astro @@ -0,0 +1,64 @@ +--- +// API overview: the public namespaces with their types and enums. +import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; +import { model, base, apiSidebar } from '../../lib/model.mjs'; +import '../../styles/api.css'; + +const m = model(); +const namespaces = m.namespaces().sort((a: any, b: any) => a.name.localeCompare(b.name)); +const groups = namespaces + .map((ns: any) => ({ + ns, + id: ns.name.replace(/::/g, '-'), + types: m + .types() + .filter((t: any) => t.scope === ns.name) + .sort((a: any, b: any) => a.short.localeCompare(b.short, 'en', { sensitivity: 'base' })), + enums: ns.visible.filter((x: any) => x.kind === 'enum'), + })) + .filter((g: any) => g.types.length || g.enums.length); +const count = m.types().length; +--- + + ({ depth: 2, slug: g.id, text: g.ns.name }))} +> +

    + These pages show the {count} public types of FairMQ and their members. Doxygen reads the installed headers at each + build of this site, so the signatures are always current. The text comes from the comments in the headers. +

    +

    + Each member links to its line in the source browser. Use the search (Ctrl K) + to find a class or a member by name. +

    + { + groups.map((g: any) => ( + <> +

    + + {g.ns.name} + +

    +
      + {[...g.types, ...g.enums.map((e: any) => ({ ...e, short: e.name, url: e.page, kind: e.strong ? 'enum class' : 'enum' }))] + .sort((a: any, b: any) => a.short.localeCompare(b.short, 'en', { sensitivity: 'base' })) + .map((c: any) => ( +
    • + + {c.short} + + {c.kind} + {c.brief ? : No comment yet.} +
    • + ))} +
    + + )) + } +
    diff --git a/docs/src/pages/source/[...path].astro b/docs/src/pages/source/[...path].astro new file mode 100644 index 00000000..aa0bf0a3 --- /dev/null +++ b/docs/src/pages/source/[...path].astro @@ -0,0 +1,142 @@ +--- +// Source browser: one page for each C++ file in fairmq/. +import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; +import { getCollection } from 'astro:content'; +import { paths } from 'virtual:fairmq/data'; +import { model, base, codeTheme, sourceSidebar, githubUrl, guidesForFile } from '../../lib/model.mjs'; +import { renderSourceFile } from '../../../scripts/source.mjs'; +import '../../styles/source.css'; + +export function getStaticPaths() { + return model().sourceFiles.map((f: string) => ({ params: { path: f } })); +} + +const file = Astro.params.path as string; +const m = model(); +const out = await renderSourceFile(m, file, { theme: codeTheme(), repoRoot: paths.repoRoot }); +const fileRec = m.files.get(file); +const defined = (fileRec?.defines ?? []).filter((c: any) => c.public); +const isPublic = m.publicHeaders.has(file); +const docs = await getCollection('docs'); +const guides = guidesForFile(docs, file); +const name = file.split('/').pop(); +--- + + + { + defined.length > 0 && ( +

    + Defines {defined.map((c: any) => `${c.kind} ${c.name}`).join(', ')}. +

    + ) + } + { + guides.length > 0 && ( +

    + Described in{' '} + {guides.map((g: any, i: number) => ( + <> + {i > 0 && ', '} + {g.label} + + ))} + . +

    + ) + } +
    + {file} + {out.lines} lines · C++ + + { + defined.map((c: any) => ( + + API: {c.short} + + )) + } + GitHub ↗ + +
    +
    +
    + +
    + diff --git a/docs/src/pages/source/index.astro b/docs/src/pages/source/index.astro new file mode 100644 index 00000000..2888bec5 --- /dev/null +++ b/docs/src/pages/source/index.astro @@ -0,0 +1,67 @@ +--- +// Source browser overview: all C++ files in fairmq/, by directory. +import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; +import { readFileSync } from 'node:fs'; +import path from 'node:path'; +import { paths } from 'virtual:fairmq/data'; +import { model, base, sourceSidebar } from '../../lib/model.mjs'; +import '../../styles/source.css'; + +const m = model(); +const dirs = new Map(); +let total = 0; +for (const f of m.sourceFiles) { + const dir = path.posix.dirname(f); + const lines = readFileSync(path.join(paths.repoRoot, f), 'utf8').replace(/\n$/, '').split('\n').length; + total += lines; + const defined = (m.files.get(f)?.defines ?? []).filter((c: any) => c.public); + if (!dirs.has(dir)) dirs.set(dir, []); + dirs.get(dir)!.push({ f, name: path.posix.basename(f), lines, defined, pub: m.publicHeaders.has(f) }); +} +const id = (d: string) => d.replace(/\//g, '-'); +--- + + ({ depth: 2, slug: id(d), text: `${d}/` }))} +> +

    + Every C++ file of fairmq/ as a page: {m.sourceFiles.length} files with {total.toLocaleString('en')} lines. + Doxygen finds the symbols. A symbol links to its API page, or to the line where it is defined. +

    +

    + Each line has an anchor, for example Channel.h/#L36. Shift-click a + second line number to mark a range. A public header is installed with FairMQ. +

    + { + [...dirs].map(([dir, list]) => ( + <> +

    + {dir}/ +

    +
      + {list.map((x) => ( +
    • + + {x.name} + + {x.lines} + + {x.pub && public} + {x.defined.slice(0, 4).map((c: any) => ( + {c.short} + ))} + {x.defined.length > 4 && +{x.defined.length - 4}} + +
    • + ))} +
    + + )) + } +
    diff --git a/docs/src/styles/api.css b/docs/src/styles/api.css new file mode 100644 index 00000000..1120ef7e --- /dev/null +++ b/docs/src/styles/api.css @@ -0,0 +1,323 @@ +/* API reference pages. */ + +.api-meta { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.5rem 1.25rem; + font: 500 0.8125rem/1.4 var(--fmq-font-mono); + margin-top: 0.25rem; +} +.api-meta a { + color: var(--fmq-link); +} +.api-inc { + display: inline-flex; + align-items: center; + gap: 0.5rem; + border: 1px solid var(--fmq-rule); + background: var(--fmq-paper-2); + border-radius: 4px; + padding: 0.2rem 0.25rem 0.2rem 0.6rem; +} +.sl-markdown-content .api-inc code { + background: none; + border: 0; + padding: 0; + font-size: 0.8125rem; + color: var(--fmq-ink); +} + +.sl-markdown-content .api-lead { + font-size: 1.125rem; + line-height: 1.55; + color: var(--fmq-ink-2); + max-width: 64ch; +} + +.api-rel { + display: grid; + grid-template-columns: max-content minmax(0, 1fr); + gap: 0.25rem 1rem; + font-size: 0.9375rem; +} +.sl-markdown-content .api-rel dt { + font: 600 0.7rem/1.9 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--fmq-ink-3); +} +.sl-markdown-content .api-rel dd { + margin: 0; + padding: 0; +} +.sl-markdown-content .api-rel :is(dt, dd) { + margin-top: 0 !important; +} + +/* Filter */ +.api-filter { + position: sticky; + top: calc(var(--sl-nav-height) + var(--sl-mobile-toc-height)); + z-index: 2; + background: var(--fmq-paper); + border-bottom: 1px solid var(--fmq-rule); + padding: 0.75rem 0 0.6rem; + margin-top: 1.5rem; +} +.api-filter input { + width: min(100%, 20rem); + font: 400 0.9375rem var(--fmq-font-body); + color: var(--fmq-ink); + background: var(--fmq-paper-2); + border: 1px solid var(--fmq-rule-strong); + border-radius: 4px; + padding: 0.4rem 0.6rem; +} +.api-chips { + display: flex; + flex-wrap: wrap; + gap: 0.35rem; + margin-top: 0.5rem !important; +} +.api-chips button { + font: 500 0.8125rem/1 var(--fmq-font-body); + border: 1px solid var(--fmq-rule-strong); + border-radius: 3px; + background: var(--fmq-paper); + color: var(--fmq-ink-2); + padding: 0.35rem 0.55rem; + cursor: pointer; +} +.api-chips button b { + font: 500 0.75rem var(--fmq-font-mono); + color: var(--fmq-ink-3); + margin-inline-start: 0.2rem; +} +.api-chips button:hover { + border-color: var(--fmq-ink-3); + color: var(--fmq-ink); +} +.api-chips button[aria-pressed='true'] { + background: var(--fmq-saffron-tint); + border-color: var(--fmq-bar); + color: var(--fmq-ink); +} +.api-count { + font-size: 0.8125rem; + color: var(--fmq-ink-3); + min-height: 1.2em; + margin: 0.4rem 0 0 !important; +} + +/* Sections and members */ +.sl-markdown-content .api-sec > h2 { + font-size: 1.375rem; + margin-top: 2.25rem; + padding-bottom: 0.4rem; + border-bottom: 1px solid var(--fmq-rule-strong); +} +.mem { + border-bottom: 1px solid var(--fmq-rule); + padding: 1rem 0 1.1rem; + scroll-margin-top: 9rem; +} +.sl-markdown-content .mem > * + * { + margin-top: 0.55rem; +} +.mem-h { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.35rem 0.6rem; +} +.sl-markdown-content .mem-name { + font: 700 1.0625rem/1.3 var(--fmq-font-mono); + margin: 0; + letter-spacing: -0.01em; + scroll-margin-top: 10rem; +} +.sl-markdown-content .mem-name a { + color: var(--fmq-ink); + text-decoration: none; +} +.sl-markdown-content .mem-name a:hover { + text-decoration: underline; +} +.mem-src { + margin-inline-start: auto; + font: 500 0.75rem var(--fmq-font-mono); +} +.sl-markdown-content a.mem-src { + color: var(--fmq-ink-3); +} +.sl-markdown-content a.mem-src:hover { + color: var(--fmq-link); +} +.sl-markdown-content pre.mem-sig { + margin: 0.5rem 0 0; + padding: 0.6rem 0.85rem; + border: 1px solid var(--fmq-rule); + border-radius: 4px; + background: var(--fmq-paper-2); + font: 400 0.8125rem/1.6 var(--fmq-font-mono); + color: var(--fmq-ink); + white-space: pre-wrap; + overflow-wrap: anywhere; + overflow-x: auto; +} +.sl-markdown-content pre.mem-sig code { + all: unset; + font: inherit; +} +.mem-sig .k { + color: var(--fmq-accent-ink); +} +.mem-sig b { + font-weight: 700; + color: var(--fmq-ink); +} +.mem-sig a { + color: var(--fmq-link); + text-decoration: none; +} +.mem-sig a:hover { + text-decoration: underline; +} +.api-templ { + margin-top: 0.75rem !important; +} +.mem-brief, +.mem-detail p { + max-width: 70ch; +} +.sl-markdown-content .mem-params { + display: grid; + grid-template-columns: max-content minmax(0, 1fr); + gap: 0.3rem 1rem; + font-size: 0.9375rem; + border-inline-start: 2px solid var(--fmq-rule); + padding-inline-start: 0.9rem; +} +.sl-markdown-content .mem-params dt, +.sl-markdown-content .mem-params dd { + margin: 0 !important; + padding: 0; + /* Long words like MessagePtr/Parts/vector must wrap on phones. */ + overflow-wrap: anywhere; +} +.sl-markdown-content .mem-params dt { + font-weight: 500; +} +.mem-params dt.mem-ret { + font: 600 0.7rem/2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--fmq-ink-3); +} +.mem-pk { + font: 500 0.6875rem var(--fmq-font-body); + color: var(--fmq-ink-3); + margin-inline-start: 0.35rem; +} +.mem-none { + font-size: 0.875rem; + color: var(--fmq-ink-3); + font-style: italic; +} +.mem-see { + font-size: 0.9375rem; +} +.muted { + color: var(--fmq-ink-3); +} + +/* Lists of types */ +.sl-markdown-content ul.api-list { + list-style: none; + padding: 0; + border-top: 1px solid var(--fmq-rule); +} +.sl-markdown-content ul.api-list > li { + display: grid; + grid-template-columns: minmax(10rem, max-content) max-content minmax(0, 1fr); + gap: 0.25rem 0.75rem; + align-items: baseline; + padding: 0.5rem 0; + border-bottom: 1px solid var(--fmq-rule); + margin: 0 !important; +} +.sl-markdown-content ul.api-list > li::before { + display: none; +} +.sl-markdown-content ul.api-list code { + background: none; + border: 0; + padding: 0; + font-size: 0.875rem; + font-weight: 600; +} +.api-list-brief { + font-size: 0.9375rem; + color: var(--fmq-ink-2); +} +@media (max-width: 40rem) { + .sl-markdown-content ul.api-list > li { + grid-template-columns: max-content minmax(0, 1fr); + } + .api-list-brief { + grid-column: 1 / -1; + } +} + +/* Tables and asides from header comments */ +.doc-table { + overflow-x: auto; +} +.sl-markdown-content .enum-values td:first-child code { + font-weight: 600; +} +.sl-markdown-content .enum-values tr:target { + background: var(--fmq-saffron-tint); +} +.doc-aside { + border: 1px solid var(--fmq-rule); + border-inline-start: 3px solid var(--fmq-sky); + background: var(--fmq-paper-2); + border-radius: 4px; + padding: 0.6rem 0.85rem; + font-size: 0.9375rem; +} +.doc-aside.caution { + border-inline-start-color: var(--fmq-ruby); +} +.doc-aside > b { + display: block; + font: 600 0.7rem/1.4 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--fmq-ink-2); + margin-bottom: 0.25rem; +} +.doc-aside > p { + margin: 0; +} +.sl-markdown-content pre.doc-code { + background: var(--fmq-code-bg); + color: var(--fmq-code-ink); + border: 1px solid var(--fmq-code-rule); + border-radius: 4px; + padding: 0.6rem 0.85rem; + font: 400 0.8125rem/1.6 var(--fmq-font-mono); + overflow-x: auto; +} +.doc-h { + font-weight: 650; +} +.mem[hidden], +.api-sec[hidden] { + display: none; +} diff --git a/docs/src/styles/code-theme.json b/docs/src/styles/code-theme.json new file mode 100644 index 00000000..ffa85aa7 --- /dev/null +++ b/docs/src/styles/code-theme.json @@ -0,0 +1,39 @@ +{ + "name": "fairmq-night", + "type": "dark", + "colors": { + "editor.background": "#22262d", + "editor.foreground": "#e6e8ec", + "editorLineNumber.foreground": "#7d8594", + "editorLineNumber.activeForeground": "#fabe5d", + "editor.selectionBackground": "#3a4150", + "editorGroupHeader.tabsBackground": "#22262d", + "tab.activeBackground": "#22262d", + "tab.activeForeground": "#e6e8ec", + "tab.inactiveForeground": "#9aa1ad", + "tab.activeBorderTop": "#fabe5d", + "titleBar.activeBackground": "#22262d", + "titleBar.activeForeground": "#e6e8ec", + "titleBar.border": "#353a44", + "panel.border": "#353a44" + }, + "tokenColors": [ + { "scope": ["source", "variable", "variable.other", "variable.parameter", "meta.block", "meta.function-call"], "settings": { "foreground": "#e6e8ec" } }, + { "scope": ["comment", "punctuation.definition.comment", "comment.block.documentation"], "settings": { "foreground": "#8d96a5", "fontStyle": "italic" } }, + { "scope": ["keyword", "keyword.control", "keyword.other", "storage", "storage.type", "storage.modifier", "keyword.operator.new", "keyword.operator.delete", "keyword.operator.sizeof", "keyword.operator.cast", "keyword.operator.alignof", "keyword.operator.noexcept", "constant.language.this", "variable.language.this"], "settings": { "foreground": "#fabe5d" } }, + { "scope": ["entity.name.type", "entity.name.class", "entity.name.struct", "entity.name.namespace", "entity.name.scope-resolution", "support.type", "support.class", "entity.other.inherited-class", "storage.type.class.std", "entity.name.type.template", "support.type.property-name.json", "support.type.property-name"], "settings": { "foreground": "#8cc8ef" } }, + { "scope": ["entity.name.function", "support.function", "meta.function-call entity.name.function", "entity.name.function.preprocessor"], "settings": { "foreground": "#ffffff", "fontStyle": "bold" } }, + { "scope": ["string", "string.quoted", "punctuation.definition.string", "string.unquoted"], "settings": { "foreground": "#a8d99b" } }, + { "scope": ["constant.numeric", "constant.language", "constant.character", "constant.other", "keyword.other.unit"], "settings": { "foreground": "#f4a597" } }, + { "scope": ["meta.preprocessor", "keyword.control.directive", "punctuation.definition.directive", "meta.preprocessor.include", "keyword.control.import"], "settings": { "foreground": "#e5b3d3" } }, + { "scope": ["meta.preprocessor.include string", "string.quoted.other.lt-gt.include"], "settings": { "foreground": "#a8d99b" } }, + { "scope": ["punctuation", "keyword.operator", "meta.brace", "punctuation.separator", "punctuation.terminator"], "settings": { "foreground": "#c3c8d1" } }, + { "scope": ["support.function.builtin.shell", "entity.name.command.shell", "support.function.builtin"], "settings": { "foreground": "#ffffff", "fontStyle": "bold" } }, + { "scope": ["variable.other.normal.shell", "variable.other.special.shell", "punctuation.definition.variable.shell"], "settings": { "foreground": "#f4a597" } }, + { "scope": ["constant.other.option", "constant.other.option.dash.shell"], "settings": { "foreground": "#8cc8ef" } }, + { "scope": ["markup.heading", "entity.name.section"], "settings": { "foreground": "#fabe5d", "fontStyle": "bold" } }, + { "scope": ["markup.bold"], "settings": { "fontStyle": "bold" } }, + { "scope": ["markup.italic"], "settings": { "fontStyle": "italic" } }, + { "scope": ["invalid"], "settings": { "foreground": "#f4a597" } } + ] +} diff --git a/docs/src/styles/source.css b/docs/src/styles/source.css new file mode 100644 index 00000000..9b8e4088 --- /dev/null +++ b/docs/src/styles/source.css @@ -0,0 +1,201 @@ +/* Source browser pages. */ + +.src-head { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.4rem 1rem; + margin-top: 0.5rem; + padding: 0.55rem 0.75rem; + border: 1px solid var(--fmq-code-rule); + border-bottom: 0; + border-radius: 6px 6px 0 0; + background: var(--fmq-code-bg); + color: var(--fmq-code-ink); + font: 500 0.8125rem/1.3 var(--fmq-font-mono); +} +.src-path { + color: var(--fmq-code-ink); + font-weight: 600; +} +.src-info { + color: var(--fmq-code-dim); +} +.src-acts { + display: flex; + flex-wrap: wrap; + gap: 0.35rem; + margin-inline-start: auto; +} +.src-head .fmq-badge { + color: var(--fmq-code-ink); + border-color: var(--fmq-stage-line); +} +.src-head .fmq-badge.mark { + color: var(--fmq-saffron); + border-color: var(--fmq-saffron); +} +.src-head .fmq-badge:hover { + border-color: var(--fmq-code-ink); +} +.src-defines, +.src-guides { + font-size: 0.875rem; + color: var(--fmq-ink-2); +} +.sl-markdown-content .src-head + .src-code, +.src-head + .src-code { + margin-top: 0 !important; +} + +.src-code { + position: relative; + border: 1px solid var(--fmq-code-rule); + border-radius: 0 0 6px 6px; + background: var(--fmq-code-bg); + overflow-x: auto; + margin-top: 0 !important; +} +.src-code pre { + margin: 0; + padding: 0.6rem 0; + font: 400 0.8125rem/1.6 var(--fmq-font-mono); + color: var(--fmq-code-ink); + tab-size: 4; + background: none; + border: 0; + min-width: max-content; +} +.src-code code { + font: inherit; + background: none; + border: 0; + padding: 0; +} +.src-code .row { + display: block; + padding-inline-end: 1rem; + scroll-margin-top: 8rem; +} +.src-code .row:target, +.src-code .row.hl { + background: rgb(250 190 93 / 0.14); + box-shadow: inset 3px 0 0 var(--fmq-saffron); +} +.src-code .ln { + display: inline-block; + width: 4.5ch; + margin-inline-end: 1.25ch; + padding-inline-end: 0.5ch; + text-align: end; + color: #6b7380; + text-decoration: none; + user-select: none; +} +.src-code .ln:hover { + color: var(--fmq-saffron); +} +.src-code .lc { + white-space: pre; +} +.src-code .t-k { color: var(--fmq-c-kw); } +.src-code .t-t { color: var(--fmq-c-type); } +.src-code .t-f { color: var(--fmq-c-fn); font-weight: 600; } +.src-code .t-s { color: var(--fmq-c-str); } +.src-code .t-n { color: var(--fmq-c-num); } +.src-code .t-c { color: var(--fmq-c-com); font-style: italic; } +.src-code .t-p { color: var(--fmq-c-pre); } +.src-code .t-o { color: var(--fmq-c-op); } +.src-code a.sym { + color: inherit; + text-decoration: underline; + text-decoration-color: rgb(140 200 239 / 0.45); + text-decoration-thickness: 1px; + text-underline-offset: 3px; +} +.src-code a.sym:hover, +.src-code a.sym:focus-visible { + text-decoration-color: var(--fmq-saffron); + background: rgb(250 190 93 / 0.12); + outline: none; +} + +.src-card { + position: absolute; + z-index: 5; + max-width: min(36rem, calc(100% - 16px)); + display: grid; + gap: 0.2rem; + padding: 0.6rem 0.75rem; + border: 1px solid var(--fmq-stage-line); + border-radius: 4px; + background: var(--fmq-stage-2); + color: var(--fmq-stage-ink); + box-shadow: 0 10px 30px -12px rgb(0 0 0 / 0.7); + font: 400 0.75rem/1.45 var(--fmq-font-mono); + pointer-events: none; +} +.src-card .k { + font: 600 0.625rem/1.2 var(--fmq-font-body); + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--fmq-stage-dim); +} +.src-card b { + font-weight: 700; + color: #fff; + overflow-wrap: anywhere; +} +.src-card code { + color: var(--fmq-c-type); + white-space: pre-wrap; + overflow-wrap: anywhere; +} +.src-card .l { + color: var(--fmq-saffron); +} + +/* Overview */ +.sl-markdown-content ul.src-list { + list-style: none; + padding: 0; + border-top: 1px solid var(--fmq-rule); +} +.sl-markdown-content ul.src-list > li { + display: grid; + grid-template-columns: minmax(12rem, max-content) 4rem minmax(0, 1fr); + gap: 0.25rem 1rem; + align-items: baseline; + padding: 0.4rem 0; + border-bottom: 1px solid var(--fmq-rule); + margin: 0 !important; +} +.sl-markdown-content ul.src-list > li::before { + display: none; +} +.sl-markdown-content ul.src-list code { + background: none; + border: 0; + padding: 0; + font-size: 0.875rem; +} +.src-lines { + font: 500 0.75rem var(--fmq-font-mono); + color: var(--fmq-ink-3); + text-align: end; + font-variant-numeric: tabular-nums; +} +.src-meta { + display: flex; + flex-wrap: wrap; + gap: 0.2rem 0.6rem; + font-size: 0.875rem; +} +@media (max-width: 40rem) { + .sl-markdown-content ul.src-list > li { + grid-template-columns: minmax(0, 1fr) max-content; + } + .src-meta { + grid-column: 1 / -1; + } +} diff --git a/docs/src/styles/theme.css b/docs/src/styles/theme.css new file mode 100644 index 00000000..ffc3e332 --- /dev/null +++ b/docs/src/styles/theme.css @@ -0,0 +1,668 @@ +/* + * FairMQ theme for Starlight. + * Tokens for the light and dark theme, the type, and the styles that all pages share. + * Starlight sets data-theme="dark" or data-theme="light" on . Dark is the base. + */ + +:root { + --fmq-paper: #15171c; + --fmq-paper-2: #1b1e24; + --fmq-paper-3: #23272f; + --fmq-rule: #2f343e; + --fmq-rule-strong: #444a56; + --fmq-ink: #eceef2; + --fmq-ink-2: #b8bec9; + --fmq-ink-3: #9198a5; + --fmq-saffron: #fabe5d; + --fmq-saffron-tint: #3a3121; + --fmq-accent-ink: #fabe5d; + --fmq-bar: #fabe5d; + --fmq-on-saffron: #1a1a1a; + --fmq-link: #7ab8ec; + --fmq-link-tint: #16293b; + --fmq-teal: #4cc3a5; + --fmq-ruby: #f07aa8; + --fmq-ruby-tint: #3a1d2a; + --fmq-sky: #5cc0dd; + --fmq-sky-tint: #15303a; + --fmq-shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 14px 36px -16px rgb(0 0 0 / 0.75); + --fmq-scrim: rgb(0 0 0 / 0.55); + + /* Code, terminal and explainer stage are dark in both themes. */ + --fmq-code-bg: #0f1115; + --fmq-code-rule: #2a2f38; + --fmq-code-ink: #e6e8ec; + --fmq-code-dim: #9aa1ad; + --fmq-c-kw: #fabe5d; + --fmq-c-type: #8cc8ef; + --fmq-c-fn: #ffffff; + --fmq-c-str: #a8d99b; + --fmq-c-num: #f4a597; + --fmq-c-com: #8d96a5; + --fmq-c-pre: #e5b3d3; + --fmq-c-op: #c3c8d1; + --fmq-stage: #111318; + --fmq-stage-2: #1a1d24; + --fmq-stage-line: #4a515d; + --fmq-stage-cell: #262b34; + --fmq-stage-ink: #eceef2; + --fmq-stage-dim: #9aa1ad; + --fmq-stage-rule: #2a2e37; + --fmq-sky-bright: #62c6e6; + --fmq-mint: #5fd0ac; + + --fmq-font-body: 'Archivo Variable', 'Helvetica Neue', Helvetica, Arial, sans-serif; + --fmq-font-mono: 'JetBrains Mono Variable', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; + + /* Starlight */ + --sl-font: var(--fmq-font-body); + --sl-font-mono: var(--fmq-font-mono); + --sl-color-white: var(--fmq-ink); + --sl-color-gray-1: #dde1e7; + --sl-color-gray-2: var(--fmq-ink-2); + --sl-color-gray-3: var(--fmq-ink-3); + --sl-color-gray-4: #6b7280; + --sl-color-gray-5: var(--fmq-rule-strong); + --sl-color-gray-6: var(--fmq-paper-2); + --sl-color-gray-7: var(--fmq-paper-2); + --sl-color-black: var(--fmq-paper); + --sl-color-accent-low: var(--fmq-link-tint); + --sl-color-accent: #3d8fd6; + --sl-color-accent-high: var(--fmq-link); + --sl-color-text: var(--fmq-ink); + --sl-color-text-accent: var(--fmq-link); + --sl-color-text-invert: var(--fmq-paper); + --sl-color-bg: var(--fmq-paper); + --sl-color-bg-nav: var(--fmq-paper); + --sl-color-bg-sidebar: var(--fmq-paper); + --sl-color-bg-inline-code: var(--fmq-paper-3); + --sl-color-bg-accent: var(--fmq-link); + --sl-color-hairline-light: var(--fmq-rule); + --sl-color-hairline: var(--fmq-rule); + --sl-color-hairline-shade: var(--fmq-rule); + --sl-color-backdrop-overlay: var(--fmq-scrim); + --sl-text-body: 1.0625rem; + --sl-text-code: 0.86rem; + --sl-text-code-sm: 0.86em; + --sl-line-height: 1.65; + --sl-line-height-headings: 1.15; + --sl-content-width: 46rem; + --sl-sidebar-width: 17.5rem; + --sl-nav-height: 3.5rem; + + color-scheme: dark; +} + +:root[data-theme='light'] { + --fmq-paper: #ffffff; + --fmq-paper-2: #f5f6f8; + --fmq-paper-3: #eceef2; + --fmq-rule: #dcdfe5; + --fmq-rule-strong: #c3c8d1; + --fmq-ink: #1a1a1a; + --fmq-ink-2: #464c57; + --fmq-ink-3: #646b78; + --fmq-saffron-tint: #fdf0d3; + --fmq-accent-ink: #8a5a00; + --fmq-bar: #b97800; + --fmq-link: #005ea8; + --fmq-link-tint: #e5eff8; + --fmq-teal: #00775f; + --fmq-ruby: #b10057; + --fmq-ruby-tint: #fbe7ef; + --fmq-sky: #0e8bae; + --fmq-sky-tint: #e3f3f8; + --fmq-shadow: 0 1px 2px rgb(20 24 33 / 0.06), 0 12px 32px -16px rgb(20 24 33 / 0.24); + --fmq-scrim: rgb(21 23 28 / 0.36); + --fmq-code-bg: #22262d; + --fmq-code-rule: #353a44; + + --sl-color-gray-1: #2b2f36; + --sl-color-gray-4: #8b919c; + --sl-color-gray-6: var(--fmq-paper-3); + --sl-color-gray-7: var(--fmq-paper-2); + --sl-color-accent: #005ea8; + --sl-color-accent-high: #004a85; + --sl-color-text-invert: #ffffff; + + color-scheme: light; +} + +@media (min-width: 50em) { + :root { + --sl-nav-height: 3.75rem; + --sl-text-h1: 2.625rem; + --sl-text-h2: 1.75rem; + --sl-text-h3: 1.3125rem; + --sl-text-h4: 1.125rem; + } +} + +/* ---------- Base ---------- */ + +body { + font-stretch: 100%; +} + +/* No ligatures: code must show the characters that are in the file. The font shorthand + resets font-variant-ligatures, so the rule must be important. */ +*, +*::before, +*::after { + font-variant-ligatures: none !important; +} + +code, +kbd, +pre, +samp { + font-family: var(--fmq-font-mono); +} + +:focus-visible { + outline: 2px solid var(--fmq-link); + outline-offset: 2px; +} + +::selection { + background: color-mix(in srgb, var(--fmq-saffron) 45%, transparent); +} + +.fmq-label { + font: 600 0.75rem/1.2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--fmq-ink-3); + margin: 0; +} + +/* Eyebrow above the page title: label, then a short saffron bar. */ +.fmq-eyebrow { + font: 600 0.75rem/1.2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--fmq-ink-3); + margin: 1.25rem 0 0; +} +.fmq-eyebrow::after { + content: ''; + display: block; + width: 1.75rem; + height: 3px; + background: var(--fmq-saffron); + margin: 0.6rem 0 0; +} + +/* ---------- Content ---------- */ + +.sl-markdown-content { + color: var(--fmq-ink); +} + +.sl-markdown-content :is(h1, h2, h3, h4, h5, h6):not(:where(.not-content *)) { + color: var(--fmq-ink); + text-wrap: balance; +} +.sl-markdown-content h2:not(:where(.not-content *)) { + font-weight: 750; + font-stretch: 108%; + letter-spacing: -0.012em; + margin-top: 2.25em; +} +.sl-markdown-content h3:not(:where(.not-content *)) { + font-weight: 700; + font-stretch: 104%; + margin-top: 1.75em; +} +.sl-markdown-content h4:not(:where(.not-content *)) { + font-weight: 650; +} + +/* The first paragraph of a page is its lead. */ +.sl-markdown-content > p:first-child { + font-size: 1.1875rem; + line-height: 1.55; + color: var(--fmq-ink-2); + max-width: 62ch; +} + +.sl-markdown-content a:not(:where(.not-content *)) { + color: var(--fmq-link); + text-decoration-thickness: 1px; + text-underline-offset: 2px; +} +.sl-markdown-content a:hover:not(:where(.not-content *)) { + color: var(--fmq-ink); +} + +.sl-markdown-content :not(pre) > code:not(:where(.not-content *)), +.fmq-code-inline { + font-size: 0.86em; + background: var(--fmq-paper-3); + border: 1px solid var(--fmq-rule); + border-radius: 3px; + padding: 0.05em 0.35em; + overflow-wrap: anywhere; +} +/* Short inline code does not break at a hyphen (scripts/nowrap-code.mjs). */ +.sl-markdown-content code.nw { + white-space: nowrap; +} +.sl-markdown-content :is(h1, h2, h3, h4, h5, h6) code { + font-size: 0.9em; + border: 0; + background: none; + padding: 0; +} + +/* Square bullets. */ +.sl-markdown-content ul:not(:where(.not-content *)) { + list-style: none; + padding-inline-start: 1.25rem; +} +.sl-markdown-content ul:not(:where(.not-content *)) > li { + position: relative; +} +.sl-markdown-content ul:not(:where(.not-content *)) > li::before { + content: ''; + position: absolute; + inset-inline-start: -1.15rem; + top: 0.68em; + width: 6px; + height: 6px; + background: var(--fmq-saffron); + outline: 1px solid var(--fmq-bar); + outline-offset: -1px; +} +.sl-markdown-content ol:not(:where(.not-content *)) { + padding-inline-start: 1.5rem; +} +.sl-markdown-content ol:not(:where(.not-content *)) > li::marker { + font: 600 0.85em var(--fmq-font-mono); + color: var(--fmq-ink-3); +} + +/* Tables */ +.sl-markdown-content table:not(:where(.not-content *)) { + font-size: 0.9375rem; + border-collapse: collapse; + width: 100%; +} +.sl-markdown-content th:not(:where(.not-content *)) { + text-align: start; + font: 600 0.7rem/1.2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--fmq-ink-3); + border-bottom: 1px solid var(--fmq-rule-strong); + white-space: nowrap; +} +.sl-markdown-content :is(th, td):not(:where(.not-content *)) { + padding: 0.55rem 0.75rem; + border-bottom-color: var(--fmq-rule); + vertical-align: top; +} +.sl-markdown-content td:not(:where(.not-content *)) { + border-bottom: 1px solid var(--fmq-rule); +} +.sl-markdown-content td:first-child code { + white-space: nowrap; +} + +.sl-markdown-content hr:not(:where(.not-content *)) { + border: 0; + border-top: 1px solid var(--fmq-rule); +} + +.sl-markdown-content blockquote:not(:where(.not-content *)) { + border-inline-start: 3px solid var(--fmq-saffron); + color: var(--fmq-ink-2); +} + +.sl-markdown-content kbd, +.fmq-kbd { + font: 600 0.8em/1 var(--fmq-font-mono); + border: 1px solid var(--fmq-rule-strong); + border-bottom-width: 2px; + border-radius: 3px; + padding: 0.15em 0.4em; + background: var(--fmq-paper); + color: var(--fmq-ink); +} + +/* Asides: square mark, quiet frame. */ +.starlight-aside { + border: 1px solid var(--fmq-rule); + border-inline-start: 3px solid var(--sl-color-asides-border); + background: var(--fmq-paper-2); + border-radius: 4px; + padding: 0.85rem 1rem; + font-size: 0.96875rem; +} +.starlight-aside--note { + --sl-color-asides-border: var(--fmq-sky); + --sl-color-asides-text-accent: var(--fmq-ink-2); +} +.starlight-aside--tip { + --sl-color-asides-border: var(--fmq-teal); + --sl-color-asides-text-accent: var(--fmq-ink-2); +} +.starlight-aside--caution { + --sl-color-asides-border: var(--fmq-saffron); + --sl-color-asides-text-accent: var(--fmq-ink-2); +} +.starlight-aside--danger { + --sl-color-asides-border: var(--fmq-ruby); + --sl-color-asides-text-accent: var(--fmq-ink-2); +} +.starlight-aside__title { + font: 600 0.7rem/1.2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.12em; + text-transform: uppercase; + gap: 0.5rem; +} +.starlight-aside__icon { + display: none; +} +.starlight-aside__title::before { + content: ''; + width: 8px; + height: 8px; + background: var(--sl-color-asides-border); + flex: none; +} + +/* Starlight badges */ +.sl-badge { + font: 600 0.65rem/1 var(--fmq-font-body); + letter-spacing: 0.08em; + text-transform: uppercase; + border-radius: 3px; +} + +/* Our badge, for kinds, versions and states. */ +.fmq-badge { + display: inline-flex; + align-items: center; + font: 600 0.66rem/1 var(--fmq-font-body); + letter-spacing: 0.08em; + text-transform: uppercase; + border: 1px solid var(--fmq-rule-strong); + color: var(--fmq-ink-2); + border-radius: 3px; + padding: 0.3em 0.45em; + vertical-align: middle; + white-space: nowrap; + text-decoration: none; +} +.fmq-badge.since { + border-color: var(--fmq-teal); + color: var(--fmq-teal); +} +.fmq-badge.deprecated { + border-color: var(--fmq-ruby); + color: var(--fmq-ruby); +} +.fmq-badge.mark { + border-color: var(--fmq-bar); + color: var(--fmq-accent-ink); +} +a.fmq-badge:hover { + border-color: var(--fmq-ink-3); + color: var(--fmq-ink); +} + +/* Starlight tabs: saffron mark under the active tab. */ +starlight-tabs .tab > [role='tab'] { + font-weight: 500; + color: var(--fmq-ink-3); + border-bottom: 2px solid transparent; +} +starlight-tabs .tab [role='tab'][aria-selected='true'] { + color: var(--fmq-ink); + font-weight: 600; + border-bottom-color: var(--fmq-saffron); +} +starlight-tabs .tablist-wrapper { + border-bottom: 1px solid var(--fmq-rule); +} + +/* Steps */ +.sl-steps > li::before { + font-family: var(--fmq-font-mono); + border-radius: 3px; + background: var(--fmq-paper-2); + box-shadow: inset 0 0 0 1px var(--fmq-rule-strong); + color: var(--fmq-ink); +} +.sl-steps > li::after { + background: var(--fmq-rule); +} + +/* Cards */ +.card { + border-radius: 4px; + border-color: var(--fmq-rule); + background: var(--fmq-paper); +} +.sl-link-card { + border-radius: 4px; + border-color: var(--fmq-rule); + box-shadow: none; +} +.sl-link-card:hover { + border-color: var(--fmq-ink-3); + background: var(--fmq-paper-2); +} + +/* ---------- Expressive Code ---------- */ + +.expressive-code { + margin-block: 1rem; +} +.expressive-code .frame .header { + font-family: var(--fmq-font-mono); +} +.expressive-code .frame.is-terminal .header .title, +.expressive-code .frame .header .title { + font-size: 0.75rem; +} +.expressive-code .copy button { + border-radius: 3px; +} + +/* ---------- Sidebar ---------- */ + +#starlight__sidebar .sidebar-content { + padding-top: 0.75rem; +} +#starlight__sidebar summary .large { + font: 600 0.7rem/1.2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--fmq-ink-3); +} +#starlight__sidebar .top-level > li > a.large { + font-size: var(--sl-text-sm); + font-weight: 500; + color: var(--fmq-ink-2); +} +#starlight__sidebar ul ul li { + border-inline-start: 0; + margin-inline-start: 0; + padding-inline-start: 0; +} +#starlight__sidebar a { + display: flex; + align-items: center; + gap: 0.5rem; + color: var(--fmq-ink-2); + border-radius: 3px; + padding: 0.28em 0.5rem; + line-height: 1.35; +} +#starlight__sidebar a:hover, +#starlight__sidebar a:focus-visible { + color: var(--fmq-ink); + background: var(--fmq-paper-2); +} +#starlight__sidebar a[aria-current='page'], +#starlight__sidebar a[aria-current='page']:hover, +#starlight__sidebar a[aria-current='page']:focus { + background: var(--fmq-saffron-tint); + color: var(--fmq-ink); + font-weight: 600; +} +#starlight__sidebar a[aria-current='page']::before { + content: ''; + width: 6px; + height: 6px; + flex: none; + background: var(--fmq-saffron); + outline: 1px solid var(--fmq-bar); + outline-offset: -1px; +} +/* Kind letters in the API tree: class, struct, enum, namespace. */ +#starlight__sidebar a[data-kind]::after { + content: attr(data-kind); + order: -1; + flex: none; + display: inline-grid; + place-items: center; + width: 1.15rem; + height: 1.15rem; + font: 600 0.62rem/1 var(--fmq-font-mono); + color: var(--fmq-ink-3); + border: 1px solid var(--fmq-rule-strong); + border-radius: 2px; +} +#starlight__sidebar a[data-kind][aria-current='page']::before { + display: none; +} +#starlight__sidebar a[data-kind][aria-current='page']::after { + color: var(--fmq-on-saffron); + background: var(--fmq-saffron); + border-color: var(--fmq-bar); +} +#starlight__sidebar a.fmq-mono { + font-family: var(--fmq-font-mono); + font-size: 0.8125rem; +} + +/* ---------- Right column ---------- */ + +.right-sidebar-panel h2 { + font: 600 0.7rem/1.2 var(--fmq-font-body); + font-stretch: 88%; + letter-spacing: 0.12em; + text-transform: uppercase; + color: var(--fmq-ink-3); +} +.right-sidebar-panel a { + color: var(--fmq-ink-2); +} +.right-sidebar-panel a[aria-current='true'] { + color: var(--fmq-ink); + font-weight: 600; +} +starlight-toc a[aria-current='true'], +starlight-toc a[aria-current='true']:hover, +starlight-toc a[aria-current='true']:focus { + color: var(--fmq-ink); +} + +/* ---------- Pagination ---------- */ + +.pagination-links a { + border-radius: 4px; + border-color: var(--fmq-rule); + box-shadow: none; + color: var(--fmq-ink); +} +.pagination-links a:hover { + border-color: var(--fmq-ink-3); +} +.pagination-links .link-title { + font-weight: 650; + font-size: 1rem; +} + +/* ---------- Header ---------- */ + +header.header { + border-bottom: 1px solid var(--fmq-rule); + background: var(--fmq-paper); +} + +/* ---------- Search dialog ---------- */ + +site-search dialog { + border-radius: 6px; + border: 1px solid var(--fmq-rule-strong); + background: var(--fmq-paper); + box-shadow: var(--fmq-shadow); +} +#starlight__search { + --pagefind-ui-primary: var(--fmq-link); + --pagefind-ui-text: var(--fmq-ink); + --pagefind-ui-background: var(--fmq-paper); + --pagefind-ui-border: var(--fmq-rule-strong); + --pagefind-ui-tag: var(--fmq-paper-3); + --pagefind-ui-font: var(--fmq-font-body); +} +#starlight__search mark { + background: var(--fmq-saffron-tint); + color: var(--fmq-ink); + box-shadow: inset 0 -2px 0 var(--fmq-saffron); +} + +/* ---------- Print ---------- */ + +@media print { + .fmq-eyebrow::after { + background: #000; + } +} + +@media (prefers-reduced-motion: reduce) { + *, + *::before, + *::after { + animation-duration: 0s !important; + animation-iteration-count: 1 !important; + transition-duration: 0s !important; + scroll-behavior: auto !important; + } +} + +#starlight__sidebar a.fmq-nested { + padding-inline-start: 1.6rem; + font-size: 0.78rem; +} + +/* No rule between the title and the content. */ +.content-panel + .content-panel { + border-top: 0; +} +.content-panel:first-of-type:not(:only-of-type) { + padding-bottom: 0; +} + +/* Source pages use the full width of the main column. */ +:root:has(.src-code) { + --sl-content-width: 76rem; +} + +/* ---------- Home ---------- */ + +html[data-has-hero] { + --sl-content-width: 74rem; +} +html[data-has-hero] .content-panel { + padding-top: 1rem; +} diff --git a/docs/tsconfig.json b/docs/tsconfig.json new file mode 100644 index 00000000..23e02bff --- /dev/null +++ b/docs/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "astro/tsconfigs/strict", + "include": [".astro/types.d.ts", "**/*"], + "exclude": ["dist", "build", "node_modules"] +}