scf_core/source/
mod.rs

1use lang_extension::any::*;
2use lang_extension::ops::function::*;
3
4use crate::property::*;
5
6pub mod default;
7
8pub trait ConfigurationSourceConfig: Value + Send + Sync {
9    /// for description use
10    ///
11    /// non-null, non-empty
12    fn get_name(&self) -> &str;
13
14    as_boxed!(ConfigurationSourceConfig);
15}
16
17boxed_value_trait!(ConfigurationSourceConfig);
18
19pub trait ConfigurationSourceConfigBuilder {
20    /// required
21    fn set_name(&mut self, name: &str) -> &mut dyn ConfigurationSourceConfigBuilder;
22
23    fn build(&self) -> Box<dyn ConfigurationSourceConfig>;
24}
25
26pub trait ConfigurationSource: Value + Send + Sync {
27    fn get_config(&self) -> &dyn ConfigurationSourceConfig;
28
29    /// get property value acccording to the property config
30    ///
31    /// if property is configured, the value is of type V
32    /// or can be converted to type V by the converters
33    /// a value of type V returned
34    ///
35    /// otherwise, None returned
36    ///
37    fn get_property_value(&self, config: &dyn RawPropertyConfig) -> Option<Box<dyn Value>>;
38
39    //// listeners to the source change, notified once source changed
40    ////
41    //// will be used by the configuration manager
42    fn add_change_listener(&self, listener: ConfigurationSourceChangeListener);
43
44    as_boxed!(ConfigurationSource);
45}
46
47boxed_value_trait!(ConfigurationSource);
48
49pub trait ConfigurationSourceChangeEvent: Value + Send + Sync {
50    fn get_source(&self) -> &dyn ConfigurationSource;
51
52    fn get_change_time(&self) -> u128;
53
54    as_boxed!(ConfigurationSourceChangeEvent);
55}
56
57boxed_value_trait!(ConfigurationSourceChangeEvent);
58
59pub type ConfigurationSourceChangeListener = ConsumerRef<dyn ConfigurationSourceChangeEvent>;