lib.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use btproto::protocol;
  2. use btrun::model::{ActorName, CallMsg, NoReply, SendMsg};
  3. use btsector::FileId;
  4. use serde::{Deserialize, Serialize};
  5. #[derive(Serialize, Deserialize)]
  6. pub struct Open {
  7. id: FileId,
  8. }
  9. impl CallMsg for Open {
  10. type Reply = ActorName;
  11. }
  12. #[derive(Serialize, Deserialize)]
  13. pub struct OpenFile;
  14. impl CallMsg for OpenFile {
  15. type Reply = NoReply;
  16. }
  17. impl SendMsg for OpenFile {}
  18. protocol! {
  19. named FsProtocol;
  20. let server = [Listening];
  21. let client = [Client];
  22. let file = [Opened];
  23. let file_handle = [FileHandle];
  24. Client -> Client, >service(Listening)!Query;
  25. Listening?Query -> Listening, >Client!Query::Reply;
  26. Client -> Client, FileHandle[Opened], >service(Listening)!Open;
  27. Listening?Open -> Listening, Opened, >Client!Open::Reply[Opened];
  28. FileHandle[Opened] -> FileHandle[Opened], >Opened!FileOp;
  29. Opened?FileOp -> Opened, >FileHandle!FileOp::Reply;
  30. FileHandle[Opened] -> End, >Opened!Close;
  31. Opened?Close -> End;
  32. }
  33. #[derive(Serialize, Deserialize)]
  34. pub struct Query;
  35. impl CallMsg for Query {
  36. type Reply = ();
  37. }
  38. #[derive(Serialize, Deserialize)]
  39. pub struct FileOp;
  40. impl CallMsg for FileOp {
  41. type Reply = ();
  42. }
  43. #[derive(Serialize, Deserialize)]
  44. pub struct Close;