1/* 2 * Copyright 2011 Julien Lavergne <gilir@ubuntu.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 * MA 02110-1301, USA. 18 */ 19 20/* http://live.gnome.org/Vala/DBusServerSample#Using_GDBus */ 21 22namespace Lxsession 23{ 24 25[DBus(name = "org.gnome.SessionManager")] 26public class GnomeSessionServer : Object { 27 string not_implemented = "Error, lxsession doesn't implement this API"; 28/* 29 string gnome_session_version = "3.2.1"; 30*/ 31 32 /* Public property, exported via D-Bus */ 33 public int something { get; set; } 34 35 /* Public signal, exported via D-Bus 36 * Can be emitted on the server side and can be connected to on the client side. 37 */ 38 public signal void ClientAdded(out string path); 39 public signal void ClientRemoved(out string path); 40 public signal void InhibitorAdded(out string path); 41 public signal void InhibitorRemoved(out string path); 42 public signal void SessionRunning(); 43 public signal void SessionOver(); 44 45 /* Public method, exported via D-Bus */ 46 47 public void Setenv( string value ) { 48 /* TODO To implement */ 49 /* Adds the variable name to the application launch environment with the specified value. May only be used during the Session Manager initialization phase. */ 50 /* <arg name="value" type="s" direction="in"> */ 51 message(not_implemented); 52 } 53 54 public void InitializationError ( string mess, bool fatal ) { 55 /* TODO To implement 56 May be used by applications launched during the Session Manager initialization phase to indicate there was a problem. 57 <arg name="mess" type="s" direction="in"> 58 The error message 59 <arg name="fatal" type="b" direction="in"> 60 Whether the error should be treated as fatal 61 */ 62 message(not_implemented); 63 } 64 65 public async void RegisterClient(string app_id, string client_startup_id) { 66 /* TODO To implement 67 <doc:para>Register the caller as a Session Management client.</doc:para> 68 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> 69 <arg type="s" name="app_id" direction="in"> 70 <doc:summary>The application identifier</doc:summary> 71 <arg type="s" name="client_startup_id" direction="in"> 72 <doc:summary>Client startup identifier</doc:summary> 73 <arg type="o" name="client_id" direction="out"> 74 <doc:summary>The object path of the newly registered client</doc:summary> 75 */ 76 message(not_implemented); 77 } 78 79 public async void UnregisterClient() { 80 /* TODO To implement 81 <doc:para>Unregister the specified client from Session Management.</doc:para> 82 <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> 83 <arg type="o" name="client_id" direction="in"> 84 <doc:summary>The object path of the client</doc:summary> 85 */ 86 message(not_implemented); 87 } 88 89 public async void Inhibit(string app_id, uint toplevel_xid, string reason, uint flags, out uint inhibit_cookie) 90 { 91 /* TODO implement completly */ 92 /* Description : 93 Applications should invoke this method when they begin an operation that 94 should not be interrupted, such as creating a CD or DVD. The types of actions 95 that may be blocked are specified by the flags parameter. When the application 96 completes the operation it should call Uninhibit() 97 or disconnect from the session bus. 98 99 app_id : The application identifier 100 toplevel_xid : the toplevel X window identifier 101 reason : The reason for the inhibit 102 flags : Flags that spefify what should be inhibited (Values for flags may be bitwise or'ed together.) 103 1 Inhibit logging out 104 2 Inhibit user switching 105 4 Inhibit suspending the session or computer 106 8 Inhibit the session being marked as idle 107 108 inhibit_cookie : The returned cookie is used to uniquely identify this request. It should be used 109 as an argument to Uninhibit() in order to remove the request. 110 */ 111 message("Call Inhibit function"); 112 inhibit_cookie = 0; 113 if (flags == 8) 114 { 115 var control = new ControlObject(); 116 control.set_status_busy(toplevel_xid); 117 uint cookie = Random.next_int(); 118 inhibit_cookie = cookie; 119 } 120 } 121 122 public async void Uninhibit(uint inhibit_cookie) 123 { 124 /* Description : Cancel a previous call to Inhibit() identified by the cookie. */ 125 var control = new ControlObject(); 126 control.exit_status_busy(); 127 } 128/* 129 130 <method name="IsInhibited"> 131 <arg type="u" name="flags" direction="in"> 132 <doc:doc> 133 <doc:summary>Flags that spefify what should be inhibited</doc:summary> 134 </doc:doc> 135 </arg> 136 <arg type="b" name="is_inhibited" direction="out"> 137 <doc:doc> 138 <doc:summary>Returns TRUE if any of the operations in the bitfield flags are inhibited</doc:summary> 139 </doc:doc> 140 </arg> 141 <doc:doc> 142 <doc:description> 143 <doc:para>Determine if operation(s) specified by the flags 144 are currently inhibited. Flags are same as those accepted 145 by the 146 <doc:ref type="method" to="org.gnome.SessionManager.Inhibit">Inhibit()</doc:ref> 147 method.</doc:para> 148 </doc:description> 149 </doc:doc> 150 </method> 151 152 <method name="GetClients"> 153 <arg name="clients" direction="out" type="ao"> 154 <doc:doc> 155 <doc:summary>an array of client IDs</doc:summary> 156 </doc:doc> 157 </arg> 158 <doc:doc> 159 <doc:description> 160 <doc:para>This gets a list of all the <doc:ref type="interface" to="org.gnome.SessionManager.Client">Clients</doc:ref> 161 that are currently known to the session manager.</doc:para> 162 <doc:para>Each Client ID is an D-Bus object path for the object that implements the 163 <doc:ref type="interface" to="org.gnome.SessionManager.Client">Client</doc:ref> interface.</doc:para> 164 </doc:description> 165 <doc:seealso><doc:ref type="interface" to="org.gnome.SessionManager.Client">org.gnome.SessionManager.Client</doc:ref></doc:seealso> 166 </doc:doc> 167 </method> 168 169 <method name="GetInhibitors"> 170 <arg name="inhibitors" direction="out" type="ao"> 171 <doc:doc> 172 <doc:summary>an array of inhibitor IDs</doc:summary> 173 </doc:doc> 174 </arg> 175 <doc:doc> 176 <doc:description> 177 <doc:para>This gets a list of all the <doc:ref type="interface" to="org.gnome.SessionManager.Inhibitor">Inhibitors</doc:ref> 178 that are currently known to the session manager.</doc:para> 179 <doc:para>Each Inhibitor ID is an D-Bus object path for the object that implements the 180 <doc:ref type="interface" to="org.gnome.SessionManager.Inhibitor">Inhibitor</doc:ref> interface.</doc:para> 181 </doc:description> 182 <doc:seealso><doc:ref type="interface" to="org.gnome.SessionManager.Inhibitor">org.gnome.SessionManager.Inhibitor</doc:ref></doc:seealso> 183 </doc:doc> 184 </method> 185 186 187 <method name="IsAutostartConditionHandled"> 188 <arg name="condition" direction="in" type="s"> 189 <doc:doc> 190 <doc:summary>The autostart condition string</doc:summary> 191 </doc:doc> 192 </arg> 193 <arg name="handled" direction="out" type="b"> 194 <doc:doc> 195 <doc:summary>True if condition is handled, false otherwise</doc:summary> 196 </doc:doc> 197 </arg> 198 <doc:doc> 199 <doc:description> 200 <doc:para>Allows the caller to determine whether the session manager is 201 handling changes to the specified autostart condition.</doc:para> 202 </doc:description> 203 </doc:doc> 204 </method> 205*/ 206 207 public void Shutdown() { 208 var session = new SessionObject(); 209 session.lxsession_shutdown(); 210 } 211 public async void CanShutdown(out bool is_available) { 212 var session = new SessionObject(); 213 is_available = yield session.lxsession_can_shutdown(); 214 } 215 216 public void Logout(uint mode) { 217 /* TODO To implement */ 218 /* 219 0 Normal 220 1 No confirmation inferface should be shown. 221 2 Forcefully logout. No confirmation will be shown and any inhibitors will be ignored. 222 */ 223 /* 224 var session = new SessionObject(); 225 session.lxsession_restart(); */ 226 stdout.printf(not_implemented); 227 } 228 229 public void IsSessionRunning(out bool running ) 230 { 231 /* TODO To implement 232 <arg name="running" direction="out" type="b"> 233 <doc:doc> 234 <doc:summary>True if the session has entered the Running phase, false otherwise</doc:summary> 235 </doc:doc> 236 </arg> 237 <doc:doc> 238 <doc:description> 239 <doc:para>Allows the caller to determine whether the session manager 240 has entered the Running phase, in case the client missed the 241 SessionRunning signal.</doc:para> 242 </doc:description> 243 </doc:doc> 244 */ 245 running = false; 246 } 247 248 249} 250 251} 252