cyfs_lib/root_state/
input_request.rs

1use super::output_request::*;
2use crate::*;
3use cyfs_base::*;
4
5use std::fmt;
6
7#[derive(Clone, Debug)]
8pub struct RootStateInputRequestCommon {
9    // 来源信息
10    pub source: RequestSourceInfo,
11
12    // 操作的目标DEC,如果为空,那么默认是source.dec
13    pub target_dec_id: Option<ObjectId>,
14
15    pub target: Option<ObjectId>,
16
17    pub flags: u32,
18}
19
20impl fmt::Display for RootStateInputRequestCommon {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        write!(f, "{}", self.source)?;
23
24        if let Some(target_dec_id) = &self.target_dec_id {
25            write!(f, ", target_dec_id: {}", target_dec_id)?;
26        }
27
28        if let Some(target) = &self.target {
29            write!(f, ", target: {}", target)?;
30        }
31
32        write!(f, ", flags: {}", self.flags)?;
33
34        Ok(())
35    }
36}
37
38// get_current_root
39
40#[derive(Clone)]
41pub struct RootStateGetCurrentRootInputRequest {
42    pub common: RootStateInputRequestCommon,
43
44    pub root_type: RootStateRootType,
45}
46
47impl fmt::Display for RootStateGetCurrentRootInputRequest {
48    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49        write!(f, "common: {}, root_type={:?}", self.common, self.root_type)
50    }
51}
52
53pub type RootStateGetCurrentRootInputResponse = RootStateGetCurrentRootOutputResponse;
54
55// create_op_env
56#[derive(Clone)]
57pub struct RootStateCreateOpEnvInputRequest {
58    pub common: RootStateInputRequestCommon,
59
60    pub op_env_type: ObjectMapOpEnvType,
61
62    pub access: Option<RootStateOpEnvAccess>,
63}
64
65impl fmt::Display for RootStateCreateOpEnvInputRequest {
66    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67        write!(f, "common: {}", self.common)?;
68        write!(f, ", op_env_type: {}", self.op_env_type.to_string())?;
69        if let Some(access) = &self.access {
70            write!(f, ", access: {}", access)?;
71        }
72
73        Ok(())
74    }
75}
76
77pub type RootStateCreateOpEnvInputResponse = RootStateCreateOpEnvOutputResponse;
78
79#[derive(Clone, Debug)]
80pub struct OpEnvInputRequestCommon {
81    // 来源信息
82    pub source: RequestSourceInfo,
83
84    // 操作的目标DEC,如果为空,那么默认是source.dec
85    pub target_dec_id: Option<ObjectId>,
86
87    pub target: Option<ObjectId>,
88
89    pub flags: u32,
90
91    // 所属session id
92    pub sid: u64,
93}
94
95impl fmt::Display for OpEnvInputRequestCommon {
96    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97        write!(f, "{}", self.source)?;
98
99        write!(f, ", flags: {}", self.flags)?;
100
101        if let Some(target_dec_id) = &self.target_dec_id {
102            write!(f, ", target_dec_id: {}", target_dec_id)?;
103        }
104
105        if let Some(target) = &self.target {
106            write!(f, ", target: {}", target)?;
107        }
108
109        write!(f, ", sid: {}", self.sid)?;
110
111        Ok(())
112    }
113}
114
115pub struct OpEnvNoParamInputRequest {
116    pub common: OpEnvInputRequestCommon,
117}
118
119impl fmt::Display for OpEnvNoParamInputRequest {
120    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
121        write!(f, "common: {}", self.common)
122    }
123}
124
125/// single_op_env methods
126// load
127pub struct OpEnvLoadInputRequest {
128    pub common: OpEnvInputRequestCommon,
129
130    pub target: ObjectId,
131    pub inner_path: Option<String>,
132}
133
134impl fmt::Display for OpEnvLoadInputRequest {
135    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136        write!(f, "common: {}", self.common)?;
137        write!(f, ", target: {}", self.target)?;
138        if let Some(inner_path) = &self.inner_path {
139            write!(f, ", inner_path: {}", inner_path)?;
140        }
141
142        Ok(())
143    }
144}
145
146// load_by_path
147pub struct OpEnvLoadByPathInputRequest {
148    pub common: OpEnvInputRequestCommon,
149
150    pub path: String,
151}
152
153impl fmt::Display for OpEnvLoadByPathInputRequest {
154    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155        write!(f, "common: {}", self.common)?;
156        write!(f, ", path: {}", self.path)
157    }
158}
159
160// create_new
161pub struct OpEnvCreateNewInputRequest {
162    pub common: OpEnvInputRequestCommon,
163
164    pub path: Option<String>,
165    pub key: Option<String>,
166
167    pub content_type: ObjectMapSimpleContentType,
168    pub owner: Option<ObjectMapField>,
169    pub dec: Option<ObjectMapField>,
170}
171
172impl fmt::Display for OpEnvCreateNewInputRequest {
173    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
174        write!(f, "common: {}", self.common)?;
175        if let Some(path) = &self.path {
176            write!(f, ", path: {}", path)?;
177        }
178        if let Some(key) = &self.key {
179            write!(f, ", key: {}", key)?;
180        }
181        write!(
182            f,
183            ", content_type: {:?}, owner={:?}, dec={:?}",
184            self.content_type, self.owner, self.dec,
185        )
186    }
187}
188
189// lock
190pub struct OpEnvLockInputRequest {
191    pub common: OpEnvInputRequestCommon,
192
193    pub path_list: Vec<String>,
194    pub duration_in_millsecs: u64,
195    pub try_lock: bool,
196}
197
198impl fmt::Display for OpEnvLockInputRequest {
199    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
200        write!(f, "common: {}", self.common)?;
201        write!(f, ", path_list: {:?}", self.path_list)?;
202        write!(f, ", duration_in_millsecs: {}", self.duration_in_millsecs)?;
203        write!(f, ", try_lock: {}", self.try_lock)
204    }
205}
206
207// get_current_root
208pub type OpEnvGetCurrentRootInputRequest = OpEnvNoParamInputRequest;
209pub type OpEnvGetCurrentRootInputResponse = OpEnvCommitOutputResponse;
210
211// commit
212pub struct OpEnvCommitInputRequest {
213    pub common: OpEnvInputRequestCommon,
214    pub op_type: Option<OpEnvCommitOpType>,
215}
216
217impl fmt::Display for OpEnvCommitInputRequest {
218    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
219        write!(f, "common: {}, op_type: {:?}", self.common, self.op_type)
220    }
221}
222
223pub type OpEnvCommitInputResponse = OpEnvCommitOutputResponse;
224
225// abort
226pub type OpEnvAbortInputRequest = OpEnvNoParamInputRequest;
227
228// metadata
229pub struct OpEnvMetadataInputRequest {
230    pub common: OpEnvInputRequestCommon,
231
232    pub path: Option<String>,
233}
234
235impl fmt::Display for OpEnvMetadataInputRequest {
236    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
237        write!(f, "common: {}, path: {:?}", self.common, self.path)
238    }
239}
240
241pub type OpEnvMetadataInputResponse = OpEnvMetadataOutputResponse;
242
243// get_by_key
244#[derive(Clone)]
245pub struct OpEnvGetByKeyInputRequest {
246    pub common: OpEnvInputRequestCommon,
247
248    pub path: Option<String>,
249    pub key: String,
250}
251
252impl fmt::Display for OpEnvGetByKeyInputRequest {
253    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
254        write!(f, "common: {}", self.common)?;
255
256        if let Some(path) = &self.path {
257            write!(f, ", path: {}", path)?;
258        }
259
260        write!(f, ", key: {}", self.key)
261    }
262}
263
264pub type OpEnvGetByKeyInputResponse = OpEnvGetByKeyOutputResponse;
265
266// insert_with_key
267#[derive(Clone)]
268pub struct OpEnvInsertWithKeyInputRequest {
269    pub common: OpEnvInputRequestCommon,
270
271    pub path: Option<String>,
272    pub key: String,
273    pub value: ObjectId,
274}
275
276impl fmt::Display for OpEnvInsertWithKeyInputRequest {
277    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
278        write!(f, "common: {}", self.common)?;
279
280        if let Some(path) = &self.path {
281            write!(f, ", path: {}", path)?;
282        }
283
284        write!(f, ", key: {}", self.key)?;
285        write!(f, ", value: {}", self.value)
286    }
287}
288
289// set_with_key
290#[derive(Clone)]
291pub struct OpEnvSetWithKeyInputRequest {
292    pub common: OpEnvInputRequestCommon,
293
294    pub path: Option<String>,
295    pub key: String,
296    pub value: ObjectId,
297    pub prev_value: Option<ObjectId>,
298    pub auto_insert: bool,
299}
300
301impl fmt::Display for OpEnvSetWithKeyInputRequest {
302    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
303        write!(f, "common: {}", self.common)?;
304
305        if let Some(path) = &self.path {
306            write!(f, ", path: {}", path)?;
307        }
308
309        write!(f, ", key: {}", self.key)?;
310        write!(f, ", value: {}", self.value)?;
311        write!(f, ", prev_value: {:?}", self.prev_value)?;
312        write!(f, ", auto_insert: {}", self.auto_insert)
313    }
314}
315
316pub type OpEnvSetWithKeyInputResponse = OpEnvSetWithKeyOutputResponse;
317
318// remove_with_key
319#[derive(Clone)]
320pub struct OpEnvRemoveWithKeyInputRequest {
321    pub common: OpEnvInputRequestCommon,
322
323    pub path: Option<String>,
324    pub key: String,
325    pub prev_value: Option<ObjectId>,
326}
327
328impl fmt::Display for OpEnvRemoveWithKeyInputRequest {
329    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
330        write!(f, "common: {}", self.common)?;
331
332        if let Some(path) = &self.path {
333            write!(f, ", path: {}", path)?;
334        }
335
336        write!(f, ", key: {}", self.key)?;
337        write!(f, ", prev_value: {:?}", self.prev_value)
338    }
339}
340
341pub type OpEnvRemoveWithKeyInputResponse = OpEnvRemoveWithKeyOutputResponse;
342
343// set模式通用的request
344pub struct OpEnvSetInputRequest {
345    pub common: OpEnvInputRequestCommon,
346
347    pub path: Option<String>,
348    pub value: ObjectId,
349}
350
351impl fmt::Display for OpEnvSetInputRequest {
352    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
353        write!(f, "common: {}", self.common)?;
354
355        if let Some(path) = &self.path {
356            write!(f, ", path: {}", path)?;
357        }
358
359        write!(f, ", value: {}", self.value)
360    }
361}
362
363pub type OpEnvSetInputResponse = OpEnvSetOutputResponse;
364
365// contains
366pub type OpEnvContainsInputRequest = OpEnvSetInputRequest;
367pub type OpEnvContainsInputResponse = OpEnvSetInputResponse;
368
369// insert
370pub type OpEnvInsertInputRequest = OpEnvSetInputRequest;
371pub type OpEnvInsertInputResponse = OpEnvSetInputResponse;
372
373// remove
374pub type OpEnvRemoveInputRequest = OpEnvSetInputRequest;
375pub type OpEnvRemoveInputResponse = OpEnvSetInputResponse;
376
377// 迭代器
378
379// next
380pub struct OpEnvNextInputRequest {
381    pub common: OpEnvInputRequestCommon,
382
383    // 步进的元素个数
384    pub step: u32,
385}
386
387impl fmt::Display for OpEnvNextInputRequest {
388    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
389        write!(f, "common: {}", self.common)?;
390
391        write!(f, ", step: {}", self.step)
392    }
393}
394
395pub type OpEnvNextInputResponse = OpEnvNextOutputResponse;
396
397// reset
398pub type OpEnvResetInputRequest = OpEnvNoParamInputRequest;
399
400// list
401// next
402pub struct OpEnvListInputRequest {
403    pub common: OpEnvInputRequestCommon,
404
405    // for path-op-env
406    pub path: Option<String>,
407}
408
409impl fmt::Display for OpEnvListInputRequest {
410    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
411        write!(f, "common: {}", self.common)?;
412
413        write!(f, ", path: {:?}", self.path)
414    }
415}
416
417pub type OpEnvListInputResponse = OpEnvNextOutputResponse;
418
419//////////////////////////
420/// global-state accessor requests
421
422// get_object_by_path
423#[derive(Clone)]
424pub struct RootStateAccessorGetObjectByPathInputRequest {
425    pub common: RootStateInputRequestCommon,
426
427    pub inner_path: String,
428}
429
430impl fmt::Display for RootStateAccessorGetObjectByPathInputRequest {
431    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
432        write!(f, "common: {}", self.common)?;
433        write!(f, ", inner_path: {}", self.inner_path)
434    }
435}
436
437pub struct RootStateAccessorGetObjectByPathInputResponse {
438    pub object: NONGetObjectInputResponse,
439    pub root: ObjectId,
440    pub revision: u64,
441}
442
443// list
444pub struct RootStateAccessorListInputRequest {
445    pub common: RootStateInputRequestCommon,
446
447    pub inner_path: String,
448
449    // read elements by page
450    pub page_index: Option<u32>,
451    pub page_size: Option<u32>,
452}
453
454impl fmt::Display for RootStateAccessorListInputRequest {
455    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
456        write!(f, "common: {}", self.common)?;
457
458        write!(
459            f,
460            ", inner_path={}, page_index: {:?}, page_size: {:?}",
461            self.inner_path, self.page_index, self.page_size
462        )
463    }
464}
465
466pub type RootStateAccessorListInputResponse = RootStateAccessorListOutputResponse;