root/trunk/midgard/apis/php5/php_midgard.h

Revision 18417, 7.7 kB (checked in by piotras, 1 month ago)

Enable replicator class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* $Id$
2 Copyright (C) 1999 Jukka Zitting <jukka.zitting@iki.fi>
3 Copyright (C) 2000 The Midgard Project ry
4 Copyright (C) 2006 Piotr Pokora <piotrek.pokora@gmail.com>
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifdef G_LOG_DOMAIN
22 #undef G_LOG_DOMAIN
23 #define G_LOG_DOMAIN "midgard-core"
24 #endif
25
26 #ifndef PHP_MIDGARD_H
27 #define PHP_MIDGARD_H
28
29 #include "config.h"
30
31 #ifdef PHP_WIN32
32 #include "config.w32.h"
33 #endif
34
35 #ifndef PHP_CONFIG_H
36 #define PHP_CONFIG_H
37 #include "php_config.h"
38 #endif
39
40 /* Do not load Apache regex when php compiled with 'system' as regex's TYPE */
41 #if REGEX == 0
42 #ifndef _REGEX_H
43 #define _REGEX_H 1
44 #endif
45 #endif
46
47 #include "php.h"
48 #include "php_globals.h"
49 #include "ext/standard/info.h"
50 #include "ext/standard/php_var.h"
51 #include "SAPI.h"
52 #include "ext/standard/php_standard.h"
53 #include "ext/standard/php_smart_str.h"
54 #include "ext/standard/info.h"
55
56 #if HAVE_MIDGARD
57
58 #define MGD_FUNCTION(ret, name, param) \
59         PHP_FUNCTION(mgd_##name)
60
61 #define MGD_FE(name, arg_types) \
62         PHP_FE(mgd_##name, arg_types)
63
64 #include <midgard/midgard.h>
65 #include <midgard/midgard_http_host.h>
66
67 #ifdef ZTS
68 #include <TSRM.h>
69 #endif
70
71 extern MidgardConnection *mgd_handle();
72 extern void mgd_handle_set(MidgardConnection *mgd);
73 extern guint global_loghandler;
74
75 int mgd_get_errno();
76 void mgd_reset_errno();
77 void mgd_set_errno(MgdErrorGeneric mgd_errno);
78
79 extern zend_module_entry midgard2_module_entry;
80
81 #ifdef ZTS
82 typedef struct {
83          MidgardConnection *mgd;
84          zval *schema_types;
85 } midgard2_globals;
86 #endif
87
88 #define phpext_midgard_ptr &midgard2_module_entry
89
90 #ifdef PHP_WIN32
91 #define PHP_MIDGARD_API __declspec(dllexport)
92 #else
93 #define PHP_MIDGARD_API
94 #endif
95
96 PHP_MINIT_FUNCTION(midgard2);
97 PHP_MSHUTDOWN_FUNCTION(midgard2);
98 PHP_RINIT_FUNCTION(midgard2);
99 PHP_RSHUTDOWN_FUNCTION(midgard2);
100 PHP_MINFO_FUNCTION(midgard2);
101
102 PHP_FUNCTION(confirm_midgard2_compiled);        /* For testing, remove later. */
103
104 ZEND_BEGIN_MODULE_GLOBALS(midgard2)
105         MidgardConnection *mgd;
106 ZEND_END_MODULE_GLOBALS(midgard2)
107
108 /* ZEND_EXTERN_MODULE_GLOBALS(midgard)  */
109
110 #ifdef ZTS
111
112 #define MGDG(v) TSRMG(midgard2_globals_id, zend_midgard2_globals *, v)
113 /* #define MGDLS_FETCH() php_midgard2_globals *midgard_globals = ts_resource(midgard2_globals_id) */
114 /* TODO , make sure if we need to get midgard_globals_id from thread safety resources.
115  * TSRMLS_FETCH() macro seems to do the same
116  */
117 #define MGDLS_FETCH()
118 #else
119 #define MGDG(v) (midgard2_globals.v)
120 #define MGDLS_FETCH()
121 #endif
122
123 #else
124
125 #define phpext_midgard2_ptr NULL
126
127 #endif
128
129 PHP_FUNCTION(_midgard_php_object_constructor);
130 /* FIXME , change name */
131 PHP_FUNCTION(_get_type_by_id);
132 PHP_FUNCTION(_midgard_php_object_get_by_guid);
133 PHP_FUNCTION(_midgard_php_object_update);
134 PHP_FUNCTION(_midgard_php_object_create);
135 PHP_FUNCTION(_midgard_php_object_is_in_parent_tree);
136 PHP_FUNCTION(_midgard_php_object_is_in_tree);
137 PHP_FUNCTION(_midgard_php_object_get_tree);
138 PHP_FUNCTION(_midgard_php_object_delete);
139 PHP_FUNCTION(_midgard_php_object_get_parent);
140 PHP_FUNCTION(_midgard_php_object_get);
141 PHP_FUNCTION(_midgard_php_object_list);
142 PHP_FUNCTION(_midgard_php_object_list_children);
143 PHP_FUNCTION(_midgard_php_object_get_by_path);
144 PHP_FUNCTION(_midgard_php_object_parent);
145 PHP_FUNCTION(_php_midgard_object_get_languages);
146 PHP_FUNCTION(_php_midgard_object_purge);
147 PHP_FUNCTION(_php_midgard_object_undelete);
148 PHP_FUNCTION(_php_midgard_object_parameter);
149 PHP_FUNCTION(_php_midgard_object_connect);
150
151 MGD_FUNCTION(ret_type, import_object, (type param));
152 MGD_FUNCTION(ret_type, get_class_data, (type param));
153 MGD_FUNCTION(ret_type, get_class_property, (type param));
154 MGD_FUNCTION(ret_type, get_class_properties, (type param));
155 MGD_FUNCTION(ret_type, get_sitegroup_size, (type param));
156
157 #define MGD_PHP_BCLASS_FROM_NAME(classname) \
158         guint name_length; \
159         zend_class_entry *__bce, **__ce; \
160         gchar *lower_class_name; \
161         name_length = strlen(classname); \
162         lower_class_name = g_ascii_strdown(classname, name_length); \
163         if (zend_hash_find(CG(class_table), \
164         lower_class_name, name_length+1, (void **) &__ce)  == SUCCESS) { \
165                 __bce = php_midgard_get_baseclass_ptr(*__ce); \
166                 zend_classname = __bce->name; \
167                 g_free(lower_class_name); \
168         } else { \
169                 g_free(lower_class_name); \
170                 php_error(E_ERROR, "%s is not registered class", classname); \
171         }
172
173 /* Underlying GObject bindings */
174 zval *php_midgard_gobject_read_property(zval *zobject, zval *prop, int type TSRMLS_DC);
175 void php_midgard_gobject_write_property(zval *zobject, zval *prop, zval *value TSRMLS_DC);
176 void php_midgard_zendobject_register_properties (zval *zobject, GObject *gobject);
177 int php_midgard_gobject_has_property(zval *zobject, zval *prop, int type TSRMLS_DC);
178 HashTable *php_midgard_zendobject_get_properties (zval *zobject TSRMLS_DC);
179
180 extern MgdObject *php_midgard_get_midgard_object(zval *zobj);
181 extern void php_midgard_array_from_objects(GObject **objects, const gchar *class_name, zval *zarray);
182
183 extern GValue *php_midgard_zval2gvalue(zval *zvalue);
184 extern gboolean php_midgard_gvalue2zval(GValue *gvalue, zval *zvalue);
185
186 extern GParameter *php_midgard_array_to_gparameter(zval *params, guint *n_params);
187
188 extern zend_class_entry *php_midgard_get_baseclass_ptr_by_name(const gchar *name);
189
190 /* closures */
191 void php_midgard_object_connect_class_closures(GObject *object, zval *zobject);
192 void php_midgard_gobject_closure_hash_new();
193 void php_midgard_gobject_closure_hash_reset();
194 void php_midgard_gobject_closure_hash_free();
195
196 zend_class_entry *midgard_php_register_internal_class(
197         const gchar *class_name, GType class_type, zend_class_entry ce,
198         function_entry *fe);
199        
200 /* Midgard core's classes */    
201 extern void php_midgard_collector_init(int module_number);
202 extern void php_midgard_config_init(int module_number);
203 extern void php_midgard_user_init(int module_number);
204 extern void php_midgard_blob_init(int module_number);
205 extern void php_midgard_sitegroup_init(int module_number);
206 extern void php_midgard_query_builder_init(int module_number);
207 extern void php_midgard_object_class_init(int module_number);
208 extern void php_midgard_request_config_init(int module_number);
209 extern void php_midgard_reflection_property_init(int module_number);
210 extern void php_midgard_connection_init(int module_number);
211 extern void php_midgard_object_init(int module_number);
212 extern void php_midgard_dbus_init(int module_number);
213 extern void php_midgard_replicator_init(int module_number);
214
215 zend_class_entry *php_midgard_get_baseclass_ptr(zend_class_entry *ce);
216 zend_class_entry *php_midgard_get_baseclass_ptr_by_name(const gchar *name);
217
218 void php_midgard_log_errors(const gchar *domain, GLogLevelFlags level,
219                 const gchar *msg, gpointer userdata);
220
221 gboolean php_midgard_error_throw_exception(MidgardConnection *mgd);
222
223 /* ROUTINES */
224 extern void php_midgard_initialize_request_for_http(MidgardHttpHost *host);
225
226 #define CHECK_MGD \
227         if (!mgd_handle()) \
228                 php_error(E_ERROR, "Can not find MidgardConnection"); \
229         gchar *_check_cname_space = NULL; \
230         gchar *_check_class_name = get_active_class_name(&_check_cname_space TSRMLS_CC); \
231         g_log("midgard-core", G_LOG_LEVEL_INFO, \
232                 " %s%s%s(...)", _check_class_name, _check_cname_space, \
233                 get_active_function_name(TSRMLS_C));
234
235 #endif  /* PHP_MIDGARD_H */
236
237 /*
238  * Local variables:
239  * tab-width: 4
240  * c-basic-offset: 4
241  * End:
242  */
Note: See TracBrowser for help on using the browser.