File: bonobo-context.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (120 lines) | stat: -rw-r--r-- 2,788 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * bonobo-context.h: Handle Global Component contexts.
 *
 * Author:
 *     Michael Meeks (michael@helixcode.com)
 *
 * Copyright 2000 Helix Code, Inc.
 */
#include <config.h>

#include <bonobo/bonobo-object.h>
#include <bonobo/bonobo-context.h>
#include <bonobo/bonobo-running-context.h>
#include <bonobo/bonobo-activation-context.h>

static GHashTable *bonobo_contexts = NULL;

/**
 * bonobo_context_add:
 * @context_name: the name to refer to the context by
 * @context: The Bonobo_Unknown; a ref. is taken on this.
 * 
 * This function adds a new context to the context system
 **/
void
bonobo_context_add (const CORBA_char *context_name,
		    Bonobo_Unknown    context)
{
	g_return_if_fail (context != CORBA_OBJECT_NIL);

	if (!bonobo_contexts) {
		bonobo_contexts = g_hash_table_new (
			g_str_hash, g_str_equal);
		g_atexit (bonobo_context_shutdown);
	}

	g_hash_table_insert (bonobo_contexts,
			     g_strdup (context_name),
			     bonobo_object_dup_ref (context, NULL));
}

/**
 * bonobo_context_get:
 * @context_name: the name of the context
 * @opt_ev: optional Environment, or NULL
 * 
 *  The most useful context is named 'Activation' and returns
 * the IDL:Bonobo/ActivationContext:1.0 interface.
 * 
 * Return value: a new reference to a global Bonobo context or CORBA_OBJECT_NIL
 **/
Bonobo_Unknown
bonobo_context_get (const CORBA_char  *context_name,
		    CORBA_Environment *opt_ev)
{
	Bonobo_Unknown ret;

	g_return_val_if_fail (context_name != NULL, CORBA_OBJECT_NIL);

	if ((ret = g_hash_table_lookup (bonobo_contexts, context_name)))
		return bonobo_object_dup_ref (ret, opt_ev);
	else
		return CORBA_OBJECT_NIL;
}

static void
context_add (BonoboObject *object, const char *name)
{
	CORBA_Object ref;

	ref = BONOBO_OBJREF (object);

	bonobo_context_add (name, ref);

	/* Don't count it as a running object; we always have it */
	bonobo_running_context_ignore_object (ref);

	bonobo_object_unref (object);
}

/**
 * bonobo_context_init:
 * @void: 
 * 
 * Sets up the context system, internal use only, called
 * by bonobo_init.
 **/
void
bonobo_context_init (void)
{
	context_add (bonobo_activation_context_new (), "Activation");
	context_add (bonobo_running_context_new (),    "Running");
}

static gboolean
context_destroy (char *key, Bonobo_Unknown handle, gpointer dummy)
{
	g_free (key);
	bonobo_object_release_unref (handle, NULL);
	return TRUE;
}

/**
 * bonobo_context_shutdown:
 * @void: 
 * 
 * Shuts down the context system, internal use only
 **/
void
bonobo_context_shutdown (void)
{
	if (!bonobo_contexts)
		return;

	g_hash_table_foreach_remove (
		bonobo_contexts, (GHRFunc) context_destroy, NULL);
	g_hash_table_destroy (bonobo_contexts);
	bonobo_contexts = NULL;
}