Back to index

lightdm  1.3.2
display-server.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 Robert Ancell.
00003  * Author: Robert Ancell <robert.ancell@canonical.com>
00004  * 
00005  * This program is free software: you can redistribute it and/or modify it under
00006  * the terms of the GNU General Public License as published by the Free Software
00007  * Foundation, either version 3 of the License, or (at your option) any later
00008  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
00009  * license.
00010  */
00011 
00012 #include <config.h>
00013 
00014 #include "display-server.h"
00015 
00016 enum {
00017     READY,
00018     STOPPED,
00019     LAST_SIGNAL
00020 };
00021 static guint signals[LAST_SIGNAL] = { 0 };
00022 
00023 struct DisplayServerPrivate
00024 {
00025     /* Unique name for this display server */
00026     gchar *name;
00027 
00028     /* TRUE if sessions should be automatically started on this display server */
00029     gboolean start_local_sessions;
00030 };
00031 
00032 G_DEFINE_TYPE (DisplayServer, display_server, G_TYPE_OBJECT);
00033 
00034 void
00035 display_server_set_name (DisplayServer *server, const gchar *name)
00036 {
00037     g_return_if_fail (server != NULL);
00038     g_free (server->priv->name);
00039     server->priv->name = g_strdup (name);
00040 }
00041 
00042 const gchar *
00043 display_server_get_name (DisplayServer *server)
00044 {
00045     g_return_val_if_fail (server != NULL, NULL);
00046     return server->priv->name;
00047 }
00048 
00049 void
00050 display_server_set_start_local_sessions (DisplayServer *server, gboolean start_local_sessions)
00051 {
00052     g_return_if_fail (server != NULL);
00053     server->priv->start_local_sessions = start_local_sessions;
00054 }
00055 
00056 gboolean
00057 display_server_get_start_local_sessions (DisplayServer *server)
00058 {
00059     g_return_val_if_fail (server != NULL, FALSE);
00060     return server->priv->start_local_sessions;
00061 }
00062 
00063 gboolean
00064 display_server_start (DisplayServer *server)
00065 {
00066     g_return_val_if_fail (server != NULL, FALSE);
00067     return DISPLAY_SERVER_GET_CLASS (server)->start (server);
00068 }
00069 
00070 static gboolean
00071 display_server_real_start (DisplayServer *server)
00072 {
00073     g_signal_emit (server, signals[READY], 0);
00074     return TRUE;
00075 }
00076 
00077 void
00078 display_server_stop (DisplayServer *server)
00079 {
00080     g_return_if_fail (server != NULL);
00081     DISPLAY_SERVER_GET_CLASS (server)->stop (server);
00082 }
00083 
00084 gboolean
00085 display_server_get_is_stopped (DisplayServer *server)
00086 {
00087     g_return_val_if_fail (server != NULL, TRUE);
00088     return DISPLAY_SERVER_GET_CLASS (server)->get_is_stopped (server);
00089 }
00090 
00091 static void
00092 display_server_real_stop (DisplayServer *server)
00093 {
00094     g_signal_emit (server, signals[STOPPED], 0);
00095 }
00096 
00097 static gboolean
00098 display_server_real_get_is_stopped (DisplayServer *server)
00099 {
00100     return TRUE;
00101 }
00102 
00103 static void
00104 display_server_init (DisplayServer *server)
00105 {
00106     server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, DISPLAY_SERVER_TYPE, DisplayServerPrivate);
00107     server->priv->start_local_sessions = TRUE;
00108 }
00109 
00110 static void
00111 display_server_class_init (DisplayServerClass *klass)
00112 {
00113     klass->start = display_server_real_start;
00114     klass->stop = display_server_real_stop;
00115     klass->get_is_stopped = display_server_real_get_is_stopped;
00116 
00117     g_type_class_add_private (klass, sizeof (DisplayServerPrivate));
00118 
00119     signals[READY] =
00120         g_signal_new ("ready",
00121                       G_TYPE_FROM_CLASS (klass),
00122                       G_SIGNAL_RUN_LAST,
00123                       G_STRUCT_OFFSET (DisplayServerClass, ready),
00124                       NULL, NULL,
00125                       g_cclosure_marshal_VOID__VOID,
00126                       G_TYPE_NONE, 0);
00127     signals[STOPPED] =
00128         g_signal_new ("stopped",
00129                       G_TYPE_FROM_CLASS (klass),
00130                       G_SIGNAL_RUN_LAST,
00131                       G_STRUCT_OFFSET (DisplayServerClass, stopped),
00132                       NULL, NULL,
00133                       g_cclosure_marshal_VOID__VOID,
00134                       G_TYPE_NONE, 0);
00135 }