Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Aug 3, 2024
1 parent 51aa14b commit c39661d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/asyncv/attribute/message/boolean/attribute/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tokio::sync::Mutex;

use bytes::Bytes;

use crate::asyncv::attribute::message::AttributeId;
use crate::AttributeError;

use super::MessageCoreMembers;
Expand Down Expand Up @@ -42,6 +43,7 @@ impl InnerBoolean {
///
pub fn new(builder: BuilderBoolean) -> InnerBoolean {
InnerBoolean {
id: builder.id,
core: MessageCoreMembers::new(
builder.message_client,
builder.message_dispatcher,
Expand Down
4 changes: 4 additions & 0 deletions src/asyncv/attribute/message/boolean/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ use std::sync::Weak;

use tokio::sync::Mutex;

use crate::asyncv::attribute::message::AttributeId;

use super::AttributeBoolean;
use super::AttributeBuilder;

pub use super::MessageClient;
pub use super::MessageDispatcher;

pub struct BuilderBoolean {
pub id: AttributeId,
/// The mqtt client
pub message_client: MessageClient,

Expand All @@ -24,6 +27,7 @@ impl BuilderBoolean {
/// New boolean builder
pub fn new(parent_builder: AttributeBuilder) -> BuilderBoolean {
BuilderBoolean {
id: parent_builder.id,
message_client: parent_builder.message_client,
message_dispatcher: parent_builder.message_dispatcher,
topic: parent_builder.topic,
Expand Down
17 changes: 13 additions & 4 deletions src/asyncv/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ use std::sync::Weak;
use tokio::sync::Mutex;

use super::attribute::message::boolean::BuilderBoolean;
use super::attribute::message::AttributeId;
pub use super::MessageClient;
pub use super::MessageDispatcher;

static mut ID_POOL: AttributeId = 0;

/// Object that allow to build an generic attribute
///
pub struct AttributeBuilder {
pub id: AttributeId,
/// The mqtt client
pub message_client: MessageClient,

Expand All @@ -26,10 +30,15 @@ impl AttributeBuilder {
message_client: MessageClient,
message_dispatcher: Weak<Mutex<MessageDispatcher>>,
) -> AttributeBuilder {
AttributeBuilder {
message_client,
message_dispatcher,
topic: None,
unsafe {
let id = ID_POOL;
ID_POOL += 1;
AttributeBuilder {
id: id,
message_client,
message_dispatcher,
topic: None,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/asyncv/reactor/message_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl MessageEngine {

pub async fn run(&mut self) {
while let Ok(event) = self.message_event_loop.poll().await {
// println!("Notification = {:?}", notification);
println!("Notification = {:?}", event);
// match notification {
// Ok(event) => {
match event {
Expand Down
13 changes: 12 additions & 1 deletion src/examples/test_async.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use async_trait::async_trait;
use panduza::asyncv::attribute::message::AttributeId;
use panduza::asyncv::attribute::message::OnMessageBoolean;
use panduza::asyncv::Reactor;
use panduza::ReactorSettings;
use tokio::time::sleep;
use tokio::time::Duration;

struct TestBehaviour {}

#[async_trait]
impl OnMessageBoolean for TestBehaviour {
async fn on_message_boolean(&mut self, id: AttributeId, data: bool) {}
}

#[tokio::main]
async fn main() {
let settings = ReactorSettings::new("localhost", 1883);
Expand All @@ -24,7 +34,8 @@ async fn main() {
.with_type_boolean()
.finish();

// pp.set(true).await.unwrap();
println!("send data");
pp.set(true).await.unwrap();

sleep(Duration::from_secs(60)).await;
}

0 comments on commit c39661d

Please sign in to comment.