Aruna
Performer.cpp
Go to the documentation of this file.
1 //
2 // Created by noeel on 15-04-20.
3 //
4 
5 #include "aruna/sis/reporter.h"
6 #include "aruna/sis/Performer.h"
7 #if defined(ESP_PLATFORM)
8 #include <freertos/FreeRTOS.h>
9 #include <freertos/task.h>
10 #else
11 #include <unistd.h>
12 #endif
13 
14 using namespace aruna::sis;
15 
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 }
30 
32  static_cast<Performer *>(_this)->update_handler();
33  return nullptr;
34 }
35 
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 }
56 
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 }
63 
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
type_t
Type of status.
Definition: sisTypes.h:26
pthread_mutex_t do_update_mut
Definition: Performer.h:22
status_t status
stores the comm status
Definition: comm.cpp:40
log::channel_t * log
Definition: Performer.h:24
void set_update(bool do_update)
Use to pauze and resume the update process.
Definition: Performer.cpp:57
char description[32]
Definition: sisTypes.h:40
uint32_t update_ms
update frequency
Definition: Performer.h:40
static void * _update_handler(void *_this)
Definition: Performer.cpp:31
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
Performer()
Performs check to see if the system is in a secure state.
Definition: Performer.cpp:16
void alert(status_t *status)
alert watcher with given status_t
Definition: reporter.cpp:23