Skip to content

Commit 5ece9b3

Browse files
authored
Merge pull request #69 from chemicstry/control_info_refactor2
Simplify generated code
2 parents 832e633 + 02596a1 commit 5ece9b3

File tree

8 files changed

+21
-63
lines changed

8 files changed

+21
-63
lines changed

libcamera-meta/src/bin/generate_from_git.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,12 @@ mod generate_rust {
308308
}
309309
out += "}\n";
310310

311-
let name_fn = match ty {
312-
ControlsType::Control => "control_id_name",
313-
ControlsType::Property => "property_id_name",
314-
};
315-
316311
out += &format!("impl {name} {{\n");
317312
out += r#"
318313
pub fn id(&self) -> u32 {
319314
u32::from(*self)
320315
}
321316
"#;
322-
out += "\n";
323-
out += &format!(
324-
"
325-
pub fn name(&self) -> String {{
326-
{name_fn}(*self)
327-
}}
328-
"
329-
);
330-
331317
out += "}\n";
332318

333319
let mut dyn_variants = String::new();
@@ -454,9 +440,7 @@ mod generate_rust {
454440
use std::ops::{{Deref, DerefMut}};
455441
use num_enum::{{IntoPrimitive, TryFromPrimitive}};
456442
#[allow(unused_imports)]
457-
use crate::control::{{
458-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name
459-
}};
443+
use crate::control::{{Control, Property, ControlEntry, DynControlEntry}};
460444
use crate::control_value::{{ControlValue, ControlValueError}};
461445
#[allow(unused_imports)]
462446
use crate::geometry::{{Rectangle, Point, Size}};

libcamera/src/control.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,20 @@ impl<'a> Drop for ControlInfoMapIter<'a> {
456456
}
457457
}
458458

459-
pub fn control_id_name(id: ControlId) -> String {
460-
unsafe { CStr::from_ptr(libcamera_control_name_from_id(id.id())) }
461-
.to_str()
462-
.unwrap()
463-
.into()
459+
impl ControlId {
460+
pub fn name(&self) -> String {
461+
unsafe { CStr::from_ptr(libcamera_control_name_from_id(self.id())) }
462+
.to_str()
463+
.unwrap()
464+
.into()
465+
}
464466
}
465467

466-
pub fn property_id_name(id: PropertyId) -> String {
467-
unsafe { CStr::from_ptr(libcamera_property_name_from_id(id.id())) }
468-
.to_str()
469-
.unwrap()
470-
.into()
468+
impl PropertyId {
469+
pub fn name(&self) -> String {
470+
unsafe { CStr::from_ptr(libcamera_property_name_from_id(self.id())) }
471+
.to_str()
472+
.unwrap()
473+
.into()
474+
}
471475
}

libcamera/versioned_files/0.4.0/controls.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22
use num_enum::{IntoPrimitive, TryFromPrimitive};
33
#[allow(unused_imports)]
4-
use crate::control::{
5-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name,
6-
};
4+
use crate::control::{Control, Property, ControlEntry, DynControlEntry};
75
use crate::control_value::{ControlValue, ControlValueError};
86
#[allow(unused_imports)]
97
use crate::geometry::{Rectangle, Point, Size};
@@ -639,9 +637,6 @@ impl ControlId {
639637
pub fn id(&self) -> u32 {
640638
u32::from(*self)
641639
}
642-
pub fn name(&self) -> String {
643-
control_id_name(*self)
644-
}
645640
}
646641
/// Enable or disable the AE.
647642
///

libcamera/versioned_files/0.4.0/properties.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22
use num_enum::{IntoPrimitive, TryFromPrimitive};
33
#[allow(unused_imports)]
4-
use crate::control::{
5-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name,
6-
};
4+
use crate::control::{Control, Property, ControlEntry, DynControlEntry};
75
use crate::control_value::{ControlValue, ControlValueError};
86
#[allow(unused_imports)]
97
use crate::geometry::{Rectangle, Point, Size};
@@ -726,9 +724,6 @@ impl PropertyId {
726724
pub fn id(&self) -> u32 {
727725
u32::from(*self)
728726
}
729-
pub fn name(&self) -> String {
730-
property_id_name(*self)
731-
}
732727
}
733728
/// Camera mounting location
734729
#[derive(Debug, Clone, Copy, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]

libcamera/versioned_files/0.5.0/controls.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22
use num_enum::{IntoPrimitive, TryFromPrimitive};
33
#[allow(unused_imports)]
4-
use crate::control::{
5-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name,
6-
};
4+
use crate::control::{Control, Property, ControlEntry, DynControlEntry};
75
use crate::control_value::{ControlValue, ControlValueError};
86
#[allow(unused_imports)]
97
use crate::geometry::{Rectangle, Point, Size};
@@ -772,9 +770,6 @@ impl ControlId {
772770
pub fn id(&self) -> u32 {
773771
u32::from(*self)
774772
}
775-
pub fn name(&self) -> String {
776-
control_id_name(*self)
777-
}
778773
}
779774
/// Enable or disable the AEGC algorithm. When this control is set to true,
780775
/// both ExposureTimeMode and AnalogueGainMode are set to auto, and if this

libcamera/versioned_files/0.5.0/properties.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22
use num_enum::{IntoPrimitive, TryFromPrimitive};
33
#[allow(unused_imports)]
4-
use crate::control::{
5-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name,
6-
};
4+
use crate::control::{Control, Property, ControlEntry, DynControlEntry};
75
use crate::control_value::{ControlValue, ControlValueError};
86
#[allow(unused_imports)]
97
use crate::geometry::{Rectangle, Point, Size};
@@ -726,9 +724,6 @@ impl PropertyId {
726724
pub fn id(&self) -> u32 {
727725
u32::from(*self)
728726
}
729-
pub fn name(&self) -> String {
730-
property_id_name(*self)
731-
}
732727
}
733728
/// Camera mounting location
734729
#[derive(Debug, Clone, Copy, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]

libcamera/versioned_files/0.5.1/controls.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22
use num_enum::{IntoPrimitive, TryFromPrimitive};
33
#[allow(unused_imports)]
4-
use crate::control::{
5-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name,
6-
};
4+
use crate::control::{Control, Property, ControlEntry, DynControlEntry};
75
use crate::control_value::{ControlValue, ControlValueError};
86
#[allow(unused_imports)]
97
use crate::geometry::{Rectangle, Point, Size};
@@ -772,9 +770,6 @@ impl ControlId {
772770
pub fn id(&self) -> u32 {
773771
u32::from(*self)
774772
}
775-
pub fn name(&self) -> String {
776-
control_id_name(*self)
777-
}
778773
}
779774
/// Enable or disable the AEGC algorithm. When this control is set to true,
780775
/// both ExposureTimeMode and AnalogueGainMode are set to auto, and if this

libcamera/versioned_files/0.5.1/properties.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ops::{Deref, DerefMut};
22
use num_enum::{IntoPrimitive, TryFromPrimitive};
33
#[allow(unused_imports)]
4-
use crate::control::{
5-
Control, Property, ControlEntry, DynControlEntry, control_id_name, property_id_name,
6-
};
4+
use crate::control::{Control, Property, ControlEntry, DynControlEntry};
75
use crate::control_value::{ControlValue, ControlValueError};
86
#[allow(unused_imports)]
97
use crate::geometry::{Rectangle, Point, Size};
@@ -726,9 +724,6 @@ impl PropertyId {
726724
pub fn id(&self) -> u32 {
727725
u32::from(*self)
728726
}
729-
pub fn name(&self) -> String {
730-
property_id_name(*self)
731-
}
732727
}
733728
/// Camera mounting location
734729
#[derive(Debug, Clone, Copy, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]

0 commit comments

Comments
 (0)