Skip to content

Commit

Permalink
Add handling of SIGUSR1 / SIGUSR2 to open / close port
Browse files Browse the repository at this point in the history
SIGUSR1 = open port
SIGUSR2 = close port
  • Loading branch information
the0ne authored and Jeija committed Sep 16, 2019
1 parent 35ccb42 commit 2511ec2
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 23 deletions.
14 changes: 5 additions & 9 deletions src/device_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@
#include <glib/gprintf.h>
#include <term_config.h>

#include "interface.h"

extern struct configuration_port config;

static inline void device_monitor_status(const bool connected) {

gchar *message;

if( connected )
Config_port();
if (connected)
interface_open_port();
else
Close_port();

message = get_port_string();

Set_status_message(message);
Set_window_title(message);
g_free(message);
interface_close_port();
}

static inline void device_monitor_handle(struct udev_device *dev) {
Expand Down
3 changes: 3 additions & 0 deletions src/gtkterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "macros.h"
#include "auto_config.h"
#include "device_monitor.h"
#include "user_signals.h"

#include <config.h>
#include <glib/gi18n.h>
Expand Down Expand Up @@ -69,6 +70,8 @@ int main(int argc, char *argv[])

device_monitor_start();

user_signals_catch();

gtk_main();

delete_buffer();
Expand Down
38 changes: 24 additions & 14 deletions src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,24 +788,12 @@ void signals_toggle_RTS_callback(GtkAction *action, gpointer data)

void signals_close_port(GtkAction *action, gpointer data)
{
Close_port();

gchar *message;
message = get_port_string();
Set_status_message(message);
Set_window_title(message);
g_free(message);
interface_close_port();
}

void signals_open_port(GtkAction *action, gpointer data)
{
Config_port();

gchar *message;
message = get_port_string();
Set_status_message(message);
Set_window_title(message);
g_free(message);
interface_open_port();
}

gboolean control_signals_read(void)
Expand All @@ -832,6 +820,28 @@ void Set_window_title(gchar *msg)
g_free(header);
}

void interface_open_port(void)
{
Config_port();

gchar *message;
message = get_port_string();
Set_status_message(message);
Set_window_title(message);
g_free(message);
}

void interface_close_port(void)
{
Close_port();

gchar *message;
message = get_port_string();
Set_status_message(message);
Set_window_title(message);
g_free(message);
}

void show_message(gchar *message, gint type_msg)
{
GtkWidget *Fenetre_msg;
Expand Down
2 changes: 2 additions & 0 deletions src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void set_view(guint);
gint send_serial(gchar *, gint);
void Put_temp_message(const gchar *, gint);
void Set_window_title(gchar *msg);
void interface_close_port(void);
void interface_open_port(void);

void toggle_logging_pause_resume(gboolean currentlyLogging);
void toggle_logging_sensitivity(gboolean currentlyLogging);
Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ sources = [
'serial.h',
'term_config.c',
'term_config.h',
'user_signals.c',
'user_signals.h',
gresources
]

Expand Down
20 changes: 20 additions & 0 deletions src/user_signals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <gtk/gtk.h>
#include "interface.h"

static gboolean handle_usr1(gpointer user_data)
{
interface_open_port();
return G_SOURCE_CONTINUE;
}

static gboolean handle_usr2(gpointer user_data)
{
interface_close_port();
return G_SOURCE_CONTINUE;
}

void user_signals_catch(void)
{
g_unix_signal_add(SIGUSR1, (GSourceFunc) handle_usr1, NULL);
g_unix_signal_add(SIGUSR2, (GSourceFunc) handle_usr2, NULL);
}
19 changes: 19 additions & 0 deletions src/user_signals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/***********************************************************************/
/* device_mintor.h */
/* --------- */
/* GTKTerm Software */
/* (c) Julien Schmitt */
/* */
/* ------------------------------------------------------------------- */
/* */
/* Purpose */
/* React to SIGUSR signals (for scriptability) */
/* */
/***********************************************************************/

#ifndef _USER_SIGNALS
#define _USER_SIGNALS

void user_signals_catch(void);

#endif

0 comments on commit 2511ec2

Please sign in to comment.