source: trunk/third/bonobo-activation/server/object-directory-activate.c @ 18311

Revision 18311, 5.0 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 *  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#include <signal.h>
28#include <stdio.h>
29#include <sys/types.h>
30#include <sys/wait.h>
31#include <unistd.h>
32#include <stdlib.h>
33#include <string.h>
34
35#include "bonobo-activation/bonobo-activation-i18n.h"
36#include "bonobo-activation/bonobo-activation-private.h"
37
38#include "server.h"
39#include "activation-server-corba-extensions.h"
40
41static CORBA_Object
42od_server_activate_factory (Bonobo_ServerInfo *si,
43                            ODActivationInfo  *actinfo,
44                            CORBA_Environment *ev)
45{
46        CORBA_Object retval = CORBA_OBJECT_NIL, factory = CORBA_OBJECT_NIL;
47        Bonobo_ActivationResult *res;
48
49        res = Bonobo_ActivationContext_activate_from_id (
50                actinfo->ac, si->location_info,
51                ((actinfo->flags |
52                  Bonobo_ACTIVATION_FLAG_NO_LOCAL) &
53                 (~Bonobo_ACTIVATION_FLAG_PRIVATE)),
54                actinfo->ctx, ev);
55
56        if (ev->_major != CORBA_NO_EXCEPTION)
57                goto out;
58
59        switch (res->res._d) {
60        case Bonobo_ACTIVATION_RESULT_NONE:
61                CORBA_free (res);
62                goto out;
63                break;
64        case Bonobo_ACTIVATION_RESULT_OBJECT:
65                factory = res->res._u.res_object;
66                break;
67        default:
68                g_assert_not_reached ();
69                break;
70        }
71
72        retval = Bonobo_GenericFactory_createObject (factory, si->iid, ev);
73        if (ev->_major != CORBA_NO_EXCEPTION)
74                retval = CORBA_OBJECT_NIL;
75
76        CORBA_free (res);
77
78 out:
79        return retval;
80}
81
82/* Copied largely from goad.c, goad_server_activate_exe() */
83static CORBA_Object
84od_server_activate_exe (Bonobo_ServerInfo *si,
85                        ODActivationInfo  *actinfo,
86                        CORBA_Object       od_obj,
87                        CORBA_Environment *ev)
88{
89        char **args;
90        char *extra_arg, *ctmp, *ctmp2;
91        int fd_arg;
92        int i;
93        char *iorstr;
94        CORBA_Object retval;
95
96        /* Munge the args */
97        args = g_alloca (36 * sizeof (char *));
98        for (i = 0, ctmp = ctmp2 = si->location_info; i < 32; i++) {
99                while (*ctmp2 && !g_ascii_isspace ((guchar) *ctmp2))
100                        ctmp2++;
101                if (!*ctmp2)
102                        break;
103
104                args[i] = g_alloca (ctmp2 - ctmp + 1);
105                strncpy (args[i], ctmp, ctmp2 - ctmp);
106                args[i][ctmp2 - ctmp] = '\0';
107
108                ctmp = ctmp2;
109                while (*ctmp2 && g_ascii_isspace ((guchar) *ctmp2))
110                        ctmp2++;
111                if (!*ctmp2)
112                        break;
113                ctmp = ctmp2;
114        }
115        if (!g_ascii_isspace ((guchar) *ctmp) && i < 32)
116                args[i++] = ctmp;
117
118        extra_arg =
119                g_alloca (strlen (si->iid) +
120                            sizeof ("--oaf-activate-iid="));
121        args[i++] = extra_arg;
122        sprintf (extra_arg, "--oaf-activate-iid=%s", si->iid);
123
124        fd_arg = i;
125        extra_arg = g_alloca (sizeof ("--oaf-ior-fd=") + 10);
126        args[i++] = "--oaf-ior-fd=%d";
127
128
129        iorstr = CORBA_ORB_object_to_string (
130                bonobo_activation_orb_get (), od_obj, ev);
131
132        if (ev->_major != CORBA_NO_EXCEPTION)
133          iorstr = NULL;
134
135        if(actinfo->flags & Bonobo_ACTIVATION_FLAG_PRIVATE) {
136                extra_arg = g_alloca (sizeof ("--oaf-private"));
137                args[i++] = extra_arg;
138                g_snprintf (extra_arg, sizeof ("--oaf-private"),
139                            "--oaf-private");
140        }
141
142        args[i] = NULL;
143
144        /*
145         * We set the process group of activated servers to our process group;
146         * this allows people to destroy all OAF servers along with oafd
147         * if necessary
148         */
149        retval = bonobo_activation_server_by_forking (
150                (const char **) args, TRUE, fd_arg, actinfo->ctx, iorstr,
151                si->iid, bonobo_object_directory_re_check_fn, actinfo, ev);
152       
153        CORBA_free (iorstr);
154
155        return retval;
156}
157
158CORBA_Object
159od_server_activate (Bonobo_ServerInfo *si,
160                    ODActivationInfo  *actinfo,
161                    CORBA_Object       od_obj,
162                    CORBA_Environment *ev)
163{
164        g_return_val_if_fail (ev->_major == CORBA_NO_EXCEPTION,
165                              CORBA_OBJECT_NIL);
166
167        if (!strcmp (si->server_type, "exe"))
168                return od_server_activate_exe (si, actinfo, od_obj, ev);
169
170        else if (!strcmp (si->server_type, "factory"))
171                return od_server_activate_factory (si, actinfo, ev);
172
173        else if (!strcmp (si->server_type, "shlib"))
174                g_warning (_("We don't handle activating shlib objects in a remote process yet"));
175
176        return CORBA_OBJECT_NIL;
177}
Note: See TracBrowser for help on using the repository browser.