Merge more cleanup bits from camel-gobject.
[platform/upstream/evolution-data-server.git] / camel / camel-service.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-service.h : Abstract class for an email service */
3 /*
4  *
5  * Authors: Bertrand Guiheneuf <bertrand@helixcode.com>
6  *          Michael Zucchi <notzed@ximian.com>
7  *
8  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU Lesser General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24
25 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
26 #error "Only <camel/camel.h> can be included directly."
27 #endif
28
29 #ifndef CAMEL_SERVICE_H
30 #define CAMEL_SERVICE_H
31
32 #include <camel/camel-object.h>
33 #include <camel/camel-url.h>
34 #include <camel/camel-provider.h>
35 #include <camel/camel-operation.h>
36
37 #define CAMEL_SERVICE_TYPE     (camel_service_get_type ())
38 #define CAMEL_SERVICE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SERVICE_TYPE, CamelService))
39 #define CAMEL_SERVICE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SERVICE_TYPE, CamelServiceClass))
40 #define CAMEL_IS_SERVICE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SERVICE_TYPE))
41 #define CAMEL_SERVICE_GET_CLASS(obj) \
42         ((CamelServiceClass *) CAMEL_OBJECT_GET_CLASS (obj))
43
44 G_BEGIN_DECLS
45
46 struct _CamelSession;
47
48 typedef struct _CamelService CamelService;
49 typedef struct _CamelServiceClass CamelServiceClass;
50 typedef struct _CamelServicePrivate CamelServicePrivate;
51
52 enum {
53         CAMEL_SERVICE_ARG_FIRST  = CAMEL_ARG_FIRST + 100,
54         CAMEL_SERVICE_ARG_USERNAME,
55         CAMEL_SERVICE_ARG_AUTH,
56         CAMEL_SERVICE_ARG_HOSTNAME,
57         CAMEL_SERVICE_ARG_PORT,
58         CAMEL_SERVICE_ARG_PATH
59 };
60
61 #define CAMEL_SERVICE_USERNAME     (CAMEL_SERVICE_ARG_USERNAME | CAMEL_ARG_STR)
62 #define CAMEL_SERVICE_AUTH         (CAMEL_SERVICE_ARG_AUTH | CAMEL_ARG_STR)
63 #define CAMEL_SERVICE_HOSTNAME     (CAMEL_SERVICE_ARG_HOSTNAME | CAMEL_ARG_STR)
64 #define CAMEL_SERVICE_PORT         (CAMEL_SERVICE_ARG_PORT | CAMEL_ARG_INT)
65 #define CAMEL_SERVICE_PATH         (CAMEL_SERVICE_ARG_PATH | CAMEL_ARG_STR)
66
67 typedef enum {
68         CAMEL_SERVICE_DISCONNECTED,
69         CAMEL_SERVICE_CONNECTING,
70         CAMEL_SERVICE_CONNECTED,
71         CAMEL_SERVICE_DISCONNECTING
72 } CamelServiceConnectionStatus;
73
74 typedef enum _CamelServiceLock {
75         CS_REC_CONNECT_LOCK,
76         CS_CONNECT_OP_LOCK
77 } CamelServiceLock;
78
79 struct _CamelService {
80         CamelObject parent;
81         CamelServicePrivate *priv;
82
83         struct _CamelSession *session;
84         CamelProvider *provider;
85         CamelServiceConnectionStatus status;
86         CamelOperation *connect_op;
87         CamelURL *url;
88 };
89
90 struct _CamelServiceClass {
91         CamelObjectClass parent_class;
92
93         gboolean        (*construct)            (CamelService *service,
94                                                  struct _CamelSession *session,
95                                                  CamelProvider *provider,
96                                                  CamelURL *url,
97                                                  CamelException *ex);
98         gboolean        (*connect)              (CamelService *service,
99                                                  CamelException *ex);
100         gboolean        (*disconnect)           (CamelService *service,
101                                                  gboolean clean,
102                                                  CamelException *ex);
103         void            (*cancel_connect)       (CamelService *service);
104         GList *         (*query_auth_types)     (CamelService *service,
105                                                  CamelException *ex);
106         gchar *         (*get_name)             (CamelService *service,
107                                                  gboolean brief);
108         gchar *         (*get_path)             (CamelService *service);
109 };
110
111 /* query_auth_types returns a GList of these */
112 typedef struct {
113         const gchar *name;               /* user-friendly name */
114         const gchar *description;
115         const gchar *authproto;
116
117         gboolean need_password;   /* needs a password to authenticate */
118 } CamelServiceAuthType;
119
120 CamelType       camel_service_get_type          (void);
121 gboolean        camel_service_construct         (CamelService *service,
122                                                  struct _CamelSession *session,
123                                                  CamelProvider *provider,
124                                                  CamelURL *url,
125                                                  CamelException *ex);
126 gboolean        camel_service_connect           (CamelService *service,
127                                                  CamelException *ex);
128 gboolean        camel_service_disconnect        (CamelService *service,
129                                                  gboolean clean,
130                                                  CamelException *ex);
131 void            camel_service_cancel_connect    (CamelService *service);
132 gchar *         camel_service_get_url           (CamelService *service);
133 gchar *         camel_service_get_name          (CamelService *service,
134                                                  gboolean brief);
135 gchar *         camel_service_get_path          (CamelService *service);
136 struct _CamelSession *
137                 camel_service_get_session       (CamelService *service);
138 CamelProvider * camel_service_get_provider      (CamelService *service);
139 GList *         camel_service_query_auth_types  (CamelService *service,
140                                                  CamelException *ex);
141
142 void            camel_service_lock              (CamelService *service, CamelServiceLock lock);
143 void            camel_service_unlock            (CamelService *service, CamelServiceLock lock);
144
145 G_END_DECLS
146
147 #endif /* CAMEL_SERVICE_H */