Skip to content

Commit

Permalink
control: send msg when log stops
Browse files Browse the repository at this point in the history
  • Loading branch information
flightlessmango committed Jul 28, 2022
1 parent ef4ace2 commit 14dcd15
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions control/src/control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,20 @@ def control(args):
conn.send(bytearray(':logging;', 'utf-8'))
elif args.cmd == 'start-logging':
conn.send(bytearray(':logging=1;', 'utf-8'))

elif args.cmd == 'stop-logging':
conn.send(bytearray(':logging=0;', 'utf-8'))
now = time.monotonic()
while True:
msg = str(conn.recv(3))
if "LoggingFinished" in msg:
print("Logging has stopped")
exit(0)
elapsed = time.monotonic() - now
if elapsed > 3:
print("Stop logging timed out")
exit(1)

elif args.cmd == 'toggle-hud':
conn.send(bytearray(':hud;', 'utf-8'))
elif args.cmd == 'toggle-fcat':
Expand Down
8 changes: 6 additions & 2 deletions src/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "app/mangoapp.h"
#endif

int global_control_client;

using namespace std;
static void parse_command(overlay_params &params,
const char *cmd, unsigned cmdlen,
Expand Down Expand Up @@ -112,7 +114,7 @@ static void process_char(const int control_client, overlay_params &params, char
}
}

static void control_send(int control_client,
void control_send(int control_client,
const char *cmd, unsigned cmdlen,
const char *param, unsigned paramlen)
{
Expand Down Expand Up @@ -160,8 +162,10 @@ static void control_send_connection_string(int control_client, const std::string
void control_client_check(int control, int& control_client, const std::string& deviceName)
{
/* Already connected, just return. */
if (control_client >= 0)
if (control_client >= 0){
global_control_client = control_client;
return;
}

int socket = os_socket_accept(control);
if (socket == -1) {
Expand Down
5 changes: 5 additions & 0 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void writeSummary(string filename){
} else {
SPDLOG_ERROR("Failed to write log file");
}
out.close();
}

void writeFile(string filename){
Expand Down Expand Up @@ -143,6 +144,7 @@ void writeFile(string filename){
} else {
SPDLOG_ERROR("Failed to write log file");
}
out.close();
}

string get_log_suffix(){
Expand Down Expand Up @@ -199,6 +201,9 @@ void Logger::stop_logging() {
#endif
}
clear_log_data();
control_client_check(m_params->control, global_control_client, gpu.c_str());
const char * cmd = "LoggingFinished";
control_send(global_control_client, cmd, strlen(cmd), 0, 0);
}

void Logger::logging(){
Expand Down
2 changes: 2 additions & 0 deletions src/overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ float get_time_stat(void *_data, int _idx);
void stop_hw_updater();
extern void control_client_check(int control, int& control_client, const std::string& deviceName);
extern void process_control_socket(int& control_client, overlay_params &params);
extern void control_send(int control_client, const char *cmd, unsigned cmdlen, const char *param, unsigned paramlen);
extern int global_control_client;
#ifdef HAVE_DBUS
void render_mpris_metadata(const overlay_params& params, mutexed_metadata& meta, uint64_t frame_timing);
#endif
Expand Down

0 comments on commit 14dcd15

Please sign in to comment.