Commit 0d2455ac authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

enabled build of the Script-Fu server for the Win32 platform using the

2004-09-21  Sven Neumann  <sven@gimp.org>

	* plug-ins/script-fu/script-fu-server.c: enabled build of the
	Script-Fu server for the Win32 platform using the winsock API.

	* plug-ins/script-fu/Makefile.am: link with -lwsock32 on Win32.

	* plug-ins/script-fu/script-fu-console.c
	* plug-ins/script-fu/script-fu.c
	* plug-ins/script-fu/siod-wrapper.c: removed Win32 specific code
	that isn't needed any longer.
parent 37912655
2004-09-21 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu-server.c: enabled build of the
Script-Fu server for the Win32 platform using the winsock API.
* plug-ins/script-fu/Makefile.am: link with -lwsock32 on Win32.
* plug-ins/script-fu/script-fu-console.c
* plug-ins/script-fu/script-fu.c
* plug-ins/script-fu/siod-wrapper.c: removed Win32 specific code
that isn't needed any longer.
2004-09-21 Michael Natterer <mitch@gimp.org>
For the sake of completeness, added a GUI for the hidden
......
......@@ -8,6 +8,7 @@ libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la
if OS_WIN32
mwindows = -mwindows
WINSOCK_LIBS = -lwsock32
endif
AM_LDFLAGS = $(mwindows)
......@@ -60,5 +61,6 @@ LDADD = \
$(REGEXREPL) \
$(GTK_LIBS) \
$(SOCKET_LIBS) \
$(WINSOCK_LIBS) \
$(RT_LIBS) \
$(INTLLIBS)
......@@ -1091,11 +1091,10 @@ marshall_proc_db_call (LISP a)
/* reverse the return values */
return_val = nreverse (return_val);
#ifndef G_OS_WIN32
/* if we're in server mode, listen for additional commands for 10 ms */
if (script_fu_server_get_mode ())
script_fu_server_listen (10);
#endif
#ifdef GDK_WINDOWING_WIN32
/* This seems to help a lot on Windoze. */
......@@ -1118,11 +1117,7 @@ script_fu_register_call (LISP a)
static LISP
script_fu_quit_call (LISP a)
{
#ifdef G_OS_WIN32
g_warning ("script_fu_server not available.");
#else
script_fu_server_quit ();
#endif
return NIL;
}
......@@ -40,11 +40,6 @@
#include <plug-ins/dbbrowser/dbbrowser_utils.h>
#ifdef G_OS_WIN32
#include <fcntl.h>
#include <io.h>
#endif
#define TEXT_WIDTH 480
#define TEXT_HEIGHT 400
......
......@@ -20,8 +20,6 @@
#include <glib.h> /* For G_OS_WIN32 */
#ifndef G_OS_WIN32
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -31,10 +29,15 @@
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef G_OS_WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
......@@ -120,19 +123,19 @@ typedef struct
* Local Functions
*/
static void server_start (gint port,
gchar *logfile);
static gboolean execute_command (SFCommand *cmd);
static gint read_from_client (gint filedes);
static gint make_socket (guint port);
static void server_log (gchar *format,
...);
static void server_start (gint port,
const gchar *logfile);
static gboolean execute_command (SFCommand *cmd);
static gint read_from_client (gint filedes);
static gint make_socket (guint port);
static void server_log (const gchar *format,
...) G_GNUC_PRINTF (1, 2);
static void server_quit (void);
static gboolean server_interface (void);
static void response_callback (GtkWidget *widget,
gint response_id,
gpointer data);
static void response_callback (GtkWidget *widget,
gint response_id,
gpointer data);
/*
......@@ -151,13 +154,13 @@ static gboolean server_mode = FALSE;
static ServerInterface sint =
{
NULL, /* port entry widget */
NULL, /* log entry widget */
NULL, /* port entry widget */
NULL, /* log entry widget */
10008, /* default port number */
NULL, /* use stdout */
NULL, /* use stdout */
FALSE /* run */
FALSE /* run */
};
/*
......@@ -184,9 +187,9 @@ script_fu_server_run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpRunMode run_mode;
static GimpParam values[1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpRunMode run_mode;
run_mode = params[0].data.d_int32;
......@@ -230,19 +233,17 @@ script_fu_server_listen (gint timeout)
{
struct sockaddr_in clientname;
struct timeval tv;
struct timeval *tvp;
gint i;
guint size;
struct timeval *tvp = NULL;
gint i;
guint size;
/* Set time struct */
if (timeout)
{
tv.tv_sec = timeout / 1000;
tv.tv_sec = timeout / 1000;
tv.tv_usec = timeout % 1000;
tvp = &tv;
}
else
tvp = NULL;
/* Block until input arrives on one or more active sockets
or timeout occurs. */
......@@ -313,12 +314,13 @@ script_fu_server_listen (gint timeout)
}
static void
server_start (gint port,
gchar *logfile)
server_start (gint port,
const gchar *logfile)
{
/* First of all, create the socket and set it up to accept connections. */
/* This may fail if there's a server running on this port already. */
server_sock = make_socket (port);
if (listen (server_sock, 5) < 0)
{
perror ("listen");
......@@ -339,7 +341,7 @@ server_start (gint port,
NULL,
(GDestroyNotify) g_free);
server_log ("Script-fu initialized and listening...\n");
server_log ("Script-fu server initialized and listening...\n");
/* Initialize the set of active sockets. */
FD_ZERO (&server_active);
......@@ -516,8 +518,29 @@ static gint
make_socket (guint port)
{
struct sockaddr_in name;
gint sock;
gint v = 1;
gint sock;
gint v = 1;
/* Win32 needs the winsock library initialized. */
#ifdef G_OS_WIN32
static gboolean winsock_initialized = FALSE;
if (! winsock_initialized)
{
WORD wVersionRequested = MAKEWORD (2, 2);
WSADATA wsaData;
if (WSAStartup (wVersionRequested, &wsaData) == 0)
{
winsock_initialized = TRUE;
}
else
{
perror ("Can't initialize the Winsock DLL");
gimp_quit ();
}
}
#endif
/* Create the socket. */
sock = socket (PF_INET, SOCK_STREAM, 0);
......@@ -526,6 +549,7 @@ make_socket (guint port)
perror ("socket");
gimp_quit ();
}
setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v));
/* Give the socket a name. */
......@@ -543,7 +567,8 @@ make_socket (guint port)
}
static void
server_log (gchar *format, ...)
server_log (const gchar *format,
...)
{
va_list args;
gchar *buf;
......@@ -554,6 +579,7 @@ server_log (gchar *format, ...)
fputs (buf, server_log_file);
g_free (buf);
if (server_log_file != stdout)
fflush (server_log_file);
}
......@@ -658,7 +684,5 @@ response_callback (GtkWidget *widget,
sint.run = TRUE;
}
gtk_widget_destroy (GTK_WIDGET (widget));
gtk_widget_destroy (widget);
}
#endif /* G_OS_WIN32 */
......@@ -143,7 +143,6 @@ script_fu_query (void)
G_N_ELEMENTS (textconsole_args), 0,
textconsole_args, NULL);
#ifndef G_OS_WIN32
gimp_install_procedure ("plug_in_script_fu_server",
"Provides a server for remote script-fu operation",
"Provides a server for remote script-fu operation",
......@@ -158,7 +157,6 @@ script_fu_query (void)
gimp_plugin_menu_register ("plug_in_script_fu_server",
N_("<Toolbox>/Xtns/Script-Fu"));
#endif
gimp_install_procedure ("plug_in_script_fu_eval",
"Evaluate scheme code",
......@@ -247,7 +245,6 @@ script_fu_run (const gchar *name,
script_fu_console_run (name, nparams, param,
nreturn_vals, return_vals);
}
#ifndef G_OS_WIN32
else if (strcmp (name, "plug_in_script_fu_server") == 0)
{
/*
......@@ -257,7 +254,6 @@ script_fu_run (const gchar *name,
script_fu_server_run (name, nparams, param,
nreturn_vals, return_vals);
}
#endif
else if (strcmp (name, "plug_in_script_fu_eval") == 0)
{
/*
......
......@@ -1091,11 +1091,10 @@ marshall_proc_db_call (LISP a)
/* reverse the return values */
return_val = nreverse (return_val);
#ifndef G_OS_WIN32
/* if we're in server mode, listen for additional commands for 10 ms */
if (script_fu_server_get_mode ())
script_fu_server_listen (10);
#endif
#ifdef GDK_WINDOWING_WIN32
/* This seems to help a lot on Windoze. */
......@@ -1118,11 +1117,7 @@ script_fu_register_call (LISP a)
static LISP
script_fu_quit_call (LISP a)
{
#ifdef G_OS_WIN32
g_warning ("script_fu_server not available.");
#else
script_fu_server_quit ();
#endif
return NIL;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment