[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue-common/src/rpc/drivers/xmlrpc RpcDoc.py
From: |
Jan Ischebeck |
Subject: |
gnue-common/src/rpc/drivers/xmlrpc RpcDoc.py |
Date: |
Mon, 01 Sep 2003 13:27:26 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue-common
Branch:
Changes by: Jan Ischebeck <address@hidden> 03/09/01 13:27:26
Modified files:
src/rpc/drivers/xmlrpc: RpcDoc.py
Log message:
add php stubs to rpcdoc
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/rpc/drivers/xmlrpc/RpcDoc.py.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
Patches:
Index: gnue-common/src/rpc/drivers/xmlrpc/RpcDoc.py
diff -c gnue-common/src/rpc/drivers/xmlrpc/RpcDoc.py:1.9
gnue-common/src/rpc/drivers/xmlrpc/RpcDoc.py:1.10
*** gnue-common/src/rpc/drivers/xmlrpc/RpcDoc.py:1.9 Mon Feb 17 02:32:48 2003
--- gnue-common/src/rpc/drivers/xmlrpc/RpcDoc.py Mon Sep 1 13:27:26 2003
***************
*** 102,109 ****
print _("'doc-php' command expects a .grpc file as its argument.")
sys.exit()
! print "PHP code generation not implemented yet."
! # gendoc(rpcdef, outfile)
elif command == 'js-stub':
--- 102,108 ----
print _("'doc-php' command expects a .grpc file as its argument.")
sys.exit()
! gendocPHP(rpcdef, outfile)
elif command == 'js-stub':
***************
*** 193,198 ****
--- 192,332 ----
gloutfile.write(name + "\n")
##
+ ## Create PHP example
+ ##
+ php_XMLRPC_types = {'int4' : '$xmlrpcI4',
+ 'integer' : '$xmlrpcInt',
+ 'boolean' : '$xmlrpcBoolean',
+ 'double' : '$xmlrpcDouble',
+ 'string' : '$xmlrpcString',
+ 'dateTime' : '$xmlrpcDateTime',
+ 'base64' : '$xmlrpcBase64',
+ 'array' : '$xmlrpcArray',
+ 'struct' : '$xmlrpcStruct'}
+
+ def gendocPHP(rpcdef, outfile):
+
+ outfile.write("<?php\n")
+ outfile.write("// ***************************************\n")
+ outfile.write("// XML-RPC Server Side Stubs\n")
+ outfile.write("// ***************************************\n\n")
+ outfile.write('include("xmlrpc.inc");\n')
+ outfile.write('include("xmlrpcs.inc");\n\n')
+ outfile.write("$server_def= array();\n")
+ gloutfile= outfile
+ rpcdef.walk(_genPHP)
+ outfile.write("$s=new xmlrpc_server($server_def)\n?>\n")
+
+
+ def _genPHP(object):
+ if hasattr(object,'name'):
+ name=object.name
+ if hasattr(object,'_path'): # and hasattr(object._parent,'name'):
+ name=object._path+'_'+name
+ else:
+ name=""
+ if object._type=="RpObject" or object._type=="RpService":
+ gloutfile.write("// ***************************************\n")
+ gloutfile.write("// Service %s \n" % name[1:])
+ gloutfile.write("// ***************************************\n\n")
+ if hasattr(object,'_children'):
+ for child in object._children:
+ child._path=name
+ if child._type=="RpMethod" or child._type=="RpAttribute":
+ _genPHP(child)
+ gloutfile.write("\n")
+ if hasattr(object,'_children'):
+ for child in object._children:
+ child._path=name
+ if child._type=="RpObject" or child._type=="RpService":
+ _genPHP(child)
+
+
+ elif object._type=="RpGnuRpc":
+ if hasattr(object,'_children'):
+ for child in object._children:
+ child._path=name
+ _genPHP(child)
+
+
+ elif object._type=="RpMethod":
+
+ if hasattr(object,"return"):
+ try:
+ sign=php_XMLRPC_types[object.return]+","
+ except KeyError:
+ sign="$xmlrpcArray,"
+ else:
+ sign="Null,"
+
+
+ # build attribut list
+ attr=""
+ delim=""
+ if hasattr(object,'_children'):
+ for child in object._children:
+ attr=attr+delim+child.name
+ try:
+ sign=sign+delim+php_XMLRPC_types[child.type]
+ except KeyError:
+ sign=sign+delim+"$xmlrpcArray"
+
+ delim=","
+ # TODO: add return type
+
+ gloutfile.write("// ***************************************\n")
+ gloutfile.write("// function %s (%s) \n" % (object.name,attr) )
+ gloutfile.write("// ***************************************\n\n")
+
+ gloutfile.write("$%s_sign = array(array(%s));\n" % \
+ (object.name,sign) )
+ gloutfile.write("$server_def['%s']=\n" % object.name)
+ gloutfile.write(" array('function' => '%s_func',\n" % object.name)
+ gloutfile.write(" 'signature' => $%s_sign,\n" % object.name)
+ if hasattr(object,'helptext'):
+ gloutfile.write(" 'docstring' => '%s');\n\n" % object.helptext)
+ else:
+ gloutfile.write(" 'docstring' => 'Some Procedure');\n\n")
+
+ gloutfile.write("function %s_func ($message) {\n" % object.name )
+
+ count=0
+ if hasattr(object,'_children'):
+ for child in object._children:
+ gloutfile.write(" $%s=$message->getParam(%s);\n" % (child.name,\
+ count))
+ count+=1
+
+ gloutfile.write("\n /* Add your code here.*/\n\n");
+ gloutfile.write("\n error_log('function %s
called',3,'/tmp/log');\n\n"\
+ % object.name );
+
+ procname=""
+
+ ret="nothing"
+
+ if hasattr(object,"return"):
+ ret=getattr(object,"return")
+
+ if ret[:1]=="<" and ret[-1:]==">":
+
+ gloutfile.write("/*Return an object handle is not supported")
+ gloutfile.write(" $s_stub = array(%s...);\n"
+ % procname)
+ gloutfile.write(" return new %s(host,handle)*/" %
+ string.join(string.split(ret[1:-1],"."),"_"))
+
+ elif ret=="nothing":
+ gloutfile.write(" return new xmlrpcresp();\n")
+
+ else:
+ gloutfile.write(" return new xmlrpcresp(new xmlrpcval(result));\n")
+ gloutfile.write(" // result should be of type %s\n" % ret)
+
+ gloutfile.write("}\n")
+
+
+ ##
## Create Javascript exsample
##
def gendocJS(rpcdef, outfile):
***************
*** 243,249 ****
attr=attr+delim+child.name
delim=","
! gloutfile.write(" self.%s = function (%s) {\n" % (object.name,attr) )
if object._parent._type=="RpObject":
procname="'['+this.handle+'].%s'" % object.name
--- 377,383 ----
attr=attr+delim+child.name
delim=","
! gloutfile.write(" this.%s = function (%s) {\n" % (object.name,attr) )
if object._parent._type=="RpObject":
procname="'['+this.handle+'].%s'" % object.name
- gnue-common/src/rpc/drivers/xmlrpc RpcDoc.py,
Jan Ischebeck <=