amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

17 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 输入服务合同
1. `input.hpp` 的 `panel` 命名空间提供 `Capability`、`Event`、`Frame`、`Slot`、`Counters`、`Reading` 和 `Service`,字段含义如下。所有调用同步、单线程,无外部 I/O;整数以十进制有符号值传入。除 `reset` 外错误均不改变服务状态,返回错误时读数为 0。
2. 服务有四个槽,编号 0..3。`Phase` 为 Empty=0、Allocated=1、Registered=2。槽的 `generation` 起始 0,每次成功 allocate 加 1;服务 reset 将所有字段、账本和计数清零。`reset()` 无返回值。
3. `allocate(slot,name)`:槽越界返回 -1;名称必须是 1..32 个 ASCII 字母、数字、下划线或减号,否则 -1;槽非 Empty 返回 -2。成功返回 0,将槽置 Allocated、保存名称并增加 generation 和 allocations,其他槽内容保持不变。
4. `Capability{type,code,lower,upper}` 中 type=1 为按键,code=0..31 且 lower=0、upper=1;type=3 为绝对轴,code=0..7 且 -32768<=lower<=upper<=32767。除此以外均非法。`normalize_capabilities(input,output)` 成功返回 0,输出按 (type,code) 升序;非法能力或重复 (type,code) 返回 -1,output 保持原值。空 input 成功产生空 output。输入与输出可以是同一个 vector。
5. `replace_capabilities(slot,caps)` 先检查槽范围,再检查槽为 Allocated,再校验整个 caps;依次不满足返回 -1、-2、-1。成功返回 0,以规范化集合替换能力;空集合也替换原集合。能力替换清除该槽 values 和 pending,增加 configurations;同一集合再次替换也增加 configurations。`capability(slot,type,code)` 返回匹配能力指针,否则 nullptr;不修改状态。
6. `attach(slot,fail)` 要求 slot 合法、fail 为 0 或 1,否则 -1;槽须为 Allocated,否则 -2。fail=1 返回 -5 且保留完整状态;fail=0 将槽置 Registered,values 按能力顺序建立按键初值 0、绝对轴初值 lower,清空 pending,增加 registrations,返回 0。没有能力的设备可以注册。
7. `report(slot,type,code,value)` 先检查槽范围,再要求 Registered,依次失败返回 -1、-2;能力缺失返回 -3;按键 value 只允许 0、1、2,绝对轴 value 必须在能力范围内,否则 -1。按键 0/1 和绝对轴在值发生变化时更新 values 并向 pending 追加该 Event;相同值成功返回 0 且不追加。按键 value=2 表示重复通知,保持当前 values 且总是追加 Event。追加事件增加 reports,pending 保持调用顺序,单槽最多 64 条;需要追加而 pending 已满时返回 -4,values 和 counters 均不变。不需追加的操作不受 pending 容量影响。
8. `sync(slot)` 检查范围和 Registered,错误依次 -1、-2。有 pending 时追加一个 Frame{serial,slot,generation,events};serial 从 1 开始,跨槽连续递增;events 为 pending 的有序副本,随后清空 pending。增加 frames 和 committed_events。pending 为空时返回 0,账本和计数保持不变。
9. `read(slot,type,code)` 检查范围、Registered、能力,错误依次 -1、-2、-3;成功返回 Reading{0,value},不改变状态。values 中保存已接受的当前值,sync 不改变它。
10. `detach(slot)` 越界 -1。Registered 槽将 pending 丢弃、values 清空,置 Allocated,增加 unregistrations;能力、名称、generation 及已提交账本保留。Allocated 或 Empty 槽成功返回 0,状态和计数保持不变。
11. `release(slot)` 越界 -1。Empty 槽返回 0,状态和计数保持不变;其余槽若 Registered 先执行 detach,再清空能力、名称、values、pending 并置 Empty,保留 generation,增加 releases。设备重用不会改写历史 Frame 的 generation 或 events。
12. `slots()`、`ledger()`、`counters()` 返回只读引用。Slot 包含 phase、generation、name、capabilities、values、pending,values 与 capabilities 同序。Counters 字段为 allocations、releases、configurations、registrations、unregistrations、reports、frames、committed_events,均为从 reset 起累计的非负整数。Frame 的 events 是值副本,不受之后调用影响。
13. `inspect(slot)` 合法时返回槽的只读指针,越界返回 nullptr。`valid_name(name)` 返回名称是否符合第 3 条;`valid_slot(slot)` 返回范围是否符合第 2 条;`capability_valid(cap)` 返回是否符合第 4 条。三个 helper 均无副作用。所有公开 helper 和方法须可直接调用,调用方可以不经过控制台。
14. 公共结构字段、签名及枚举值保持 `input.hpp` 所示,可以改变内部实现和增加声明。服务无按时间触发的行为,普通 Linux 进程足以验证。候选只能交付 README 中列出的五个文件。