medit/moo/mooterm/mootermpt.c

134 lines
3.5 KiB
C
Raw Normal View History

2005-06-22 11:20:32 -07:00
/*
2005-07-07 04:06:23 -07:00
* mooterm/mootermpt.c
2005-06-22 11:20:32 -07:00
*
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#define MOOTERM_COMPILATION
#include "mooterm/mootermpt-private.h"
#include "mooterm/mooterm.h"
2005-06-22 15:13:12 -07:00
#include "mooutils/moomarshals.h"
#include "mooutils/moocompat.h"
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
static void moo_term_pt_finalize (GObject *object);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
/* MOO_TYPE_TERM_PT */
G_DEFINE_TYPE (MooTermPt, moo_term_pt, G_TYPE_OBJECT)
2005-06-22 11:20:32 -07:00
enum {
2005-06-22 15:13:12 -07:00
CHILD_DIED,
2005-06-22 11:20:32 -07:00
LAST_SIGNAL
};
enum {
PROP_0
2005-06-22 11:20:32 -07:00
};
2005-06-22 15:13:12 -07:00
static guint signals[LAST_SIGNAL];
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
static void moo_term_pt_class_init (MooTermPtClass *klass)
2005-06-22 11:20:32 -07:00
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
2005-07-07 04:06:23 -07:00
gobject_class->finalize = moo_term_pt_finalize;
2005-06-22 11:20:32 -07:00
2005-06-22 15:13:12 -07:00
klass->set_size = NULL;
klass->fork_command = NULL;
klass->write = NULL;
2005-06-22 15:13:12 -07:00
klass->kill_child = NULL;
klass->child_died = NULL;
signals[CHILD_DIED] =
g_signal_new ("child-died",
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST,
2005-07-07 04:06:23 -07:00
G_STRUCT_OFFSET (MooTermPtClass, child_died),
2005-06-22 15:13:12 -07:00
NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
static void moo_term_pt_init (MooTermPt *pt)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
pt->priv = g_new0 (MooTermPtPrivate, 1);
pt->priv->pending_write = g_queue_new ();
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
static void moo_term_pt_finalize (GObject *object)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
MooTermPt *pt = MOO_TERM_PT (object);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
pt_flush_pending_write (pt);
g_queue_free (pt->priv->pending_write);
2005-07-07 04:06:23 -07:00
g_free (pt->priv);
2005-06-22 11:20:32 -07:00
2005-07-07 04:06:23 -07:00
G_OBJECT_CLASS (moo_term_pt_parent_class)->finalize (object);
2005-06-22 11:20:32 -07:00
}
MooTermPt *moo_term_pt_new (MooTerm *term)
2005-06-22 11:20:32 -07:00
{
MooTermPt *pt;
2005-06-22 15:13:12 -07:00
#ifdef __WIN32__
pt = g_object_new (MOO_TYPE_TERM_PT_WIN, NULL);
2005-06-22 15:13:12 -07:00
#else /* !__WIN32__ */
pt = g_object_new (MOO_TYPE_TERM_PT_UNIX, NULL);
2005-06-22 15:13:12 -07:00
#endif /* !__WIN32__ */
pt->priv->term = term;
return pt;
2005-06-22 15:13:12 -07:00
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_set_size (MooTermPt *pt,
guint width,
guint height)
2005-06-22 15:13:12 -07:00
{
2005-07-07 04:06:23 -07:00
g_return_if_fail (MOO_IS_TERM_PT (pt));
MOO_TERM_PT_GET_CLASS(pt)->set_size (pt, width, height);
2005-06-22 15:13:12 -07:00
}
2005-07-07 04:06:23 -07:00
gboolean moo_term_pt_fork_command (MooTermPt *pt,
2005-06-22 15:13:12 -07:00
const char *cmd,
const char *working_dir,
char **envp)
{
2005-07-07 04:06:23 -07:00
g_return_val_if_fail (MOO_IS_TERM_PT (pt), FALSE);
return MOO_TERM_PT_GET_CLASS(pt)->fork_command (pt, cmd, working_dir, envp);
2005-06-22 15:13:12 -07:00
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_kill_child (MooTermPt *pt)
2005-06-22 15:13:12 -07:00
{
2005-07-07 04:06:23 -07:00
g_return_if_fail (MOO_IS_TERM_PT (pt));
MOO_TERM_PT_GET_CLASS(pt)->kill_child (pt);
2005-06-22 11:20:32 -07:00
}
2005-07-07 04:06:23 -07:00
void moo_term_pt_write (MooTermPt *pt,
2005-06-22 15:13:12 -07:00
const char *data,
gssize len)
2005-06-22 11:20:32 -07:00
{
2005-07-07 04:06:23 -07:00
g_return_if_fail (MOO_IS_TERM_PT (pt));
MOO_TERM_PT_GET_CLASS(pt)->write (pt, data, len);
2005-06-22 11:20:32 -07:00
}
gboolean moo_term_pt_child_alive (MooTermPt *pt)
{
return pt->priv->child_alive;
}