Skip to content

Commit

Permalink
Add event names + custom serde, use new camloc API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris030 committed Aug 4, 2023
1 parent fa486c9 commit 0e27c5f
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 166 deletions.
70 changes: 22 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/src/transports/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Subscribable for Tcp {
true,
),
);
self.inner.events.lock().unwrap().insert(ev, id);
self.inner.events.lock().unwrap().insert(ev.clone(), id);

self.cmd_id(cmd::Subscribe(ev), id)?;

Expand All @@ -155,7 +155,7 @@ impl Subscribable for Tcp {

fn unsubscribe<E: roblib::event::Event>(&self, ev: E) -> Result<()> {
let ev = ev.into();
let cmd = cmd::Unsubscribe(ev);
let cmd = cmd::Unsubscribe(ev.clone());

let mut lock = self.inner.events.lock().unwrap();
match lock.entry(ev) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/transports/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Subscribable for Udp {

fn unsubscribe<E: roblib::event::Event>(&self, ev: E) -> Result<()> {
let ev = ev.into();
let cmd: cmd::Concrete = cmd::Unsubscribe(ev).into();
let cmd: cmd::Concrete = cmd::Unsubscribe(ev.clone()).into();

self.sock
.send(&bincode::Options::serialize(bincode::options(), &cmd)?)?;
Expand Down
4 changes: 2 additions & 2 deletions client/src/transports/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl SubscribableAsync for Ws {

let (tx, mut worker_rx) = mpsc::channel(1);
self.inner.handlers.lock().await.insert(id, tx);
self.inner.events.lock().await.insert(ev, id);
self.inner.events.lock().await.insert(ev.clone(), id);
self.send(id, cmd::Subscribe(ev)).await?;

let (client_tx, client_rx) = broadcast::channel(128);
Expand All @@ -167,7 +167,7 @@ impl SubscribableAsync for Ws {
let ev = ev.into();

let mut lock = self.inner.events.lock().await;
match lock.entry(ev) {
match lock.entry(ev.clone()) {
std::collections::hash_map::Entry::Occupied(v) => {
let id = v.remove();
self.send(id, cmd::Unsubscribe(ev)).await?;
Expand Down
5 changes: 4 additions & 1 deletion roblib/src/camloc/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub use camloc_server::service::Subscriber;
use camloc_server::{PlacedCamera, Position};
use roblib_macro::Event;
use serde::{Deserialize, Serialize};
Expand All @@ -7,23 +6,27 @@ use std::net::SocketAddr;
#[derive(Event, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct CamlocConnect;
impl crate::event::Event for CamlocConnect {
const NAME: &'static str = "camloc_connect";
type Item = (SocketAddr, PlacedCamera);
}

#[derive(Event, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct CamlocDisconnect;
impl crate::event::Event for CamlocDisconnect {
const NAME: &'static str = "camloc_disconnect";
type Item = SocketAddr;
}

#[derive(Event, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct CamlocPosition;
impl crate::event::Event for CamlocPosition {
const NAME: &'static str = "position";
type Item = Position;
}

#[derive(Event, Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct CamlocInfoUpdate;
impl crate::event::Event for CamlocInfoUpdate {
const NAME: &'static str = "camloc_info_update";
type Item = (SocketAddr, PlacedCamera);
}
6 changes: 1 addition & 5 deletions roblib/src/camloc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
pub mod cmd;
pub mod event;

pub mod server {
pub use camloc_server::*;
}

pub use camloc_server::{MotionHint, Position, MAIN_PORT};
pub use camloc_server::{service, MotionHint, Position};

pub trait Camloc {
fn get_position(&self) -> anyhow::Result<Option<Position>>;
Expand Down
60 changes: 0 additions & 60 deletions roblib/src/event.rs

This file was deleted.

Loading

1 comment on commit 0e27c5f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts

View all

base roland
aarch64-unknown-linux-gnu Download Download
aarch64-unknown-linux-musl Download Download
armv7-unknown-linux-gnueabihf Download Download
armv7-unknown-linux-musleabihf Download Download
x86_64-pc-windows-msvc Download Download
x86_64-unknown-linux-gnu Download Download
x86_64-unknown-linux-musl Download Download

Please sign in to comment.