cyfs_core/app/
app_setting.rs

1use crate::coreobj::CoreObjectType;
2use crate::DecAppId;
3use cyfs_base::*;
4use serde::Serialize;
5
6pub const APP_SETTING_MAIN_PATH: &str = "/app_setting";
7
8#[derive(Clone, ProtobufEncode, ProtobufDecode, ProtobufTransform, Serialize)]
9#[cyfs_protobuf_type(crate::codec::protos::AppSettingDesc)]
10pub struct AppSettingDesc {
11    id: DecAppId,
12    auto_update: bool,
13}
14
15impl DescContent for AppSettingDesc {
16    fn obj_type() -> u16 {
17        CoreObjectType::AppSetting as u16
18    }
19
20    fn format(&self) -> u8 {
21        OBJECT_CONTENT_CODEC_FORMAT_PROTOBUF
22    }
23
24    type OwnerType = Option<ObjectId>;
25    type AreaType = SubDescNone;
26    type AuthorType = SubDescNone;
27    type PublicKeyType = SubDescNone;
28}
29
30#[derive(Clone, Default, ProtobufEmptyEncode, ProtobufEmptyDecode, Serialize)]
31pub struct AppSettingBody {}
32
33impl BodyContent for AppSettingBody {
34    fn format(&self) -> u8 {
35        OBJECT_CONTENT_CODEC_FORMAT_PROTOBUF
36    }
37}
38
39type AppSettingType = NamedObjType<AppSettingDesc, AppSettingBody>;
40type AppSettingBuilder = NamedObjectBuilder<AppSettingDesc, AppSettingBody>;
41
42pub type AppSettingId = NamedObjectId<AppSettingType>;
43pub type AppSetting = NamedObjectBase<AppSettingType>;
44
45pub trait AppSettingObj {
46    fn create(owner: ObjectId, id: DecAppId) -> Self;
47    fn app_id(&self) -> &DecAppId;
48
49    fn auto_update(&self) -> bool;
50    fn set_auto_update(&mut self, auto_update: bool);
51}
52
53impl AppSettingObj for AppSetting {
54    fn create(owner: ObjectId, id: DecAppId) -> Self {
55        let body = AppSettingBody {};
56        let desc = AppSettingDesc {
57            id,
58            auto_update: false,
59        };
60        AppSettingBuilder::new(desc, body)
61            .owner(owner)
62            .no_create_time()
63            .build()
64    }
65
66    fn app_id(&self) -> &DecAppId {
67        &self.desc().content().id
68    }
69
70    fn auto_update(&self) -> bool {
71        self.desc().content().auto_update
72    }
73
74    fn set_auto_update(&mut self, auto_update: bool) {
75        self.desc_mut().content_mut().auto_update = auto_update;
76    }
77}