• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2024 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 mod manager;
15 
16 cfg_oh! {
17     use ipc::parcel::MsgParcel;
18     use ipc::remote::RemoteObj;
19     use ipc::IpcResult;
20 }
21 pub(crate) use manager::{RunCountManager, RunCountManagerEntry};
22 use ylong_runtime::sync::oneshot::Sender;
23 
24 use super::interface;
25 use crate::error::ErrorCode;
26 
27 pub(crate) enum RunCountEvent {
28     #[cfg(feature = "oh")]
29     Subscribe(u64, RemoteObj, Sender<ErrorCode>),
30     Unsubscribe(u64, Sender<ErrorCode>),
31     #[cfg(feature = "oh")]
32     Change(usize),
33 }
34 
35 struct Client {
36     #[cfg(feature = "oh")]
37     obj: RemoteObj,
38 }
39 
40 impl Client {
new(#[cfg(feature = "oh")] obj: RemoteObj) -> Self41     fn new(#[cfg(feature = "oh")] obj: RemoteObj) -> Self {
42         Self {
43             #[cfg(feature = "oh")]
44             obj,
45         }
46     }
47 
48     #[cfg(feature = "oh")]
notify_run_count(&self, run_count: i64) -> IpcResult<()>49     fn notify_run_count(&self, run_count: i64) -> IpcResult<()> {
50         info!("notify run_count is {}", run_count);
51         #[cfg(feature = "oh")]
52         {
53             let mut parcel = MsgParcel::new();
54 
55             parcel.write_interface_token("OHOS.Download.NotifyInterface")?;
56             parcel.write(&(run_count))?;
57 
58             self.obj
59                 .send_request(interface::NOTIFY_RUN_COUNT, &mut parcel)?;
60             Ok(())
61         }
62     }
63 }
64