chiark / gitweb /
move cmd into mgmtchannel
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Dec 2020 17:58:08 +0000 (17:58 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Dec 2020 17:58:08 +0000 (17:58 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/mgmtchannel.rs

index 3a5f1c76d34bdfca7753f7f4b137d516da8541a3..c0faf783ef7ab61026ebab805b29469a4290fc75 100644 (file)
@@ -440,30 +440,15 @@ struct Conn {
   chan: MgmtChannel,
 }
 
-impl Conn {
-  #[throws(AE)]
-  fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse {
-    use MgmtResponse::*;
-    self.chan.write(&cmd).context("send command")?;
-    let resp = self.chan.read().context("read response")?;
-    match &resp {
-      Fine | GamesList{..} | LibraryItems(_) => { },
-      AlterGame { error: None, .. } => { },
-      Error { error } => {
-        Err(error.clone()).context(
-          format!("got error response to: {:?}",&cmd)
-        )?;
-      },
-      AlterGame { error: Some(error), .. } => {
-        Err(error.clone()).context(format!(
-          "game alterations failed (maybe partially); response to: {:?}",
-          &cmd
-        ))?;
-      }
-    };
-    resp
-  }
+impl Deref for Conn {
+  type Target = MgmtChannel;
+  fn deref(&self) -> &MgmtChannel { &self.chan }
+}
+impl DerefMut for Conn {
+  fn deref_mut(&mut self) -> &mut MgmtChannel { &mut self.chan }
+}
 
+impl Conn {
   #[throws(AE)]
   fn prep_access_account(&mut self, ma: &MainOpts) {
     #[derive(Debug)]
index 245510fee2a13b67ec2356336b25e5ba3bc4461a..038697295d74d7b09b8d2d53dde1f25596227002 100644 (file)
@@ -53,6 +53,29 @@ impl MgmtChannel {
     write!(self.write, "\n")?;
     self.write.flush()?;
   }
+
+  #[throws(AE)]
+  pub fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse {
+    use MgmtResponse::*;
+    self.write(&cmd).context("send command")?;
+    let resp = self.read().context("read response")?;
+    match &resp {
+      Fine | GamesList{..} | LibraryItems(_) => { },
+      AlterGame { error: None, .. } => { },
+      Error { error } => {
+        Err(error.clone()).context(
+          format!("got error response to: {:?}",&cmd)
+        )?;
+      },
+      AlterGame { error: Some(error), .. } => {
+        Err(error.clone()).context(format!(
+          "game alterations failed (maybe partially); response to: {:?}",
+          &cmd
+        ))?;
+      }
+    };
+    resp
+  }
 }
 
 pub trait IoTryClone: Sized {