1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* pas-card-cursor.c: Implements card cursors.
*
* Author:
* Christopher James Lahey <clahey@ximian.com.
*/
#include <config.h>
#include "addressbook.h"
#include "pas-card-cursor.h"
struct _PASCardCursorPrivate {
long (*get_length) (PASCardCursor *cursor, gpointer data);
char * (*get_nth) (PASCardCursor *cursor, long n, gpointer data);
gpointer data;
};
/*
* A pointer to our parent object class
*/
static BonoboObjectClass *parent_class;
/*
* The VEPV for the CardCursor object
*/
static POA_GNOME_Evolution_Addressbook_CardCursor__vepv cursor_vepv;
/*
* Implemented GtkObject::destroy
*/
static void
pas_card_cursor_destroy (GtkObject *object)
{
PASCardCursor *cursor = PAS_CARD_CURSOR (object);
if ( cursor->priv )
g_free ( cursor->priv );
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
/*
* CORBA Demo::Echo::echo method implementation
*/
static CORBA_long
impl_pas_card_cursor_get_length (PortableServer_Servant servant,
CORBA_Environment *ev)
{
PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant));
if ( cursor->priv->get_length )
return cursor->priv->get_length( cursor, cursor->priv->data );
else
return 0;
}
/*
* CORBA Demo::Echo::echo method implementation
*/
static char *
impl_pas_card_cursor_get_nth (PortableServer_Servant servant,
const CORBA_long n,
CORBA_Environment *ev)
{
PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant));
if ( cursor->priv->get_nth ) {
char *vcard = cursor->priv->get_nth( cursor, n, cursor->priv->data );
char *retval = CORBA_string_dup (vcard);
g_free (vcard);
return retval;
} else
return CORBA_string_dup ("");
}
/*
* If you want users to derive classes from your implementation
* you need to support this method.
*/
POA_GNOME_Evolution_Addressbook_CardCursor__epv *
pas_card_cursor_get_epv (void)
{
POA_GNOME_Evolution_Addressbook_CardCursor__epv *epv;
epv = g_new0 (POA_GNOME_Evolution_Addressbook_CardCursor__epv, 1);
/*
* This is the method invoked by CORBA
*/
epv->count = impl_pas_card_cursor_get_length;
epv->getNth = impl_pas_card_cursor_get_nth;
return epv;
}
static void
init_pas_card_cursor_corba_class (void)
{
cursor_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv ();
cursor_vepv.GNOME_Evolution_Addressbook_CardCursor_epv = pas_card_cursor_get_epv ();
}
static void
pas_card_cursor_class_init (PASCardCursorClass *klass)
{
GtkObjectClass *object_class = (GtkObjectClass *) klass;
parent_class = gtk_type_class (bonobo_object_get_type ());
object_class->destroy = pas_card_cursor_destroy;
init_pas_card_cursor_corba_class ();
}
static void
pas_card_cursor_init (PASCardCursor *cursor)
{
cursor->priv = g_new(PASCardCursorPrivate, 1);
cursor->priv->get_length = NULL;
cursor->priv->get_nth = NULL;
cursor->priv->data = NULL;
}
GtkType
pas_card_cursor_get_type (void)
{
static GtkType type = 0;
if (!type){
GtkTypeInfo info = {
"PASCardCursor",
sizeof (PASCardCursor),
sizeof (PASCardCursorClass),
(GtkClassInitFunc) pas_card_cursor_class_init,
(GtkObjectInitFunc) pas_card_cursor_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (bonobo_object_get_type (), &info);
}
return type;
}
PASCardCursor *
pas_card_cursor_construct (PASCardCursor *cursor,
GNOME_Evolution_Addressbook_CardCursor corba_cursor,
PASCardCursorLengthFunc get_length,
PASCardCursorNthFunc get_nth,
gpointer data)
{
g_return_val_if_fail (cursor != NULL, NULL);
g_return_val_if_fail (PAS_IS_CARD_CURSOR (cursor), NULL);
g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL);
/*
* Call parent constructor
*/
if (!bonobo_object_construct (BONOBO_OBJECT (cursor), (CORBA_Object) corba_cursor))
return NULL;
/*
* Initialize cursor
*/
cursor->priv->get_length = get_length;
cursor->priv->get_nth = get_nth;
cursor->priv->data = data;
/*
* Success: return the GtkType we were given
*/
return cursor;
}
/*
* This routine creates the ORBit CORBA server and initializes the
* CORBA side of things
*/
static GNOME_Evolution_Addressbook_CardCursor
create_cursor (BonoboObject *cursor)
{
POA_GNOME_Evolution_Addressbook_CardCursor *servant;
CORBA_Environment ev;
servant = (POA_GNOME_Evolution_Addressbook_CardCursor *) g_new0 (BonoboObjectServant, 1);
servant->vepv = &cursor_vepv;
CORBA_exception_init (&ev);
POA_GNOME_Evolution_Addressbook_CardCursor__init ((PortableServer_Servant) servant, &ev);
if (ev._major != CORBA_NO_EXCEPTION){
g_free (servant);
CORBA_exception_free (&ev);
return CORBA_OBJECT_NIL;
}
CORBA_exception_free (&ev);
/*
* Activates the CORBA object.
*/
return (GNOME_Evolution_Addressbook_CardCursor) bonobo_object_activate_servant (cursor, servant);
}
PASCardCursor *
pas_card_cursor_new (PASCardCursorLengthFunc get_length,
PASCardCursorNthFunc get_nth,
gpointer data)
{
PASCardCursor *cursor;
GNOME_Evolution_Addressbook_CardCursor corba_cursor;
cursor = gtk_type_new (pas_card_cursor_get_type ());
corba_cursor = create_cursor (BONOBO_OBJECT (cursor));
if (corba_cursor == CORBA_OBJECT_NIL){
gtk_object_unref (GTK_OBJECT (cursor));
return NULL;
}
return pas_card_cursor_construct (cursor,
corba_cursor,
get_length,
get_nth,
data);
}
|