[18310] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
| 2 | /* |
---|
| 3 | * bonobo-activation-client.c: A client client to enable caching |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2002 Ximian Inc. |
---|
| 6 | * |
---|
| 7 | * This library is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU Library General Public |
---|
| 9 | * License as published by the Free Software Foundation; either |
---|
| 10 | * version 2 of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This library is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 15 | * Library General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU Library General Public |
---|
| 18 | * License along with this library; if not, write to the Free |
---|
| 19 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 20 | * |
---|
| 21 | * Author: Michael Meeks (michael@ximian.com) |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include <config.h> |
---|
| 25 | #include <bonobo-activation/bonobo-activation.h> |
---|
[18562] | 26 | #include <bonobo-activation/bonobo-activation-private.h> |
---|
[18310] | 27 | #include <bonobo-activation/bonobo-activation-client.h> |
---|
| 28 | #include <bonobo-activation/Bonobo_ActivationContext.h> |
---|
| 29 | |
---|
| 30 | static GSList *reset_notify_callbacks = NULL; |
---|
| 31 | |
---|
| 32 | static void |
---|
| 33 | reset_caches (void) |
---|
| 34 | { |
---|
| 35 | GSList *l; |
---|
| 36 | GVoidFunc cb; |
---|
| 37 | |
---|
| 38 | for (l = reset_notify_callbacks; l; l = l->next) { |
---|
| 39 | cb = l->data; |
---|
| 40 | cb (); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void |
---|
| 45 | bonobo_activation_add_reset_notify (GVoidFunc fn) |
---|
| 46 | { |
---|
| 47 | if (!g_slist_find (reset_notify_callbacks, fn)) |
---|
| 48 | reset_notify_callbacks = g_slist_prepend ( |
---|
| 49 | reset_notify_callbacks, fn); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | typedef struct { |
---|
| 53 | POA_Bonobo_ActivationClient servant; |
---|
| 54 | } impl_POA_Bonobo_ActivationClient; |
---|
| 55 | |
---|
| 56 | static void |
---|
| 57 | impl_Bonobo_ActivationClient__finalize (PortableServer_Servant servant, |
---|
| 58 | CORBA_Environment *ev) |
---|
| 59 | { |
---|
| 60 | g_free (servant); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | static void |
---|
| 64 | impl_Bonobo_ActivationClient_resetCache (PortableServer_Servant servant, |
---|
| 65 | CORBA_Environment *ev) |
---|
| 66 | { |
---|
| 67 | /* Reset the cache ! */ |
---|
| 68 | #ifdef BONOBO_ACTIVATION_DEBUG |
---|
| 69 | g_warning ("Reset cache"); |
---|
| 70 | #endif |
---|
| 71 | reset_caches (); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | static PortableServer_ServantBase__epv impl_Bonobo_ActivationClient_base_epv = { |
---|
| 75 | NULL, /* private data */ |
---|
| 76 | impl_Bonobo_ActivationClient__finalize, |
---|
| 77 | NULL, /* default_POA routine */ |
---|
| 78 | }; |
---|
| 79 | static POA_Bonobo_ActivationClient__epv impl_Bonobo_ActivationClient_epv = { |
---|
| 80 | NULL, /* private */ |
---|
| 81 | &impl_Bonobo_ActivationClient_resetCache |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | static POA_Bonobo_Unknown__epv impl_Bonobo_Unknown_epv = { |
---|
| 85 | NULL, /* private data */ |
---|
| 86 | NULL, |
---|
| 87 | NULL, |
---|
| 88 | NULL |
---|
| 89 | }; |
---|
| 90 | |
---|
| 91 | static POA_Bonobo_ActivationClient__vepv impl_Bonobo_ActivationClient_vepv = { |
---|
| 92 | &impl_Bonobo_ActivationClient_base_epv, |
---|
| 93 | &impl_Bonobo_Unknown_epv, |
---|
| 94 | &impl_Bonobo_ActivationClient_epv, |
---|
| 95 | }; |
---|
| 96 | |
---|
| 97 | static CORBA_Object |
---|
| 98 | bonobo_activation_corba_client_new (void) |
---|
| 99 | { |
---|
| 100 | CORBA_ORB orb; |
---|
| 101 | CORBA_Object retval; |
---|
| 102 | CORBA_Environment *ev, real_ev; |
---|
| 103 | PortableServer_POA poa; |
---|
| 104 | PortableServer_POAManager manager; |
---|
| 105 | impl_POA_Bonobo_ActivationClient *newservant; |
---|
| 106 | |
---|
| 107 | ev = &real_ev; |
---|
| 108 | CORBA_exception_init (ev); |
---|
| 109 | |
---|
| 110 | orb = bonobo_activation_orb_get (); |
---|
| 111 | |
---|
| 112 | poa = (PortableServer_POA) CORBA_ORB_resolve_initial_references (orb, "RootPOA", ev); |
---|
| 113 | manager = PortableServer_POA__get_the_POAManager (poa, ev); |
---|
| 114 | PortableServer_POAManager_activate (manager, ev); |
---|
| 115 | |
---|
| 116 | newservant = g_new0 (impl_POA_Bonobo_ActivationClient, 1); |
---|
| 117 | newservant->servant.vepv = &impl_Bonobo_ActivationClient_vepv; |
---|
| 118 | |
---|
| 119 | POA_Bonobo_ActivationClient__init ((PortableServer_Servant) newservant, ev); |
---|
| 120 | retval = PortableServer_POA_servant_to_reference (poa, newservant, ev); |
---|
| 121 | |
---|
| 122 | CORBA_Object_release ((CORBA_Object) manager, ev); |
---|
| 123 | CORBA_Object_release ((CORBA_Object) poa, ev); |
---|
| 124 | |
---|
| 125 | CORBA_exception_free (ev); |
---|
| 126 | |
---|
| 127 | return retval; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | static CORBA_Object client = CORBA_OBJECT_NIL; |
---|
| 131 | |
---|
| 132 | void |
---|
| 133 | bonobo_activation_release_corba_client (void) |
---|
| 134 | { |
---|
| 135 | CORBA_Environment ev; |
---|
| 136 | |
---|
| 137 | CORBA_exception_init (&ev); |
---|
| 138 | |
---|
| 139 | CORBA_Object_release (client, &ev); |
---|
| 140 | reset_caches (); |
---|
| 141 | |
---|
| 142 | CORBA_exception_free (&ev); |
---|
| 143 | client = CORBA_OBJECT_NIL; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | static char * |
---|
| 147 | get_lang_list (void) |
---|
| 148 | { |
---|
| 149 | static char *result = NULL; |
---|
| 150 | static gboolean result_set = FALSE; |
---|
| 151 | GString *str; |
---|
| 152 | gboolean add_comma = FALSE; |
---|
[18562] | 153 | const GList *language_list; |
---|
| 154 | const GList *l; |
---|
[18310] | 155 | |
---|
| 156 | if (result_set) |
---|
| 157 | return result; |
---|
| 158 | |
---|
| 159 | str = g_string_new (NULL); |
---|
[18562] | 160 | language_list = bonobo_activation_i18n_get_language_list ("LANG"); |
---|
| 161 | for (l = language_list; l; l = l->next) { |
---|
| 162 | if (add_comma) |
---|
| 163 | g_string_append (str, ","); |
---|
| 164 | else |
---|
| 165 | add_comma = TRUE; |
---|
| 166 | g_string_append (str, l->data); |
---|
| 167 | } |
---|
[18310] | 168 | |
---|
| 169 | result_set = TRUE; |
---|
| 170 | |
---|
| 171 | result = str->str ? str->str : ""; |
---|
| 172 | g_string_free (str, FALSE); |
---|
| 173 | |
---|
| 174 | return result; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | void |
---|
| 178 | bonobo_activation_register_client (Bonobo_ActivationContext context, |
---|
| 179 | CORBA_Environment *ev) |
---|
| 180 | { |
---|
| 181 | if (client == CORBA_OBJECT_NIL) { |
---|
| 182 | client = bonobo_activation_corba_client_new (); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | Bonobo_ActivationContext_addClient (context, client, get_lang_list (), ev); |
---|
| 186 | } |
---|