source: trunk/third/bonobo-activation/bonobo-activation/bonobo-activation-client.c @ 18311

Revision 18311, 6.1 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18310, which included commits to RCS files with non-trunk default branches.
Line 
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>
26#include <bonobo-activation/bonobo-activation-client.h>
27#include <bonobo-activation/Bonobo_ActivationContext.h>
28
29static GSList *reset_notify_callbacks = NULL;
30
31static void
32reset_caches (void)
33{
34        GSList   *l;
35        GVoidFunc cb;
36
37        for (l = reset_notify_callbacks; l; l = l->next) {
38                cb = l->data;
39                cb ();
40        }
41}
42
43void
44bonobo_activation_add_reset_notify (GVoidFunc fn)
45{
46        if (!g_slist_find (reset_notify_callbacks, fn))
47                reset_notify_callbacks = g_slist_prepend (
48                        reset_notify_callbacks, fn);
49}
50
51typedef struct {
52        POA_Bonobo_ActivationClient servant;
53} impl_POA_Bonobo_ActivationClient;
54
55static void
56impl_Bonobo_ActivationClient__finalize (PortableServer_Servant servant,
57                                        CORBA_Environment     *ev)
58{
59        g_free (servant);
60}
61
62static void
63impl_Bonobo_ActivationClient_resetCache (PortableServer_Servant servant,
64                                         CORBA_Environment     *ev)
65{
66        /* Reset the cache ! */
67#ifdef BONOBO_ACTIVATION_DEBUG
68        g_warning ("Reset cache");
69#endif
70        reset_caches ();
71}
72
73static PortableServer_ServantBase__epv impl_Bonobo_ActivationClient_base_epv = {
74        NULL, /* private data */
75        impl_Bonobo_ActivationClient__finalize,
76        NULL, /* default_POA routine */
77};
78static POA_Bonobo_ActivationClient__epv impl_Bonobo_ActivationClient_epv = {
79        NULL, /* private */
80        &impl_Bonobo_ActivationClient_resetCache
81};
82
83static POA_Bonobo_Unknown__epv impl_Bonobo_Unknown_epv = {
84        NULL, /* private data */
85        NULL,
86        NULL,
87        NULL
88};
89
90static POA_Bonobo_ActivationClient__vepv impl_Bonobo_ActivationClient_vepv = {
91        &impl_Bonobo_ActivationClient_base_epv,
92        &impl_Bonobo_Unknown_epv,
93        &impl_Bonobo_ActivationClient_epv,
94};
95
96static CORBA_Object
97bonobo_activation_corba_client_new (void)
98{
99        CORBA_ORB orb;
100        CORBA_Object retval;
101        CORBA_Environment *ev, real_ev;
102        PortableServer_POA poa;
103        PortableServer_POAManager manager;
104        impl_POA_Bonobo_ActivationClient *newservant;
105
106        ev = &real_ev;
107        CORBA_exception_init (ev);
108
109        orb = bonobo_activation_orb_get ();
110
111        poa = (PortableServer_POA) CORBA_ORB_resolve_initial_references (orb, "RootPOA", ev);
112        manager = PortableServer_POA__get_the_POAManager (poa, ev);
113        PortableServer_POAManager_activate (manager, ev);
114
115        newservant = g_new0 (impl_POA_Bonobo_ActivationClient, 1);
116        newservant->servant.vepv = &impl_Bonobo_ActivationClient_vepv;
117
118        POA_Bonobo_ActivationClient__init ((PortableServer_Servant) newservant, ev);
119        retval = PortableServer_POA_servant_to_reference (poa, newservant, ev);
120
121        CORBA_Object_release ((CORBA_Object) manager, ev);
122        CORBA_Object_release ((CORBA_Object) poa, ev);
123
124        CORBA_exception_free (ev);
125
126        return retval;
127}
128
129static CORBA_Object client = CORBA_OBJECT_NIL;
130
131void
132bonobo_activation_release_corba_client (void)
133{
134        CORBA_Environment ev;
135
136        CORBA_exception_init (&ev);
137
138        CORBA_Object_release (client, &ev);
139        reset_caches ();
140
141        CORBA_exception_free (&ev);
142        client = CORBA_OBJECT_NIL;
143}
144
145
146static char *
147get_lang_list (void)
148{
149        static char *result = NULL;
150        static gboolean result_set = FALSE;
151        const char *tmp;
152        char *tmp2, *lang, *lang_with_locale, *equal_char;
153        GString *str;
154        gboolean add_comma = FALSE;
155       
156        lang_with_locale = NULL;
157       
158        if (result_set)
159                return result;
160       
161        tmp = g_getenv ("LANGUAGE");
162
163        if (!tmp)
164                tmp = g_getenv ("LANG");
165       
166        lang = g_strdup (tmp);
167        tmp2 = lang;
168
169        str = g_string_new (NULL);
170       
171        if (lang) {
172                /* envs can be in NAME=VALUE form */
173                equal_char = strchr (lang, '=');
174                if (equal_char)
175                        lang = equal_char + 1;
176
177                /* check if the locale has a _ */
178                equal_char = strchr (lang, '_');
179                if (equal_char != NULL) {
180                        lang_with_locale = g_strdup (lang);
181                        *equal_char = 0;
182                }
183
184                if (lang_with_locale && strcmp (lang_with_locale, "")) {
185                        g_string_append (str, lang_with_locale);
186                        add_comma = TRUE;
187                }
188                if (lang && strcmp (lang, "")) {
189                        if (add_comma)
190                                g_string_append (str, ",");
191                        g_string_append (str, lang);
192                }
193
194        }
195        result_set = TRUE;
196        g_free (tmp2);
197        g_free (lang_with_locale);
198       
199        result = str->str ? str->str : "";
200        g_string_free (str, FALSE);
201       
202        return result;
203}
204
205void
206bonobo_activation_register_client (Bonobo_ActivationContext context,
207                                   CORBA_Environment       *ev)
208{
209        if (client == CORBA_OBJECT_NIL) {
210                client = bonobo_activation_corba_client_new ();
211        }
212
213        Bonobo_ActivationContext_addClient (context, client, get_lang_list (), ev);
214}
Note: See TracBrowser for help on using the repository browser.