Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload operators for Sink/Source #34

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Threading/Demo_Source_Sink_Counter/Consumer.inot
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ void setup()

void loop()
{
Serial.println(counter.read());
Serial.println(counter);
}
2 changes: 1 addition & 1 deletion examples/Threading/Demo_Source_Sink_Counter/Producer.inot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ void setup()
void loop()
{
static int i = 0;
counter.write(i);
counter = i;
i++;
}
3 changes: 1 addition & 2 deletions examples/Threading/Demo_Source_Sink_LED/Sink_Thread.inot
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ void loop()
* this call will surely block until something comes from the connected SOURCE. In this case
* the pace is dictated by the SOURCE that sends data every 100 ms.
*/
bool led_on = led.read();
digitalWrite(LED_BUILTIN, led_on);
digitalWrite(LED_BUILTIN, led);
}
4 changes: 2 additions & 2 deletions examples/Threading/Demo_Source_Sink_LED/Source_Thread.inot
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ void setup()

void loop()
{
led.write(true);
led = true;
delay(100);
led.write(false);
led = false;
delay(100);
}
10 changes: 5 additions & 5 deletions src/threading/Sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SinkBase

virtual ~SinkBase() { }

virtual T read() = 0;
virtual operator T() = 0;
virtual void inject(T const & value) = 0;
};

Expand All @@ -48,7 +48,7 @@ class SinkNonBlocking : public SinkBase<T>
SinkNonBlocking() { }
virtual ~SinkNonBlocking() { }

virtual T read() override;
virtual operator T() override;
virtual void inject(T const & value) override;


Expand All @@ -67,7 +67,7 @@ class SinkBlocking : public SinkBase<T>
SinkBlocking();
virtual ~SinkBlocking() { }

virtual T read() override;
virtual operator T() override;
virtual void inject(T const & value) override;


Expand All @@ -86,7 +86,7 @@ class SinkBlocking : public SinkBase<T>
**************************************************************************************/

template<typename T>
T SinkNonBlocking<T>::read()
SinkNonBlocking<T>::operator T()
{
_mutex.lock();
return _data;
Expand All @@ -113,7 +113,7 @@ SinkBlocking<T>::SinkBlocking()
{ }

template<typename T>
T SinkBlocking<T>::read()
SinkBlocking<T>::operator T()
{
_mutex.lock();
while (!_is_data_available)
Expand Down
4 changes: 2 additions & 2 deletions src/threading/Source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Source
public:

void connectTo(SinkBase<T> & sink);
void write(T const & value);
void operator = (T const & other);

private:
std::list<SinkBase<T> *> _sink_list;
Expand All @@ -60,7 +60,7 @@ void Source<T>::connectTo(SinkBase<T> & sink)
}

template<typename T>
void Source<T>::write(T const & value)
void Source<T>::operator = (T const & value)
{
std::for_each(std::begin(_sink_list),
std::end (_sink_list),
Expand Down