Handle the EINTR error when doing a waitpid() in wvmagicloopback.
[wvapps.git] / evolution / camel / camel-exchangeit-store.cc
blob639900656d8e64452c6bd54f193a05449679fb04
1 /*
2 * Authors : Peter Colijn <pcolijn@nit.ca>
3 * William Lachance <wlach@nit.ca>
4 * Sharvil Nanavati <s2nanava@uwaterloo.ca>
6 * Copyright 2003-2004, Net Integration Technologies, Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 // this one should be included BEFORE camel shit
28 #include "wvunixsocket.h"
30 extern "C" {
31 #include <glib.h>
32 #include <gtk/gtk.h>
33 #include <stdio.h>
34 #include <stdint.h>
36 #define new _new
37 #define namespace _namespace
38 #include <camel/camel-store.h>
39 #undef namespace
40 #undef new
42 #include <camel/camel-session.h>
43 #include <camel/camel-service.h>
44 #include <camel/camel-operation.h>
45 #include <unistd.h>
47 #include <malloc.h>
49 #include "camel-exchangeit-store.h"
52 // This file was created by using camel/providers/pop3/camel-pop3-store.c
53 // as a template.
55 /* Forward declarations */
56 static void camel_exchangeit_store_class_init(CamelExchangeITStoreClass *camel_exchangeit_store_class);
57 static void camel_exchangeit_store_init(CamelExchangeITStore *store,
58 gpointer klass);
59 static void camel_exchangeit_store_finalize(CamelObject *object);
61 /* Forward declarations of "member functions" */
62 static gboolean exchangeit_connect(CamelService *service,
63 CamelException *ex);
64 static gboolean exchangeit_disconnect(CamelService *service,
65 gboolean clean,
66 CamelException *ex);
68 /* For internal use only, to communicate with shell */
69 static WvStream *stream = NULL;
71 /* Called when a new connection should be established with the server with the
72 * given service (send/receive clicked or a scheduled send/receive is run)
73 * But we just use it to update the progress bar in a super cheesey way by
74 * reading progress across a pipe from our shell component :)
75 */
76 static gboolean exchangeit_connect(CamelService *service, CamelException *ex)
78 WvString socket_name("%s/.evolution-exchangeit/pipehack",
79 g_get_home_dir());
80 stream = new WvUnixConn(socket_name);
81 uint32_t start_cmd = 1;
83 if (!stream->isok())
85 g_warning("******** Connection not accepted!");
86 goto end;
88 if (sizeof(uint32_t) != stream->write(&start_cmd, sizeof(start_cmd)))
90 g_warning("******** Unable to write start_cmd!");
91 goto end;
94 while (stream->isok())
96 stream->runonce();
97 uint32_t progress;
98 if (sizeof(uint32_t) == stream->read(&progress, sizeof(uint32_t)))
100 if (progress > 0 && progress <= 100)
102 if (camel_operation_cancel_check (NULL))
104 // Try to tell the shell to stop sending stuff
105 if (stream)
107 uint32_t end_cmd = 0;
108 stream->write(&end_cmd, sizeof(uint32_t));
111 camel_operation_cancel(NULL);
112 goto end;
115 camel_operation_start(NULL, _("Syncing..."));
116 camel_operation_progress(NULL, progress);
118 else
120 g_warning("******** Received failure message from shell!");
121 // FIXME: pop up an error instead of saying we're complete
122 // in this case (maybe not here though, maybe send a message
123 // back to the shell? pcolijn)
124 break;
127 if (progress == 100)
128 break;
131 end:
132 camel_operation_end(NULL);
133 WvStream *tmp_stream = stream;
134 stream = NULL;
135 WVRELEASE(tmp_stream);
137 // Returning FALSE lets us get called again
138 return FALSE;
141 /* Called when a disconnect should occur */
142 static gboolean exchangeit_disconnect(CamelService *service,
143 gboolean clean,
144 CamelException *ex)
146 return TRUE;
149 /* Class constructor */
150 static void camel_exchangeit_store_class_init(CamelExchangeITStoreClass *camel_exchangeit_store_class)
152 CamelServiceClass *service =
153 CAMEL_SERVICE_CLASS(camel_exchangeit_store_class);
155 /* Overload virtual methods */
156 service->connect = exchangeit_connect;
157 service->disconnect = exchangeit_disconnect;
160 /* Constructor */
161 static void camel_exchangeit_store_init(CamelExchangeITStore *store,
162 gpointer klass)
166 /* Registers a new class with Camel and returns the type */
167 CamelType camel_exchangeit_store_get_type()
169 static CamelType camel_exchangeit_store_type = CAMEL_INVALID_TYPE;
171 if (!camel_exchangeit_store_type)
173 camel_exchangeit_store_type =
174 camel_type_register(CAMEL_STORE_TYPE,
175 "CamelExchangeITStore",
176 sizeof(CamelExchangeITStore),
177 sizeof(CamelExchangeITStoreClass),
178 (CamelObjectClassInitFunc)camel_exchangeit_store_class_init,
179 NULL,
180 (CamelObjectInitFunc)camel_exchangeit_store_init,
181 camel_exchangeit_store_finalize);
183 return camel_exchangeit_store_type;
186 /* Destructor */
187 static void camel_exchangeit_store_finalize(CamelObject *object)
189 // Nothing special