libvirt-sandbox-context-interactive.c 6.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
/*
 * libvirt-sandbox-context-interactive.c: libvirt sandbox interactive context
 *
 * Copyright (C) 2011 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#include <config.h>
#include <string.h>

#include "libvirt-sandbox/libvirt-sandbox.h"

/**
 * SECTION: libvirt-sandbox-context-interactive
 * @short_description: Desktop application sandbox context
 * @include: libvirt-sandbox/libvirt-sandbox.h
 * @see_also: #GVirSandboxContext
 *
 * Provides a base class for implementing interactive desktop application sandboxes
 *
 * The GVirSandboxContextInteractive object extends the functionality provided by
 * #GVirSandboxContext to allow the application to display output in a interactive
 * desktop.
 */

#define GVIR_SANDBOX_CONTEXT_INTERACTIVE_GET_PRIVATE(obj)                         \
        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONTEXT_INTERACTIVE, GVirSandboxContextInteractivePrivate))

struct _GVirSandboxContextInteractivePrivate
{
    gboolean unused;
};

G_DEFINE_TYPE(GVirSandboxContextInteractive, gvir_sandbox_context_interactive, GVIR_SANDBOX_TYPE_CONTEXT);


enum {
    PROP_0,
};

enum {
    LAST_SIGNAL
};

//static gint signals[LAST_SIGNAL];


static void gvir_sandbox_context_interactive_get_property(GObject *object,
                                                          guint prop_id,
                                                          GValue *value G_GNUC_UNUSED,
                                                          GParamSpec *pspec)
{
#if 0
    GVirSandboxContextInteractive *context = GVIR_SANDBOX_CONTEXT_INTERACTIVE(object);
    GVirSandboxContextInteractivePrivate *priv = context->priv;
#endif

    switch (prop_id) {

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}


static void gvir_sandbox_context_interactive_set_property(GObject *object,
                                                          guint prop_id,
                                                          const GValue *value G_GNUC_UNUSED,
                                                          GParamSpec *pspec)
{
#if 0
    GVirSandboxContextInteractive *context = GVIR_SANDBOX_CONTEXT_INTERACTIVE(object);
    GVirSandboxContextInteractivePrivate *priv = context->priv;
#endif

    switch (prop_id) {

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}


static void gvir_sandbox_context_interactive_finalize(GObject *object)
{
#if 0
    GVirSandboxContextInteractive *context = GVIR_SANDBOX_CONTEXT_INTERACTIVE(object);
    GVirSandboxContextInteractivePrivate *priv = context->priv;
#endif

    G_OBJECT_CLASS(gvir_sandbox_context_interactive_parent_class)->finalize(object);
}


static void gvir_sandbox_context_interactive_class_init(GVirSandboxContextInteractiveClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    object_class->finalize = gvir_sandbox_context_interactive_finalize;
    object_class->get_property = gvir_sandbox_context_interactive_get_property;
    object_class->set_property = gvir_sandbox_context_interactive_set_property;

    g_type_class_add_private(klass, sizeof(GVirSandboxContextInteractivePrivate));
}


static void gvir_sandbox_context_interactive_init(GVirSandboxContextInteractive *context)
{
    context->priv = GVIR_SANDBOX_CONTEXT_INTERACTIVE_GET_PRIVATE(context);
}


/**
 * gvir_sandbox_context_interactive_new:
 * @connection: (transfer none): the libvirt connection
 * @config: (transfer none): the initial configuratoion
 *
 * Create a new interactive application sandbox context
 *
 * Returns: (transfer full): a new interactive sandbox context object
 */
GVirSandboxContextInteractive *gvir_sandbox_context_interactive_new(GVirConnection *connection,
                                                                    GVirSandboxConfigInteractive *config)
{
    return GVIR_SANDBOX_CONTEXT_INTERACTIVE(g_object_new(GVIR_SANDBOX_TYPE_CONTEXT_INTERACTIVE,
                                                         "connection", connection,
                                                         "config", config,
                                                         NULL));
}
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182


/**
 * gvir_sandbox_context_interactive_get_app_console:
 * @ctxt: (transfer none): the sandbox context
 *
 * Returns: (transfer full)(allow-none): the sandbox console (or NULL)
 */
GVirSandboxConsole *gvir_sandbox_context_interactive_get_app_console(GVirSandboxContextInteractive *ctxt,
                                                                     GError **error)
{
    GVirSandboxConsole *console;
    const char *devname = NULL;
    GVirDomain *domain;
    GVirConnection *conn;

    if (!(domain = gvir_sandbox_context_get_domain(GVIR_SANDBOX_CONTEXT(ctxt), error)))
        return NULL;

    conn = gvir_sandbox_context_get_connection(GVIR_SANDBOX_CONTEXT(ctxt));

    /* XXX get from config + shell */
    if (strstr(gvir_connection_get_uri(conn), "lxc")) {
        GVirSandboxConfig *config = gvir_sandbox_context_get_config(GVIR_SANDBOX_CONTEXT(ctxt));
        if (gvir_sandbox_config_get_shell(config))
            devname = "console2";
        else
            devname = "console1";
    } else {
        devname = "console1";
    }

    console = GVIR_SANDBOX_CONSOLE(gvir_sandbox_console_rpc_new(conn,
                                                                domain,
                                                                devname));
    g_object_unref(domain);
    return console;
}