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
//!  SPDX-License-Identifier: MIT
//!
//! Copyright (c) 2023, eunomia-bpf
//! All rights reserved.
//!

/// The HTTP client
#[cfg(feature = "http-client")]
pub mod http;
/// The native client
#[cfg(feature = "native-client")]
pub mod native;

use crate::{config::ProgramType, error::Result};

use super::{LogEntry, ProgramHandle};

/// Status of an exist program
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProgramStatus {
    Running,
    Paused,
}
/// Description of an exist program
#[derive(Debug, Clone)]
pub struct ProgramDesc {
    pub id: ProgramHandle,
    pub name: String,
    pub status: ProgramStatus,
}
/// Common interfaces for client
#[async_trait::async_trait]
pub trait AbstractClient {
    async fn start_program(
        &self,
        name: Option<String>,
        prog_buf: &[u8],
        prog_type: ProgramType,
        export_json: bool,
        args: &[String],
        btf_archive_path: Option<String>,
    ) -> Result<ProgramHandle>;
    async fn terminate_program(&self, handle: ProgramHandle) -> Result<()>;
    async fn set_program_pause_state(&self, handle: ProgramHandle, pause: bool) -> Result<()>;
    async fn fetch_logs(
        &self,
        handle: ProgramHandle,
        cursor: Option<usize>,
        maximum_count: Option<usize>,
    ) -> Result<Vec<(usize, LogEntry)>>;
    async fn get_program_list(&self) -> Result<Vec<ProgramDesc>>;
}