/[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.2 - (hide annotations)
Thu Feb 13 00:42:44 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.1: +10 -6 lines
+- renamed modules

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

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