root/trunk/midgard/apis/php5/php_midgard_dbus.c

Revision 16471, 2.4 kB (checked in by piotras, 6 months ago)

MidgardConnection? pointer added to constructor and send method

Line 
1 /* Copyright (C) 2008 Piotr Pokora <piotrek.pokora@gmail.com>
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms of the GNU Lesser General Public License as published
4  * by the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15 */
16
17 #include "php_midgard.h"
18 #include "php_midgard_gobject.h"
19
20 static zend_class_entry *php_midgard_dbus_class;
21
22 /* Object constructor */
23 static PHP_METHOD(midgard_dbus, __construct)
24 {       
25         RETVAL_FALSE;
26         CHECK_MGD;
27         gchar *path;
28         guint path_length;
29         zval *object = getThis();
30
31         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
32                                 &path, &path_length) == FAILURE)
33                 return;
34        
35         MidgardConnection *mgd = mgd_handle();
36         MidgardDbus *mbus = midgard_dbus_new(mgd, path);
37
38         if(!mbus)
39                 RETURN_FALSE;
40
41         php_midgard_gobject *php_gobject =
42                 (php_midgard_gobject *)zend_object_store_get_object(object TSRMLS_CC);
43         php_gobject->gobject = G_OBJECT(mbus);
44 }
45
46 static PHP_METHOD(midgard_dbus, send)
47 {
48         RETVAL_FALSE;
49         CHECK_MGD;
50         gchar *path, *msg;
51         guint path_length, msg_length;
52        
53         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
54                                 &path, &path_length, &msg, &msg_length) == FAILURE)
55                 return;
56
57         MidgardConnection *mgd = mgd_handle();
58         midgard_dbus_send(mgd, path, msg);
59
60         return;
61 }
62
63 /* Initialize ZEND&PHP class */
64 void php_midgard_dbus_init(int module_numer)
65 {
66
67         static function_entry midgard_dbus_methods[] = {
68                 PHP_ME(midgard_dbus,    __construct,    NULL, ZEND_ACC_PUBLIC)
69                 PHP_ME(midgard_dbus,    send,           NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
70                 {NULL, NULL, NULL}
71         };
72
73         static zend_class_entry php_midgard_dbus_class_entry;
74
75         INIT_CLASS_ENTRY(
76                         php_midgard_dbus_class_entry,
77                         "midgard_dbus", midgard_dbus_methods);
78
79         php_midgard_dbus_class =
80                 zend_register_internal_class(
81                                 &php_midgard_dbus_class_entry TSRMLS_CC);
82        
83         /* Set function to initialize underlying data */
84         php_midgard_dbus_class->create_object = php_midgard_gobject_new;       
85 }
Note: See TracBrowser for help on using the browser.