1999-03-07 20:56:03 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
1998-01-25 18:26:47 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-01-25 18:26:47 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
1999-03-07 20:56:03 +08:00
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2000-05-14 20:09:43 +08:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
1999-03-07 20:56:03 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1998-01-25 18:26:47 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-04-13 13:44:11 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
1999-03-07 20:56:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-03-07 20:56:03 +08:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <sys/param.h>
|
1999-03-07 20:56:03 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <sys/types.h>
|
1999-03-07 20:56:03 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <unistd.h>
|
1999-03-07 20:56:03 +08:00
|
|
|
#endif
|
|
|
|
|
2001-07-16 04:47:03 +08:00
|
|
|
#include <glib.h>
|
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
1999-03-07 20:56:03 +08:00
|
|
|
#include <process.h>
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gimpwire.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _WireHandler WireHandler;
|
|
|
|
|
|
|
|
struct _WireHandler
|
|
|
|
{
|
2000-05-14 20:09:43 +08:00
|
|
|
guint32 type;
|
|
|
|
WireReadFunc read_func;
|
|
|
|
WireWriteFunc write_func;
|
1997-11-25 06:05:25 +08:00
|
|
|
WireDestroyFunc destroy_func;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
static void wire_init (void);
|
|
|
|
static guint wire_hash (guint32 *key);
|
|
|
|
static gboolean wire_compare (guint32 *a,
|
|
|
|
guint32 *b);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-07-16 04:47:03 +08:00
|
|
|
static GHashTable *wire_ht = NULL;
|
|
|
|
static WireIOFunc wire_read_func = NULL;
|
2000-05-14 20:09:43 +08:00
|
|
|
static WireIOFunc wire_write_func = NULL;
|
|
|
|
static WireFlushFunc wire_flush_func = NULL;
|
2001-07-16 04:47:03 +08:00
|
|
|
static gboolean wire_error_val = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
wire_register (guint32 type,
|
|
|
|
WireReadFunc read_func,
|
|
|
|
WireWriteFunc write_func,
|
|
|
|
WireDestroyFunc destroy_func)
|
|
|
|
{
|
|
|
|
WireHandler *handler;
|
|
|
|
|
|
|
|
if (!wire_ht)
|
|
|
|
wire_init ();
|
|
|
|
|
|
|
|
handler = g_hash_table_lookup (wire_ht, &type);
|
|
|
|
if (!handler)
|
|
|
|
handler = g_new (WireHandler, 1);
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
handler->type = type;
|
|
|
|
handler->read_func = read_func;
|
|
|
|
handler->write_func = write_func;
|
1997-11-25 06:05:25 +08:00
|
|
|
handler->destroy_func = destroy_func;
|
|
|
|
|
|
|
|
g_hash_table_insert (wire_ht, &handler->type, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wire_set_reader (WireIOFunc read_func)
|
|
|
|
{
|
|
|
|
wire_read_func = read_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wire_set_writer (WireIOFunc write_func)
|
|
|
|
{
|
|
|
|
wire_write_func = write_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wire_set_flusher (WireFlushFunc flush_func)
|
|
|
|
{
|
|
|
|
wire_flush_func = flush_func;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read (GIOChannel *channel,
|
|
|
|
guint8 *buf,
|
2002-05-17 01:41:38 +08:00
|
|
|
gsize count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (wire_read_func)
|
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
if (!(* wire_read_func) (channel, buf, count, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-05-11 05:21:23 +08:00
|
|
|
g_warning ("%s: wire_read: error", g_get_prgname ());
|
1997-11-25 06:05:25 +08:00
|
|
|
wire_error_val = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-30 01:48:28 +08:00
|
|
|
GIOStatus status;
|
|
|
|
GError *error = NULL;
|
|
|
|
gsize bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
while (count > 0)
|
|
|
|
{
|
2000-05-14 20:09:43 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
bytes = 0;
|
2001-08-30 01:48:28 +08:00
|
|
|
status = g_io_channel_read_chars (channel,
|
|
|
|
(gchar *) buf, count,
|
|
|
|
&bytes,
|
|
|
|
&error);
|
2000-05-14 20:09:43 +08:00
|
|
|
}
|
2001-08-30 01:48:28 +08:00
|
|
|
while (status == G_IO_STATUS_AGAIN);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-30 01:48:28 +08:00
|
|
|
if (status != G_IO_STATUS_NORMAL)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-30 09:09:58 +08:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("%s: wire_read(): error: %s",
|
|
|
|
g_get_prgname (), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s: wire_read(): error",
|
|
|
|
g_get_prgname ());
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
wire_error_val = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
if (bytes == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-30 01:48:28 +08:00
|
|
|
g_warning ("%s: wire_read(): unexpected EOF", g_get_prgname ());
|
1997-11-25 06:05:25 +08:00
|
|
|
wire_error_val = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
count -= bytes;
|
|
|
|
buf += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write (GIOChannel *channel,
|
|
|
|
guint8 *buf,
|
2002-05-17 01:41:38 +08:00
|
|
|
gsize count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (wire_write_func)
|
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
if (!(* wire_write_func) (channel, buf, count, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-05-11 05:21:23 +08:00
|
|
|
g_warning ("%s: wire_write: error", g_get_prgname ());
|
1997-11-25 06:05:25 +08:00
|
|
|
wire_error_val = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-30 01:48:28 +08:00
|
|
|
GIOStatus status;
|
|
|
|
GError *error = NULL;
|
|
|
|
gsize bytes;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
while (count > 0)
|
|
|
|
{
|
2000-05-14 20:09:43 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
bytes = 0;
|
2001-08-30 01:48:28 +08:00
|
|
|
status = g_io_channel_write_chars (channel,
|
|
|
|
(gchar *) buf, count,
|
|
|
|
&bytes,
|
|
|
|
&error);
|
2000-05-14 20:09:43 +08:00
|
|
|
}
|
2001-08-30 01:48:28 +08:00
|
|
|
while (status == G_IO_STATUS_AGAIN);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-30 01:48:28 +08:00
|
|
|
if (status != G_IO_STATUS_NORMAL)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-30 09:09:58 +08:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("%s: wire_write(): error: %s",
|
|
|
|
g_get_prgname (), error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s: wire_write(): error",
|
|
|
|
g_get_prgname ());
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
wire_error_val = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
count -= bytes;
|
|
|
|
buf += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
2002-05-17 01:41:38 +08:00
|
|
|
wire_flush (GIOChannel *channel,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (wire_flush_func)
|
2002-05-17 01:41:38 +08:00
|
|
|
return (* wire_flush_func) (channel, user_data);
|
2000-05-14 20:09:43 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
|
|
|
wire_error (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
return wire_error_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-14 20:09:43 +08:00
|
|
|
wire_clear_error (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
wire_error_val = FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read_msg (GIOChannel *channel,
|
2002-05-17 01:41:38 +08:00
|
|
|
WireMessage *msg,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
WireHandler *handler;
|
|
|
|
|
|
|
|
if (wire_error_val)
|
|
|
|
return !wire_error_val;
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_read_int32 (channel, &msg->type, 1, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
handler = g_hash_table_lookup (wire_ht, &msg->type);
|
|
|
|
if (!handler)
|
1999-03-07 20:56:03 +08:00
|
|
|
g_error ("could not find handler for message: %d", msg->type);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
(* handler->read_func) (channel, msg, user_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return !wire_error_val;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write_msg (GIOChannel *channel,
|
2002-05-17 01:41:38 +08:00
|
|
|
WireMessage *msg,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
WireHandler *handler;
|
|
|
|
|
|
|
|
if (wire_error_val)
|
|
|
|
return !wire_error_val;
|
|
|
|
|
|
|
|
handler = g_hash_table_lookup (wire_ht, &msg->type);
|
|
|
|
if (!handler)
|
1999-03-07 20:56:03 +08:00
|
|
|
g_error ("could not find handler for message: %d", msg->type);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_write_int32 (channel, &msg->type, 1, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
(* handler->write_func) (channel, msg, user_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return !wire_error_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wire_destroy (WireMessage *msg)
|
|
|
|
{
|
|
|
|
WireHandler *handler;
|
|
|
|
|
|
|
|
handler = g_hash_table_lookup (wire_ht, &msg->type);
|
|
|
|
if (!handler)
|
|
|
|
g_error ("could not find handler for message: %d\n", msg->type);
|
|
|
|
|
|
|
|
(* handler->destroy_func) (msg);
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read_int32 (GIOChannel *channel,
|
|
|
|
guint32 *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (count > 0)
|
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_read_int8 (channel, (guint8 *) data, count * 4, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
1998-11-23 17:25:10 +08:00
|
|
|
*data = g_ntohl (*data);
|
1997-11-25 06:05:25 +08:00
|
|
|
data++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read_int16 (GIOChannel *channel,
|
|
|
|
guint16 *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (count > 0)
|
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_read_int8 (channel, (guint8 *) data, count * 2, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
1998-11-23 17:25:10 +08:00
|
|
|
*data = g_ntohs (*data);
|
1997-11-25 06:05:25 +08:00
|
|
|
data++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read_int8 (GIOChannel *channel,
|
|
|
|
guint8 *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
return wire_read (channel, data, count, user_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read_double (GIOChannel *channel,
|
|
|
|
gdouble *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-11-25 18:12:02 +08:00
|
|
|
gdouble *t;
|
|
|
|
guint8 tmp[8];
|
|
|
|
gint i;
|
2001-07-16 04:47:03 +08:00
|
|
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
2002-11-25 18:12:02 +08:00
|
|
|
gint j;
|
|
|
|
guint8 swap;
|
2001-07-16 04:47:03 +08:00
|
|
|
#endif
|
|
|
|
|
2002-11-25 18:12:02 +08:00
|
|
|
t = (gdouble *) tmp;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2002-11-25 18:12:02 +08:00
|
|
|
if (! wire_read_int8 (channel, tmp, 8, user_data))
|
|
|
|
return FALSE;
|
2001-07-16 04:47:03 +08:00
|
|
|
|
|
|
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
2002-11-25 18:12:02 +08:00
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
swap = tmp[j];
|
|
|
|
tmp[j] = tmp[7 - j];
|
|
|
|
tmp[7 - j] = swap;
|
|
|
|
}
|
2001-07-16 04:47:03 +08:00
|
|
|
#endif
|
|
|
|
|
2002-11-25 18:12:02 +08:00
|
|
|
data[i] = *t;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_read_string (GIOChannel *channel,
|
|
|
|
gchar **data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
guint32 tmp;
|
2000-05-14 20:09:43 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
if (!wire_read_int32 (channel, &tmp, 1, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (tmp > 0)
|
|
|
|
{
|
|
|
|
data[i] = g_new (gchar, tmp);
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_read_int8 (channel, (guint8 *) data[i], tmp, user_data))
|
1998-03-01 09:18:45 +08:00
|
|
|
{
|
|
|
|
g_free (data[i]);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write_int32 (GIOChannel *channel,
|
|
|
|
guint32 *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
guint32 tmp;
|
2000-05-14 20:09:43 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
1998-11-23 17:25:10 +08:00
|
|
|
tmp = g_htonl (data[i]);
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_write_int8 (channel, (guint8 *) &tmp, 4, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write_int16 (GIOChannel *channel,
|
|
|
|
guint16 *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
guint16 tmp;
|
2000-05-14 20:09:43 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
1998-11-23 17:25:10 +08:00
|
|
|
tmp = g_htons (data[i]);
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_write_int8 (channel, (guint8 *) &tmp, 2, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write_int8 (GIOChannel *channel,
|
|
|
|
guint8 *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-05-17 01:41:38 +08:00
|
|
|
return wire_write (channel, data, count, user_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write_double (GIOChannel *channel,
|
|
|
|
gdouble *data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-11-25 18:12:02 +08:00
|
|
|
gdouble *t;
|
|
|
|
guint8 tmp[8];
|
2001-07-16 04:47:03 +08:00
|
|
|
gint i;
|
|
|
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
2002-11-25 18:12:02 +08:00
|
|
|
gint j;
|
|
|
|
guint8 swap;
|
2001-07-16 04:47:03 +08:00
|
|
|
#endif
|
|
|
|
|
2002-11-25 18:12:02 +08:00
|
|
|
t = (gdouble *) tmp;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2002-11-25 18:12:02 +08:00
|
|
|
*t = data[i];
|
2001-07-16 04:47:03 +08:00
|
|
|
|
|
|
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
2002-11-25 18:12:02 +08:00
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
swap = tmp[j];
|
|
|
|
tmp[j] = tmp[7 - j];
|
|
|
|
tmp[7 - j] = swap;
|
|
|
|
}
|
2001-07-16 04:47:03 +08:00
|
|
|
#endif
|
|
|
|
|
2002-11-25 18:12:02 +08:00
|
|
|
if (! wire_write_int8 (channel, tmp, 8, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
2001-07-16 04:47:03 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
{
|
2002-11-25 18:12:02 +08:00
|
|
|
gint k;
|
2001-07-16 04:47:03 +08:00
|
|
|
|
|
|
|
g_print ("Wire representation of %f:\t", data[i]);
|
|
|
|
|
2002-11-25 18:12:02 +08:00
|
|
|
for (k = 0; k < 8; k++)
|
2001-07-16 04:47:03 +08:00
|
|
|
{
|
2002-11-25 18:12:02 +08:00
|
|
|
g_print ("%02x ", tmp[k]);
|
2001-07-16 04:47:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
gboolean
|
1999-03-07 20:56:03 +08:00
|
|
|
wire_write_string (GIOChannel *channel,
|
|
|
|
gchar **data,
|
2002-05-17 01:41:38 +08:00
|
|
|
gint count,
|
|
|
|
gpointer user_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
guint32 tmp;
|
2000-05-14 20:09:43 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (data[i])
|
|
|
|
tmp = strlen (data[i]) + 1;
|
|
|
|
else
|
|
|
|
tmp = 0;
|
|
|
|
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_write_int32 (channel, &tmp, 1, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
if (tmp > 0)
|
2002-05-17 01:41:38 +08:00
|
|
|
if (! wire_write_int8 (channel, (guint8 *) data[i], tmp, user_data))
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-14 20:09:43 +08:00
|
|
|
wire_init (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (!wire_ht)
|
|
|
|
{
|
|
|
|
wire_ht = g_hash_table_new ((GHashFunc) wire_hash,
|
|
|
|
(GCompareFunc) wire_compare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
wire_hash (guint32 *key)
|
|
|
|
{
|
|
|
|
return *key;
|
|
|
|
}
|
|
|
|
|
2000-05-14 20:09:43 +08:00
|
|
|
static gboolean
|
1997-11-25 06:05:25 +08:00
|
|
|
wire_compare (guint32 *a,
|
|
|
|
guint32 *b)
|
|
|
|
{
|
|
|
|
return (*a == *b);
|
|
|
|
}
|