Skip to content

Commit

Permalink
legiond: pretty output
Browse files Browse the repository at this point in the history
Signed-off-by: ston <ston.jia@outlook.com>
  • Loading branch information
st0nie committed Apr 26, 2024
1 parent 691b0e5 commit 16868db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
13 changes: 7 additions & 6 deletions extra/service/legiond/legiond.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "modules/parseconf.h"
#include "modules/setapply.h"
#include "modules/powerstate.h"
#include "modules/output.h"

LEGIOND_CONFIG config;

Expand All @@ -25,14 +26,14 @@ void term_handler(int signum)

void timer_handler()
{
printf("---set_all start---\n");
pretty("set_all start");
set_all(get_powerstate(), &config);

if (delayed)
delayed = 0;

triggered = true;
printf("---set_all end----\n");
pretty("set_all end");
}

void set_timer(struct itimerspec *its, long delay_s, long delay_ns,
Expand Down Expand Up @@ -116,14 +117,14 @@ int main()
delayed = delay;
}
} else if (ret[0] == 'B' && triggered == true) {
printf("---set_cpu start---\n");
pretty("set_cpu start");
set_cpu(get_powerstate(), &config);
printf("---set_cpu end-----\n");
pretty("set_cpu end");
} else if (ret[0] == 'R') {
printf("---config reload start---\n");
pretty("config reload start");
parseconf(&config);
set_all(get_powerstate(), &config);
printf("---config reload end-----\n");
pretty("config reload end");
} else {
printf("do nothing\n");
}
Expand Down
20 changes: 20 additions & 0 deletions extra/service/legiond/modules/output.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "output.h"
#include <string.h>
#include <stdio.h>

void pretty(char *msg)
{
int len = strlen(msg);
len = len > 30 ? len : 30;
printf("\033[1m");
for (int i = 0; i < len / 2; i++) {
putchar('-');
}
printf("%s", msg);
for (int i = 0; i < len / 2; i++) {
putchar('-');
}
printf("\033[m");

putchar('\n');
}
6 changes: 6 additions & 0 deletions extra/service/legiond/modules/output.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef OUTPUT_H_
#define OUTPUT_H_

void pretty(char *msg);

#endif // OUTPUT_H_
6 changes: 3 additions & 3 deletions extra/service/legiond/modules/powerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ static POWER_STATE get_ppdstate()
POWER_STATE get_powerstate()
{
static bool use_ppd = false;
static bool reload = false;
static bool initialize = false;
POWER_STATE power_state = -1;
FILE *fp;

if (!reload) {
reload = true;
if (!initialize) {
initialize = true;
if (access(profile_path, F_OK)) {
use_ppd = true;
}
Expand Down

0 comments on commit 16868db

Please sign in to comment.