ohos_libqos_sys/qos_ffi.rs
1// automatically generated by rust-bindgen 0.71.1
2
3#![allow(non_upper_case_globals)]
4#![allow(non_camel_case_types)]
5#![allow(non_snake_case)]
6#[cfg(feature = "api-20")]
7#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
8pub const OH_QOS_GEWU_INVALID_SESSION_ID: OH_QoS_GewuSession = 0xffff_ffff;
9#[cfg(feature = "api-20")]
10#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
11pub const OH_QOS_GEWU_INVALID_REQUEST_ID: OH_QoS_GewuRequest = 0xffff_ffff;
12
13#[cfg(feature = "api-12")]
14#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
15impl QoS_Level {
16 /// Means the QoS level is background.
17 pub const QOS_BACKGROUND: QoS_Level = QoS_Level(0);
18 /// Means the QoS level is utility.
19 pub const QOS_UTILITY: QoS_Level = QoS_Level(1);
20 /// Means the QoS level is default.
21 pub const QOS_DEFAULT: QoS_Level = QoS_Level(2);
22 /// Means the QoS level is user-initiated.
23 pub const QOS_USER_INITIATED: QoS_Level = QoS_Level(3);
24 /// Means the QoS level is user-request.
25 pub const QOS_DEADLINE_REQUEST: QoS_Level = QoS_Level(4);
26 /// Means the QoS level is user-interactive.
27 pub const QOS_USER_INTERACTIVE: QoS_Level = QoS_Level(5);
28}
29#[repr(transparent)]
30/// Describes the level of QoS.
31///
32///
33/// Available since API-level: 12
34#[cfg(feature = "api-12")]
35#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
36#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
37pub struct QoS_Level(pub ::core::ffi::c_uint);
38/// Session id
39///
40///
41/// Available since API-level: 20
42#[cfg(feature = "api-20")]
43#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
44pub type OH_QoS_GewuSession = ::core::ffi::c_uint;
45/// Request id
46///
47///
48/// Available since API-level: 20
49#[cfg(feature = "api-20")]
50#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
51pub type OH_QoS_GewuRequest = ::core::ffi::c_uint;
52#[cfg(feature = "api-20")]
53#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
54pub type OH_QoS_GewuResult = Result<(), OH_QoS_GewuErrorCode>;
55#[cfg(feature = "api-20")]
56#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
57impl OH_QoS_GewuErrorCode {
58 pub const NOPERM: OH_QoS_GewuErrorCode =
59 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(201).unwrap() });
60 pub const NOMEM: OH_QoS_GewuErrorCode =
61 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(203).unwrap() });
62 pub const INVAL: OH_QoS_GewuErrorCode =
63 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(401).unwrap() });
64 pub const EXIST: OH_QoS_GewuErrorCode =
65 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(501).unwrap() });
66 pub const NOENT: OH_QoS_GewuErrorCode =
67 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(502).unwrap() });
68 pub const NOSYS: OH_QoS_GewuErrorCode =
69 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(801).unwrap() });
70 pub const FAULT: OH_QoS_GewuErrorCode =
71 OH_QoS_GewuErrorCode(const { core::num::NonZero::new(901).unwrap() });
72}
73#[repr(transparent)]
74/// Gewu error codes.
75///
76///
77/// Available since API-level: 20
78#[cfg(feature = "api-20")]
79#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
80#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
81pub struct OH_QoS_GewuErrorCode(pub core::num::NonZero<::core::ffi::c_uint>);
82/// # Arguments
83///
84/// * `session` - The created session id
85///
86/// * `error` - Error code of CreateSession
87/// - OH_QOS_GEWU_OK will be returned if the session is created successfully.
88/// - OH_QOS_GEWU_NOMEM will be returned if the system does not have sufficient memory to
89/// create the session.
90///
91///
92/// Available since API-level: 20
93#[cfg(feature = "api-20")]
94#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
95#[repr(C)]
96#[derive(Debug, Copy, Clone)]
97pub struct OH_QoS_GewuCreateSessionResult {
98 pub session: OH_QoS_GewuSession,
99 pub error: OH_QoS_GewuResult,
100}
101/// # Arguments
102///
103/// * `request` - The created request id
104///
105/// * `error` - Error code of request submission.
106/// - OH_QOS_GEWU_OK will be returned if the request is submitted successfully.
107/// - OH_QOS_GEWU_NOMEM will be returned if the system does not have sufficient memory to
108/// submit the request.
109///
110///
111/// Available since API-level: 20
112#[cfg(feature = "api-20")]
113#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
114#[repr(C)]
115#[derive(Debug, Copy, Clone)]
116pub struct OH_QoS_GewuSubmitRequestResult {
117 pub request: OH_QoS_GewuRequest,
118 pub error: OH_QoS_GewuResult,
119}
120/// Callback to receive response of the request.
121///
122/// # Arguments
123///
124/// * `context` - The user context specified when submitting the request.
125///
126/// * `reponse` - The json string of the response, including the following parameters:
127/// - message: A message that contains the following fields.
128/// - role: string. Must be "assistant".
129/// - content: string. The message generated by the model in response to user messages.
130/// - finish_reason: string or null. The reason the inference stopped. Possible values:
131/// - null: Not finished yet, only present in streaming mode.
132/// - "stop": The model stopped natually.
133/// - "abort": The inference request was aborted.
134/// - "length": The generated tokens reached the limit.
135///
136///
137/// Available since API-level: 20
138#[cfg(feature = "api-20")]
139#[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
140pub type OH_QoS_GewuOnResponse = ::core::option::Option<
141 unsafe extern "C" fn(context: *mut ::core::ffi::c_void, response: *const ::core::ffi::c_char),
142>;
143extern "C" {
144 /// Set the QoS level of the current thread.
145 ///
146 /// # Arguments
147 ///
148 /// * `level` - Indicates the level to set. Specific level can be referenced [`QoS_Level`].
149 ///
150 /// # Returns
151 ///
152 /// * Returns 0 if the operation is successful; returns -1 if level is out of range or
153 /// internal error failed.
154 /// [`QoS_Level`]
155 /// Available since API-level: 12
156 #[cfg(feature = "api-12")]
157 #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
158 pub fn OH_QoS_SetThreadQoS(level: QoS_Level) -> ::core::ffi::c_int;
159 /// Cancel the QoS level of the current thread.
160 ///
161 ///
162 /// # Returns
163 ///
164 /// * Returns 0 if the operation is successful; returns -1 if not set QoS for current thread
165 /// or internal error failed.
166 /// [`QoS_Level`]
167 /// Available since API-level: 12
168 #[cfg(feature = "api-12")]
169 #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
170 pub fn OH_QoS_ResetThreadQoS() -> ::core::ffi::c_int;
171 /// Obtains the QoS level of the current thread.
172 ///
173 /// # Arguments
174 ///
175 /// * `level` - This parameter is the output parameter,
176 /// and the QoS level of the thread as a [`QoS_Level`] is written to this variable.
177 ///
178 /// # Returns
179 ///
180 /// * Returns 0 if the operation is successful; returns -1 if level is null, not
181 /// set QoS for current thread or internal error failed.
182 /// [`QoS_Level`]
183 /// Available since API-level: 12
184 #[cfg(feature = "api-12")]
185 #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
186 pub fn OH_QoS_GetThreadQoS(level: *mut QoS_Level) -> ::core::ffi::c_int;
187 /// Create a gewu session for inference.
188 /// The lifecycle of the returned session object spans from the return of CreateSession
189 /// to the call to DestroySession.
190 ///
191 /// json string of session attributes.
192 ///
193 /// The json string of session attributes include the following parameters
194 /// - model: string. The directory of the model of the session.
195 ///
196 /// An example of json string of session attributes:
197 /// ```json
198 /// {
199 /// "model": "/data/storage/el2/base/files/qwen2/"
200 /// }
201 /// ```
202 ///
203 /// # Arguments
204 ///
205 /// * `attributes` - The json string of session attributes.
206 ///
207 ///
208 /// # Returns
209 ///
210 /// * Result of CreateSession.
211 ///
212 ///
213 /// Available since API-level: 20
214 #[cfg(feature = "api-20")]
215 #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
216 pub fn OH_QoS_GewuCreateSession(
217 attributes: *const ::core::ffi::c_char,
218 ) -> OH_QoS_GewuCreateSessionResult;
219 /// Destroy the specified session.
220 /// It is recommended that the client shall wait until all ongoing requests are done before calling
221 /// this interface to destroy the session. If there are remaining requests in the session when this
222 /// interface is called, those requests will be aborted and no further responses for those requests
223 /// will be sent to the client.
224 /// Note that after calling this function successfully, the session cannot be used by the user code
225 /// any more.
226 ///
227 /// # Arguments
228 ///
229 /// * `session` - The session that will be destroyed.
230 ///
231 ///
232 /// # Returns
233 ///
234 /// * Error code.
235 /// - OH_QOS_GEWU_OK will be returned if the session is destroyed successfully.
236 /// - OH_QOS_GEWU_NOENT will be returned if the session is not found.
237 ///
238 ///
239 /// Available since API-level: 20
240 #[cfg(feature = "api-20")]
241 #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
242 pub fn OH_QoS_GewuDestroySession(session: OH_QoS_GewuSession) -> OH_QoS_GewuResult;
243 /// Abort the specified request.
244 /// Note that after calling this function successfully, the client will not receive further responses
245 /// for this request, and the request object cannot be used by the user code any more.
246 ///
247 /// # Arguments
248 ///
249 /// * `session` - The session that the request was submitted through.
250 ///
251 /// * `request` - The request object.
252 ///
253 ///
254 /// # Returns
255 ///
256 /// * Error code.
257 /// - OH_QOS_GEWU_OK will be returned if the request is aborted successfully.
258 /// - OH_QOS_GEWU_NOENT will be returned if the request is not found.
259 ///
260 ///
261 /// Available since API-level: 20
262 #[cfg(feature = "api-20")]
263 #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
264 pub fn OH_QoS_GewuAbortRequest(
265 session: OH_QoS_GewuSession,
266 request: OH_QoS_GewuRequest,
267 ) -> OH_QoS_GewuResult;
268 /// Submit a request.
269 ///
270 /// json string of completion request.
271 /// Completion request is a json string that specifies the following parameters:
272 /// - messages: array. A list of messages. Each message contains the following fields:
273 /// - role: string. The message type, which could be one of the following:
274 /// - "developer": Developer-provided instructions.
275 /// - "user": User-provided instructions.
276 /// - "assistant": Message generated by the model in response to user messages.
277 /// - content: string. The message content.
278 /// - stream: boolean or null; optional. Enable streaming mode or not. If set to true, partial
279 /// responses will be sent. If null or not set, defaults to nonstreaming mode.
280 ///
281 /// An example of completion request:
282 /// ```json
283 /// {
284 /// "messages": [
285 /// {
286 /// "role": "developer",
287 /// "content": "Your are a helpful assistant."
288 /// },
289 /// {
290 /// "role": "user",
291 /// "content": "What is OpenHarmony"
292 /// }
293 /// ],
294 /// "stream": true
295 /// }
296 /// ```
297 ///
298 /// # Arguments
299 ///
300 /// * `session` - The session object that the request should be submitted through.
301 ///
302 /// * `request` - The json string of request.
303 ///
304 /// * `callback` - The callback to receive response.
305 ///
306 /// * `context` - The user context that should be passed to the response callback.
307 ///
308 ///
309 /// # Returns
310 ///
311 /// * Gewu request submission result.
312 /// - OH_QOS_GEWU_OK will be returned if the request is accepted.
313 /// - OH_QOS_GEWU_NOMEM will be returned if the system does not have sufficient memory
314 /// to accept the request.
315 ///
316 ///
317 /// Available since API-level: 20
318 #[cfg(feature = "api-20")]
319 #[cfg_attr(docsrs, doc(cfg(feature = "api-20")))]
320 pub fn OH_QoS_GewuSubmitRequest(
321 session: OH_QoS_GewuSession,
322 request: *const ::core::ffi::c_char,
323 callback: OH_QoS_GewuOnResponse,
324 context: *mut ::core::ffi::c_void,
325 ) -> OH_QoS_GewuSubmitRequestResult;
326}