1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This file is part of fpgad, an application to manage FPGA subsystem together with device-tree and kernel modules.
//
// Copyright 2025 Canonical Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only
//
// fpgad is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, as published by the Free Software Foundation.
//
// fpgad is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
//! Remove command implementation for the FPGA CLI.
//!
//! This module handles the removal of FPGA bitstreams and device tree overlays through
//! the fpgad daemon's DBus interface. It provides functionality to:
//! - Remove device tree overlays from the system
//! - Remove FPGA bitstreams (platform-dependent, currently not implemented)
//! - Automatically detect and remove the first overlay when not specified
//!
//! The module communicates with the fpgad daemon via DBus to perform these privileged
//! operations on the FPGA subsystem.
//!
//! For information on [Device Handles], [Overlay Handles], and [Error Handling],
//! see the [Common Concepts](../index.html#common-concepts) section in the main CLI documentation.
//!
//! [Device Handles]: ../index.html#device-handles
//! [Overlay Handles]: ../index.html#overlay-handles
//! [Error Handling]: ../index.html#error-handling
use crateRemoveSubcommand;
use cratecontrol_proxy;
use crate;
use Connection;
/// Removes a bitstream from an FPGA device.
///
/// # Note
///
/// This functionality is currently not implemented as bitstream removal is
/// vendor-specific and depends on platform capabilities that may be added
/// through softener implementations in the future.
///
/// # Returns: `Result<String, zbus::Error>`
/// * `Err(zbus::Error)` - Always returns "Not implemented" error
async
/// Sends the DBus command to remove a device tree overlay.
///
/// Communicates with the fpgad daemon via DBus to remove a previously loaded
/// device tree overlay from the system.
///
/// # Arguments
///
/// * `device_handle` - Platform identifier for the [device](../index.html#device-handles)
/// * `overlay_handle` - [Overlay handle](../index.html#overlay-handles) of the overlay to remove
///
/// # Returns: `Result<String, zbus::Error>`
/// * `Ok(String)` - Success message from the daemon
/// * `Err(zbus::Error)` - DBus communication error, invalid handle(s), or FpgadError.
/// See [Error Handling](../index.html#error-handling) for details.
async
/// Removes a device tree overlay with automatic platform and handle detection.
///
/// This function handles the logic for determining the appropriate platform and overlay
/// handle based on what the user has provided. It supports:
/// - Auto-detecting the first platform if no device handle is provided
/// - Auto-detecting the first overlay if no overlay handle is provided
/// - Using provided handles when available
///
/// # Arguments
///
/// * `device_handle` - Optional [device handle](../index.html#device-handles) for platform detection
/// * `overlay_handle` - Optional [overlay handle](../index.html#overlay-handles) of the specific overlay to remove
///
/// # Returns: `Result<String, zbus::Error>`
/// * `Ok(String)` - Success message from the daemon
/// * `Err(zbus::Error)` - DBus communication error, detection failure, or FpgadError.
/// See [Error Handling](../index.html#error-handling) for details.
async
/// Main handler for the remove command.
///
/// Dispatches to the appropriate remove function based on the subcommand type
/// (overlay or bitstream). This is the entry point called by the CLI's main
/// function when a remove command is issued.
///
/// # Arguments
///
/// * `dev_handle` - Optional [device handle](../index.html#device-handles)
/// * `sub_command` - The remove subcommand specifying what to remove (overlay or bitstream)
///
/// # Returns: `Result<String, zbus::Error>`
/// * `Ok(String)` - Success message from the operation
/// * `Err(zbus::Error)` - DBus communication error, operation failure, or FpgadError.
/// See [Error Handling](../index.html#error-handling) for details.
pub async