summaryrefslogtreecommitdiff
path: root/ext/satellite/corba.c
blob: a2dcb8b9cf3b03dce54ba32bd572de280a7115ee (plain)
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
121
122
123
124
125
126
127
128
129
130
131
/*
   +----------------------------------------------------------------------+
   | PHP Version 4                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2002 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available at through the world-wide-web at                           |
   | http://www.php.net/license/2_02.txt.                                 |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: David Eriksson <david@2good.com>                            |
   +----------------------------------------------------------------------+
 */

/*
 * $Id$
 * vim: syntax=c tabstop=2 shiftwidth=2
 */

/* -----------------------------------------------------------------------
 * 
 * Control access to CORBA_ORB and CORBA_Environment objects
 * Adjust these functions to get thread safety!
 *
 * -----------------------------------------------------------------------
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "corba.h"

#include "php_config.h"	/* for COMPILE_DL_ORBIT */

/* ZTS = thread-safe Zend */
#ifdef ZTS
#error ORBit support not thread-safe, you should at least modify corba.c
#endif

static CORBA_ORB corba_orb = NULL;
static CORBA_Environment corba_environment;
static CORBA_boolean corba_initialized = FALSE;

CORBA_boolean orbit_corba_init()
{
	int argc = 1;
	char * argv[2] = { "dummy", NULL };


#if COMPILE_DL_SATELLITE
	/*
	   IIOP normally registers a function with atexit, but that's pretty stupid
	   when it is called from a dynamic module that is unloaded before exit()
	   is called...
	 
	  	"In addition, for David Eriksson (I think), added:
      				int giop_skip_atexit;
			to IIOP. Applications may set this TRUE prior to invoking any
			CORBA_ORB_init() calls, and it will not invoke atexit. This is
			perhaps an ugly way of doing this, but I'm assuming this feature
			will only be used from within specialized sharedlib applications
			that know what they are doing...

			Kennard"
	 */
	
	giop_skip_atexit = TRUE;
#endif

	CORBA_exception_init(&corba_environment);
	corba_orb = CORBA_ORB_init(
			&argc, argv, "orbit-local-orb", &corba_environment);

	/* check return value */
	if (corba_orb == NULL || orbit_caught_exception())
	{
/*		printf("orbit_corba_init failed\n");*/
		return FALSE;
	}

	corba_initialized = TRUE;

	return TRUE;
}

CORBA_boolean orbit_corba_shutdown()
{
	if (corba_initialized)
	{
		/* the orb's reference count is two.. what to do? */
		CORBA_Object_release((CORBA_Object)corba_orb, &corba_environment);
		CORBA_Object_release((CORBA_Object)corba_orb, &corba_environment);
		/*CORBA_ORB_destroy(corba_orb, &corba_environment); */
		
		CORBA_exception_free(orbit_get_environment());

		corba_initialized = FALSE;
		corba_orb = NULL;
		return TRUE;
	}
	else
		return FALSE;
}

CORBA_ORB orbit_get_orb()
{
	return corba_orb;
}

CORBA_Environment * orbit_get_environment()
{
	return &corba_environment;
}

CORBA_boolean orbit_caught_exception()
{
#if 0 /*debug*/
	if (orbit_get_environment()->_major != CORBA_NO_EXCEPTION)
	{
		printf("Caught exception %s\n", 
				CORBA_exception_id(orbit_get_environment()));
	}
#endif
	return orbit_get_environment()->_major != CORBA_NO_EXCEPTION;
}