Changeset 586


Ignore:
Timestamp:
Feb 16, 2015, 10:45:52 PM (10 years ago)
Author:
djay
Message:

Add the PHP ZOO-API, fix issue if ZTS is not defined, correct loading of the PHP script depending of the ZOO-Kernel location, use a ZEND_HANDLE_FD rather than the ZEND_HANDLE_FP used before, correct location of the hello.php service.

Location:
trunk
Files:
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/docs/services/howtos.txt

    r528 r586  
    146146.. code-block:: python
    147147
     148  import zoo
    148149  import sys
    149150  def HelloPy(conf,inputs,outputs):
    150151     outputs["Result"]["value"]="Hello "+inputs["a"]["value"]+" from Python World !"
    151      return 3
     152     return zoo.SERVICE_SUCCEEDED
    152153
    153154PHP
    154155---
    155156
     157ZOO-API
     158*******
     159
     160The ZOO-API for the PHP language is automatically available from your
     161service code. Tthe following functions are defined in the ZOO-API:
     162
     163int zoo_SERVICE_SUCCEEDED()
     164    return the value of SERVICE_SUCCEEDED
     165int zoo_SERVICE_FAILED()
     166    return the value of SERVICE_FAILED
     167string zoo_Translate(string a)
     168    return the translated string (using the "zoo-service" `textdomain
     169    <http://www.gnu.org/software/libc/manual/html_node/Locating-gettext-catalog.html#index-textdomain>`__)
     170
     171void zoo_UpdateStatus(Array conf,string message,int pourcent)
     172    update the status of the running service
     173
     174PHP ZCFG requirements
     175**********************************
     176
     177The ZCFG file should contain the following :
     178
     179serviceType
     180    PHP
     181serviceProvider
     182    The name of the php script (ie. service.php) to use as a ZOO Service Provider.
     183
     184PHP Data Structure used
     185********************************
     186
     187The three parameters are passed to the PHP function as
     188`Arrays <php.net/manual/language.types.array.php>`__.
     189
     190Sample ZOO PHP Services Provider
     191******************************************
     192
    156193.. code-block:: php
    157194
    158195  <?
    159196  function HelloPHP(&$main_conf,&$inputs,&$outputs){
    160      $outputs["Result"]["value"]="Hello ".$inputs[S][value]." from PHP world !";
    161      return 3;
     197     $tmp="Hello ".$inputs[S][value]." from PHP world !";
     198     $outputs["Result"]["value"]=zoo_Translate($tmp)
     199     return zoo_SERVICE_SUCCEEDED();
    162200  }
    163201  ?>
     
    203241    named ``HelloWorld.class`` then you should use ``HelloWorld``.
    204242
    205 
    206243Java Data Structure used
    207244********************************
    208245
    209 The three parameters of the function are passed to the Java function
    210 as `java.util.HashMap <http://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html>`__.
     246The three parameters are passed to the Java function as
     247`java.util.HashMap <http://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html>`__.
    211248
    212249Sample ZOO Java Services Provider
  • trunk/zoo-project/HISTORY.txt

    r576 r586  
    11Version 1.5.0-dev
     2  * Add ZOO-API for the PHP language (with documentation)
     3  * Add doxygen comments in source code
    24  * Add support for multiple Exception nodes
    35  * Add a length key when creating MapArray
    4   * Add Orfeo Toolbox support for applications as a service
     6  * Add OTB support for applications as a service
    57  * Add the otb2zcfg utility to produce zcfg for otb applications
    68  * Add OTB Application Observer to have progress status updates
  • trunk/zoo-project/zoo-kernel/service_internal_js.c

    r581 r586  
    386386 *
    387387 * @param cx the JavaScript context
    388  * @param globale the global JavaScript object (not used)
     388 * @param global the global JavaScript object (not used)
    389389 * @param filename the file name to load
    390390 * @return a JavaScript Object on success, NULL if an errro occured
  • trunk/zoo-project/zoo-kernel/service_internal_ms.c

    r579 r586  
    2323 */
    2424
    25 #ifdef USE_MS
     25/**
     26 * Cross platform definition of layerObj->class
     27 */
    2628#ifndef WIN32
    2729#define CLASS class
     
    3234
    3335/**
     36 * Get a list of configuration keys having a corresponding mandatory ows_*.
    3437 * Map composed by a main.cfg maps name as key and the corresponding
    3538 * MapServer Mafile Metadata name to use
     
    3841 *  - http://mapserver.org/ogc/wfs_server.html
    3942 *  - http://mapserver.org/ogc/wcs_server.html
     43 *
     44 * @return a new map containing a table linking a name of a configuration key
     45 * to a corresponding mandatory ows_* keyword (ie. "fees" => "ows_fees").
    4046 */
    4147map* getCorrespondance(){
     
    6773}
    6874
     75/**
     76 * Add width and height keys to an output maps containing the maximum width
     77 * and height for displaying the full data extent.
     78 * Restriction to an image having a size of 640x480 (width * height)
     79 *
     80 * @param output
     81 * @param minx the lower left x coordinate
     82 * @param miny the lower left y coordinate
     83 * @param maxx the upper right x coordinate
     84 * @param maxy the upper right y coordinate
     85 */
    6986void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){
    7087  double maxWidth=640;
     
    104121}
    105122
     123/**
     124 * Add a Reference key to an output containing the WMFS/WFS/WCS request for
     125 * accessing service result
     126 *
     127 * @param m the conf maps containing the main.cfg settings
     128 * @param tmpI the specific output maps to add the Reference key
     129 */
    106130void setReferenceUrl(maps* m,maps* tmpI){
    107131  outputMapfile(m,tmpI);
     
    205229
    206230/**
    207  * Set projection using Authority Code and Name if available or fallback to
    208  * proj4 definition if available or fallback to default EPSG:4326
     231 * Set projection for a layer in a MAPFILE using Authority Code and Name if
     232 * available or fallback to proj4 definition if available or fallback to
     233 * default EPSG:4326
     234 *
     235 * @param output the output maps
     236 * @param m the opened mapObj
     237 * @param myLayer the layerObj
     238 * @param pszProjection a char* containing the SRS definition in WKT format
    209239 */
    210240void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer,
     
    299329}
    300330
     331/**
     332 * Set the MAPFILE extent, the the ows_extent for the layer, add wms_extent and
     333 * wfs_extent to the output maps and call setMapSize.
     334 *
     335 * @param output the specific output
     336 * @param m the mapObj
     337 * @param myLayer the layerObj
     338 * @param minX the lower left x coordinate
     339 * @param minY the lower left y coordinate
     340 * @param maxX the upper right x coordinate
     341 * @param maxY the upper right y coordinate
     342 * @see setMapSize
     343 */
    301344void setMsExtent(maps* output,mapObj* m,layerObj* myLayer,
    302345                 double minX,double minY,double maxX,double maxY){
     
    357400}
    358401
     402/**
     403 * Try to open a vector output and define the corresponding layer in the MAPFILE
     404 *
     405 * @param conf the conf maps containing the main.cfg settings
     406 * @param output the specific output maps
     407 * @param m the mapObj
     408 */
    359409int tryOgr(maps* conf,maps* output,mapObj* m){
    360410
     
    663713}
    664714
    665 
     715/**
     716 * Try to open a raster output and define the corresponding layer in the MAPFILE
     717 *
     718 * @param conf the conf maps containing the main.cfg settings
     719 * @param output the specific output maps
     720 * @param m the mapObj
     721 */
    666722int tryGdal(maps* conf,maps* output,mapObj* m){
    667723  map* tmpMap=getMap(output->content,"storage");
     
    914970/**
    915971 * Create a MapFile for WMS, WFS or WCS Service output
     972 *
     973 * @param conf the conf maps containing the main.cfg settings
     974 * @param outputs a specific output maps
    916975 */
    917976void outputMapfile(maps* conf,maps* outputs){
    918977
    919978  /**
    920    * Firs store the value on disk
     979   * First store the value on disk
    921980   */
    922981  map* mime=getMap(outputs->content,"mimeType");
     
    11061165}
    11071166
    1108 #endif
  • trunk/zoo-project/zoo-kernel/service_internal_ms.h

    r579 r586  
    2424#ifndef ZOO_SERVICE_INTERNAL_MS_H
    2525#define ZOO_SERVICE_INTERNAL_MS_H 1
    26 #ifdef USE_MS
    2726
    2827#include <sys/stat.h>
     
    4443extern "C" {
    4544#endif
    46   //#include <mapserver.h>
    47   /**
    48    * Map composed by a main.cfg maps name as key and the corresponding
    49    * MapServer Mafile Metadata name to use
    50    * see doc from here :
    51    *  - http://mapserver.org/ogc/wms_server.html
    52    *  - http://mapserver.org/ogc/wfs_server.html
    53    *  - http://mapserver.org/ogc/wcs_server.html
    54    */
    5545  map* getCorrespondance();
    5646  void setMapSize(maps* output,double minx,double miny,double maxy,double maxx);
    5747  void setReferenceUrl(maps* m,maps* tmpI);
    5848
    59   /**
    60    * Set projection using Authority Code and Name if available or fallback to
    61    * proj4 definition if available or fallback to default EPSG:4326
    62    */
    6349  void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer, char* pszProjection);
    6450 
     
    6854 
    6955  int tryGdal(maps* conf,maps* output,mapObj* m);
    70   /**
    71    * Create a MapFile for WMS, WFS or WCS Service output
    72    */
    7356  void outputMapfile(maps* conf,maps* outputs);
    7457#ifdef __cplusplus
     
    7760
    7861#endif
    79 #endif
    8062 
  • trunk/zoo-project/zoo-kernel/service_internal_php.c

    r580 r586  
    3232#include <zend_stream.h>
    3333
    34 #ifdef ZTS
    35 void ***tsrm_ls;
    36 #endif
    37 
    3834zval *php_Array_from_maps(maps* t);
    3935zval*  php_Array_from_map(map*);
    4036maps* php_maps_from_Array(HashTable* t);
    4137map* php_map_from_HasTable(HashTable* t);
     38
     39#ifdef ZTS
     40void ***tsrm_ls;
     41#endif
     42
     43ZEND_BEGIN_MODULE_GLOBALS(zoo)
     44long _SERVICE_SUCCEEDED;
     45long _SERVICE_FAILED;
     46ZEND_END_MODULE_GLOBALS(zoo)
     47
     48#ifdef ZTS
     49#define ZOO_G(v) TSRMG(zoo_globals_id, zend_zoo_globals *, v)
     50#else
     51#define ZOO_G(v) (zoo_globals.v)
     52#endif
     53
     54#define PHP_ZOO_VERSION "1.0"
     55#define PHP_ZOO_EXTNAME "ZOO"
     56
     57PHP_MINIT_FUNCTION(zoo);
     58PHP_MSHUTDOWN_FUNCTION(zoo);
     59PHP_RINIT_FUNCTION(zoo);
     60
     61PHP_FUNCTION(zoo_Translate);
     62PHP_FUNCTION(zoo_UpdateStatus);
     63PHP_FUNCTION(zoo_SERVICE_SUCCEEDED);
     64PHP_FUNCTION(zoo_SERVICE_FAILED);
     65
     66extern zend_module_entry zoo_module_entry;
     67#define phpext_zoo_ptr &zoo_entry
     68
     69ZEND_DECLARE_MODULE_GLOBALS(zoo)
     70
     71static zend_function_entry zoo_functions[] = {
     72  PHP_FE(zoo_Translate, NULL)
     73  PHP_FE(zoo_UpdateStatus, NULL)
     74  PHP_FE(zoo_SERVICE_SUCCEEDED, NULL)
     75  PHP_FE(zoo_SERVICE_FAILED, NULL)
     76  {NULL, NULL, NULL}
     77};
     78
     79zend_module_entry zoo_module_entry = {
     80#if ZEND_MODULE_API_NO >= 20010901
     81    STANDARD_MODULE_HEADER,
     82#endif
     83    PHP_ZOO_EXTNAME,
     84    zoo_functions,
     85    PHP_MINIT(zoo),
     86    PHP_MSHUTDOWN(zoo),
     87    PHP_RINIT(zoo),
     88    NULL,
     89    NULL,
     90#if ZEND_MODULE_API_NO >= 20010901
     91    PHP_ZOO_VERSION,
     92#endif
     93    STANDARD_MODULE_PROPERTIES
     94};
     95
     96ZEND_GET_MODULE(zoo)
     97
     98PHP_INI_BEGIN()
     99PHP_INI_END()
     100
     101static void
     102php_zoo_init_globals(zend_zoo_globals *zoo_globals)
     103{
     104  zoo_globals->_SERVICE_SUCCEEDED=3;
     105  zoo_globals->_SERVICE_FAILED=4;
     106}
     107
     108PHP_RINIT_FUNCTION(zoo)
     109{
     110  return SUCCESS;
     111}
     112
     113PHP_MINIT_FUNCTION(zoo)
     114{
     115  ZEND_INIT_MODULE_GLOBALS(zoo, php_zoo_init_globals,NULL);
     116  REGISTER_INI_ENTRIES();
     117  return SUCCESS;
     118}
     119
     120PHP_MSHUTDOWN_FUNCTION(zoo)
     121{
     122  UNREGISTER_INI_ENTRIES();
     123  return SUCCESS;
     124}
     125
     126PHP_FUNCTION(zoo_Translate)
     127{
     128  char *value;
     129  int value_len;
     130  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
     131    RETURN_NULL();
     132  }
     133  RETURN_STRING(_ss(value), 1);
     134}
     135
     136PHP_FUNCTION(zoo_UpdateStatus)
     137{
     138  zval *arr;
     139  char *message;
     140  int message_len;
     141  long pourcent;
     142  char *status=(char*)malloc(4*sizeof(char));
     143  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "asl", &arr, &message, &message_len,&pourcent) == FAILURE) {
     144    RETURN_NULL();
     145  }
     146  HashTable* t=HASH_OF(arr);
     147  maps* conf=php_maps_from_Array(t);
     148  setMapInMaps(conf,"lenv","message",message);
     149  sprintf(status,"%d",pourcent);
     150  setMapInMaps(conf,"lenv","status",status);
     151  _updateStatus(conf);
     152  freeMaps(&conf);
     153  free(conf);
     154  free(status);
     155  RETURN_NULL();
     156}
     157
     158PHP_FUNCTION(zoo_SERVICE_SUCCEEDED)
     159{
     160  RETURN_LONG(ZOO_G(_SERVICE_SUCCEEDED));
     161}
     162
     163PHP_FUNCTION(zoo_SERVICE_FAILED)
     164{
     165  RETURN_LONG(ZOO_G(_SERVICE_FAILED));
     166}
    42167
    43168/**
     
    62187
    63188  tmp=getMap(s->content,"serviceProvider");
     189  map* cwd=getMapFromMaps(m,"lenv","cwd");
     190  map* mp=getMap(request,"metapath");
     191  char *scriptName;
     192  if(mp!=NULL && strlen(mp->value)>0){
     193    scriptName=(char*)malloc((strlen(cwd->value)+strlen(mp->value)+strlen(tmp->value)+3)*sizeof(char));
     194    sprintf(scriptName,"%s/%s/%s",cwd->value,mp->value,tmp->value);
     195  }else{
     196    scriptName=(char*)malloc((strlen(cwd->value)+strlen(tmp->value)+2)*sizeof(char));
     197    sprintf(scriptName,"%s/%s",cwd->value,tmp->value);
     198  }
    64199  zend_file_handle iscript;
    65   iscript.type=ZEND_HANDLE_FP;
     200  iscript.type=ZEND_HANDLE_FD;
     201  iscript.opened_path=NULL;
    66202  iscript.filename=tmp->value;
    67   iscript.opened_path=NULL;
    68   //iscript.free_filname=0;
    69   if(!(iscript.handle.fp=fopen(iscript.filename,"rb"))){
     203  iscript.free_filename=0;
     204  FILE* temp=fopen(scriptName,"rb");
     205  if(temp==NULL){
    70206    char tmp1[1024];
    71     sprintf(tmp1,"Unable to load PHP file %s",tmp->value);
    72     map* err=createMap("text",tmp1);
    73     addToMap(err,"code","NoApplicableCode");
    74     printExceptionReportResponse(m,err);
    75     exit(-1);
    76   }
    77 
    78   php_embed_init(0,NULL,&tsrm_ls);
     207    sprintf(tmp1,_("Unable to load the PHP file %s"),tmp->value);
     208    free(scriptName);
     209    return errorException(m,tmp1,"NoApplicableCode",NULL);
     210  }
     211  iscript.handle.fd=fileno(temp);
     212
     213  php_embed_init(0,NULL PTSRMLS_CC);
    79214   
    80215  zend_try {
    81 
     216    zend_startup_module(&zoo_module_entry);
    82217    php_execute_script(&iscript TSRMLS_CC);
    83 
    84218    zval *iargs[3];
    85219    zval iret, ifunc,ifile;
     
    89223    iargs[1] = php_Array_from_maps(*real_inputs);
    90224    iargs[2] = php_Array_from_maps(*real_outputs);
    91    
    92     call_user_function(EG(function_table), NULL, &ifunc, &iret, 3, iargs TSRMLS_CC);
    93 
    94     HashTable* t=HASH_OF(iargs[2]);
    95     *real_outputs=php_maps_from_Array(t);
    96    
    97     char tmp1[1024];
    98 
    99     res=SERVICE_SUCCEEDED;
    100 
     225     
     226    if((res=call_user_function(EG(function_table), NULL, &ifunc, &iret, 3, iargs TSRMLS_CC))==SUCCESS){
     227     
     228      HashTable* t=HASH_OF(iargs[2]);
     229      HashTable* t1=HASH_OF(iargs[0]);
     230      *real_outputs=php_maps_from_Array(t);
     231      *main_conf=php_maps_from_Array(t1);
     232
     233      res=Z_LVAL(iret);
     234    }else{
     235      free(scriptName);
     236      fclose(temp);
     237      return errorException(m,"Unable to process.","NoApplicableCode",NULL);;
     238    }
    101239  } zend_catch {
    102     map* err=createMap("text","Unable to process.");
    103     addToMap(err,"code","NoApplicableCode");
    104     printExceptionReportResponse(m,err);
    105     exit(-1);
     240    free(scriptName);
     241    fclose(temp);
     242    return errorException(m,"Unable to process.","NoApplicableCode",NULL);;
    106243  } zend_end_try();
    107 
     244  free(scriptName);
     245  fclose(temp);
    108246  php_embed_shutdown(TSRMLS_C);
    109247
     
    216354    if(final_res==NULL)
    217355      final_res=cursor;
    218     else
     356    else{
    219357      addMapsToMaps(&final_res,cursor);
     358      freeMaps(&cursor);
     359      free(cursor);
     360    }
    220361#ifdef DEBUG
    221362    fprintf(stderr,"key : %s\n",key);
     
    289430  return final_res;
    290431}
    291 
    292 
    293 
    294 
    295 
    296 
    297 
    298 
    299 
    300 
    301 
    302 
    303 
    304 
  • trunk/zoo-project/zoo-services/hello-php/cgi-env/hello.php

    r573 r586  
    2626
    2727function HelloPHP(&$main_conf,&$inputs,&$outputs){
    28   $outputs=Array();
    29   $outputs["Result"]["value"]="Hello ".$inputs[S][value]." from the PHP world !!";
    30   return 3;
     28  $tmp="Hello ".$inputs["S"]["value"]." from the PHP world !!";
     29  $outputs["Result"]["value"]=zoo_Translate($tmp);
     30  zoo_UpdateStatus($main_conf,"Final step",99);
     31  return zoo_SERVICE_SUCCEEDED();
    3132}
    3233
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png