/[cvs]/nfo/php/libs/org.netfrag.glib/Data/Driver/RPC/Remote.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/Data/Driver/RPC/Remote.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Thu Feb 13 21:51:29 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.2: +56 -7 lines
+ now can remember its connection-state
+ sub ping

1 joko 1.1 <?
2     /*
3     ## --------------------------------------------------------------------------
4 joko 1.3 ## $Id: Remote.php,v 1.2 2003/02/13 00:42:44 joko Exp $
5 joko 1.1 ## --------------------------------------------------------------------------
6     ## $Log: Remote.php,v $
7 joko 1.3 ## Revision 1.2 2003/02/13 00:42:44 joko
8     ## +- renamed modules
9     ##
10 joko 1.2 ## Revision 1.1 2003/02/09 17:25:38 joko
11     ## + refactored from flib/Application/RPC/Remote.php
12     ##
13 joko 1.1 ## Revision 1.6 2003/02/03 03:37:45 jonen
14     ## - removed unused argument '$decode' at function '_call()'
15     ## + added argument '$options=array()' at function '_call()'
16     ## which will be passed to function '&decodeData()' for e.g. utf8 decoding
17     ## + added '$encoder->toISO()' at '&decodeData()', (re)moved from 'ProxyObject.php'
18     ##
19     ## Revision 1.5 2002/12/22 13:24:09 jonen
20     ## + added utf8 encoding at 'send()' toggled by option
21     ##
22     ## Revision 1.4 2002/12/19 02:02:25 jonen
23     ## + minor changes
24     ##
25     ## Revision 1.3 2002/12/19 01:59:37 jonen
26     ## + minor changes: coment debug prints
27     ##
28     ## Revision 1.2 2002/12/05 21:45:31 joko
29     ## + debugging
30     ##
31     ## Revision 1.1 2002/12/01 17:23:58 joko
32     ## + initial check-in
33     ##
34     ## Revision 1.3 2002/12/01 06:22:57 cvsjoko
35     ## + minor update: now can use config defaults or given args
36     ##
37     ## Revision 1.2 2002/10/29 19:14:45 cvsjoko
38     ## - bugfix: dont' do utf8-encoding here
39     ##
40     ## Revision 1.1 2002/10/09 00:51:39 cvsjoko
41     ## + new
42     ##
43     ##
44     ## -------------------------------------------------------------------------
45     */
46    
47    
48     /*
49    
50     TODO:
51     o SOAP?
52    
53    
54     */
55    
56    
57     class Data_Driver_RPC_Remote extends DesignPattern_Logger {
58    
59     var $configured;
60 joko 1.3 var $meta;
61 joko 1.1
62     function Data_Driver_RPC_Remote($args = array()) {
63 joko 1.3
64 joko 1.1 parent::constructor();
65 joko 1.3
66 joko 1.1 //print Dumper($this, $args);
67 joko 1.3
68     global $Data_Driver_RPC_Remote_meta;
69     session_register_safe("Data_Driver_RPC_Remote_meta");
70     $this->meta = $Data_Driver_RPC_Remote_meta;
71    
72     if (!isset($this->meta[connected]) || $args[connect]) {
73     $this->meta[connected] = 1;
74     }
75     $this->_save_meta();
76    
77 joko 1.1 if ($args['Host']) { $this->host = $args['Host']; }
78     if ($args['Port']) { $this->port = $args['Port']; }
79 joko 1.3
80 joko 1.1 // check if host is valid
81     if (!$this->host) {
82     $this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings");
83     return;
84     }
85    
86     if (!$this->port) {
87     $this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings");
88     return;
89     }
90    
91     $this->configured = 1;
92    
93     }
94    
95 joko 1.3 function _save_meta() {
96     global $Data_Driver_RPC_Remote_meta;
97     $Data_Driver_RPC_Remote_meta = $this->meta;
98     }
99    
100 joko 1.1 function send($command, $data = "", $options = array()) {
101 joko 1.3
102     $this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG);
103    
104     if (!$this->isConnected()) {
105     $this->_raiseException( "->send: not connected!");
106     return;
107     }
108    
109 joko 1.1 // do 'encode' here and ...
110     if ($options[utf8]) {
111 joko 1.2 $encoder = new Data_Encode($data);
112 joko 1.1 $encoder->toUTF8();
113     }
114     // call '_call' with 'decode'
115     return $this->_call($command, $data, $options);
116     }
117    
118     function _call($command, $data = "", $options = array() ) {
119    
120     if (!$this->configured) {
121     $this->_raiseException( "->_call: class not configured properly");
122     return;
123     }
124    
125 joko 1.3 // populate options list - mostly for debugging purposes
126     $options_list = array();
127     foreach ($options as $key => $value) {
128     array_push($options_list, "$key=$value");
129     }
130    
131     $data_debug = $data;
132     if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); }
133     $options_debug = join(", ", $options_list);
134     $this->log(get_class($this) . ": " . $command . "(" . $data_debug . ") [" . $options_debug . "]", PEAR_LOG_DEBUG);
135    
136 joko 1.2 // trace
137     //print "call: $command<hr>";
138     //print Dumper($data);
139     //print Dumper($this);
140 joko 1.1
141     // data
142     $data_enc = XML_RPC_encode($data);
143    
144     // message - request
145     $msg = new XML_RPC_Message($command);
146     $msg->addParam($data_enc);
147     //print htmlentities($msg->serialize());
148     // remote procedure call
149     $rpc = new XML_RPC_Client("/", $this->host, $this->port);
150     $rpc->setDebug(0);
151     if ( !$msg_response = $rpc->send($msg) ) {
152     // TODO: redirect this error elsewhere!
153     //print "RPC-error!<br>";
154     $this->_raiseException( "->_call: no response");
155     return;
156     }
157     // message - response
158     $response_enc = $msg_response->value();
159    
160     // TODO: what's this? prematurely returning here should not be considered "stable"....
161     return $this->decodeData($response_enc, $options);
162     }
163    
164     function &decodeData(&$payload, $options = array() ) {
165     //if (!is_object($payload)) { return; }
166     if ($payload) {
167     // data
168     $data = XML_RPC_decode($payload);
169     //print "data: " . dumpVar($response);
170    
171     // decode UTF8 to ISO if wanted
172     if($options[utf8]) {
173 joko 1.2 $encoder = new Data_Encode($data);
174 joko 1.1 $encoder->toISO();
175     }
176 joko 1.3
177     $this->meta[connected] = 1;
178     $this->_save_meta();
179 joko 1.1
180     return $data;
181     } else {
182     //print "ERROR!<br>";
183     return 0;
184     }
185     }
186    
187     function _raiseException($message) {
188 joko 1.3 $this->meta[connected] = 0;
189     $this->_save_meta();
190     $this->log(get_class($this) . $message, PEAR_LOG_ERR);
191     }
192    
193     function isConnected() {
194     return $this->meta[connected];
195     }
196    
197     function ping() {
198     $this->_call('ping');
199 joko 1.1 }
200    
201     }
202    
203     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed