Files
gui/linux/src/app.h
T
Claude c6dba26742 Linux app: the modem built in (libdmodem_embed), no dmodemd needed
D-Modem is now a git submodule (external/D-Modem). With
DMODEM_GUI_EMBED (on when the submodule is there, on Linux), the app
runs the modem in a thread for the SIP, USB and ALSA lines. Its DTE is
a socket, so there is no pty, no /dev/ttyDM0 and no root. The modem's
log goes to the Log page. Line settings > Advanced > Built-in modem
(on by default) turns it off, and the app starts dmodemd as before.

libssh's sha1() and sha256() are renamed, because libre has functions
of the same names. The bundled Mbed TLS is now 3.6.7, the same release
as D-Modem's.

Docs: docs/embedded-modem.md (STE), with links from the README,
building.md and design.md. CI: the Linux job checks out the submodule
and installs libasound2-dev and libusb-1.0-0-dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRTRNP9YEnRxydbrw9G
2026-11-23 15:16:24 +00:00

217 lines
7.6 KiB
C

/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* app.h - the Linux app (GTK 4, libadwaita): what its parts share
*/
#ifndef DMODEM_GUI_APP_H
#define DMODEM_GUI_APP_H
#include <adwaita.h>
#include "dmodemctl.h"
#define APP_ID "io.github.d_modem.DModem"
/* the line settings, kept in ~/.config/dmodem-gui/settings.ini */
typedef struct Config {
/* "sip", "usb", "alsa", or "device" (a modem that already runs) */
char *line;
char *sip_user, *sip_password, *sip_server;
/* SIP with no account (dmodemd's SIP_LOGIN=anonymous): nothing
registered, SIP addresses (sip:user@host, user@host) dialled as
they are, from "Anonymous" */
gboolean sip_anonymous;
gboolean listen, t38, v152, v150;
char *srtp; /* "", "no" or "require" */
char *country; /* dmodemd -c's, "" for its default */
char *usb, *alsa; /* --usb's (auto), -a's (hw:1) */
char *device; /* the modem's device, "device" line */
char *dmodemd; /* its path, "" to look for it */
/* the modem built into the app (libdmodem_embed, DMODEM_GUI_EMBED)
for the SIP, USB and ALSA lines; FALSE: dmodemd started */
gboolean builtin;
char *init; /* commands sent when the modem opens */
int debug; /* dmodemd -d */
/* the answering machine ([voice]): on, after how many RINGs, a
message's longest (s) */
gboolean voicemail;
int vm_rings, vm_max;
/* the Remote page's last login ([remote]): "SSH", "Telnet" or
"rlogin", the server, its port (0: the protocol's), the user */
char *remote_proto, *remote_host, *remote_user;
/* how SSH logs in: "auto" (OpenSSH's keys and the agent), "agent"
or "key" (remote_key's file: OpenSSH's, PEM or PuTTY's .ppk);
the agent's socket ("": SSH_AUTH_SOCK's) */
char *remote_auth, *remote_key, *remote_agent;
/* the terminals' kinds (dmc_vt profiles' ids) */
char *term_type, *remote_term;
int remote_port;
} Config;
typedef struct App App;
/* a command's response */
typedef void (*ResponseFn)(App *a, const dmc_event *ev, gpointer data);
struct App {
AdwApplication *gapp;
GtkWindow *window;
AdwToastOverlay *toasts;
Config cfg;
/* the modem */
dmc_session *s;
GSubprocess *proc;
/* the modem built in (modem.c; a struct dmodem_embed), when it
runs; its start's number, so that the news of an older start is
ignored */
void *embed;
gboolean embed_running;
guint embed_gen;
GCancellable *cancel;
char *device; /* the DTE's path */
int fd;
guint fd_watch, tick;
GByteArray *pending; /* written when the DTE takes it */
GHashTable *waiting; /* tag -> struct Waiting */
int last_state;
/* the pages' widgets */
AdwViewStack *stack;
GtkWidget *status_icon, *status_title, *status_detail;
GtkWidget *number, *dial_btn, *answer_btn, *hangup_btn;
GtkWidget *run_row, *run_btn, *device_row, *copy_btn;
GtkWidget *term, *term_type;
GtkWidget *term_buttons;
AdwPreferencesPage *settings_page;
GPtrArray *settings_groups;
GPtrArray *setting_rows; /* by the setting's index */
int settings_gen; /* a new model: older answers ignored */
GtkWidget *settings_status, *init_row;
dmc_model *model;
gboolean settings_quiet; /* (rows set by the app, not the user) */
AdwPreferencesGroup *stats_group;
GPtrArray *stats_rows;
GtkWidget *stats_report, *stats_empty;
GtkTextBuffer *log;
/* the Phone page (voice.c) */
struct Voice *voice;
};
/* config.c */
void config_load(Config *c);
void config_save(const Config *c);
void config_free(Config *c);
/* "SIP: alice@sip.example.com" and the like */
char *config_summary(const Config *c);
/* the SIP line has what dmodemd needs: an account, or none (anonymous) */
gboolean config_sip_ready(const Config *c);
/* the line settings dialog */
void prefs_show(App *a);
/* usbmodem.c: a MultiTech MT9234MU (or MT9234ZBA-USB) on USB, from
sysfs */
typedef struct UsbModem {
char *name; /* "MultiTech MT9234MU" */
char *tty; /* "/dev/ttyUSB0", or NULL if it has none */
gboolean no_firmware; /* in the boot ROM: no firmware loaded */
} UsbModem;
/* the first one plugged in, or NULL */
UsbModem *usbmodem_find(void);
/* what it is and where, or what it needs, for the user */
char *usbmodem_describe(const UsbModem *m);
/* whether Linux has its firmware file (mts_mt9234mu.fw) */
gboolean usbmodem_firmware_present(void);
/* the copy of mts_mt9234mu.fw that comes with the app, or NULL */
char *usbmodem_shipped_firmware(void);
/* whether tty path is such a modem's */
gboolean usbmodem_is(const char *path);
void usbmodem_free(UsbModem *m);
/* modem.c */
void modem_start(App *a);
void modem_stop(App *a);
gboolean modem_running(App *a);
/* bytes typed in the terminal */
void modem_type(App *a, const char *data, gsize n);
/* a command; fn (may be NULL) gets its response */
int modem_command(App *a, const char *cmd, int flags, ResponseFn fn,
gpointer data);
/* fn (may be NULL) gets the response of the session's command tag
(dmc_voice_dial()'s and the like) */
void modem_wait(App *a, int tag, ResponseFn fn, gpointer data);
/* the session's output, terminal bytes and events handled now */
void modem_pump(App *a);
void app_log(App *a, const char *line);
/* window.c */
void window_build(App *a);
void window_state(App *a);
void window_toast(App *a, const char *text);
/* the modem's events (the session's DMC_EV_*) */
void window_event(App *a, const dmc_event *ev);
void window_opened(App *a);
void window_closed(App *a);
/* settings.c */
GtkWidget *settings_page_new(App *a);
void settings_load(App *a);
void settings_clear(App *a);
void settings_sensitive(App *a, gboolean on);
/* voice.c: the Phone page, voice calls' audio, the answering machine
and its messages */
GtkWidget *voice_page_new(App *a);
void voice_state(App *a);
void voice_event(App *a, const dmc_event *ev);
/* the answering machine's settings to the session */
void voice_configure(App *a);
/* audio.c: the sound card, 8 kHz mono (PulseAudio, or PipeWire's) */
/* the speaker's next samples: how many of n there were (the rest
silence); the microphone's */
typedef int (*AudioPull)(App *a, int16_t *pcm, int n);
typedef void (*AudioPush)(App *a, const int16_t *pcm, int n);
/* sound from pull and to push (either NULL for none): FALSE if there
is no sound here */
gboolean audio_start(App *a, AudioPull pull, AudioPush push);
void audio_stop(App *a);
gboolean audio_available(void);
/* termview.c: a terminal widget of its own screen (dmc_vt), whose keys
go to fn */
typedef void (*TermTypedFn)(const char *data, int n, void *ctx);
GtkWidget *termview_new(TermTypedFn fn, void *ctx);
/* bytes from the far end */
void termview_feed(GtkWidget *w, const char *data, int n);
void termview_reset(GtkWidget *w);
void termview_size(GtkWidget *w, int *cols, int *rows);
/* what Backspace sends (DEL unless set) */
void termview_set_backspace(GtkWidget *w, int code);
/* the kind of terminal it is (dmc_vt_set_profile()'s id) */
void termview_set_profile(GtkWidget *w, const char *id);
const char *termview_profile(GtkWidget *w);
void termview_focus(GtkWidget *w);
/* a drop-down of the kinds of terminal, id chosen; the one chosen */
GtkWidget *term_types_new(const char *id);
const char *term_types_chosen(GtkWidget *d);
/* remote.c: the Remote page, a login by SSH, Telnet or rlogin */
GtkWidget *remote_page_new(App *a);
/* its connection ended (the app is quitting) */
void remote_stop(App *a);
/* pathview.c: the connection path at the top of the Settings page, as
the line settings and the modem are now */
GtkWidget *pathview_new(App *a);
void pathview_update(App *a);
/* stats.c */
GtkWidget *stats_page_new(App *a);
void stats_refresh(App *a);
#endif