1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /** |
---|
3 | * bonobo-moniker-extender: extending monikers |
---|
4 | * |
---|
5 | * Author: |
---|
6 | * Dietmar Maurer (dietmar@maurer-it.com) |
---|
7 | * |
---|
8 | * Copyright 2000, Helix Code, Inc. |
---|
9 | */ |
---|
10 | #include <config.h> |
---|
11 | |
---|
12 | #include <bonobo/bonobo-exception.h> |
---|
13 | #include <bonobo/bonobo-moniker.h> |
---|
14 | #include <bonobo/bonobo-moniker-util.h> |
---|
15 | #include <bonobo/bonobo-moniker-extender.h> |
---|
16 | #include <liboaf/liboaf.h> |
---|
17 | |
---|
18 | #define PARENT_TYPE BONOBO_X_OBJECT_TYPE |
---|
19 | |
---|
20 | static GtkObjectClass *bonobo_moniker_extender_parent_class; |
---|
21 | |
---|
22 | #define CLASS(o) BONOBO_MONIKER_EXTENDER_CLASS (GTK_OBJECT (o)->klass) |
---|
23 | |
---|
24 | static inline BonoboMonikerExtender * |
---|
25 | bonobo_moniker_extender_from_servant (PortableServer_Servant servant) |
---|
26 | { |
---|
27 | return BONOBO_MONIKER_EXTENDER (bonobo_object_from_servant (servant)); |
---|
28 | } |
---|
29 | |
---|
30 | static Bonobo_Unknown |
---|
31 | impl_Bonobo_MonikerExtender_resolve (PortableServer_Servant servant, |
---|
32 | const Bonobo_Moniker parent, |
---|
33 | const Bonobo_ResolveOptions *options, |
---|
34 | const CORBA_char *display_name, |
---|
35 | const CORBA_char *requested_interface, |
---|
36 | CORBA_Environment *ev) |
---|
37 | { |
---|
38 | BonoboMonikerExtender *extender = bonobo_moniker_extender_from_servant (servant); |
---|
39 | |
---|
40 | if (extender->resolve) |
---|
41 | return extender->resolve (extender, parent, options, display_name, |
---|
42 | requested_interface, ev); |
---|
43 | else |
---|
44 | return CLASS (extender)->resolve (extender, parent, options, display_name, |
---|
45 | requested_interface, ev); |
---|
46 | } |
---|
47 | |
---|
48 | static Bonobo_Unknown |
---|
49 | bonobo_moniker_extender_resolve (BonoboMonikerExtender *extender, |
---|
50 | const Bonobo_Moniker parent, |
---|
51 | const Bonobo_ResolveOptions *options, |
---|
52 | const CORBA_char *display_name, |
---|
53 | const CORBA_char *requested_interface, |
---|
54 | CORBA_Environment *ev) |
---|
55 | { |
---|
56 | |
---|
57 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
58 | ex_Bonobo_Moniker_InterfaceNotFound, NULL); |
---|
59 | |
---|
60 | return CORBA_OBJECT_NIL; |
---|
61 | } |
---|
62 | |
---|
63 | static void |
---|
64 | bonobo_moniker_extender_destroy (GtkObject *object) |
---|
65 | { |
---|
66 | bonobo_moniker_extender_parent_class->destroy (object); |
---|
67 | } |
---|
68 | |
---|
69 | static void |
---|
70 | bonobo_moniker_extender_class_init (BonoboMonikerExtenderClass *klass) |
---|
71 | { |
---|
72 | GtkObjectClass *oclass = (GtkObjectClass *)klass; |
---|
73 | POA_Bonobo_MonikerExtender__epv *epv = &klass->epv; |
---|
74 | |
---|
75 | bonobo_moniker_extender_parent_class = gtk_type_class (PARENT_TYPE); |
---|
76 | |
---|
77 | oclass->destroy = bonobo_moniker_extender_destroy; |
---|
78 | |
---|
79 | klass->resolve = bonobo_moniker_extender_resolve; |
---|
80 | |
---|
81 | epv->resolve = impl_Bonobo_MonikerExtender_resolve; |
---|
82 | } |
---|
83 | |
---|
84 | static void |
---|
85 | bonobo_moniker_extender_init (GtkObject *object) |
---|
86 | { |
---|
87 | /* nothing to do */ |
---|
88 | } |
---|
89 | |
---|
90 | BONOBO_X_TYPE_FUNC_FULL (BonoboMonikerExtender, |
---|
91 | Bonobo_MonikerExtender, |
---|
92 | PARENT_TYPE, |
---|
93 | bonobo_moniker_extender); |
---|
94 | |
---|
95 | /** |
---|
96 | * bonobo_moniker_extender_new: |
---|
97 | * @resolve: the resolve function that will be used to do the extension |
---|
98 | * @data: user data to be passed back to the resolve function. |
---|
99 | * |
---|
100 | * This creates a new moniker extender. |
---|
101 | * |
---|
102 | * Return value: the extender object |
---|
103 | **/ |
---|
104 | BonoboMonikerExtender * |
---|
105 | bonobo_moniker_extender_new (BonoboMonikerExtenderFn resolve, gpointer data) |
---|
106 | { |
---|
107 | BonoboMonikerExtender *extender = NULL; |
---|
108 | |
---|
109 | extender = gtk_type_new (bonobo_moniker_extender_get_type ()); |
---|
110 | |
---|
111 | extender->resolve = resolve; |
---|
112 | extender->data = data; |
---|
113 | |
---|
114 | return extender; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * bonobo_moniker_find_extender: |
---|
119 | * @name: the name of the moniker we want to extend eg. 'file:' |
---|
120 | * @interface: the interface we want to resolve to |
---|
121 | * @ev: a corba exception environment. |
---|
122 | * |
---|
123 | * This routine tries to locate an extender for our moniker |
---|
124 | * by examining a registry of extenders that map new interfaces |
---|
125 | * to certain moniker names. |
---|
126 | * |
---|
127 | * Return value: an appropriate extender or CORBA_OBJECT_NIL. |
---|
128 | **/ |
---|
129 | Bonobo_MonikerExtender |
---|
130 | bonobo_moniker_find_extender (const gchar *name, |
---|
131 | const gchar *interface, |
---|
132 | CORBA_Environment *ev) |
---|
133 | { |
---|
134 | gchar *query; |
---|
135 | OAF_ActivationID ret_id; |
---|
136 | Bonobo_Unknown extender; |
---|
137 | |
---|
138 | query = g_strdup_printf ( |
---|
139 | "repo_ids.has ('IDL:Bonobo/MonikerExtender:1.0') AND " |
---|
140 | "repo_ids.has ('%s') AND " |
---|
141 | "bonobo:moniker_extender.has ('%s')", interface, name); |
---|
142 | |
---|
143 | extender = oaf_activate (query, NULL, 0, &ret_id, ev); |
---|
144 | |
---|
145 | g_free (query); |
---|
146 | |
---|
147 | return extender; |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * bonobo_moniker_use_extender: |
---|
152 | * @extender_oafiid: The IID of the extender to use |
---|
153 | * @moniker: the moniker to extend |
---|
154 | * @options: resolve options |
---|
155 | * @requested_interface: the requested interface |
---|
156 | * @ev: corba environment |
---|
157 | * |
---|
158 | * Locates a known extender via. OAFIID; eg. |
---|
159 | * OAFIID:Bonobo_Moniker_Extender_file |
---|
160 | * |
---|
161 | * Return value: the resolved result or CORBA_OBJECT_NIL. |
---|
162 | **/ |
---|
163 | Bonobo_Unknown |
---|
164 | bonobo_moniker_use_extender (const gchar *extender_oafiid, |
---|
165 | BonoboMoniker *moniker, |
---|
166 | const Bonobo_ResolveOptions *options, |
---|
167 | const CORBA_char *requested_interface, |
---|
168 | CORBA_Environment *ev) |
---|
169 | { |
---|
170 | Bonobo_MonikerExtender extender; |
---|
171 | Bonobo_Unknown retval; |
---|
172 | |
---|
173 | g_return_val_if_fail (ev != NULL, CORBA_OBJECT_NIL); |
---|
174 | g_return_val_if_fail (options != NULL, CORBA_OBJECT_NIL); |
---|
175 | g_return_val_if_fail (moniker != NULL, CORBA_OBJECT_NIL); |
---|
176 | g_return_val_if_fail (extender_oafiid != NULL, CORBA_OBJECT_NIL); |
---|
177 | g_return_val_if_fail (requested_interface != NULL, CORBA_OBJECT_NIL); |
---|
178 | |
---|
179 | extender = oaf_activate_from_id ( |
---|
180 | (gchar *) extender_oafiid, 0, NULL, ev); |
---|
181 | |
---|
182 | if (BONOBO_EX (ev) || extender == CORBA_OBJECT_NIL) |
---|
183 | return CORBA_OBJECT_NIL; |
---|
184 | |
---|
185 | retval = Bonobo_MonikerExtender_resolve (extender, |
---|
186 | BONOBO_OBJREF (moniker), options, |
---|
187 | bonobo_moniker_get_name_full (moniker), |
---|
188 | requested_interface, ev); |
---|
189 | |
---|
190 | bonobo_object_release_unref (extender, ev); |
---|
191 | |
---|
192 | return retval; |
---|
193 | } |
---|