1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * soup-session-sync.c
4 *
5 * Copyright (C) 2000-2003, Ximian, Inc.
6 */
7
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "soup-session-sync.h"
13 #include "soup.h"
14 #include "soup-session-private.h"
15 #include "soup-message-private.h"
16 #include "soup-message-queue.h"
17
18 /**
19 * SECTION:soup-session-sync
20 * @short_description: SoupSession for blocking I/O in multithreaded programs
21 * (deprecated).
22 *
23 * #SoupSessionSync is an implementation of #SoupSession that uses
24 * synchronous I/O, intended for use in multi-threaded programs.
25 *
26 * Deprecated: 2.42: Use the #SoupSession class (which uses both asynchronous
27 * and synchronous I/O, depending on the API used). See the
28 * <link linkend="libsoup-session-porting">porting guide</link>.
29 **/
30
31 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
32
G_DEFINE_TYPE(SoupSessionSync,soup_session_sync,SOUP_TYPE_SESSION)33 G_DEFINE_TYPE (SoupSessionSync, soup_session_sync, SOUP_TYPE_SESSION)
34
35 static void
36 soup_session_sync_init (SoupSessionSync *ss)
37 {
38 }
39
40 /**
41 * soup_session_sync_new:
42 *
43 * Creates an synchronous #SoupSession with the default options.
44 *
45 * Return value: the new session.
46 *
47 * Deprecated: #SoupSessionSync is deprecated; use a plain
48 * #SoupSession, created with soup_session_new(). See the <link
49 * linkend="libsoup-session-porting">porting guide</link>.
50 **/
51 SoupSession *
soup_session_sync_new(void)52 soup_session_sync_new (void)
53 {
54 return g_object_new (SOUP_TYPE_SESSION_SYNC, NULL);
55 }
56
57 /**
58 * soup_session_sync_new_with_options:
59 * @optname1: name of first property to set
60 * @...: value of @optname1, followed by additional property/value pairs
61 *
62 * Creates an synchronous #SoupSession with the specified options.
63 *
64 * Return value: the new session.
65 *
66 * Deprecated: #SoupSessionSync is deprecated; use a plain
67 * #SoupSession, created with soup_session_new_with_options(). See the
68 * <link linkend="libsoup-session-porting">porting guide</link>.
69 **/
70 SoupSession *
soup_session_sync_new_with_options(const char * optname1,...)71 soup_session_sync_new_with_options (const char *optname1, ...)
72 {
73 SoupSession *session;
74 va_list ap;
75
76 va_start (ap, optname1);
77 session = (SoupSession *)g_object_new_valist (SOUP_TYPE_SESSION_SYNC,
78 optname1, ap);
79 va_end (ap);
80
81 return session;
82 }
83
84 static gboolean
queue_message_callback(gpointer data)85 queue_message_callback (gpointer data)
86 {
87 SoupMessageQueueItem *item = data;
88
89 item->callback (item->session, item->msg, item->callback_data);
90 soup_message_queue_item_unref (item);
91 return FALSE;
92 }
93
94 static gpointer
queue_message_thread(gpointer data)95 queue_message_thread (gpointer data)
96 {
97 SoupMessageQueueItem *item = data;
98
99 soup_session_process_queue_item (item->session, item, NULL, TRUE);
100 if (item->callback) {
101 soup_add_completion (soup_session_get_async_context (item->session),
102 queue_message_callback, item);
103 } else
104 soup_message_queue_item_unref (item);
105
106 return NULL;
107 }
108
109 static void
soup_session_sync_queue_message(SoupSession * session,SoupMessage * msg,SoupSessionCallback callback,gpointer user_data)110 soup_session_sync_queue_message (SoupSession *session, SoupMessage *msg,
111 SoupSessionCallback callback, gpointer user_data)
112 {
113 SoupMessageQueueItem *item;
114 GThread *thread;
115
116 item = soup_session_append_queue_item (session, msg, FALSE, FALSE,
117 callback, user_data);
118 thread = g_thread_new ("SoupSessionSync:queue_message",
119 queue_message_thread, item);
120 g_thread_unref (thread);
121 }
122
123 static void
soup_session_sync_class_init(SoupSessionSyncClass * session_sync_class)124 soup_session_sync_class_init (SoupSessionSyncClass *session_sync_class)
125 {
126 SoupSessionClass *session_class = SOUP_SESSION_CLASS (session_sync_class);
127
128 /* virtual method override */
129 session_class->queue_message = soup_session_sync_queue_message;
130 }
131
132 G_GNUC_END_IGNORE_DEPRECATIONS;
133