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

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

Make ZOO Kernel able to speak the natural language you teach him by using gettext tools for creating translation files. Add basic french translation .po files as current messages.po. Gettext Domains used are zoo-kernel and zoo-services.

File size: 5.1 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
25#include "service.h"
26
27extern "C" {
28#include <libxml/tree.h>
29#include <libxml/parser.h>
30#include <libxml/xpath.h>
31#include <libxml/xpathInternals.h>
32
33#include <libxslt/xslt.h>
34#include <libxslt/xsltInternals.h>
35#include <libxslt/transform.h>
36#include <libxslt/xsltutils.h>
37
38#include <dirent.h>
39#include "service_internal.h"
40
41  /**
42   * GetStatus ZOO Service :
43   * This service is used in the ZOO-Project to get information about Services
44   * running as background tasks. The service will first get the XML document
45   * cached by the ZOO-Kernel before calling effectively the Service, then
46   * will access the shared memory space created by the Kernel to extract the
47   * current status of the running Service. Using a simple XSL file it will
48   * finally produce the final ExecuteResponse including the updated
49   * percentCompleted attribute of the ProcessStarted node of the cached
50   * document if any (so if the Service is currently running) else it will
51   * return the final ExecuteResponse stored on the Server file system.
52   */
53#ifdef WIN32
54  __declspec(dllexport)
55#endif
56  int GetStatus(maps*& conf,maps*& inputs,maps*& outputs){
57    const char *params[2 + 1];
58    int xmlLoadExtDtdDefaultValue;
59    map* tmpMap=NULL,*tmpMmap=NULL, *tmpTmap=NULL;
60    tmpMap=getMapFromMaps(inputs,"sid","value");
61    tmpTmap=getMapFromMaps(conf,"main","tmpPath");
62    tmpMmap=getMapFromMaps(conf,"main","dataPath");
63    xmlInitParser();
64    struct dirent *dp;
65    DIR *dirp = opendir(tmpTmap->value);
66    char fileName[1024],xslFileName[1024];
67    int hasFile=-1;
68    if(dirp!=NULL){
69      char tmp[128];
70      sprintf(tmp,"_%s.xml",tmpMap->value);
71      while ((dp = readdir(dirp)) != NULL)
72        if(strstr(dp->d_name,tmp)!=0){
73          sprintf(fileName,"%s/%s",tmpTmap->value,dp->d_name);
74          hasFile=1;
75        }
76    }else{
77      char tmp[1024];
78      snprintf(tmp,1024,_ss("GetStatus was unable to use the tmpPath value set in main.cfg file as directory %s."),tmpTmap->value);
79      setMapInMaps(conf,"lenv","message",tmp);
80      return SERVICE_FAILED;
81    }
82    if(hasFile<0){
83      char tmp[1024];
84      snprintf(tmp,1024,_ss("GetStatus was unable to find any cache file for Service ID %s."),tmpMap->value);
85      setMapInMaps(conf,"lenv","message",tmp);
86      return SERVICE_FAILED;
87    }
88    sprintf(xslFileName,"%s/updateStatus.xsl",tmpMmap->value);
89    xmlSubstituteEntitiesDefault(1);
90    xmlLoadExtDtdDefaultValue = 0;
91    xsltStylesheetPtr cur = NULL;
92    xmlDocPtr doc, res;
93    cur = xsltParseStylesheetFile(BAD_CAST xslFileName);
94    doc = xmlParseFile(fileName);
95    if(cur!=NULL && doc!=NULL){
96      params[0]="value";
97      params[1]=getStatus(atoi(tmpMap->value));
98      params[2]=NULL;
99      res = xsltApplyStylesheet(cur, doc, params);
100      xmlChar *xmlbuff;
101      int buffersize;
102      xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1);
103      setMapInMaps(outputs,"Result","value",(char*)xmlbuff);
104      setMapInMaps(outputs,"Result","mimeType","text/xml");
105      setMapInMaps(outputs,"Result","encoding","UTF-8");
106      xmlFree(xmlbuff);
107    }
108    else{
109      char tmp[1024];
110      sprintf(tmp,_ss("ZOO GetStatus Service was unable to parse the cache xml file available for the Service ID %s."),tmpMap->value);
111      setMapInMaps(conf,"lenv","message",tmp);
112      return SERVICE_FAILED;
113    }
114    return SERVICE_SUCCEEDED;
115  }
116
117
118  /**
119   * longProcess ZOO Service :
120   * Simple Service which just loop over 100 times then return a welcome message
121   * string, at each step the service will sleep for one second.
122   */
123#ifdef WIN32
124  __declspec(dllexport)
125#endif
126  int longProcess(maps*& conf,maps*& inputs,maps*& outputs){
127    int i=0;
128    while(i<100){
129      char tmp[4];
130      sprintf(tmp,"%i",i);
131      map* tmpMap=NULL;
132      tmpMap=getMapFromMaps(conf,"lenv","sid");
133      if(tmpMap!=NULL)
134        fprintf(stderr,"Status %s %s\n",tmpMap->value,tmp);
135      setMapInMaps(conf,"lenv","status",tmp);
136      updateStatus(conf);
137      sleep(1);
138      i+=5;
139    }
140    setMapInMaps(outputs,"Result","value","\"Running long process successfully\"");
141    return SERVICE_SUCCEEDED;
142  }
143
144}
Note: See TracBrowser for help on using the repository browser.

Search

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