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

Revision 18311, 5.9 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: A library for accessing bonobo-activation-server.
4 *
5 *  Copyright (C) 1999, 2000 Red Hat, Inc.
6 *  Copyright (C) 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 Library General Public
10 *  License as published by the Free Software Foundation; either
11 *  version 2 of the 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 *  Library General Public License for more details.
17 *
18 *  You should have received a copy of the GNU Library General Public
19 *  License along with this library; if not, write to the Free
20 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 *  Author: Elliot Lee <sopwith@redhat.com>
23 *
24 */
25
26#include <config.h>
27#include <bonobo-activation/bonobo-activation-register.h>
28#include <bonobo-activation/bonobo-activation-private.h>
29#include <bonobo-activation/bonobo-activation-init.h>
30#include <bonobo-activation/Bonobo_ObjectDirectory.h>
31
32#include <stdio.h>
33#include <unistd.h>
34
35static gboolean check_registration = TRUE;
36static gboolean need_ior_printout  = TRUE;
37
38void
39bonobo_activation_timeout_reg_check_set (gboolean on)
40{
41        check_registration = on;
42}
43
44gboolean
45bonobo_activation_timeout_reg_check (gpointer data)
46{
47        if (!check_registration)
48                return FALSE;
49
50        if (need_ior_printout) {
51                g_error ("This process has not registered the required OAFIID "
52                         "your source code should register '%s'. If your code is "
53                         "performing delayed registration and this message is trapped "
54                         "in error, see bonobo_activation_idle_reg_check_set.",
55                         bonobo_activation_iid_get ());
56        }
57
58        return FALSE;
59}
60
61
62/**
63 * bonobo_activation_active_server_register:
64 * @iid: IID of the server to register.
65 * @obj: CORBA::Object to register.
66 *
67 * Registers @obj with @iid in the local
68 * bonobo-activation-server daemon.
69 *
70 * Return value: status of the registration.
71 */
72Bonobo_RegistrationResult
73bonobo_activation_active_server_register (const char  *registration_id,
74                                          CORBA_Object obj)
75{
76        Bonobo_ObjectDirectory od;
77        CORBA_Environment ev;
78        Bonobo_RegistrationResult retval;
79        const char *actid;
80        const char *iid;
81
82        iid = strrchr (registration_id, ',');
83
84        if (iid == NULL) {
85                iid = registration_id;
86        } else {
87                iid++;
88        }
89
90        CORBA_exception_init (&ev);
91
92#ifdef BONOBO_ACTIVATION_DEBUG
93        g_message ("About to register '%s': %p%s",
94                   registration_id, obj,
95                   CORBA_Object_non_existent (obj, &ev) ? " (nonexistent)" : "");
96#endif
97
98        actid = bonobo_activation_iid_get ();
99
100        if (actid && strcmp (actid, iid) == 0 && bonobo_activation_private) {
101                retval = Bonobo_ACTIVATION_REG_SUCCESS;
102        } else {
103                od = bonobo_activation_object_directory_get (
104                        bonobo_activation_username_get (),
105                        bonobo_activation_hostname_get (),
106                        NULL);
107               
108                if (CORBA_Object_is_nil (od, &ev)) {
109                        return Bonobo_ACTIVATION_REG_ERROR;
110                }
111               
112                retval = Bonobo_ObjectDirectory_register_new (
113                        od, (char *) registration_id, obj, &ev);
114        }
115
116#ifdef BONOBO_ACTIVATION_DEBUG
117        g_warning ("registration of '%s' returns %d", registration_id, retval);
118#endif
119        if (actid && strcmp (actid, iid) == 0 && need_ior_printout) {
120                char *iorstr;
121                FILE *fh;
122                int iorfd = bonobo_activation_ior_fd_get ();
123
124                need_ior_printout = FALSE;
125
126                if (iorfd == 1)
127                        fh = stdout;
128                else {
129                        fh = fdopen (iorfd, "w");
130                        if (!fh)
131                                fh = stdout;
132                }
133
134                iorstr = CORBA_ORB_object_to_string (
135                        bonobo_activation_orb_get (), obj, &ev);
136
137                if (ev._major == CORBA_NO_EXCEPTION) {
138                        fprintf (fh, "%s\n", iorstr);
139                        CORBA_free (iorstr);
140                }
141
142                if (fh != stdout) {
143                        fclose (fh);
144                } else if (iorfd > 2) {
145                        close (iorfd);
146                }
147        }
148#ifdef BONOBO_ACTIVATION_DEBUG
149        else if (actid && need_ior_printout) {
150                g_message ("Unusual '%s' was activated, but "
151                           "'%s' is needed", iid, actid);
152        }
153#endif
154
155        CORBA_exception_free (&ev);
156
157#ifdef BONOBO_ACTIVATION_DEBUG
158        g_message ("Successfully registered `%s'", registration_id);
159#endif
160
161        return retval;
162}
163
164
165/**
166 * bonobo_activation_active_server_unregister:
167 * @iid: IID of the server to unregister.
168 * @obj: CORBA::Object to unregister.
169 *
170 * Unregisters @obj with @iid in the local OAF daemon.
171 */
172void
173bonobo_activation_active_server_unregister (const char *iid, CORBA_Object obj)
174{
175        Bonobo_ObjectDirectory od;
176        CORBA_Environment ev;
177        const char *actid;
178
179        actid = bonobo_activation_iid_get ();
180        if(actid && strcmp (actid, iid) == 0 && bonobo_activation_private) {
181                return;
182        }
183
184        od = bonobo_activation_object_directory_get (
185                bonobo_activation_username_get (),
186                bonobo_activation_hostname_get (),
187                NULL);
188
189        CORBA_exception_init (&ev);
190        if (CORBA_Object_is_nil (od, &ev))
191                return;
192
193        Bonobo_ObjectDirectory_unregister (od, (char *) iid, obj, &ev);
194
195        CORBA_exception_free (&ev);
196}
197
198
199char *
200bonobo_activation_make_registration_id (const char *iid, const char *display)
201{
202#ifdef BONOBO_ACTIVATION_DEBUG
203        g_warning ("Make registration id from '%s' '%s'", iid, display);
204#endif
205        if (display == NULL) {
206                return g_strdup (iid);
207        } else {
208                return g_strconcat (display, ",", iid, NULL);
209        }
210}
Note: See TracBrowser for help on using the repository browser.