1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11 
12 #include <config.h>
13 
14 #include "display-server.h"
15 
16 enum {
17     READY,
18     STOPPED,
19     LAST_SIGNAL
20 };
21 static guint signals[LAST_SIGNAL] = { 0 };
22 
23 typedef struct
24 {
25     /* TRUE when started */
26     gboolean is_ready;
27 
28     /* TRUE when being stopped */
29     gboolean stopping;
30 
31     /* TRUE when the display server has stopped */
32     gboolean stopped;
33 } DisplayServerPrivate;
34 
35 static void display_server_logger_iface_init (LoggerInterface *iface);
36 
G_DEFINE_TYPE_WITH_CODE(DisplayServer,display_server,G_TYPE_OBJECT,G_ADD_PRIVATE (DisplayServer)G_IMPLEMENT_INTERFACE (LOGGER_TYPE,display_server_logger_iface_init))37 G_DEFINE_TYPE_WITH_CODE (DisplayServer, display_server, G_TYPE_OBJECT,
38                          G_ADD_PRIVATE (DisplayServer)
39                          G_IMPLEMENT_INTERFACE (LOGGER_TYPE, display_server_logger_iface_init))
40 
41 const gchar *
42 display_server_get_session_type (DisplayServer *server)
43 {
44     return DISPLAY_SERVER_GET_CLASS (server)->get_session_type (server);
45 }
46 
47 DisplayServer *
display_server_get_parent(DisplayServer * server)48 display_server_get_parent (DisplayServer *server)
49 {
50     g_return_val_if_fail (server != NULL, NULL);
51     return DISPLAY_SERVER_GET_CLASS (server)->get_parent (server);
52 }
53 
54 static DisplayServer *
display_server_real_get_parent(DisplayServer * server)55 display_server_real_get_parent (DisplayServer *server)
56 {
57     return NULL;
58 }
59 
60 gboolean
display_server_get_can_share(DisplayServer * server)61 display_server_get_can_share (DisplayServer *server)
62 {
63     g_return_val_if_fail (server != NULL, FALSE);
64     return DISPLAY_SERVER_GET_CLASS (server)->get_can_share (server);
65 }
66 
67 static gboolean
display_server_real_get_can_share(DisplayServer * server)68 display_server_real_get_can_share (DisplayServer *server)
69 {
70     return FALSE;
71 }
72 
73 gint
display_server_get_vt(DisplayServer * server)74 display_server_get_vt (DisplayServer *server)
75 {
76     g_return_val_if_fail (server != NULL, -1);
77     return DISPLAY_SERVER_GET_CLASS (server)->get_vt (server);
78 }
79 
80 static gint
display_server_real_get_vt(DisplayServer * server)81 display_server_real_get_vt (DisplayServer *server)
82 {
83     return -1;
84 }
85 
86 gboolean
display_server_start(DisplayServer * server)87 display_server_start (DisplayServer *server)
88 {
89     g_return_val_if_fail (server != NULL, FALSE);
90     return DISPLAY_SERVER_GET_CLASS (server)->start (server);
91 }
92 
93 gboolean
display_server_get_is_ready(DisplayServer * server)94 display_server_get_is_ready (DisplayServer *server)
95 {
96     DisplayServerPrivate *priv = display_server_get_instance_private (server);
97     g_return_val_if_fail (server != NULL, FALSE);
98     return priv->is_ready;
99 }
100 
101 static gboolean
display_server_real_start(DisplayServer * server)102 display_server_real_start (DisplayServer *server)
103 {
104     DisplayServerPrivate *priv = display_server_get_instance_private (server);
105     priv->is_ready = TRUE;
106     g_signal_emit (server, signals[READY], 0);
107     return TRUE;
108 }
109 
110 void
display_server_connect_session(DisplayServer * server,Session * session)111 display_server_connect_session (DisplayServer *server, Session *session)
112 {
113     return DISPLAY_SERVER_GET_CLASS (server)->connect_session (server, session);
114 }
115 
116 static void
display_server_real_connect_session(DisplayServer * server,Session * session)117 display_server_real_connect_session (DisplayServer *server, Session *session)
118 {
119 }
120 
121 void
display_server_disconnect_session(DisplayServer * server,Session * session)122 display_server_disconnect_session (DisplayServer *server, Session *session)
123 {
124     return DISPLAY_SERVER_GET_CLASS (server)->disconnect_session (server, session);
125 }
126 
127 static void
display_server_real_disconnect_session(DisplayServer * server,Session * session)128 display_server_real_disconnect_session (DisplayServer *server, Session *session)
129 {
130 }
131 
132 void
display_server_stop(DisplayServer * server)133 display_server_stop (DisplayServer *server)
134 {
135     DisplayServerPrivate *priv = display_server_get_instance_private (server);
136 
137     g_return_if_fail (server != NULL);
138 
139     if (priv->stopping)
140         return;
141     priv->stopping = TRUE;
142 
143     DISPLAY_SERVER_GET_CLASS (server)->stop (server);
144 }
145 
146 gboolean
display_server_get_is_stopping(DisplayServer * server)147 display_server_get_is_stopping (DisplayServer *server)
148 {
149     DisplayServerPrivate *priv = display_server_get_instance_private (server);
150     g_return_val_if_fail (server != NULL, FALSE);
151     return priv->stopping;
152 }
153 
154 static void
display_server_real_stop(DisplayServer * server)155 display_server_real_stop (DisplayServer *server)
156 {
157     g_signal_emit (server, signals[STOPPED], 0);
158 }
159 
160 static void
display_server_init(DisplayServer * server)161 display_server_init (DisplayServer *server)
162 {
163 }
164 
165 static void
display_server_class_init(DisplayServerClass * klass)166 display_server_class_init (DisplayServerClass *klass)
167 {
168     klass->get_parent = display_server_real_get_parent;
169     klass->get_can_share = display_server_real_get_can_share;
170     klass->get_vt = display_server_real_get_vt;
171     klass->start = display_server_real_start;
172     klass->connect_session = display_server_real_connect_session;
173     klass->disconnect_session = display_server_real_disconnect_session;
174     klass->stop = display_server_real_stop;
175 
176     signals[READY] =
177         g_signal_new (DISPLAY_SERVER_SIGNAL_READY,
178                       G_TYPE_FROM_CLASS (klass),
179                       G_SIGNAL_RUN_LAST,
180                       G_STRUCT_OFFSET (DisplayServerClass, ready),
181                       NULL, NULL,
182                       NULL,
183                       G_TYPE_NONE, 0);
184     signals[STOPPED] =
185         g_signal_new (DISPLAY_SERVER_SIGNAL_STOPPED,
186                       G_TYPE_FROM_CLASS (klass),
187                       G_SIGNAL_RUN_LAST,
188                       G_STRUCT_OFFSET (DisplayServerClass, stopped),
189                       NULL, NULL,
190                       NULL,
191                       G_TYPE_NONE, 0);
192 }
193 
194 static gint
display_server_real_logprefix(Logger * self,gchar * buf,gulong buflen)195 display_server_real_logprefix (Logger *self, gchar *buf, gulong buflen)
196 {
197     return g_snprintf (buf, buflen, "DisplayServer: ");
198 }
199 
200 static void
display_server_logger_iface_init(LoggerInterface * iface)201 display_server_logger_iface_init (LoggerInterface *iface)
202 {
203     iface->logprefix = &display_server_real_logprefix;
204 }
205