/[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.1 - (hide annotations)
Sun Feb 9 17:25:38 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
+ refactored from flib/Application/RPC/Remote.php

1 joko 1.1 <?
2     /*
3     ## --------------------------------------------------------------------------
4     ## $Id: Remote.php,v 1.6 2003/02/03 03:37:45 jonen Exp $
5     ## --------------------------------------------------------------------------
6     ## $Log: Remote.php,v $
7     ## Revision 1.6 2003/02/03 03:37:45 jonen
8     ## - removed unused argument '$decode' at function '_call()'
9     ## + added argument '$options=array()' at function '_call()'
10     ## which will be passed to function '&decodeData()' for e.g. utf8 decoding
11     ## + added '$encoder->toISO()' at '&decodeData()', (re)moved from 'ProxyObject.php'
12     ##
13     ## Revision 1.5 2002/12/22 13:24:09 jonen
14     ## + added utf8 encoding at 'send()' toggled by option
15     ##
16     ## Revision 1.4 2002/12/19 02:02:25 jonen
17     ## + minor changes
18     ##
19     ## Revision 1.3 2002/12/19 01:59:37 jonen
20     ## + minor changes: coment debug prints
21     ##
22     ## Revision 1.2 2002/12/05 21:45:31 joko
23     ## + debugging
24     ##
25     ## Revision 1.1 2002/12/01 17:23:58 joko
26     ## + initial check-in
27     ##
28     ## Revision 1.3 2002/12/01 06:22:57 cvsjoko
29     ## + minor update: now can use config defaults or given args
30     ##
31     ## Revision 1.2 2002/10/29 19:14:45 cvsjoko
32     ## - bugfix: dont' do utf8-encoding here
33     ##
34     ## Revision 1.1 2002/10/09 00:51:39 cvsjoko
35     ## + new
36     ##
37     ##
38     ## -------------------------------------------------------------------------
39     */
40    
41    
42     /*
43    
44     TODO:
45     o SOAP?
46    
47    
48     */
49    
50    
51     class Data_Driver_RPC_Remote extends DesignPattern_Logger {
52    
53     var $configured;
54    
55     function Data_Driver_RPC_Remote($args = array()) {
56    
57     parent::constructor();
58    
59     //print Dumper($this, $args);
60    
61     if ($args['Host']) { $this->host = $args['Host']; }
62     if ($args['Port']) { $this->port = $args['Port']; }
63    
64     // check if host is valid
65     if (!$this->host) {
66     $this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings");
67     return;
68     }
69    
70     if (!$this->port) {
71     $this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings");
72     return;
73     }
74    
75     $this->configured = 1;
76    
77     }
78    
79     function send($command, $data = "", $options = array()) {
80     // do 'encode' here and ...
81     if ($options[utf8]) {
82     $encoder = new TextEncode($data);
83     $encoder->toUTF8();
84     }
85     // call '_call' with 'decode'
86     return $this->_call($command, $data, $options);
87     }
88    
89     function _call($command, $data = "", $options = array() ) {
90    
91     if (!$this->configured) {
92     $this->_raiseException( "->_call: class not configured properly");
93     return;
94     }
95    
96     //print "call: $command<hr>";
97    
98     // print Dumper($data);
99    
100     // data
101     $data_enc = XML_RPC_encode($data);
102    
103     // message - request
104     $msg = new XML_RPC_Message($command);
105     $msg->addParam($data_enc);
106     //print htmlentities($msg->serialize());
107     // remote procedure call
108     $rpc = new XML_RPC_Client("/", $this->host, $this->port);
109     $rpc->setDebug(0);
110     if ( !$msg_response = $rpc->send($msg) ) {
111     // TODO: redirect this error elsewhere!
112     //print "RPC-error!<br>";
113     $this->_raiseException( "->_call: no response");
114     return;
115     }
116     // message - response
117     $response_enc = $msg_response->value();
118    
119     // TODO: what's this? prematurely returning here should not be considered "stable"....
120     return $this->decodeData($response_enc, $options);
121     }
122    
123     function &decodeData(&$payload, $options = array() ) {
124     //if (!is_object($payload)) { return; }
125     if ($payload) {
126     // data
127     $data = XML_RPC_decode($payload);
128     //print "data: " . dumpVar($response);
129    
130     // decode UTF8 to ISO if wanted
131     if($options[utf8]) {
132     $encoder = new TextEncode($data);
133     $encoder->toISO();
134     }
135    
136     return $data;
137     } else {
138     //print "ERROR!<br>";
139     return 0;
140     }
141     }
142    
143     function _raiseException($message) {
144     $this->log(get_class($this) . $message, PEAR_LOG_CRIT);
145     //dprint(get_class($this) . $message);
146     }
147    
148     }
149    
150     ?>

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