summaryrefslogtreecommitdiff
path: root/ext/satellite/php_orbit.c
blob: 6b740b9f82892fcdfdcb4dc8064ff4e7aec072eb (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
   +----------------------------------------------------------------------+
   | PHP version 4.0                                                      |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2001 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
 */

/*
 * Interface to PHP
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <php.h>
#include <php_ini.h>	 /* for DISPLAY_INI_ENTRIES() */
#include <ext/standard/info.h>	/* for php_info_print_table_*() */
#include "php_orbit.h"
#include "corba.h"
#include "typemanager.h"
#include "namedvalue_to_zval.h"

/* classes */
#include "enum.h"
#include "object.h"
#include "struct.h"


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

/* see php4/README.SELF-CONTAINED-EXTENSIONS */
#if COMPILE_DL_SATELLITE
ZEND_GET_MODULE(satellite)
#endif

PHP_MINFO_FUNCTION(satellite);

PHP_INI_BEGIN()
	PHP_INI_ENTRY1("idl_directory", NULL, 0, NULL, NULL)
PHP_INI_END()

/*
 * functions in module
 */
static function_entry satellite_functions[] = {
	PHP_FE(satellite_load_idl,					NULL)
	PHP_FE(satellite_get_repository_id, NULL)
	PHP_FE(satellite_caught_exception, 	NULL)
	PHP_FE(satellite_exception_id, 			NULL)
	PHP_FE(satellite_exception_value, 	NULL)

	/* support the old prefix orbit_ */
 	PHP_FALIAS(orbit_load_idl, 					satellite_load_idl, 					NULL)
	PHP_FALIAS(orbit_get_repository_id,	satellite_get_repository_id,	NULL)
	PHP_FALIAS(orbit_caught_exception, 	satellite_caught_exception, 	NULL)
	PHP_FALIAS(orbit_exception_id, 			satellite_exception_id, 			NULL)
	PHP_FALIAS(orbit_exception_value, 	satellite_exception_value, 		NULL)

 {NULL, NULL, NULL}
};


/*
 * module entry
 */
zend_module_entry satellite_module_entry = {
  "satellite",
  satellite_functions,
  PHP_MINIT(satellite),			/* module startup */
  PHP_MSHUTDOWN(satellite),	/* module shutdown */
  NULL,											/* request startup */
  NULL,											/* request shutdown */
  PHP_MINFO(satellite),			/* module info */
  STANDARD_MODULE_PROPERTIES
};

/*
 * module initialization
 */
PHP_MINIT_FUNCTION(satellite)
{
	zend_bool success;
	
	REGISTER_INI_ENTRIES();
	
	success = 
		orbit_corba_init() &&
		TypeManager_Init(INI_STR("idl_directory")) &&
		OrbitEnum_Init(module_number) &&
		OrbitObject_Init(module_number) &&
		OrbitStruct_Init(module_number);

	return success ? SUCCESS : FAILURE;
}

/*
 * shutdown module!
*/
PHP_MSHUTDOWN_FUNCTION(satellite)
{
	TypeManager_Shutdown();
	orbit_corba_shutdown();
	
	UNREGISTER_INI_ENTRIES();
	
	return SUCCESS;
}

/*
 * some function
 */
PHP_MINFO_FUNCTION(satellite) 
{

	php_info_print_table_start();
	php_info_print_table_header(2, "CORBA support via Satellite", "enabled");
	php_info_print_table_end();

  DISPLAY_INI_ENTRIES();
}

/* instruct the type manager to load an IDL file if not already loaded */
PHP_FUNCTION(satellite_load_idl)
{
	zval * p_parameter;
	
	if (ZEND_NUM_ARGS() != 1)
	{
		WRONG_PARAM_COUNT;
		RETURN_NULL();
	}

	getParameters(ht, 1, &p_parameter);

	if (p_parameter->type != IS_STRING)
	{
		RETURN_NULL();
	}

	RETURN_BOOL(TypeManager_LoadFile(p_parameter->value.str.val));
}

/* 
 * NOT IMPLEMENTED
 *
 * get the repository id for an Orbit* object (nice for debugging...)
 */
PHP_FUNCTION(satellite_get_repository_id)
{
}

PHP_FUNCTION(satellite_caught_exception)
{
	RETURN_BOOL(orbit_caught_exception());
}

PHP_FUNCTION(satellite_exception_id)
{
	CORBA_char * p_id = CORBA_exception_id(orbit_get_environment());
	
	RETURN_STRING(p_id, TRUE);
}

/* real name: php_if_orbit_exception_value */
PHP_FUNCTION(satellite_exception_value)
{
	CORBA_NamedValue source;
	ExceptionType * p_exception = NULL;
	
	memset(&source, 0, sizeof(CORBA_NamedValue));
	
	/* get exception type info */
	p_exception = TypeManager_FindException(
			CORBA_exception_id(orbit_get_environment()));
	
	/* get exception typecode */
	source.argument._type = ExceptionType_GetTypeCode(p_exception);
	/* get exception value */
	source.argument._value = CORBA_exception_value(orbit_get_environment());
	
	/* create structure with exception data */
	orbit_namedvalue_to_zval(&source, return_value);
}