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
14as_boxed!(ConfigurationSourceConfig);
15}
16
17boxed_value_trait!(ConfigurationSourceConfig);
18
19pub trait ConfigurationSourceConfigBuilder {
20
21    /// required
22    fn set_name(&mut self, name: &str) -> &mut dyn ConfigurationSourceConfigBuilder;
23
24    fn build(&self) -> Box<dyn ConfigurationSourceConfig>;
25
26}
27
28pub trait ConfigurationSource: Value + Send + Sync {
29
30    fn get_config(&self) -> &dyn ConfigurationSourceConfig;
31
32    /// get property value acccording to the property config
33    /// 
34    /// if property is configured, the value is of type V
35    /// or can be converted to type V by the converters
36    /// a value of type V returned
37    /// 
38    /// otherwise, None returned
39    ///
40    fn get_property_value(&self, config: &dyn RawPropertyConfig) -> Option<Box<dyn Value>>;
41
42    //// listeners to the source change, notified once source changed
43    //// 
44    //// will be used by the configuration manager
45    fn add_change_listener(&self, listener: ConfigurationSourceChangeListener);
46
47as_boxed!(ConfigurationSource);
48}
49
50boxed_value_trait!(ConfigurationSource);
51
52pub trait ConfigurationSourceChangeEvent: Value + Send + Sync {
53
54    fn get_source(&self) -> &dyn ConfigurationSource;
55
56    fn get_change_time(&self) -> u128;
57
58as_boxed!(ConfigurationSourceChangeEvent);
59}
60
61boxed_value_trait!(ConfigurationSourceChangeEvent);
62
63pub type ConfigurationSourceChangeListener = ConsumerRef<dyn ConfigurationSourceChangeEvent>;