Aruna
aruna::sis::Performer Class Referenceabstract

#include <Performer.h>

Inheritance diagram for aruna::sis::Performer:
Collaboration diagram for aruna::sis::Performer:

Public Member Functions

 Performer ()
 Performs check to see if the system is in a secure state. More...
 
 ~Performer ()
 
virtual status_tupdate_status ()=0
 Perform check to see if system is secure and return updated status. More...
 
void set_update (bool do_update)
 Use to pauze and resume the update process. More...
 

Public Attributes

uint32_t update_ms = 500
 update frequency More...
 

Protected Member Functions

void update_handler ()
 

Static Protected Member Functions

static void * _update_handler (void *_this)
 

Protected Attributes

pthread_t thread
 
pthread_cond_t do_update_con
 
pthread_mutex_t do_update_mut
 
log::channel_tlog
 
char log_tag [10] = "SIS perf"
 
bool do_update = false
 
bool interrupt_based = false
 

Private Attributes

status_t status
 

Detailed Description

Definition at line 15 of file Performer.h.

Constructor & Destructor Documentation

◆ Performer()

aruna::sis::Performer::Performer ( )

Performs check to see if the system is in a secure state.

Definition at line 16 of file Performer.cpp.

17  log = new log::channel_t(log_tag);
18 
19  if (not interrupt_based) {
20 // create task
21  pthread_cond_init(&do_update_con, NULL);
22  pthread_mutex_init(&do_update_mut, NULL);
23  pthread_create(&thread, NULL, _update_handler, this);
24  }
25 // set standard values for status_t
28  strcpy(status.description, "System is good");
29 }
pthread_cond_t do_update_con
Definition: Performer.h:21
pthread_mutex_t do_update_mut
Definition: Performer.h:22
log::channel_t * log
Definition: Performer.h:24
char description[32]
Definition: sisTypes.h:40
static void * _update_handler(void *_this)
Definition: Performer.cpp:31
Here is the call graph for this function:

◆ ~Performer()

Performer::~Performer ( )

Definition at line 64 of file Performer.cpp.

64  {
65 // TODO if interrupt_based in changed between constructor and destructor,
66 // it will try to delete things that don't exists or don't delete the thread.
67  if (not interrupt_based) {
68  pthread_cond_destroy(&do_update_con);
69  pthread_mutex_destroy(&do_update_mut);
70  pthread_exit(&thread);
71  }
72 }
pthread_cond_t do_update_con
Definition: Performer.h:21
pthread_mutex_t do_update_mut
Definition: Performer.h:22

Member Function Documentation

◆ _update_handler()

void * aruna::sis::Performer::_update_handler ( void *  _this)
staticprotected

Definition at line 31 of file Performer.cpp.

31  {
32  static_cast<Performer *>(_this)->update_handler();
33  return nullptr;
34 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_update()

void aruna::sis::Performer::set_update ( bool  do_update)

Use to pauze and resume the update process.

Parameters
do_update,bool

Definition at line 57 of file Performer.cpp.

57  {
58  pthread_mutex_lock(&do_update_mut);
59  this->do_update = do_update;
60  pthread_mutex_unlock(&do_update_mut);
61  pthread_cond_signal(&do_update_con);
62 }
pthread_cond_t do_update_con
Definition: Performer.h:21
pthread_mutex_t do_update_mut
Definition: Performer.h:22

◆ update_handler()

void aruna::sis::Performer::update_handler ( )
protected

Definition at line 36 of file Performer.cpp.

36  {
38  while (1) {
39  while (do_update) {
40  status = update_status();
41  sis::reporter::alert(status);
42 #if defined(ESP_PLATFORM)
43  vTaskDelay(update_ms / portTICK_PERIOD_MS);
44 #else
45 // usleep blocks CPU in ESP-IDF 3.2.2
46 // TODO update to newer version of EPS-IDF
47 // TODO ms and us are not the same thing
48  usleep(update_ms);
49 #endif
50  }
51  pthread_mutex_lock(&do_update_mut);
52  pthread_cond_wait(&do_update_con, &do_update_mut);
53  pthread_mutex_unlock(&do_update_mut);
54  }
55 }
pthread_cond_t do_update_con
Definition: Performer.h:21
pthread_mutex_t do_update_mut
Definition: Performer.h:22
uint32_t update_ms
update frequency
Definition: Performer.h:40
virtual status_t * update_status()=0
Perform check to see if system is secure and return updated status.
status that is to be reported to the watcher
Definition: sisTypes.h:36
void alert(status_t *status)
alert watcher with given status_t
Definition: reporter.cpp:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_status()

virtual status_t* aruna::sis::Performer::update_status ( )
pure virtual

Perform check to see if system is secure and return updated status.

Returns
status_t pointer

Implemented in aruna::sensor::Water.

Here is the caller graph for this function:

Member Data Documentation

◆ do_update

bool aruna::sis::Performer::do_update = false
protected

Definition at line 27 of file Performer.h.

◆ do_update_con

pthread_cond_t aruna::sis::Performer::do_update_con
protected

Definition at line 21 of file Performer.h.

◆ do_update_mut

pthread_mutex_t aruna::sis::Performer::do_update_mut
protected

Definition at line 22 of file Performer.h.

◆ interrupt_based

bool aruna::sis::Performer::interrupt_based = false
protected

Definition at line 35 of file Performer.h.

◆ log

log::channel_t* aruna::sis::Performer::log
protected

Definition at line 24 of file Performer.h.

◆ log_tag

char aruna::sis::Performer::log_tag[10] = "SIS perf"
protected

Definition at line 25 of file Performer.h.

◆ status

status_t aruna::sis::Performer::status
private

Definition at line 17 of file Performer.h.

◆ thread

pthread_t aruna::sis::Performer::thread
protected

Definition at line 20 of file Performer.h.

◆ update_ms

uint32_t aruna::sis::Performer::update_ms = 500

update frequency

Definition at line 40 of file Performer.h.


The documentation for this class was generated from the following files: