So in TinyOS an interface is composed of commands and events. When a module uses an interface, it calls its commands and provides an implementation of its events (provides an event handler).
The sense of the return type of a command is clear, it is the same as that of any function/method in any programming language, but, the return type of an event results unclear to me.
Let's take an example:
interface Counter{
command int64_t getCounter(int64_t destinationId);
event int64_t counterSent(int64_t destinationId);
}
Let's define a module that provides the Counter interface.
module Provider{
provides interface Counter;
}
implementation {
int64_t counter;
counter = 75; //Random number
/**
Returns the value of the counter and signals an event that
someone with id equal to destinationId asked for the counter.
**/
command int64_t getCounter(int64_t destinationId){
int64_t signalReturnedValue;
signalReturnedValue = signal counterSent(destinationId);
return counter;
}
}
Now let's define two module which use this interface.
module EvenIDChecker{
uses interface Counter;
}
implementation{
/**
Returns 1 if the destinationId is even, 0 otherwise
**/
event int64_t counterSent(int64_t destinationId){
if(destinationId % 2 == 0){
return 1;
} else {
return 0;
}
}
}
Now let's define another module which uses the same interface but does the inverse of the EvenIDChecker module.
module OddIDChecker{
uses interface Counter;
}
implementation{
/**
Returns 1 if the destinationId is odd, 0 otherwise
**/
event int64_t counterSent(int64_t destinationId){
if(destinationId % 2 == 1){
return 1;
} else {
return 0;
}
}
}
In the end, what would be the final value of the var signalReturnedValue?
calls to Counter.counterSent in ... are uncombined? - IvanR