source: trunk/zoo-services/utils/status/service.c @ 26

Last change on this file since 26 was 26, checked in by djay, 14 years ago

ZOO-Kernel updates and bug fixes :

  • Fixing gestion of RawDataOutput? when the Service return SERVICE_FAILED an ExceptionReport? was returned to the client.
  • Use gcc when compiling service_internal.c to avoid strange error messages about switch ....
  • Function setMapInMaps was added in service.h to let users set the value of a specific map in a maps.
  • Fixing JavaScript? issue during the context destruction process.
  • Use the GetStatus? ZOO Service when it is available on the local installation for statusLocation.
  • Add some comments for ServiceStarted?, ServiceSucceeded?, ServiceFailed? and ServiceAccepted?.
  • Dynamic creation of a lenv maps in the main configuration file maps, containing the current status and a sid (Service ID). Those informations can be used later by the GetStatus? Service to let user check the on-going status during the Service runs.
  • Function updateStatus was added to service_internal.h which let the Services developers set the current percentCompleted value.

ZOO-Service updates and bug fixes :

  • Add GetStatus? Service and its demo longProcess Service. All are in the wps_status.zo Services Provider.
  • Use the setMapInMaps in the base-vect-ops code to enhance readibility.

ZOO-API updates :

  • Add the function ZOO.UpdateStatus? to the ZOO JavaScript? API which simply point on ZOOUpdateStatus which can be called as-is from JavaScript?. Use : ZOOUpdateStatus(conf,value) where conf is the main configuration file maps and value the the value of the current status.
File size: 4.8 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#include "service.h"
25
26extern "C" {
27#include <libxml/tree.h>
28#include <libxml/parser.h>
29#include <libxml/xpath.h>
30#include <libxml/xpathInternals.h>
31
32#include <libxslt/xslt.h>
33#include <libxslt/xsltInternals.h>
34#include <libxslt/transform.h>
35#include <libxslt/xsltutils.h>
36
37#include <dirent.h>
38#include "service_internal.h"
39
40  /**
41   * GetStatus ZOO Service :
42   * This service is used in the ZOO-Project to get information about Services
43   * running as background tasks. The service will first get the XML document
44   * cached by the ZOO-Kernel before calling effectively the Service, then
45   * will access the shared memory space created by the Kernel to extract the
46   * current status of the running Service. Using a simple XSL file it will
47   * finally produce the final ExecuteResponse including the updated
48   * percentCompleted attribute of the ProcessStarted node of the cached
49   * document if any (so if the Service is currently running) else it will
50   * return the final ExecuteResponse stored on the Server file system.
51   */
52#ifdef WIN32
53  __declspec(dllexport)
54#endif
55  int GetStatus(maps*& conf,maps*& inputs,maps*& outputs){
56    const char *params[2 + 1];
57    int xmlLoadExtDtdDefaultValue;
58    map* tmpMap=NULL,*tmpMmap=NULL, *tmpTmap=NULL;
59    tmpMap=getMapFromMaps(inputs,"sid","value");
60    tmpTmap=getMapFromMaps(conf,"main","tmpPath");
61    tmpMmap=getMapFromMaps(conf,"main","dataPath");
62    xmlInitParser();
63    struct dirent *dp;
64    DIR *dirp = opendir(tmpTmap->value);
65    char fileName[1024],xslFileName[1024];
66    if(dirp!=NULL){
67      char tmp[128];
68      sprintf(tmp,"_%s.xml",tmpMap->value);
69      while ((dp = readdir(dirp)) != NULL)
70        if(strstr(dp->d_name,tmp)!=0)
71          sprintf(fileName,"%s/%s",tmpTmap->value,dp->d_name);
72    }else{ 
73      setMapInMaps(conf,"lenv","message","GetStatus was unable to use the tmpPath value set in main.cfg file.");
74      return SERVICE_FAILED;
75    }
76    sprintf(xslFileName,"%s/updateStatus.xsl",tmpMmap->value);
77    xmlSubstituteEntitiesDefault(1);
78    xmlLoadExtDtdDefaultValue = 0;
79    xsltStylesheetPtr cur = NULL;
80    xmlDocPtr doc, res;
81    cur = xsltParseStylesheetFile(BAD_CAST xslFileName);
82    doc = xmlParseFile(fileName);
83    if(cur!=NULL && doc!=NULL){
84      params[0]="value";
85      params[1]=getStatus(atoi(tmpMap->value));
86      params[2]=NULL;
87      res = xsltApplyStylesheet(cur, doc, params);
88      xmlChar *xmlbuff;
89      int buffersize;
90      xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1);
91      setMapInMaps(outputs,"Result","value",(char*)xmlbuff);
92      setMapInMaps(outputs,"Result","mimeType","text/xml");
93      setMapInMaps(outputs,"Result","encoding","UTF-8");
94      xmlFree(xmlbuff);
95    }
96    else{   
97      char tmp[1024];
98      sprintf(tmp,"ZOO GetStatus Service was unable to find or parse the cache xml file available for the Service ID %s.",tmpMap->value);
99      setMapInMaps(conf,"lenv","message",tmp);
100      return SERVICE_FAILED;
101    }
102    return SERVICE_SUCCEEDED;
103  }
104
105
106  /**
107   * longProcess ZOO Service :
108   * Simple Service which just loop over 100 times then return a welcome message
109   * string, at each step the service will sleep for one second.
110   */
111#ifdef WIN32
112  __declspec(dllexport)
113#endif
114  int longProcess(maps*& conf,maps*& inputs,maps*& outputs){
115    int i=0;
116    while(i<100){
117      char tmp[4];
118      sprintf(tmp,"%i",i);
119      map* tmpMap=NULL;
120      tmpMap=getMapFromMaps(conf,"lenv","sid");
121      if(tmpMap!=NULL)
122        fprintf(stderr,"Status %s %s\n",tmpMap->value,tmp);
123      setMapInMaps(conf,"lenv","status",tmp);
124      updateStatus(conf);
125      sleep(1);
126      i+=5;
127    }
128    setMapInMaps(outputs,"Result","value","\"Running long process successfully\"");
129    return SERVICE_SUCCEEDED;
130  }
131
132}
Note: See TracBrowser for help on using the repository browser.

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