| 210 | | As you know how to read and access the map fields from a maps, you can now learn how to write in such a datastructure. This is done by using the simple addToMap function once again defined in zoo- kernel/service.h. The addToMap function also takes three parameters : |
| 211 | | |
| 212 | | * m : a map pointer you want to update, |
| 213 | | * n : the name of the map you want to add or update the value, |
| 214 | | * v : the value you want to set for this map. |
| 215 | | |
| 216 | | Here is an example of how to add or edit the content map of a maps called outputs : |
| | 210 | As you know how to read and access the map fields from a maps, you can now learn how to write in such a datastructure. This is done by using the simple addToMap function once again defined in {{{zoo- kernel/service.h}}}. The {{{addToMap}}} function also takes three parameters : |
| | 211 | |
| | 212 | * {{{m}}} : a map pointer you want to update, |
| | 213 | * {{{n}}} : the name of the map you want to add or update the value, |
| | 214 | * {{{v}}} : the value you want to set for this map. |
| | 215 | |
| | 216 | Here is an example of how to add or edit the content {{{map}}} of a {{{maps}}} called {{{outputs}}} : |
| 294 | | The only thing we will focus on is the call to the errorException function used in the function body. This function is declared in the zoo-kernel/service_internal.h and defined in zoo- kernel/service_internal.c file. It takes three parameters as follow : |
| 295 | | |
| 296 | | * the main environment maps, |
| 297 | | * a char* representing the error message to display, |
| 298 | | * a char* representing the error code (as defined in the WPS specification – Table 62). |
| 299 | | |
| 300 | | In other words, if the WFS response cannot be parsed properly, then you will return anExceptionReport document informing the client that a problem occured. |
| | 294 | The only thing we will focus on is the call to the errorException function used in the function body. This function is declared in the {{{zoo-kernel/service_internal.h}}} and defined in {{{zoo- kernel/service_internal.c}}} file. It takes three parameters as follow : |
| | 295 | |
| | 296 | * the main environment {{{maps}}}, |
| | 297 | * a {{{char*}}} representing the error message to display, |
| | 298 | * a {{{char*}}} representing the error code (as defined in the WPS specification – Table 62). |
| | 299 | |
| | 300 | In other words, if the WFS response cannot be parsed properly, then you will return an {{{ExceptionReport}}} document informing the client that a problem occured. |
| 347 | | Once you can access the input geometry object, you can use the OGR_G_GetBoundary function and store the result in the res geometry variable. Then, you only have to store the value in the right format : GeoJSON per default or GML as we declared it as a supported output format. |
| 348 | | |
| 349 | | Please note that ZOO Kernel will give you pre-filled outputs values, so you will only have to fill the value for the key named value, even if in our example we override the mimeType using the text/plain value rather than the application/json (to show that we can also edit other fields of a map). Indeed, depending on the format requested by the client (or the default one) we will provide JSON or GML representation of the geometry. |
| | 353 | Once you can access the input geometry object, you can use the [http://www.gdal.org/ogr/ogr__api_8h.html#a797af4266c02846d52b9cf3207ef958 OGR_G_GetBoundary] function and store the result in the res geometry variable. Then, you only have to store the value in the right format : GeoJSON per default or GML as we declared it as a supported output format. |
| | 354 | |
| | 355 | Please note that ZOO Kernel will give you pre-filled outputs values, so you will only have to fill the value for the key named value, even if in our example we override the mimeType using the {{{text/plain}}} value rather than the {{{application/json}}} (to show that we can also edit other fields of a map). Indeed, depending on the format requested by the client (or the default one) we will provide JSON or GML representation of the geometry. |
| 363 | | The Boundary ZOO Service is now implemented and you need to compile it to produce a Shared Library. As you just used functions defined in service.h (getMapFromMaps and addToMap), you must include this file in your C code. The same requirement is needed to be able to use the errorException function declared in zoo-kernel/service_internal.h, you also must link your service object file to the zoo- kernel/service_internal.o in order to use errorException on runtime. You must then include the required files to access the libxml2 and OGR C-API. |
| 364 | | |
| 365 | | For the need of the Shared Library, you have to put your code in a block declared asextern "C". The final Service code should be stored in a service.c file located in the root of the Services Provider directory (so in /home/zoows/sources/zoo-services/ws_sp). It should look like this : |
| | 369 | The Boundary ZOO Service is now implemented and you need to compile it to produce a Shared Library. As you just used functions defined in service.h ({{{getMapFromMaps}}} and {{{addToMap}}}), you must include this file in your C code. The same requirement is needed to be able to use the errorException function declared in {{{zoo-kernel/service_internal.h}}}, you also must link your service object file to the {{{zoo- kernel/service_internal.o}}} in order to use {{{errorException}}} on runtime. You must then include the required files to access the libxml2 and OGR C-API. |
| | 370 | |
| | 371 | For the need of the Shared Library, you have to put your code in a block declared asextern "C". The final Service code should be stored in a service.c file located in the root of the Services Provider directory (so in {{{/home/zoows/sources/zoo-services/ws_sp}}}). It should look like this : |
| 387 | | Please note that the CLFAGS and LDFLAGS environment variables values must be set before. |
| 388 | | |
| 389 | | The CFLAGS must contain all the requested paths to find included headers, so the path to the directories where the ogr_api.h, libxml2 directory, service.h and service_internal.h files are located. Thanks to the OSGeoLive environment, some of the provided tools can be used to retrieve those values : xml2-config and gdal-config, both used with the --cflags argument. They will produce the desired paths for you. |
| 390 | | |
| 391 | | If you follow the instructions to create your ZOO Services Provider main directory inzoo-services, then you should find the ZOO Kernel headers and source tree which is located in the../../zoo-kernel directory relatively to your current path (/home/user/zoows/sources/zoo-services/ws_sp). Note that you can also use a full path to the zoo-kernel directory but using relative path will let you move your sources tree somewhere else and keep your code compiling using exactly the same command line. So you must add a -I../../zoo-kernel to your CFLAGS to make the compiler able to find the service.h and service_internal.h files. |
| 392 | | |
| 393 | | The full CFLAGS definition should look like this : |
| 394 | | |
| 395 | | {{{ |
| | 393 | Please note that the {{{CFLAGS}}} and {{{LDFLAGS}}} environment variables values must be set before. |
| | 394 | |
| | 395 | The {{{CFLAGS}}} must contain all the requested paths to find included headers, so the path to the directories where the {{{ogr_api.h}}}, libxml2 directory, {{{service.h}}} and {{{service_internal.h}}} files are located. Thanks to the OSGeoLive environment, some of the provided tools can be used to retrieve those values : {{{xml2-config}}} and {{{gdal-config}}}, both used with the {{{--cflags}}} argument. They will produce the desired paths for you. |
| | 396 | |
| | 397 | If you follow the instructions to create your ZOO Services Provider main directory in {{{zoo-services}}}, then you should find the ZOO Kernel headers and source tree which is located in the {{{../../zoo-kernel}}} directory relatively to your current path ({{{/home/user/zoows/sources/zoo-services/ws_sp}}}). Note that you can also use a full path to the zoo-kernel directory but using relative path will let you move your sources tree somewhere else and keep your code compiling using exactly the same command line. So you must add a {{{-I../../zoo-kernel}}} to your {{{CFLAGS}}} to make the compiler able to find the {{{service.h}}} and {{{service_internal.h}}} files. |
| | 398 | |
| | 399 | The full {{{CFLAGS}}} definition should look like this : |
| | 400 | |
| | 401 | {{{ |
| | 402 | #!sh |
| 419 | | Using this Makefile, you should be able to run make from your ZOO Service Provider main directory and to get the resulting ogr_ws_service_provider.zo file located in the cgi-env directory. |
| 420 | | |
| 421 | | The metadata file and the ZOO Service Shared Object are now both located in the cgi-env directory. In order to deploy your new !ServicesProvider, you only have to copy the ZOO Service Shared Object and its corresponding metadata file in the directory where ZOO Kernel is located, so in/usr/lib/cgi-bin. You must use a sudo command to achieve this task: |
| | 427 | Using this {{{Makefile}}}, you should be able to run make from your ZOO Service Provider main directory and to get the resulting {{{ogr_ws_service_provider.zo}}} file located in the {{{cgi-env}}} directory. |
| | 428 | |
| | 429 | The metadata file and the ZOO Service Shared Object are now both located in the {{{cgi-env}}} directory. In order to deploy your new !ServicesProvider, you only have to copy the ZOO Service Shared Object and its corresponding metadata file in the directory where ZOO Kernel is located, so in{{{/usr/lib/cgi-bin}}}. You must use a {{{sudo}}} command to achieve this task: |