eclipse / mita

mita
Eclipse Public License 2.0
56 stars 20 forks source link

RFC: Signal instance events #301

Open wegendt-bosch opened 5 years ago

wegendt-bosch commented 5 years ago

Introduction

The root elements in platforms are system resources. They offer events, modalities and signals. Users can supply event handlers to these events, can read modalities and read and write signals. Modalities and events are singular in the sense that per application there is only one instance of each of them. In contrast to that signals can be set up multiple times in signal instances.

This makes it so that users can for example react to an event in the accelerometer but not to an MQTT message.

Current Situation

Currently events per signal instance are not supported.

Proposal

I propose adding events to signal instances. For example an MQTT topic signal offers an message event or a GPIO pin offers input events like risingEdge, fallingEdge.

Code Example

The platform could declare signal instance events like this:

signal topic(name : string, qos : uint32 = 0) : string {
  event message
  event sendError
  event sendSuccess
}

A user would react like this:

setup mqtt: MQTT {
  var t = topic("foo");
}

every mqtt.t.message {
  /* can't do a lot yet until events have payloads */
}
justindannguyen commented 5 years ago

Dear @wegendt-bosch , This is what i am thinking and was looking for. As your comments, event functions can't do alot yet because we don't have payload.

Can we implement something like this?

every mqtt.t.message {
    var payload = mqtt.t.read();
    /* implement stuff here */
}

or better ways we should modify the event function to add payload (maybe it may requires the changes in Mita)

wegendt-bosch commented 5 years ago

PR #344 already allows the following:

import platforms.xdk110;

every MQTT.msgReceived(msg) { // msg has type array<500>. Reacts to *any* incoming message.
  println(msg);
}

The next step is then to implement this RFC, which should be a lot easier than #344, since its mostly language design and scoping. Then we would have full interactivity like this:

every mqtt.t.msgReceived(msg) {

}