1dfe32fa1Soh_ci/* 2dfe32fa1Soh_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3dfe32fa1Soh_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4dfe32fa1Soh_ci * you may not use this file except in compliance with the License. 5dfe32fa1Soh_ci * You may obtain a copy of the License at 6dfe32fa1Soh_ci * 7dfe32fa1Soh_ci * http://www.apache.org/licenses/LICENSE-2.0 8dfe32fa1Soh_ci * 9dfe32fa1Soh_ci * Unless required by applicable law or agreed to in writing, software 10dfe32fa1Soh_ci * distributed under the License is distributed on an "AS IS" BASIS, 11dfe32fa1Soh_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12dfe32fa1Soh_ci * See the License for the specific language governing permissions and 13dfe32fa1Soh_ci * limitations under the License. 14dfe32fa1Soh_ci */ 15dfe32fa1Soh_ci 16dfe32fa1Soh_ci//! This module defines the interface of the Asset Rust SDK. 17dfe32fa1Soh_ci 18dfe32fa1Soh_cipub use asset_definition::Value; 19dfe32fa1Soh_ciuse ipc::parcel::MsgParcel; 20dfe32fa1Soh_ciuse std::any::Any; 21dfe32fa1Soh_ciuse std::collections::HashMap; 22dfe32fa1Soh_ci 23dfe32fa1Soh_ci/// Defines a type alias `ExtDbMap` as a `HashMap` with keys of type `&'static str` and values of type `Value`. 24dfe32fa1Soh_cipub type ExtDbMap = HashMap<&'static str, Value>; 25dfe32fa1Soh_ci 26dfe32fa1Soh_ci/// An enumeration representing different event types related to specific operations. 27dfe32fa1Soh_ci#[derive(Default, Hash, PartialEq, Eq, Clone)] 28dfe32fa1Soh_cipub enum EventType { 29dfe32fa1Soh_ci /// Sync operate. 30dfe32fa1Soh_ci #[default] 31dfe32fa1Soh_ci Sync = 0, 32dfe32fa1Soh_ci 33dfe32fa1Soh_ci /// Clean cloud flag. 34dfe32fa1Soh_ci CleanCloudFlag = 1, 35dfe32fa1Soh_ci 36dfe32fa1Soh_ci /// Delete cloud data. 37dfe32fa1Soh_ci DeleteCloudData, 38dfe32fa1Soh_ci 39dfe32fa1Soh_ci /// Device upgrade event. 40dfe32fa1Soh_ci OnDeviceUpgrade, 41dfe32fa1Soh_ci 42dfe32fa1Soh_ci /// App upgrade event. 43dfe32fa1Soh_ci OnAppRestore, 44dfe32fa1Soh_ci 45dfe32fa1Soh_ci /// User unlock envent. 46dfe32fa1Soh_ci OnUserUnlocked, 47dfe32fa1Soh_ci 48dfe32fa1Soh_ci /// App call event. 49dfe32fa1Soh_ci OnAppCall, 50dfe32fa1Soh_ci 51dfe32fa1Soh_ci /// Package clear event. 52dfe32fa1Soh_ci OnPackageClear, 53dfe32fa1Soh_ci 54dfe32fa1Soh_ci /// User removed. 55dfe32fa1Soh_ci OnUserRemoved, 56dfe32fa1Soh_ci} 57dfe32fa1Soh_ci 58dfe32fa1Soh_ci/// param name for bundle name 59dfe32fa1Soh_cipub const PARAM_NAME_BUNDLE_NAME: &str = "BundleName"; 60dfe32fa1Soh_ci 61dfe32fa1Soh_ci/// param name for user id 62dfe32fa1Soh_cipub const PARAM_NAME_USER_ID: &str = "UserId"; 63dfe32fa1Soh_ci 64dfe32fa1Soh_ci/// param name for app index 65dfe32fa1Soh_cipub const PARAM_NAME_APP_INDEX: &str = "AppIndex"; 66dfe32fa1Soh_ci 67dfe32fa1Soh_ci/// param name for owner type 68dfe32fa1Soh_cipub const PARAM_NAME_IS_HAP: &str = "IsHap"; 69dfe32fa1Soh_ci 70dfe32fa1Soh_ci/// An enumeration representing different plugin types. 71dfe32fa1Soh_ci#[derive(Default, Hash, PartialEq, Eq, Clone)] 72dfe32fa1Soh_cipub enum PluginType { 73dfe32fa1Soh_ci /// Default plugin. 74dfe32fa1Soh_ci #[default] 75dfe32fa1Soh_ci Asset = 0, 76dfe32fa1Soh_ci} 77dfe32fa1Soh_ci 78dfe32fa1Soh_ci/// Defines an interface for an asset plugin context, which outlines the basic methods for 79dfe32fa1Soh_ci/// an asset plugin to operate on an asset database. 80dfe32fa1Soh_cipub trait IAssetPluginCtx: Any + Sync + Send + std::panic::RefUnwindSafe { 81dfe32fa1Soh_ci /// Initializes the plugin before usage. 82dfe32fa1Soh_ci fn init(&mut self, user_id: i32) -> Result<(), u32>; 83dfe32fa1Soh_ci 84dfe32fa1Soh_ci /// Adds an asset to de db. 85dfe32fa1Soh_ci fn add(&mut self, attributes: &ExtDbMap) -> Result<i32, u32>; 86dfe32fa1Soh_ci 87dfe32fa1Soh_ci /// Adds an asset to ce cb. 88dfe32fa1Soh_ci fn ce_add(&mut self, attributes: &ExtDbMap) -> Result<i32, u32>; 89dfe32fa1Soh_ci 90dfe32fa1Soh_ci /// Adds an asset with replace to de db. 91dfe32fa1Soh_ci fn replace(&mut self, condition: &ExtDbMap, attributes: &ExtDbMap) -> std::result::Result<(), u32>; 92dfe32fa1Soh_ci 93dfe32fa1Soh_ci /// Adds an asset with replace to ce db. 94dfe32fa1Soh_ci fn ce_replace(&mut self, condition: &ExtDbMap, attributes: &ExtDbMap) -> std::result::Result<(), u32>; 95dfe32fa1Soh_ci 96dfe32fa1Soh_ci /// Queries de db. 97dfe32fa1Soh_ci fn query(&mut self, attributes: &ExtDbMap) -> Result<Vec<ExtDbMap>, u32>; 98dfe32fa1Soh_ci 99dfe32fa1Soh_ci /// Queries ce db. 100dfe32fa1Soh_ci fn ce_query(&mut self, attributes: &ExtDbMap) -> Result<Vec<ExtDbMap>, u32>; 101dfe32fa1Soh_ci 102dfe32fa1Soh_ci /// Removes an asset from de db. 103dfe32fa1Soh_ci fn remove(&mut self, attributes: &ExtDbMap) -> Result<i32, u32>; 104dfe32fa1Soh_ci 105dfe32fa1Soh_ci /// Removes an asset from ce db. 106dfe32fa1Soh_ci fn ce_remove(&mut self, attributes: &ExtDbMap) -> Result<i32, u32>; 107dfe32fa1Soh_ci 108dfe32fa1Soh_ci /// Removes assets from de db with specific condition. 109dfe32fa1Soh_ci fn remove_with_specific_cond(&mut self, specific_cond: &str, condition_value: &[Value]) -> Result<i32, u32>; 110dfe32fa1Soh_ci 111dfe32fa1Soh_ci /// Removes assets from ce db with specific condition. 112dfe32fa1Soh_ci fn ce_remove_with_specific_cond(&mut self, specific_cond: &str, condition_value: &[Value]) -> Result<i32, u32>; 113dfe32fa1Soh_ci 114dfe32fa1Soh_ci /// Updates the attributes of an asset in de db. 115dfe32fa1Soh_ci fn update(&mut self, attributes: &ExtDbMap, attrs_to_update: &ExtDbMap) -> Result<i32, u32>; 116dfe32fa1Soh_ci 117dfe32fa1Soh_ci /// Updates the attributes of an asset in ce db. 118dfe32fa1Soh_ci fn ce_update(&mut self, attributes: &ExtDbMap, attrs_to_update: &ExtDbMap) -> Result<i32, u32>; 119dfe32fa1Soh_ci 120dfe32fa1Soh_ci /// Returns the storage path for de db. 121dfe32fa1Soh_ci fn get_storage_path(&self) -> String; 122dfe32fa1Soh_ci 123dfe32fa1Soh_ci /// Increase count 124dfe32fa1Soh_ci fn increase_count(&mut self); 125dfe32fa1Soh_ci 126dfe32fa1Soh_ci /// Decrease count 127dfe32fa1Soh_ci fn decrease_count(&mut self); 128dfe32fa1Soh_ci} 129dfe32fa1Soh_ci 130dfe32fa1Soh_ci/// Defines a trait `IAssetPlugin` that specifies the required functionality for an asset plugin implementation. 131dfe32fa1Soh_cipub trait IAssetPlugin: Any + Sync + Send + std::panic::RefUnwindSafe { 132dfe32fa1Soh_ci /// Initialize the plugin. 133dfe32fa1Soh_ci fn init(&self, ctx: Box<dyn IAssetPluginCtx>) -> Result<(), u32>; 134dfe32fa1Soh_ci 135dfe32fa1Soh_ci /// Uninitialize the plugin. 136dfe32fa1Soh_ci fn uninit(&self); 137dfe32fa1Soh_ci 138dfe32fa1Soh_ci /// Process the event. 139dfe32fa1Soh_ci fn process_event(&self, event_type: EventType, params: &ExtDbMap) -> Result<(), u32>; 140dfe32fa1Soh_ci 141dfe32fa1Soh_ci /// Redirect request. 142dfe32fa1Soh_ci fn redirect_request(&self, code: u32, data: &mut MsgParcel, reply: &mut MsgParcel) -> Result<(), i32>; 143dfe32fa1Soh_ci} 144