[18310] | 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 { |
---|
[18562] | 178 | Bonobo_ActivationEnvironment environment; |
---|
| 179 | Bonobo_ActivationResult *res; |
---|
[18310] | 180 | |
---|
[18562] | 181 | memset (&environment, 0, sizeof (Bonobo_ActivationEnvironment)); |
---|
| 182 | |
---|
| 183 | res = Bonobo_ActivationContext_activateMatching ( |
---|
| 184 | ac, specs, &reqs, &environment, 0, |
---|
[18310] | 185 | bonobo_activation_context_get (), &ev); |
---|
| 186 | switch (ev._major) { |
---|
| 187 | case CORBA_NO_EXCEPTION: |
---|
| 188 | g_print ("Activation ID \"%s\" ", res->aid); |
---|
| 189 | switch (res->res._d) { |
---|
| 190 | case Bonobo_ACTIVATION_RESULT_OBJECT: |
---|
| 191 | g_print ("RESULT_OBJECT\n"); |
---|
| 192 | acior = |
---|
| 193 | CORBA_ORB_object_to_string (orb, |
---|
| 194 | res-> |
---|
| 195 | res._u.res_object, |
---|
| 196 | &ev); |
---|
| 197 | g_print ("%s\n", acior); |
---|
| 198 | break; |
---|
| 199 | case Bonobo_ACTIVATION_RESULT_SHLIB: |
---|
| 200 | g_print ("RESULT_SHLIB\n"); |
---|
| 201 | break; |
---|
| 202 | case Bonobo_ACTIVATION_RESULT_NONE: |
---|
| 203 | g_print ("RESULT_NONE\n"); |
---|
| 204 | break; |
---|
| 205 | } |
---|
| 206 | break; |
---|
| 207 | case CORBA_USER_EXCEPTION: |
---|
| 208 | { |
---|
| 209 | char *id; |
---|
| 210 | id = CORBA_exception_id (&ev); |
---|
| 211 | g_print |
---|
| 212 | ("User exception \"%s\" resulted from query\n", |
---|
| 213 | id); |
---|
| 214 | if (!strcmp (id,"IDL:Bonobo/ActivationContext/ParseFailed:1.0")) { |
---|
| 215 | Bonobo_Activation_ParseFailed |
---|
| 216 | * exdata = |
---|
| 217 | CORBA_exception_value (&ev); |
---|
| 218 | |
---|
| 219 | if (exdata) |
---|
| 220 | g_print ("Description: %s\n", |
---|
| 221 | exdata->description); |
---|
| 222 | } |
---|
| 223 | else if (!strcmp (id,"IDL:Bonobo/GeneralError:1.0")) { |
---|
| 224 | Bonobo_GeneralError *exdata; |
---|
| 225 | |
---|
| 226 | exdata = CORBA_exception_value (&ev); |
---|
| 227 | |
---|
| 228 | if (exdata) |
---|
| 229 | g_print ("Description: %s\n", |
---|
| 230 | exdata->description); |
---|
| 231 | |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | break; |
---|
| 235 | case CORBA_SYSTEM_EXCEPTION: |
---|
| 236 | { |
---|
| 237 | char *id; |
---|
| 238 | id = CORBA_exception_id (&ev); |
---|
| 239 | g_print |
---|
| 240 | ("System exception \"%s\" resulted from query\n", |
---|
| 241 | id); |
---|
| 242 | } |
---|
| 243 | break; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | CORBA_exception_free (&ev); |
---|
| 248 | |
---|
| 249 | return 0; |
---|
| 250 | } |
---|