1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * oafd: OAF CORBA dameon. |
---|
4 | * |
---|
5 | * Copyright (C) 1999, 2000 Red Hat, Inc. |
---|
6 | * Copyright (C) 1999, 2000 Eazel, Inc. |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License as |
---|
10 | * published by the Free Software Foundation; either version 2 of the |
---|
11 | * License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This library is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | * General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this library; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | * |
---|
22 | * Authors: Elliot Lee <sopwith@redhat.com>, |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "config.h" |
---|
27 | |
---|
28 | #include <stdio.h> |
---|
29 | #include <popt.h> |
---|
30 | #include <string.h> |
---|
31 | |
---|
32 | #include <bonobo-activation/bonobo-activation.h> |
---|
33 | #include <bonobo-activation/bonobo-activation-private.h> |
---|
34 | #include <bonobo-activation/Bonobo_ActivationContext.h> |
---|
35 | |
---|
36 | static char *acior = NULL, *specs = NULL; |
---|
37 | static int do_query; |
---|
38 | |
---|
39 | static struct poptOption options[] = { |
---|
40 | |
---|
41 | {"ac-ior", '\0', POPT_ARG_STRING, &acior, 0, |
---|
42 | "IOR of ActivationContext to use", "IOR"}, |
---|
43 | {"do-query", 'q', POPT_ARG_NONE, &do_query, 0, |
---|
44 | "Run a query instead of activating", "QUERY"}, |
---|
45 | {"spec", 's', POPT_ARG_STRING, &specs, 0, |
---|
46 | "Specification string for object to activate", "SPEC"}, |
---|
47 | POPT_AUTOHELP {NULL} |
---|
48 | }; |
---|
49 | |
---|
50 | static void |
---|
51 | od_dump_list (Bonobo_ServerInfoList * list) |
---|
52 | { |
---|
53 | int i, j, k; |
---|
54 | |
---|
55 | for (i = 0; i < list->_length; i++) { |
---|
56 | g_print ("IID %s, type %s, location %s\n", |
---|
57 | list->_buffer[i].iid, |
---|
58 | list->_buffer[i].server_type, |
---|
59 | list->_buffer[i].location_info); |
---|
60 | for (j = 0; j < list->_buffer[i].props._length; j++) { |
---|
61 | Bonobo_ActivationProperty *prop = |
---|
62 | &(list->_buffer[i].props._buffer[j]); |
---|
63 | g_print (" %s = ", prop->name); |
---|
64 | switch (prop->v._d) { |
---|
65 | case Bonobo_ACTIVATION_P_STRING: |
---|
66 | g_print ("\"%s\"\n", prop->v._u.value_string); |
---|
67 | break; |
---|
68 | case Bonobo_ACTIVATION_P_NUMBER: |
---|
69 | g_print ("%f\n", prop->v._u.value_number); |
---|
70 | break; |
---|
71 | case Bonobo_ACTIVATION_P_BOOLEAN: |
---|
72 | g_print ("%s\n", |
---|
73 | prop->v. |
---|
74 | _u.value_boolean ? "TRUE" : "FALSE"); |
---|
75 | break; |
---|
76 | case Bonobo_ACTIVATION_P_STRINGV: |
---|
77 | g_print ("["); |
---|
78 | for (k = 0; |
---|
79 | k < prop->v._u.value_stringv._length; |
---|
80 | k++) { |
---|
81 | g_print ("\"%s\"", |
---|
82 | prop->v._u. |
---|
83 | value_stringv._buffer[k]); |
---|
84 | if (k < |
---|
85 | (prop->v._u. |
---|
86 | value_stringv._length - 1)) |
---|
87 | g_print (", "); |
---|
88 | } |
---|
89 | g_print ("]\n"); |
---|
90 | break; |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | int |
---|
97 | main (int argc, char *argv[]) |
---|
98 | { |
---|
99 | CORBA_Environment ev; |
---|
100 | Bonobo_ActivationContext ac; |
---|
101 | poptContext ctx; |
---|
102 | gboolean do_usage_exit = FALSE; |
---|
103 | Bonobo_ServerInfoList *slist; |
---|
104 | CORBA_ORB orb; |
---|
105 | Bonobo_StringList reqs = { 0 }; |
---|
106 | |
---|
107 | CORBA_exception_init (&ev); |
---|
108 | |
---|
109 | ctx = poptGetContext ("oaf-client", argc, (const char **)argv, options, 0); |
---|
110 | while (poptGetNextOpt (ctx) >= 0) |
---|
111 | /**/; |
---|
112 | |
---|
113 | orb = bonobo_activation_init (argc, argv); |
---|
114 | |
---|
115 | if (!specs) { |
---|
116 | g_print ("You must specify an operation to perform.\n"); |
---|
117 | do_usage_exit = TRUE; |
---|
118 | } |
---|
119 | |
---|
120 | if (do_usage_exit) { |
---|
121 | poptPrintUsage (ctx, stdout, 0); |
---|
122 | return 1; |
---|
123 | } |
---|
124 | |
---|
125 | if (acior) { |
---|
126 | ac = CORBA_ORB_string_to_object (orb, acior, &ev); |
---|
127 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
128 | g_print ("Error doing string_to_object(%s)\n", acior); |
---|
129 | do_usage_exit = TRUE; |
---|
130 | } |
---|
131 | } else |
---|
132 | ac = bonobo_activation_activation_context_get (); |
---|
133 | |
---|
134 | poptFreeContext (ctx); |
---|
135 | |
---|
136 | g_print ("Query spec is \"%s\"\n", specs); |
---|
137 | |
---|
138 | if (do_query) { |
---|
139 | |
---|
140 | slist = |
---|
141 | Bonobo_ActivationContext_query ( |
---|
142 | ac, specs, &reqs, |
---|
143 | bonobo_activation_context_get (), &ev); |
---|
144 | switch (ev._major) { |
---|
145 | case CORBA_NO_EXCEPTION: |
---|
146 | od_dump_list (slist); |
---|
147 | CORBA_free (slist); |
---|
148 | break; |
---|
149 | case CORBA_USER_EXCEPTION: |
---|
150 | { |
---|
151 | char *id; |
---|
152 | id = CORBA_exception_id (&ev); |
---|
153 | g_print |
---|
154 | ("User exception \"%s\" resulted from query\n", |
---|
155 | id); |
---|
156 | if (!strcmp (id, "IDL:Bonobo/ActivationContext/ParseFailed:1.0")) { |
---|
157 | Bonobo_Activation_ParseFailed |
---|
158 | * exdata = |
---|
159 | CORBA_exception_value (&ev); |
---|
160 | |
---|
161 | if (exdata) |
---|
162 | g_print ("Description: %s\n", |
---|
163 | exdata->description); |
---|
164 | } |
---|
165 | } |
---|
166 | break; |
---|
167 | case CORBA_SYSTEM_EXCEPTION: |
---|
168 | { |
---|
169 | char *id; |
---|
170 | id = CORBA_exception_id (&ev); |
---|
171 | g_print |
---|
172 | ("System exception \"%s\" resulted from query\n", |
---|
173 | id); |
---|
174 | } |
---|
175 | break; |
---|
176 | } |
---|
177 | } else { |
---|
178 | Bonobo_ActivationResult *res; |
---|
179 | |
---|
180 | res = Bonobo_ActivationContext_activate ( |
---|
181 | ac, specs, &reqs, 0, |
---|
182 | bonobo_activation_context_get (), &ev); |
---|
183 | switch (ev._major) { |
---|
184 | case CORBA_NO_EXCEPTION: |
---|
185 | g_print ("Activation ID \"%s\" ", res->aid); |
---|
186 | switch (res->res._d) { |
---|
187 | case Bonobo_ACTIVATION_RESULT_OBJECT: |
---|
188 | g_print ("RESULT_OBJECT\n"); |
---|
189 | acior = |
---|
190 | CORBA_ORB_object_to_string (orb, |
---|
191 | res-> |
---|
192 | res._u.res_object, |
---|
193 | &ev); |
---|
194 | g_print ("%s\n", acior); |
---|
195 | break; |
---|
196 | case Bonobo_ACTIVATION_RESULT_SHLIB: |
---|
197 | g_print ("RESULT_SHLIB\n"); |
---|
198 | break; |
---|
199 | case Bonobo_ACTIVATION_RESULT_NONE: |
---|
200 | g_print ("RESULT_NONE\n"); |
---|
201 | break; |
---|
202 | } |
---|
203 | break; |
---|
204 | case CORBA_USER_EXCEPTION: |
---|
205 | { |
---|
206 | char *id; |
---|
207 | id = CORBA_exception_id (&ev); |
---|
208 | g_print |
---|
209 | ("User exception \"%s\" resulted from query\n", |
---|
210 | id); |
---|
211 | if (!strcmp (id,"IDL:Bonobo/ActivationContext/ParseFailed:1.0")) { |
---|
212 | Bonobo_Activation_ParseFailed |
---|
213 | * exdata = |
---|
214 | CORBA_exception_value (&ev); |
---|
215 | |
---|
216 | if (exdata) |
---|
217 | g_print ("Description: %s\n", |
---|
218 | exdata->description); |
---|
219 | } |
---|
220 | else if (!strcmp (id,"IDL:Bonobo/GeneralError:1.0")) { |
---|
221 | Bonobo_GeneralError *exdata; |
---|
222 | |
---|
223 | exdata = CORBA_exception_value (&ev); |
---|
224 | |
---|
225 | if (exdata) |
---|
226 | g_print ("Description: %s\n", |
---|
227 | exdata->description); |
---|
228 | |
---|
229 | } |
---|
230 | } |
---|
231 | break; |
---|
232 | case CORBA_SYSTEM_EXCEPTION: |
---|
233 | { |
---|
234 | char *id; |
---|
235 | id = CORBA_exception_id (&ev); |
---|
236 | g_print |
---|
237 | ("System exception \"%s\" resulted from query\n", |
---|
238 | id); |
---|
239 | } |
---|
240 | break; |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | CORBA_exception_free (&ev); |
---|
245 | |
---|
246 | return 0; |
---|
247 | } |
---|