mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Added events for handle parent_call_string() and parent_call()
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
a01b8edd7a
commit
6621250292
@ -48,6 +48,21 @@ typedef struct
|
||||
const char *node;
|
||||
} ev_help_t;
|
||||
|
||||
/* MCEVENT_GROUP_CORE:background_parent_call */
|
||||
/* MCEVENT_GROUP_CORE:background_parent_call_string */
|
||||
typedef struct
|
||||
{
|
||||
void *routine;
|
||||
gpointer *ctx;
|
||||
int argc;
|
||||
va_list ap;
|
||||
union
|
||||
{
|
||||
int i;
|
||||
char *s;
|
||||
} ret;
|
||||
} ev_background_parent_call_t;
|
||||
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
|
@ -39,9 +39,7 @@
|
||||
#include "lib/strutil.h"
|
||||
#include "lib/util.h" /* tilde_expand() */
|
||||
#include "lib/widget.h"
|
||||
|
||||
/* TODO: these includes should be removed! */
|
||||
#include "src/background.h" /* parent_call */
|
||||
#include "lib/event.h" /* mc_event_raise() */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
@ -237,6 +235,37 @@ fg_input_dialog_help (const char *header, const char *text, const char *help,
|
||||
return (ret != B_CANCEL) ? my_str : NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
wtools_parent_call (void *routine, gpointer ctx, int argc, ...)
|
||||
{
|
||||
ev_background_parent_call_t event_data;
|
||||
|
||||
event_data.routine = routine;
|
||||
event_data.ctx = ctx;
|
||||
event_data.argc = argc;
|
||||
va_start (event_data.ap, argc);
|
||||
mc_event_raise (MCEVENT_GROUP_CORE, "background_parent_call", (gpointer) & event_data);
|
||||
va_end (event_data.ap);
|
||||
return event_data.ret.i;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
wtools_parent_call_string (void *routine, int argc, ...)
|
||||
{
|
||||
ev_background_parent_call_t event_data;
|
||||
|
||||
event_data.routine = routine;
|
||||
event_data.argc = argc;
|
||||
va_start (event_data.ap, argc);
|
||||
mc_event_raise (MCEVENT_GROUP_CORE, "background_parent_call_string", (gpointer) & event_data);
|
||||
va_end (event_data.ap);
|
||||
return event_data.ret.s;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -372,11 +401,6 @@ message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
union
|
||||
{
|
||||
void *p;
|
||||
void (*f) (int, int *, char *, const char *);
|
||||
} func;
|
||||
|
||||
va_start (ap, text);
|
||||
p = g_strdup_vprintf (text, ap);
|
||||
@ -388,8 +412,15 @@ message (int flags, const char *title, const char *text, ...)
|
||||
#ifdef WITH_BACKGROUND
|
||||
if (mc_global.we_are_background)
|
||||
{
|
||||
union
|
||||
{
|
||||
void *p;
|
||||
void (*f) (int, int *, char *, const char *);
|
||||
} func;
|
||||
func.f = bg_message;
|
||||
parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, strlen (p), p);
|
||||
|
||||
wtools_parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title,
|
||||
strlen (p), p);
|
||||
}
|
||||
else
|
||||
#endif /* WITH_BACKGROUND */
|
||||
@ -419,11 +450,11 @@ input_dialog_help (const char *header, const char *text, const char *help,
|
||||
if (mc_global.we_are_background)
|
||||
{
|
||||
func.f = fg_input_dialog_help;
|
||||
return parent_call_string (func.p, 5,
|
||||
strlen (header), header, strlen (text),
|
||||
text, strlen (help), help,
|
||||
strlen (history_name), history_name,
|
||||
strlen (def_text), def_text);
|
||||
return wtools_parent_call_string (func.p, 5,
|
||||
strlen (header), header, strlen (text),
|
||||
text, strlen (help), help,
|
||||
strlen (history_name), history_name,
|
||||
strlen (def_text), def_text);
|
||||
}
|
||||
else
|
||||
#endif /* WITH_BACKGROUND */
|
||||
|
155
src/background.c
155
src/background.c
@ -46,6 +46,7 @@
|
||||
#include "lib/global.h"
|
||||
#include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */
|
||||
#include "lib/widget.h" /* message() */
|
||||
#include "lib/event-types.h"
|
||||
|
||||
#include "filemanager/fileopctx.h" /* FileOpContext */
|
||||
|
||||
@ -407,6 +408,71 @@ parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext
|
||||
ret = write (parent_fd, ctx, sizeof (FileOpContext));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
parent_va_call (void *routine, gpointer data, int argc, va_list ap)
|
||||
{
|
||||
int i;
|
||||
ssize_t ret;
|
||||
struct FileOpContext *ctx = (struct FileOpContext *) data;
|
||||
|
||||
parent_call_header (routine, argc, Return_Integer, ctx);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
int len;
|
||||
void *value;
|
||||
|
||||
len = va_arg (ap, int);
|
||||
value = va_arg (ap, void *);
|
||||
ret = write (parent_fd, &len, sizeof (int));
|
||||
ret = write (parent_fd, value, len);
|
||||
}
|
||||
|
||||
ret = read (from_parent_fd, &i, sizeof (int));
|
||||
if (ctx)
|
||||
ret = read (from_parent_fd, ctx, sizeof (FileOpContext));
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
parent_va_call_string (void *routine, int argc, va_list ap)
|
||||
{
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
parent_call_header (routine, argc, Return_String, NULL);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
int len;
|
||||
void *value;
|
||||
|
||||
len = va_arg (ap, int);
|
||||
value = va_arg (ap, void *);
|
||||
if ((write (parent_fd, &len, sizeof (int)) != sizeof (int)) ||
|
||||
(write (parent_fd, value, len) != len))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (read (from_parent_fd, &i, sizeof (int)) != sizeof (int))
|
||||
return NULL;
|
||||
if (!i)
|
||||
return NULL;
|
||||
str = g_malloc (i + 1);
|
||||
if (read (from_parent_fd, str, i) != i)
|
||||
{
|
||||
g_free (str);
|
||||
return NULL;
|
||||
}
|
||||
str[i] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -505,29 +571,14 @@ do_background (struct FileOpContext *ctx, char *info)
|
||||
int
|
||||
parent_call (void *routine, struct FileOpContext *ctx, int argc, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
int i;
|
||||
ssize_t ret;
|
||||
|
||||
va_start (ap, argc);
|
||||
parent_call_header (routine, argc, Return_Integer, ctx);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
int len;
|
||||
void *value;
|
||||
|
||||
len = va_arg (ap, int);
|
||||
value = va_arg (ap, void *);
|
||||
ret = write (parent_fd, &len, sizeof (int));
|
||||
ret = write (parent_fd, value, len);
|
||||
}
|
||||
|
||||
ret = read (from_parent_fd, &i, sizeof (int));
|
||||
if (ctx)
|
||||
ret = read (from_parent_fd, ctx, sizeof (FileOpContext));
|
||||
|
||||
ret = parent_va_call (routine, (gpointer) ctx, argc, ap);
|
||||
va_end (ap);
|
||||
return i;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -537,40 +588,52 @@ parent_call_string (void *routine, int argc, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
va_start (ap, argc);
|
||||
parent_call_header (routine, argc, Return_String, NULL);
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
int len;
|
||||
void *value;
|
||||
|
||||
len = va_arg (ap, int);
|
||||
value = va_arg (ap, void *);
|
||||
if ((write (parent_fd, &len, sizeof (int)) != sizeof (int)) ||
|
||||
(write (parent_fd, value, len) != len))
|
||||
{
|
||||
va_end (ap);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
str = parent_va_call_string (routine, argc, ap);
|
||||
va_end (ap);
|
||||
|
||||
if (read (from_parent_fd, &i, sizeof (int)) != sizeof (int))
|
||||
return NULL;
|
||||
if (!i)
|
||||
return NULL;
|
||||
str = g_malloc (i + 1);
|
||||
if (read (from_parent_fd, str, i) != i)
|
||||
{
|
||||
g_free (str);
|
||||
return NULL;
|
||||
}
|
||||
str[i] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* event callback */
|
||||
gboolean
|
||||
background_parent_call (const gchar * event_group_name, const gchar * event_name,
|
||||
gpointer init_data, gpointer data)
|
||||
{
|
||||
ev_background_parent_call_t *event_data = (ev_background_parent_call_t *) data;
|
||||
|
||||
(void) event_group_name;
|
||||
(void) event_name;
|
||||
(void) init_data;
|
||||
|
||||
event_data->ret.i =
|
||||
parent_va_call (event_data->routine, event_data->ctx, event_data->argc, event_data->ap);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* event callback */
|
||||
gboolean
|
||||
background_parent_call_string (const gchar * event_group_name, const gchar * event_name,
|
||||
gpointer init_data, gpointer data)
|
||||
{
|
||||
ev_background_parent_call_t *event_data = (ev_background_parent_call_t *) data;
|
||||
|
||||
(void) event_group_name;
|
||||
(void) event_name;
|
||||
(void) init_data;
|
||||
|
||||
event_data->ret.s =
|
||||
parent_va_call_string (event_data->routine, event_data->argc, event_data->ap);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* WITH_BACKGROUND */
|
||||
|
@ -46,6 +46,13 @@ char *parent_call_string (void *routine, int argc, ...);
|
||||
void unregister_task_running (pid_t pid, int fd);
|
||||
void unregister_task_with_pid (pid_t pid);
|
||||
|
||||
gboolean background_parent_call (const gchar * event_group_name, const gchar * event_name,
|
||||
gpointer init_data, gpointer data);
|
||||
|
||||
gboolean
|
||||
background_parent_call_string (const gchar * event_group_name, const gchar * event_name,
|
||||
gpointer init_data, gpointer data);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* !WITH_BACKGROUND */
|
||||
|
@ -27,9 +27,12 @@
|
||||
|
||||
#include "lib/event.h"
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
#include "background.h" /* (background_parent_call), background_parent_call_string() */
|
||||
#endif /* WITH_BACKGROUND */
|
||||
#include "clipboard.h" /* clipboard events */
|
||||
#include "help.h" /* help_interactive_display() */
|
||||
#include "execute.h" /* execute_suspend() */
|
||||
#include "help.h" /* help_interactive_display() */
|
||||
|
||||
#include "events_init.h"
|
||||
|
||||
@ -63,6 +66,11 @@ events_init (GError ** error)
|
||||
{MCEVENT_GROUP_CORE, "help", help_interactive_display, NULL},
|
||||
{MCEVENT_GROUP_CORE, "suspend", execute_suspend, NULL},
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
{MCEVENT_GROUP_CORE, "background_parent_call", background_parent_call, NULL},
|
||||
{MCEVENT_GROUP_CORE, "background_parent_call_string", background_parent_call_string, NULL},
|
||||
#endif /* WITH_BACKGROUND */
|
||||
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
Loading…
Reference in New Issue
Block a user