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

Last change on this file since 680 was 680, checked in by djay, 9 years ago

Various fixes for Windows support: generate uuid using UuidCreate?, pass usid to the created process, call TerminateProcess? on dismiss request.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 5.2 KB
RevLine 
[26]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 */
[34]24
[26]25#include "service.h"
[384]26#include "service_internal.h"
[26]27
28extern "C" {
29#include <libxml/tree.h>
30#include <libxml/parser.h>
31#include <libxml/xpath.h>
32#include <libxml/xpathInternals.h>
33
34#include <libxslt/xslt.h>
35#include <libxslt/xsltInternals.h>
36#include <libxslt/transform.h>
37#include <libxslt/xsltutils.h>
38
39#include <dirent.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   */
[680]53  ZOO_DLL_EXPORT int GetStatus(maps*& conf,maps*& inputs,maps*& outputs){
[440]54    const char *params[4 + 1];
[26]55    int xmlLoadExtDtdDefaultValue;
56    map* tmpMap=NULL,*tmpMmap=NULL, *tmpTmap=NULL;
[440]57
[26]58    tmpMap=getMapFromMaps(inputs,"sid","value");
59    tmpTmap=getMapFromMaps(conf,"main","tmpPath");
60    tmpMmap=getMapFromMaps(conf,"main","dataPath");
[495]61    if(tmpMmap==NULL)
62      tmpMmap=tmpTmap;
[26]63    xmlInitParser();
[32]64    int hasFile=-1;
[652]65    char xslFileName[1024];
66    char* mem=_getStatusFile(conf,tmpMap->value);
67    if(mem==NULL){
[32]68      char tmp[1024];
[34]69      snprintf(tmp,1024,_ss("GetStatus was unable to find any cache file for Service ID %s."),tmpMap->value);
[32]70      setMapInMaps(conf,"lenv","message",tmp);
71      return SERVICE_FAILED;
72    }
[26]73    sprintf(xslFileName,"%s/updateStatus.xsl",tmpMmap->value);
74    xmlSubstituteEntitiesDefault(1);
75    xmlLoadExtDtdDefaultValue = 0;
76    xsltStylesheetPtr cur = NULL;
77    xmlDocPtr doc, res;
78    cur = xsltParseStylesheetFile(BAD_CAST xslFileName);
[652]79    doc = xmlParseMemory(mem,strlen(mem));
80    //doc = xmlParseFile(fileName);
[26]81    if(cur!=NULL && doc!=NULL){
[440]82      /**
83       * Parse Status to extract Status / Message
84       */
[652]85      char *tmpStr=_getStatus(conf,tmpMap->value);
[478]86#ifdef DEBUG
[471]87      fprintf(stderr,"DEBUG: %s \n",tmpStr);
[478]88#endif
[440]89      if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
90        char *tmpStr1=strdup(tmpStr);
91        char *tmpStr0=strdup(strstr(tmpStr,"|")+1);
[515]92        free(tmpStr);
[440]93        tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
94        char *tmpStrFinal=(char*)malloc((strlen(tmpStr0)+11)*sizeof(char));
95        sprintf(tmpStrFinal,"string(\"%s\")",tmpStr0);
96        params[0]="value";
97        params[1]=tmpStr1;
98        params[2]="message";
99        params[3]=tmpStrFinal;
100        params[4]=NULL;
101        res = xsltApplyStylesheet(cur, doc, params);
102        xmlChar *xmlbuff;
103        int buffersize;
104        xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1);
105        setMapInMaps(outputs,"Result","value",(char*)xmlbuff);
106        xmlFree(xmlbuff);
107        free(tmpStr1);
108        free(tmpStr0);
109        free(tmpStrFinal);
110      }else{
111        xmlChar *xmlbuff;
112        int buffersize;
113        xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
114        setMapInMaps(outputs,"Result","value",(char*)xmlbuff);
115        xmlFree(xmlbuff);
116      }
[26]117    }
[32]118    else{
[26]119      char tmp[1024];
[34]120      sprintf(tmp,_ss("ZOO GetStatus Service was unable to parse the cache xml file available for the Service ID %s."),tmpMap->value);
[26]121      setMapInMaps(conf,"lenv","message",tmp);
122      return SERVICE_FAILED;
123    }
124    return SERVICE_SUCCEEDED;
125  }
126
127
128  /**
129   * longProcess ZOO Service :
130   * Simple Service which just loop over 100 times then return a welcome message
131   * string, at each step the service will sleep for one second.
132   */
133#ifdef WIN32
134  __declspec(dllexport)
135#endif
136  int longProcess(maps*& conf,maps*& inputs,maps*& outputs){
137    int i=0;
138    while(i<100){
[440]139      char message[10];
140      sprintf(message,"Step %d",i);
[471]141      updateStatus(conf,i,message);
[216]142#ifndef WIN32
[26]143      sleep(1);
[216]144#else
145      Sleep(1000);
146#endif
[26]147      i+=5;
148    }
[643]149    setOutputValue(outputs,"Result",(char*)"\"Long process run successfully\"",-1);
[26]150    return SERVICE_SUCCEEDED;
151  }
152
153}
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