activity_sdk_policy_inventory.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. #include <span>
  5. #include <string>
  6. #include <string_view>
  7. #include <vector>
  8. #include "../../../state/activity_sdk/format.h"
  9. namespace sunrise::client::content::activity::sdk_generation::policy_inventory {
  10. namespace format = state::activity_sdk::format;
  11. /** Format-safety bounds reject pathological installed inputs without replaying captured totals. */
  12. inline constexpr std::size_t kMaximumActivityCount = 1U << 12U;
  13. inline constexpr std::size_t kMaximumScenarioCount = 1U << 12U;
  14. inline constexpr std::size_t kMaximumObjectCount = 1U << 20U;
  15. inline constexpr std::size_t kMaximumOccurrenceCount = 1U << 22U;
  16. inline constexpr std::size_t kMaximumSlotCount = 1U << 22U;
  17. inline constexpr std::size_t kMaximumPolicyTextCount = 1U << 22U;
  18. inline constexpr std::size_t kMaximumPolicyCapabilityCount = 1U << 22U;
  19. inline constexpr std::size_t kMaximumPolicyGateCount = 1U << 24U;
  20. inline constexpr std::size_t kMaximumPolicyRefusalCount = 1U << 22U;
  21. inline constexpr std::size_t kMaximumHostSurfaceCount = 6;
  22. inline constexpr std::size_t kMaximumTextBytes = 512;
  23. /** One owned string-pool handle retained until final pack string linking. */
  24. struct Text final {
  25. std::uint32_t stringIndex{};
  26. bool operator==(const Text&) const = default;
  27. };
  28. /** The four activity-to-scenario identity outcomes used by mission binding policy. */
  29. enum class ActivityJoinStatus : std::uint8_t {
  30. exact,
  31. sourceNameMissing,
  32. liveNameMissing,
  33. liveNameAmbiguous,
  34. };
  35. /** Slot extraction distinguishes a complete empty walk from a partial walk. */
  36. enum class ExtractionStatus : std::uint8_t {
  37. complete,
  38. completeEmpty,
  39. partial,
  40. };
  41. /** One final activity row with the names and join outcome consumed by policy. */
  42. struct ActivityInput final {
  43. std::uint32_t activityIndex{};
  44. std::string_view id{};
  45. std::string_view internalName{};
  46. std::string_view displayName{};
  47. ActivityJoinStatus joinStatus{ActivityJoinStatus::liveNameMissing};
  48. };
  49. /** One final slot row with all schema and verification facts consumed by policy. */
  50. struct SlotInput final {
  51. std::uint32_t objectIndex{format::kAbsentIndex};
  52. std::uint32_t slotIndex{};
  53. std::uint32_t slotType{};
  54. std::uint32_t componentClass{format::kAbsentIndex};
  55. std::uint32_t senseSchema{format::kAbsentIndex};
  56. std::uint32_t authSchema{format::kAbsentIndex};
  57. std::string_view id{};
  58. std::string_view name{};
  59. std::string_view senseSchemaId{};
  60. std::string_view authSchemaId{};
  61. ExtractionStatus extractionStatus{ExtractionStatus::complete};
  62. std::uint32_t flags{};
  63. };
  64. /** One extra slot-name candidate joined to a final slot row. */
  65. struct SlotAliasInput final {
  66. std::uint32_t slotIndex{format::kAbsentIndex};
  67. std::string_view value{};
  68. };
  69. /** One complete occurrence binding used by the type-23 route cardinality gate. */
  70. struct OccurrenceInput final {
  71. std::uint32_t scenarioIndex{format::kAbsentIndex};
  72. std::uint32_t objectIndex{format::kAbsentIndex};
  73. };
  74. /** One host API declaration whose operation selects the compiled adapter gate set. */
  75. struct HostSurface final {
  76. std::string_view id{};
  77. std::string_view operation{};
  78. };
  79. /** All inputs must use final parent row order and complete name, schema, and route evidence. */
  80. struct Inputs final {
  81. std::span<const ActivityInput> activities{};
  82. std::span<const SlotInput> slots{};
  83. std::span<const SlotAliasInput> slotAliases{};
  84. std::span<const OccurrenceInput> occurrences{};
  85. std::span<const HostSurface> hostSurfaces{};
  86. std::uint32_t scenarioCount{};
  87. std::uint32_t objectCount{};
  88. };
  89. /** One format-v12 Text row before its string offset is linked. */
  90. struct TextRow final {
  91. Text value{};
  92. std::uint32_t kind{};
  93. std::uint32_t reserved{};
  94. bool operator==(const TextRow&) const = default;
  95. };
  96. /** One format-v12 Capability row before its strings are linked. */
  97. struct Capability final {
  98. Text id{};
  99. Text operation{};
  100. Text valueSchemaId{};
  101. std::uint32_t subjectKind{};
  102. std::uint32_t subjectIndex{};
  103. std::uint32_t exposureFlags{};
  104. std::uint32_t candidateExposureFlags{};
  105. format::Range gates{};
  106. format::Range refusals{};
  107. /** @return True when all deferred fields and owned ranges match. */
  108. [[nodiscard]] bool operator==(const Capability& other) const noexcept {
  109. return id == other.id && operation == other.operation
  110. && valueSchemaId == other.valueSchemaId && subjectKind == other.subjectKind
  111. && subjectIndex == other.subjectIndex && exposureFlags == other.exposureFlags
  112. && candidateExposureFlags == other.candidateExposureFlags
  113. && gates.first == other.gates.first && gates.count == other.gates.count
  114. && refusals.first == other.refusals.first && refusals.count == other.refusals.count;
  115. }
  116. };
  117. /** One format-v12 Gate row before its strings are linked. */
  118. struct Gate final {
  119. Text gate{};
  120. Text status{};
  121. Text reasonCode{};
  122. Text required{};
  123. Text observed{};
  124. Text wouldConfirm{};
  125. bool operator==(const Gate&) const = default;
  126. };
  127. /** One format-v12 Refusal row before its strings are linked. */
  128. struct Refusal final {
  129. Text id{};
  130. Text exposure{};
  131. Text status{};
  132. format::Range reasonCodes{};
  133. std::uint32_t capabilityIndex{};
  134. std::uint32_t reserved{};
  135. /** @return True when all deferred fields, scalars, and the reason range match. */
  136. [[nodiscard]] bool operator==(const Refusal& other) const noexcept {
  137. return id == other.id && exposure == other.exposure && status == other.status
  138. && reasonCodes.first == other.reasonCodes.first
  139. && reasonCodes.count == other.reasonCodes.count
  140. && capabilityIndex == other.capabilityIndex && reserved == other.reserved;
  141. }
  142. };
  143. /** One sorted host subject and its contiguous capability range. */
  144. struct HostSubject final {
  145. Text id{};
  146. format::Range capabilities{};
  147. /** @return True when the deferred id and capability range match. */
  148. [[nodiscard]] bool operator==(const HostSubject& other) const noexcept {
  149. return id == other.id && capabilities.first == other.capabilities.first
  150. && capabilities.count == other.capabilities.count;
  151. }
  152. };
  153. /** Canonical sections 8 through 11 and every range owned by earlier parent rows. */
  154. struct Snapshot final {
  155. std::vector<std::string> strings{};
  156. std::vector<TextRow> texts{};
  157. std::vector<Capability> capabilities{};
  158. std::vector<Gate> gates{};
  159. std::vector<Refusal> refusals{};
  160. std::vector<format::Range> activityAliases{};
  161. std::vector<format::Range> activityCapabilities{};
  162. std::vector<format::Range> slotAliases{};
  163. std::vector<format::Range> slotCapabilities{};
  164. std::vector<HostSubject> hostSubjects{};
  165. /** @return The owned UTF-8 value or an empty view for an invalid handle. */
  166. [[nodiscard]] std::string_view value(Text text) const noexcept;
  167. };
  168. /** @return The five compiled host surfaces whose policy is emitted by this build. */
  169. [[nodiscard]] std::span<const HostSurface> host_surfaces() noexcept;
  170. /** Builds canonical policy rows transactionally from complete final parent inventories. */
  171. [[nodiscard]] bool build(const Inputs& inputs, Snapshot& output) noexcept;
  172. } // namespace sunrise::client::content::activity::sdk_generation::policy_inventory