1 #[perlmod::package(name = "PVE::RS::Notify")]
3 use anyhow
::{bail, Error}
;
8 use proxmox_notify
::Config
;
10 pub struct NotificationConfig
{
11 config
: Mutex
<Config
>,
14 perlmod
::declare_magic
!(Box
<NotificationConfig
> : &NotificationConfig
as "PVE::RS::Notify");
16 /// Support `dclone` so this can be put into the `ccache` of `PVE::Cluster`.
17 #[export(name = "STORABLE_freeze", raw_return)]
19 #[try_from_ref] this: &NotificationConfig,
21 ) -> Result
<Value
, Error
> {
23 bail
!("freezing Notification config not supported!");
26 let mut cloned
= Box
::new(NotificationConfig
{
27 config
: Mutex
::new(this
.config
.lock().unwrap().clone()),
29 let value
= Value
::new_pointer
::<NotificationConfig
>(&mut *cloned
);
30 let _perl
= Box
::leak(cloned
);
34 /// Instead of `thaw` we implement `attach` for `dclone`.
35 #[export(name = "STORABLE_attach", raw_return)]
39 #[raw] serialized: Value,
40 ) -> Result
<Value
, Error
> {
42 bail
!("STORABLE_attach called with cloning=false");
44 let data
= unsafe { Box::from_raw(serialized.pv_raw::<NotificationConfig>()?) }
;
45 Ok(perlmod
::instantiate_magic
!(&class
, MAGIC
=> data
))
52 raw_private_config
: &[u8],
53 ) -> Result
<Value
, Error
> {
54 let raw_config
= std
::str::from_utf8(raw_config
)?
;
55 let raw_private_config
= std
::str::from_utf8(raw_private_config
)?
;
57 Ok(perlmod
::instantiate_magic
!(&class
, MAGIC
=> Box
::new(
59 config
: Mutex
::new(Config
::new(raw_config
, raw_private_config
)?
)
65 fn write_config(#[try_from_ref] this: &NotificationConfig) -> Result<(String, String), Error> {
66 Ok(this
.config
.lock().unwrap().write()?
)
70 fn digest(#[try_from_ref] this: &NotificationConfig) -> String {
71 let config
= this
.config
.lock().unwrap();
72 hex
::encode(config
.digest())