Changeset 586
- Timestamp:
- Feb 16, 2015, 10:45:52 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/docs/services/howtos.txt
r528 r586 146 146 .. code-block:: python 147 147 148 import zoo 148 149 import sys 149 150 def HelloPy(conf,inputs,outputs): 150 151 outputs["Result"]["value"]="Hello "+inputs["a"]["value"]+" from Python World !" 151 return 3152 return zoo.SERVICE_SUCCEEDED 152 153 153 154 PHP 154 155 --- 155 156 157 ZOO-API 158 ******* 159 160 The ZOO-API for the PHP language is automatically available from your 161 service code. Tthe following functions are defined in the ZOO-API: 162 163 int zoo_SERVICE_SUCCEEDED() 164 return the value of SERVICE_SUCCEEDED 165 int zoo_SERVICE_FAILED() 166 return the value of SERVICE_FAILED 167 string 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 171 void zoo_UpdateStatus(Array conf,string message,int pourcent) 172 update the status of the running service 173 174 PHP ZCFG requirements 175 ********************************** 176 177 The ZCFG file should contain the following : 178 179 serviceType 180 PHP 181 serviceProvider 182 The name of the php script (ie. service.php) to use as a ZOO Service Provider. 183 184 PHP Data Structure used 185 ******************************** 186 187 The three parameters are passed to the PHP function as 188 `Arrays <php.net/manual/language.types.array.php>`__. 189 190 Sample ZOO PHP Services Provider 191 ****************************************** 192 156 193 .. code-block:: php 157 194 158 195 <? 159 196 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(); 162 200 } 163 201 ?> … … 203 241 named ``HelloWorld.class`` then you should use ``HelloWorld``. 204 242 205 206 243 Java Data Structure used 207 244 ******************************** 208 245 209 The three parameters of the function are passed to the Java function210 as`java.util.HashMap <http://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html>`__.246 The 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>`__. 211 248 212 249 Sample ZOO Java Services Provider -
trunk/zoo-project/HISTORY.txt
r576 r586 1 1 Version 1.5.0-dev 2 * Add ZOO-API for the PHP language (with documentation) 3 * Add doxygen comments in source code 2 4 * Add support for multiple Exception nodes 3 5 * Add a length key when creating MapArray 4 * Add O rfeo Toolboxsupport for applications as a service6 * Add OTB support for applications as a service 5 7 * Add the otb2zcfg utility to produce zcfg for otb applications 6 8 * Add OTB Application Observer to have progress status updates -
trunk/zoo-project/zoo-kernel/service_internal_js.c
r581 r586 386 386 * 387 387 * @param cx the JavaScript context 388 * @param global ethe global JavaScript object (not used)388 * @param global the global JavaScript object (not used) 389 389 * @param filename the file name to load 390 390 * @return a JavaScript Object on success, NULL if an errro occured -
trunk/zoo-project/zoo-kernel/service_internal_ms.c
r579 r586 23 23 */ 24 24 25 #ifdef USE_MS 25 /** 26 * Cross platform definition of layerObj->class 27 */ 26 28 #ifndef WIN32 27 29 #define CLASS class … … 32 34 33 35 /** 36 * Get a list of configuration keys having a corresponding mandatory ows_*. 34 37 * Map composed by a main.cfg maps name as key and the corresponding 35 38 * MapServer Mafile Metadata name to use … … 38 41 * - http://mapserver.org/ogc/wfs_server.html 39 42 * - 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"). 40 46 */ 41 47 map* getCorrespondance(){ … … 67 73 } 68 74 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 */ 69 86 void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){ 70 87 double maxWidth=640; … … 104 121 } 105 122 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 */ 106 130 void setReferenceUrl(maps* m,maps* tmpI){ 107 131 outputMapfile(m,tmpI); … … 205 229 206 230 /** 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 209 239 */ 210 240 void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer, … … 299 329 } 300 330 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 */ 301 344 void setMsExtent(maps* output,mapObj* m,layerObj* myLayer, 302 345 double minX,double minY,double maxX,double maxY){ … … 357 400 } 358 401 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 */ 359 409 int tryOgr(maps* conf,maps* output,mapObj* m){ 360 410 … … 663 713 } 664 714 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 */ 666 722 int tryGdal(maps* conf,maps* output,mapObj* m){ 667 723 map* tmpMap=getMap(output->content,"storage"); … … 914 970 /** 915 971 * 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 916 975 */ 917 976 void outputMapfile(maps* conf,maps* outputs){ 918 977 919 978 /** 920 * Firs store the value on disk979 * First store the value on disk 921 980 */ 922 981 map* mime=getMap(outputs->content,"mimeType"); … … 1106 1165 } 1107 1166 1108 #endif -
trunk/zoo-project/zoo-kernel/service_internal_ms.h
r579 r586 24 24 #ifndef ZOO_SERVICE_INTERNAL_MS_H 25 25 #define ZOO_SERVICE_INTERNAL_MS_H 1 26 #ifdef USE_MS27 26 28 27 #include <sys/stat.h> … … 44 43 extern "C" { 45 44 #endif 46 //#include <mapserver.h>47 /**48 * Map composed by a main.cfg maps name as key and the corresponding49 * MapServer Mafile Metadata name to use50 * see doc from here :51 * - http://mapserver.org/ogc/wms_server.html52 * - http://mapserver.org/ogc/wfs_server.html53 * - http://mapserver.org/ogc/wcs_server.html54 */55 45 map* getCorrespondance(); 56 46 void setMapSize(maps* output,double minx,double miny,double maxy,double maxx); 57 47 void setReferenceUrl(maps* m,maps* tmpI); 58 48 59 /**60 * Set projection using Authority Code and Name if available or fallback to61 * proj4 definition if available or fallback to default EPSG:432662 */63 49 void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer, char* pszProjection); 64 50 … … 68 54 69 55 int tryGdal(maps* conf,maps* output,mapObj* m); 70 /**71 * Create a MapFile for WMS, WFS or WCS Service output72 */73 56 void outputMapfile(maps* conf,maps* outputs); 74 57 #ifdef __cplusplus … … 77 60 78 61 #endif 79 #endif80 62 -
trunk/zoo-project/zoo-kernel/service_internal_php.c
r580 r586 32 32 #include <zend_stream.h> 33 33 34 #ifdef ZTS35 void ***tsrm_ls;36 #endif37 38 34 zval *php_Array_from_maps(maps* t); 39 35 zval* php_Array_from_map(map*); 40 36 maps* php_maps_from_Array(HashTable* t); 41 37 map* php_map_from_HasTable(HashTable* t); 38 39 #ifdef ZTS 40 void ***tsrm_ls; 41 #endif 42 43 ZEND_BEGIN_MODULE_GLOBALS(zoo) 44 long _SERVICE_SUCCEEDED; 45 long _SERVICE_FAILED; 46 ZEND_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 57 PHP_MINIT_FUNCTION(zoo); 58 PHP_MSHUTDOWN_FUNCTION(zoo); 59 PHP_RINIT_FUNCTION(zoo); 60 61 PHP_FUNCTION(zoo_Translate); 62 PHP_FUNCTION(zoo_UpdateStatus); 63 PHP_FUNCTION(zoo_SERVICE_SUCCEEDED); 64 PHP_FUNCTION(zoo_SERVICE_FAILED); 65 66 extern zend_module_entry zoo_module_entry; 67 #define phpext_zoo_ptr &zoo_entry 68 69 ZEND_DECLARE_MODULE_GLOBALS(zoo) 70 71 static 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 79 zend_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 96 ZEND_GET_MODULE(zoo) 97 98 PHP_INI_BEGIN() 99 PHP_INI_END() 100 101 static void 102 php_zoo_init_globals(zend_zoo_globals *zoo_globals) 103 { 104 zoo_globals->_SERVICE_SUCCEEDED=3; 105 zoo_globals->_SERVICE_FAILED=4; 106 } 107 108 PHP_RINIT_FUNCTION(zoo) 109 { 110 return SUCCESS; 111 } 112 113 PHP_MINIT_FUNCTION(zoo) 114 { 115 ZEND_INIT_MODULE_GLOBALS(zoo, php_zoo_init_globals,NULL); 116 REGISTER_INI_ENTRIES(); 117 return SUCCESS; 118 } 119 120 PHP_MSHUTDOWN_FUNCTION(zoo) 121 { 122 UNREGISTER_INI_ENTRIES(); 123 return SUCCESS; 124 } 125 126 PHP_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 136 PHP_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 158 PHP_FUNCTION(zoo_SERVICE_SUCCEEDED) 159 { 160 RETURN_LONG(ZOO_G(_SERVICE_SUCCEEDED)); 161 } 162 163 PHP_FUNCTION(zoo_SERVICE_FAILED) 164 { 165 RETURN_LONG(ZOO_G(_SERVICE_FAILED)); 166 } 42 167 43 168 /** … … 62 187 63 188 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 } 64 199 zend_file_handle iscript; 65 iscript.type=ZEND_HANDLE_FP; 200 iscript.type=ZEND_HANDLE_FD; 201 iscript.opened_path=NULL; 66 202 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){ 70 206 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); 79 214 80 215 zend_try { 81 216 zend_startup_module(&zoo_module_entry); 82 217 php_execute_script(&iscript TSRMLS_CC); 83 84 218 zval *iargs[3]; 85 219 zval iret, ifunc,ifile; … … 89 223 iargs[1] = php_Array_from_maps(*real_inputs); 90 224 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 } 101 239 } 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);; 106 243 } zend_end_try(); 107 244 free(scriptName); 245 fclose(temp); 108 246 php_embed_shutdown(TSRMLS_C); 109 247 … … 216 354 if(final_res==NULL) 217 355 final_res=cursor; 218 else 356 else{ 219 357 addMapsToMaps(&final_res,cursor); 358 freeMaps(&cursor); 359 free(cursor); 360 } 220 361 #ifdef DEBUG 221 362 fprintf(stderr,"key : %s\n",key); … … 289 430 return final_res; 290 431 } 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 26 26 27 27 function 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(); 31 32 } 32 33
Note: See TracChangeset
for help on using the changeset viewer.