/[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.4 - (hide annotations)
Thu Feb 20 21:42:43 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.3: +7 -3 lines
+ fix: always converting from utf8 into latin here (for now)

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

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