maliput-sys 0.26.0

FFI Rust bindings for maliput
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
// BSD 3-Clause License
//
// Copyright (c) 2024, Woven by Toyota.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
//   contributors may be used to endorse or promote products derived from
//   this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#[cxx::bridge(namespace = "maliput::api::rules")]
#[allow(clippy::needless_lifetimes)] // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/5787
pub mod ffi {
    /// Shared struct for `TrafficLight` pointers.
    /// This is needed because `*const` can't be used directly in the CxxVector collection.
    struct ConstTrafficLightPtr {
        pub traffic_light: *const TrafficLight,
    }
    /// Shared struct for `BulbGroup` pointers.
    /// This is needed because `*const` can't be used directly in the CxxVector collection.
    struct ConstBulbGroupPtr {
        pub bulb_group: *const BulbGroup,
    }
    /// Shared struct for `Bulb` pointers.
    /// This is needed because `*const` can't be used directly in the CxxVector collection.
    struct ConstBulbPtr {
        pub bulb: *const Bulb,
    }
    /// Shared struct for `TrafficSign` pointers.
    /// This is needed because `*const` can't be used directly in the CxxVector collection.
    struct ConstTrafficSignPtr {
        pub traffic_sign: *const TrafficSign,
    }
    /// Shared struct for `BulbState` references.
    /// This is needed because `&f` can't be used directly in the CxxVector collection.
    struct ConstBulbStateRef<'a> {
        pub bulb_state: &'a BulbState,
    }
    /// Shared struct for floats types.
    /// This is needed because `f64` can't be used directly in the UniquePtr type.
    struct FloatWrapper {
        pub value: f64,
    }
    /// Shared struct for optional string types.
    /// This is needed because `String` can't be used directly in the UniquePtr type.
    /// A null `UniquePtr<StringWrapper>` represents `std::nullopt`.
    struct StringWrapper {
        pub value: String,
    }
    /// Shared struct for pairs in a RelatedRules collection.
    ///  - key: Group name of the rules.
    ///  - value: Rule ids.
    /// This is needed because maps can't be bound directly.
    struct RelatedRule {
        pub group_name: String,
        pub rule_ids: Vec<String>,
    }
    /// Shared struct for pairs in a RelatedRules collection.
    ///  - key: Group name.
    ///  - value: Unique Ids.
    /// This is needed because maps can't be bound directly.
    struct RelatedUniqueId {
        pub group_name: String,
        pub unique_ids: Vec<String>,
    }
    /// Shared struct for pairs in a DiscreteValueRules collection.
    ///  - key: Rule type ids.
    ///  - value: Discrete Values.
    /// This is needed because maps can't be bound directly.
    struct DiscreteValueRuleType {
        pub type_id: String,
        pub values: UniquePtr<CxxVector<DiscreteValueRuleDiscreteValue>>,
    }
    /// Shared struct for pairs in a DiscreteValues collection.
    ///  - key: Rule ids.
    ///  - value: Discrete Value State.
    /// This is needed because maps can't be bound directly.
    struct DiscreteValueRuleState {
        pub rule_id: String,
        pub state: UniquePtr<DiscreteValueRuleDiscreteValue>,
    }
    /// Shared struct for pairs in a RangeValueRules collection.
    ///  - key: Rule type ids.
    ///  - value: Range Values.
    /// This is needed because maps can't be bound directly.
    struct RangeValueRuleType {
        pub type_id: String,
        pub values: UniquePtr<CxxVector<RangeValueRuleRange>>,
    }

    /// Shared struct for `LaneSRange` constant reference.
    /// Interestingly this was done at maliput::api module but
    /// couldn't reference to that so it was necessary to
    /// redefine it here.
    struct ConstLaneSRangeRef<'a> {
        pub lane_s_range: &'a LaneSRange,
    }

    /// Shared struct for a `NextPhase` in a `PhaseRing`.
    ///  - phase_id: ID of the `NextPhase`.
    ///  - duration_until: Optional field to suggest a default duration of the current `Phase`
    ///    until the `NextPhase`.
    /// Redefinition is necessary since std::optional<T> isn't supported.
    struct NextPhase {
        pub phase_id: String,
        pub duration_until: UniquePtr<FloatWrapper>,
    }

    struct DiscreteValueNextState {
        pub state: UniquePtr<DiscreteValueRuleDiscreteValue>,
        pub duration_until: UniquePtr<FloatWrapper>,
    }

    struct RangeValueNextState {
        pub state: UniquePtr<RangeValueRuleRange>,
        pub duration_until: UniquePtr<FloatWrapper>,
    }

    #[repr(i32)]
    enum BulbColor {
        kRed = 0,
        kYellow,
        kGreen,
    }

    #[repr(i32)]
    enum BulbType {
        kRound = 0,
        kArrow,
        kArrowLeft,
        kArrowRight,
        kArrowUp,
        kArrowUpperLeft,
        kArrowUpperRight,
        kUTurnLeft,
        kUTurnRight,
        kWalk,
        kDontWalk,
    }

    #[repr(i32)]
    enum BulbState {
        kOff = 0,
        kOn,
        kBlinking,
    }

    #[repr(i32)]
    enum TrafficSignType {
        kStop = 0,
        kYield,
        kSpeedLimit,
        kNoEntry,
        kOneWay,
        kPedestrianCrossing,
        kNoLeftTurn,
        kNoRightTurn,
        kNoUTurn,
        kSchoolZone,
        kConstruction,
        kRailroadCrossing,
        kNoOvertaking,
        kUnknown,
    }

    unsafe extern "C++" {
        include!("api/rules/rules.h");
        include!("api/rules/aliases.h");
        include!("cxx_utils/error_handling.h");

        // Forward declarations
        #[namespace = "maliput::api"]
        type InertialPosition = crate::api::ffi::InertialPosition;
        #[namespace = "maliput::api"]
        type Rotation = crate::api::ffi::Rotation;
        #[namespace = "maliput::api"]
        type LaneSRange = crate::api::ffi::LaneSRange;
        #[namespace = "maliput::api"]
        type LaneSRoute = crate::api::ffi::LaneSRoute;
        #[namespace = "maliput::api"]
        type RoadPosition = crate::api::ffi::RoadPosition;
        #[namespace = "maliput::math"]
        type Vector3 = crate::math::ffi::Vector3;
        #[namespace = "maliput::math"]
        type RollPitchYaw = crate::math::ffi::RollPitchYaw;
        #[namespace = "maliput::math"]
        type BoundingBox = crate::math::ffi::BoundingBox;

        // TrafficLightBook bindings definitions.
        type TrafficLightBook;
        fn TrafficLightBook_TrafficLights(book: &TrafficLightBook) -> UniquePtr<CxxVector<ConstTrafficLightPtr>>;
        fn TrafficLightBook_GetTrafficLight(book: &TrafficLightBook, id: &String) -> *const TrafficLight;
        fn TrafficLightBook_FindByLane(
            book: &TrafficLightBook,
            lane_id: &String,
        ) -> UniquePtr<CxxVector<ConstTrafficLightPtr>>;

        // TrafficLight bindings definitions.
        type TrafficLight;
        fn TrafficLight_id(traffic_light: &TrafficLight) -> String;
        fn TrafficLight_position_road_network(traffic_light: &TrafficLight) -> UniquePtr<InertialPosition>;
        fn TrafficLight_orientation_road_network(traffic_light: &TrafficLight) -> UniquePtr<Rotation>;
        fn TrafficLight_bulb_groups(traffic_light: &TrafficLight) -> UniquePtr<CxxVector<ConstBulbGroupPtr>>;
        fn TrafficLight_GetBulbGroup(traffic_light: &TrafficLight, id: &String) -> *const BulbGroup;
        fn TrafficLight_related_lanes(traffic_light: &TrafficLight) -> Vec<String>;

        // TrafficSignBook bindings definitions.
        type TrafficSignBook;
        type TrafficSignType;
        fn TrafficSignBook_TrafficSigns(book: &TrafficSignBook) -> UniquePtr<CxxVector<ConstTrafficSignPtr>>;
        fn TrafficSignBook_GetTrafficSign(book: &TrafficSignBook, id: &String) -> *const TrafficSign;
        fn TrafficSignBook_FindByLane(
            book: &TrafficSignBook,
            lane_id: &String,
        ) -> UniquePtr<CxxVector<ConstTrafficSignPtr>>;
        fn TrafficSignBook_FindByType(
            book: &TrafficSignBook,
            sign_type: TrafficSignType,
        ) -> UniquePtr<CxxVector<ConstTrafficSignPtr>>;

        // TrafficSign bindings definitions.
        type TrafficSign;
        fn TrafficSign_id(sign: &TrafficSign) -> String;
        // This method could be bound as `fn type(self: &TrafficSign) -> TrafficSignType` but it causes a conflict with the `type` keyword in Rust.
        fn TrafficSign_type(sign: &TrafficSign) -> &TrafficSignType;
        fn TrafficSign_position_road_network(sign: &TrafficSign) -> UniquePtr<InertialPosition>;
        fn TrafficSign_orientation_road_network(sign: &TrafficSign) -> UniquePtr<Rotation>;
        fn TrafficSign_message(sign: &TrafficSign) -> UniquePtr<StringWrapper>;
        fn TrafficSign_related_lanes(sign: &TrafficSign) -> Vec<String>;
        fn TrafficSign_bounding_box(sign: &TrafficSign) -> UniquePtr<BoundingBox>;

        type BulbColor;
        type BulbState;
        type BulbType;
        // Bulb bindings definitions.
        type Bulb;
        fn Bulb_id(bulb: &Bulb) -> String;
        fn Bulb_unique_id(bulb: &Bulb) -> UniquePtr<UniqueBulbId>;
        fn Bulb_position_bulb_group(bulb: &Bulb) -> UniquePtr<InertialPosition>;
        fn Bulb_orientation_bulb_group(bulb: &Bulb) -> UniquePtr<Rotation>;
        fn color(self: &Bulb) -> &BulbColor;
        // We can't automatically use the name `type` as it is a reserved keyword in Rust.
        fn Bulb_type(bulb: &Bulb) -> &BulbType;
        fn Bulb_arrow_orientation_rad(bulb: &Bulb) -> UniquePtr<FloatWrapper>;
        fn Bulb_states(bulb: &Bulb) -> UniquePtr<CxxVector<BulbState>>;
        fn GetDefaultState(self: &Bulb) -> BulbState;
        fn IsValidState(self: &Bulb, state: &BulbState) -> bool;
        fn Bulb_bounding_box_min(bulb: &Bulb) -> UniquePtr<Vector3>;
        fn Bulb_bounding_box_max(bulb: &Bulb) -> UniquePtr<Vector3>;
        fn Bulb_bulb_group(bulb: &Bulb) -> *const BulbGroup;

        // BulbGroup bindings definitions.
        type BulbGroup;
        fn BulbGroup_id(bulb_group: &BulbGroup) -> String;
        fn BulbGroup_unique_id(bulb: &BulbGroup) -> UniquePtr<UniqueBulbGroupId>;
        fn BulbGroup_position_traffic_light(bulb_group: &BulbGroup) -> UniquePtr<InertialPosition>;
        fn BulbGroup_orientation_traffic_light(bulb_group: &BulbGroup) -> UniquePtr<Rotation>;
        fn BulbGroup_bulbs(bulb_group: &BulbGroup) -> UniquePtr<CxxVector<ConstBulbPtr>>;
        fn BulbGroup_GetBulb(bulb_group: &BulbGroup, id: &String) -> *const Bulb;
        fn BulbGroup_traffic_light(bulb_group: &BulbGroup) -> *const TrafficLight;

        // UniqueBulbId bindings definitions.
        type UniqueBulbId;
        fn string(self: &UniqueBulbId) -> &CxxString;
        fn UniqueBulbId_traffic_light_id(id: &UniqueBulbId) -> String;
        fn UniqueBulbId_bulb_group_id(id: &UniqueBulbId) -> String;
        fn UniqueBulbId_bulb_id(id: &UniqueBulbId) -> String;
        fn UniqueBulbId_create_unique_ptr(id: &UniqueBulbId) -> UniquePtr<UniqueBulbId>;

        // UniqueBulbGroupId bindings definitions.
        type UniqueBulbGroupId;
        fn string(self: &UniqueBulbGroupId) -> &CxxString;
        fn UniqueBulbGroupId_traffic_light_id(id: &UniqueBulbGroupId) -> String;
        fn UniqueBulbGroupId_bulb_group_id(id: &UniqueBulbGroupId) -> String;

        // QueryResults bindings definitions.
        type QueryResults;
        fn QueryResults_discrete_value_rules(query_results: &QueryResults) -> Vec<String>;
        fn QueryResults_range_value_rules(query_results: &QueryResults) -> Vec<String>;

        // RoadRulebook bindings definitions.
        type RoadRulebook;
        fn RoadRulebook_GetDiscreteValueRule(book: &RoadRulebook, rule_id: &String) -> UniquePtr<DiscreteValueRule>;
        fn RoadRulebook_GetRangeValueRule(book: &RoadRulebook, rule_id: &String) -> UniquePtr<RangeValueRule>;
        fn RoadRulebook_Rules(book: &RoadRulebook) -> UniquePtr<QueryResults>;
        #[allow(clippy::needless_lifetimes)]
        fn RoadRulebook_FindRules(
            book: &RoadRulebook,
            ranges: &Vec<ConstLaneSRangeRef>,
            tolerance: f64,
        ) -> Result<UniquePtr<QueryResults>>;

        // DiscreteValueRule::DiscreteValue bindings definitions.
        type DiscreteValueRuleDiscreteValue;
        fn DiscreteValueRuleDiscreteValue_value(value: &DiscreteValueRuleDiscreteValue) -> String;
        fn DiscreteValueRuleDiscreteValue_severity(value: &DiscreteValueRuleDiscreteValue) -> i32;
        fn DiscreteValueRuleDiscreteValue_related_rules(
            value: &DiscreteValueRuleDiscreteValue,
        ) -> UniquePtr<CxxVector<RelatedRule>>;
        fn DiscreteValueRuleDiscreteValue_related_unique_ids(
            value: &DiscreteValueRuleDiscreteValue,
        ) -> UniquePtr<CxxVector<RelatedUniqueId>>;

        // DiscreteValueRule bindings definitions.
        type DiscreteValueRule;
        fn states(self: &DiscreteValueRule) -> &CxxVector<DiscreteValueRuleDiscreteValue>;
        fn DiscreteValueRule_id(rule: &DiscreteValueRule) -> String;
        fn DiscreteValueRule_type_id(rule: &DiscreteValueRule) -> String;
        fn DiscreteValueRule_zone(rule: &DiscreteValueRule) -> UniquePtr<LaneSRoute>;

        // RangeValueRule::Range bindings definitions.
        type RangeValueRuleRange;
        fn RangeValueRuleRange_description(range: &RangeValueRuleRange) -> String;
        fn RangeValueRuleRange_min(range: &RangeValueRuleRange) -> f64;
        fn RangeValueRuleRange_max(range: &RangeValueRuleRange) -> f64;
        fn RangeValueRuleRange_severity(range: &RangeValueRuleRange) -> i32;
        fn RangeValueRuleRange_related_rules(range: &RangeValueRuleRange) -> UniquePtr<CxxVector<RelatedRule>>;
        fn RangeValueRuleRange_related_unique_ids(range: &RangeValueRuleRange)
            -> UniquePtr<CxxVector<RelatedUniqueId>>;
        // RangeValueRule::Range bindings definitions.
        type RangeValueRule;
        fn RangeValueRule_id(rule: &RangeValueRule) -> String;
        fn RangeValueRule_type_id(rule: &RangeValueRule) -> String;
        fn RangeValueRule_zone(rule: &RangeValueRule) -> UniquePtr<LaneSRoute>;
        fn states(self: &RangeValueRule) -> &CxxVector<RangeValueRuleRange>;

        // Phase bindings definitions.
        type Phase;
        fn Phase_id(phase: &Phase) -> String;
        fn Phase_discrete_value_rule_states(phase: &Phase) -> UniquePtr<CxxVector<DiscreteValueRuleState>>;
        fn Phase_unique_bulb_ids(phase: &Phase) -> UniquePtr<CxxVector<UniqueBulbId>>;
        fn Phase_bulb_state(phase: &Phase, bulb_id: &UniqueBulbId) -> UniquePtr<BulbState>;
        // Helper method to implement [Phase_unique_bulb_ids] API method.
        fn ptr_from_unique_bulb_id(id: &UniqueBulbId) -> UniquePtr<UniqueBulbId>;

        // PhaseRing bindings definitions.
        type PhaseRing;
        fn PhaseRing_id(phase_ring: &PhaseRing) -> String;
        fn PhaseRing_GetPhase(phase_ring: &PhaseRing, id: &String) -> UniquePtr<Phase>;
        fn PhaseRing_phases_ids(phase_ring: &PhaseRing) -> Vec<String>;
        fn PhaseRing_GetNextPhases(phase_ring: &PhaseRing, id: &String) -> Result<UniquePtr<CxxVector<NextPhase>>>;

        // StateProviderResult<Phase::Id> bindings definitions.
        type PhaseStateProviderQuery;
        fn PhaseStateProvider_state(phase_state_provider: &PhaseStateProviderQuery) -> String;
        fn PhaseStateProvider_next(phase_state_provider: &PhaseStateProviderQuery) -> UniquePtr<NextPhase>;

        // PhaseProvider bindings definitions.
        type PhaseProvider;
        fn PhaseProvider_GetPhase(
            phase_provider: &PhaseProvider,
            phase_ring_id: &String,
        ) -> UniquePtr<PhaseStateProviderQuery>;

        // PhaseRingBook bindings definitions.
        type PhaseRingBook;
        fn PhaseRingBook_GetPhaseRingsId(book: &PhaseRingBook) -> Vec<String>;
        fn PhaseRingBook_GetPhaseRing(book: &PhaseRingBook, id: &String) -> UniquePtr<PhaseRing>;
        fn PhaseRingBook_FindPhaseRing(book: &PhaseRingBook, rule_id: &String) -> UniquePtr<PhaseRing>;

        // RuleRegistry bindings definitions.
        type RuleRegistry;
        fn RuleRegistry_DiscreteValueRuleTypes(registry: &RuleRegistry) -> UniquePtr<CxxVector<DiscreteValueRuleType>>;
        fn RuleRegistry_RangeValueRuleTypes(registry: &RuleRegistry) -> UniquePtr<CxxVector<RangeValueRuleType>>;

        // DiscreteValueRuleStateProviderQuery bindings definitions.
        type DiscreteValueRuleStateProviderQuery;
        fn DiscreteValueRuleStateProviderQuery_state(
            state_provider_query: &DiscreteValueRuleStateProviderQuery,
        ) -> UniquePtr<DiscreteValueRuleDiscreteValue>;
        fn DiscreteValueRuleStateProviderQuery_next(
            state_provider_query: &DiscreteValueRuleStateProviderQuery,
        ) -> UniquePtr<DiscreteValueNextState>;

        // DiscreteValueRuleStateProvider bindings definitions.
        type DiscreteValueRuleStateProvider;
        fn DiscreteValueRuleStateProvider_GetStateById(
            state_provider: &DiscreteValueRuleStateProvider,
            id: &String,
        ) -> UniquePtr<DiscreteValueRuleStateProviderQuery>;
        fn DiscreteValueRuleStateProvider_GetStateByType(
            state_provider: &DiscreteValueRuleStateProvider,
            road_position: &RoadPosition,
            rule_type: &String,
            tolerance: f64,
        ) -> UniquePtr<DiscreteValueRuleStateProviderQuery>;

        // RangeValueRuleStateProviderQuery bindings definitions.
        type RangeValueRuleStateProviderQuery;
        fn RangeValueRuleStateProviderQuery_state(
            state_provider_query: &RangeValueRuleStateProviderQuery,
        ) -> UniquePtr<RangeValueRuleRange>;
        fn RangeValueRuleStateProviderQuery_next(
            state_provider_query: &RangeValueRuleStateProviderQuery,
        ) -> UniquePtr<RangeValueNextState>;

        // RangeValueRuleStateProvider bindings definitions.
        type RangeValueRuleStateProvider;
        fn RangeValueRuleStateProvider_GetStateById(
            state_provider: &RangeValueRuleStateProvider,
            id: &String,
        ) -> UniquePtr<RangeValueRuleStateProviderQuery>;
        fn RangeValueRuleStateProvider_GetStateByType(
            state_provider: &RangeValueRuleStateProvider,
            road_position: &RoadPosition,
            rule_type: &String,
            tolerance: f64,
        ) -> UniquePtr<RangeValueRuleStateProviderQuery>;
    }
}