1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2  *
3  * Copyright (C) 2007 Novell, Inc.
4  * Copyright (C) 2008 Red Hat, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA
19  * 02110-1335, USA.
20  */
21 
22 #ifndef __CSM_CLIENT_H__
23 #define __CSM_CLIENT_H__
24 
25 #include <glib.h>
26 #include <glib-object.h>
27 #include <sys/types.h>
28 
29 G_BEGIN_DECLS
30 
31 #define CSM_TYPE_CLIENT            (csm_client_get_type ())
32 #define CSM_CLIENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CSM_TYPE_CLIENT, CsmClient))
33 #define CSM_CLIENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CSM_TYPE_CLIENT, CsmClientClass))
34 #define CSM_IS_CLIENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CSM_TYPE_CLIENT))
35 #define CSM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CSM_TYPE_CLIENT))
36 #define CSM_CLIENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CSM_TYPE_CLIENT, CsmClientClass))
37 
38 typedef struct _CsmClient        CsmClient;
39 typedef struct _CsmClientClass   CsmClientClass;
40 
41 typedef struct CsmClientPrivate CsmClientPrivate;
42 
43 typedef enum {
44         CSM_CLIENT_UNREGISTERED = 0,
45         CSM_CLIENT_REGISTERED,
46         CSM_CLIENT_FINISHED,
47         CSM_CLIENT_FAILED
48 } CsmClientStatus;
49 
50 typedef enum {
51         CSM_CLIENT_RESTART_NEVER = 0,
52         CSM_CLIENT_RESTART_IF_RUNNING,
53         CSM_CLIENT_RESTART_ANYWAY,
54         CSM_CLIENT_RESTART_IMMEDIATELY
55 } CsmClientRestartStyle;
56 
57 typedef enum {
58         CSM_CLIENT_END_SESSION_FLAG_FORCEFUL = 1 << 0,
59         CSM_CLIENT_END_SESSION_FLAG_SAVE     = 1 << 1,
60         CSM_CLIENT_END_SESSION_FLAG_LAST     = 1 << 2
61 } CsmClientEndSessionFlag;
62 
63 struct _CsmClient
64 {
65         GObject           parent;
66         CsmClientPrivate *priv;
67 };
68 
69 struct _CsmClientClass
70 {
71         GObjectClass parent_class;
72 
73         /* signals */
74         void         (*disconnected)               (CsmClient  *client);
75         void         (*end_session_response)       (CsmClient  *client,
76                                                     gboolean    ok,
77                                                     gboolean    do_last,
78                                                     gboolean    cancel,
79                                                     const char *reason);
80 
81         /* virtual methods */
82         char *                (*impl_get_app_name)           (CsmClient *client);
83         CsmClientRestartStyle (*impl_get_restart_style_hint) (CsmClient *client);
84         guint                 (*impl_get_unix_process_id)    (CsmClient *client);
85         gboolean              (*impl_query_end_session)      (CsmClient *client,
86                                                               guint      flags,
87                                                               GError   **error);
88         gboolean              (*impl_end_session)            (CsmClient *client,
89                                                               guint      flags,
90                                                               GError   **error);
91         gboolean              (*impl_cancel_end_session)     (CsmClient *client,
92                                                               GError   **error);
93         gboolean              (*impl_stop)                   (CsmClient *client,
94                                                               GError   **error);
95         GKeyFile *            (*impl_save)                   (CsmClient *client,
96                                                               GError   **error);
97 };
98 
99 typedef enum
100 {
101         CSM_CLIENT_ERROR_GENERAL = 0,
102         CSM_CLIENT_ERROR_NOT_REGISTERED,
103         CSM_CLIENT_NUM_ERRORS
104 } CsmClientError;
105 
106 #define CSM_CLIENT_ERROR csm_client_error_quark ()
107 
108 GQuark                csm_client_error_quark                (void);
109 
110 GType                 csm_client_get_type                   (void) G_GNUC_CONST;
111 
112 const char           *csm_client_peek_id                    (CsmClient  *client);
113 
114 
115 const char *          csm_client_peek_startup_id            (CsmClient  *client);
116 const char *          csm_client_peek_app_id                (CsmClient  *client);
117 guint                 csm_client_peek_restart_style_hint    (CsmClient  *client);
118 guint                 csm_client_peek_status                (CsmClient  *client);
119 
120 
121 char                 *csm_client_get_app_name               (CsmClient  *client);
122 void                  csm_client_set_app_id                 (CsmClient  *client,
123                                                              const char *app_id);
124 void                  csm_client_set_status                 (CsmClient  *client,
125                                                              guint       status);
126 
127 gboolean              csm_client_end_session                (CsmClient  *client,
128                                                              guint       flags,
129                                                              GError    **error);
130 gboolean              csm_client_query_end_session          (CsmClient  *client,
131                                                              guint       flags,
132                                                              GError    **error);
133 gboolean              csm_client_cancel_end_session         (CsmClient  *client,
134                                                              GError    **error);
135 
136 void                  csm_client_disconnected               (CsmClient  *client);
137 
138 GKeyFile             *csm_client_save                       (CsmClient  *client,
139                                                              GError    **error);
140 gboolean              csm_client_stop                       (CsmClient  *client,
141                                                              GError    **error);
142 
143 /* private */
144 
145 void                  csm_client_end_session_response       (CsmClient  *client,
146                                                              gboolean    is_ok,
147                                                              gboolean    do_last,
148                                                              gboolean    cancel,
149                                                              const char *reason);
150 
151 G_END_DECLS
152 
153 #endif /* __CSM_CLIENT_H__ */
154