From 41d5f980ef11a4cc7a16b42d59790290d3e2ff76 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 15 Feb 2022 23:13:09 -0500 Subject: [PATCH] Starting a command type. --- src/mpvctl/command.rs | 9 +++++++++ src/mpvctl/mod.rs | 1 + src/mpvctl/mpvctl.rs | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/mpvctl/command.rs diff --git a/src/mpvctl/command.rs b/src/mpvctl/command.rs new file mode 100644 index 0000000..5e0ca67 --- /dev/null +++ b/src/mpvctl/command.rs @@ -0,0 +1,9 @@ +pub struct Command { + command: Vec, +} + +impl Command { + pub fn new(command: Vec) -> Self { + Command { command: command } + } +} diff --git a/src/mpvctl/mod.rs b/src/mpvctl/mod.rs index 43251b4..0d0fa9f 100644 --- a/src/mpvctl/mod.rs +++ b/src/mpvctl/mod.rs @@ -1,3 +1,4 @@ +mod command; mod mpvctl; pub use mpvctl::MpvCtl; diff --git a/src/mpvctl/mpvctl.rs b/src/mpvctl/mpvctl.rs index eaff0a3..d40119c 100644 --- a/src/mpvctl/mpvctl.rs +++ b/src/mpvctl/mpvctl.rs @@ -1 +1,39 @@ -pub struct MpvCtl; +use std::collections::HashMap; +use std::{collections::BTreeMap, path::Path}; +use tokio::net::UnixStream; + +use super::command::Command; + +pub struct MpvCtl { + socket: UnixStream, + next_request_id: u64, +} + +impl MpvCtl { + pub async fn connect>( + socket_path: P, + ) -> Result> { + let socket = UnixStream::connect(socket_path).await?; + Ok(MpvCtl { + socket, + next_request_id: 0, + }) + } + + fn grab_request_id(&mut self) -> u64 { + let ret = self.next_request_id; + self.next_request_id += 1; + ret + } + + async fn send_command(&self, cmd: Command) { + // + // let serialized = + } + + pub async fn get_client_name(&mut self) -> Result<(), Box> { + let request_id = self.grab_request_id(); + let cmd = Command::new(vec!["client_name".to_string()]); + Ok(()) + } +}