|
@@ -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 */
|