New. An interface for objects that want to act on every message passing
[platform/upstream/libsoup.git] / libsoup / soup-types.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2003, Ximian, Inc.
4  */
5
6 #ifndef SOUP_TYPES_H
7 #define SOUP_TYPES_H 1
8
9 #include <glib/gtypes.h>
10 #include <glib-object.h>
11
12 #include <libsoup/soup-status.h>
13
14 typedef struct SoupAddress           SoupAddress;
15 typedef struct SoupConnection        SoupConnection;
16 typedef struct SoupMessage           SoupMessage;
17 typedef struct SoupMessageFilter     SoupMessageFilter;
18 typedef struct SoupServer            SoupServer;
19 typedef union  SoupServerAuth        SoupServerAuth;
20 typedef struct SoupServerAuthContext SoupServerAuthContext;
21 typedef struct SoupServerMessage     SoupServerMessage;
22 typedef struct SoupSession           SoupSession;
23 typedef struct SoupSessionAsync      SoupSessionAsync;
24 typedef struct SoupSessionSync       SoupSessionSync;
25 typedef struct SoupSocket            SoupSocket;
26 typedef struct SoupUri               SoupUri;
27
28 #define SOUP_MAKE_TYPE(type_name,TypeName,class_init,init,parent) \
29 GType type_name##_get_type(void)\
30 {\
31         static GType type = 0;                          \
32         if (!type){                                     \
33                 static GTypeInfo const object_info = {  \
34                         sizeof (TypeName##Class),       \
35                                                         \
36                         (GBaseInitFunc) NULL,           \
37                         (GBaseFinalizeFunc) NULL,       \
38                                                         \
39                         (GClassInitFunc) class_init,    \
40                         (GClassFinalizeFunc) NULL,      \
41                         NULL,   /* class_data */        \
42                                                         \
43                         sizeof (TypeName),              \
44                         0,      /* n_preallocs */       \
45                         (GInstanceInitFunc) init,       \
46                 };                                      \
47                 type = g_type_register_static (parent, #TypeName, &object_info, 0); \
48         }                                               \
49         return type;                                    \
50 }
51
52 #define SOUP_MAKE_INTERFACE(type_name,TypeName,base_init) \
53 GType type_name##_get_type(void)\
54 {\
55         static GType type = 0;                          \
56         if (!type){                                     \
57                 static GTypeInfo const object_info = {  \
58                         sizeof (TypeName##Class),       \
59                                                         \
60                         (GBaseInitFunc) base_init,      \
61                         (GBaseFinalizeFunc) NULL,       \
62                                                         \
63                         (GClassInitFunc) NULL,          \
64                         (GClassFinalizeFunc) NULL,      \
65                         NULL,   /* class_data */        \
66                                                         \
67                         0,                              \
68                         0,      /* n_preallocs */       \
69                         (GInstanceInitFunc) NULL,       \
70                 };                                      \
71                 type = g_type_register_static (G_TYPE_INTERFACE, #TypeName, &object_info, 0); \
72         }                                               \
73         return type;                                    \
74 }
75
76 #define SOUP_MAKE_TYPE_WITH_IFACE(type_name,TypeName,class_init,init,parent,iface_init,iparent) \
77 GType type_name##_get_type(void)\
78 {\
79         static GType type = 0;                          \
80         if (!type){                                     \
81                 static GTypeInfo const object_info = {  \
82                         sizeof (TypeName##Class),       \
83                                                         \
84                         (GBaseInitFunc) NULL,           \
85                         (GBaseFinalizeFunc) NULL,       \
86                                                         \
87                         (GClassInitFunc) class_init,    \
88                         (GClassFinalizeFunc) NULL,      \
89                         NULL,   /* class_data */        \
90                                                         \
91                         sizeof (TypeName),              \
92                         0,      /* n_preallocs */       \
93                         (GInstanceInitFunc) init,       \
94                 };                                      \
95                 static GInterfaceInfo const iface_info = {      \
96                         (GInterfaceInitFunc) iface_init,        \
97                         NULL,                                   \
98                         NULL                                    \
99                 };                                              \
100                 type = g_type_register_static (parent, #TypeName, &object_info, 0);     \
101                 g_type_add_interface_static (type, iparent, &iface_info);               \
102         }                                               \
103         return type;                                    \
104 }
105
106 #endif