source: branches/branch-1.2/zoo-services/arithmetics/test_service.c @ 335

Last change on this file since 335 was 217, checked in by djay, 13 years ago

Merge trunk r111:r216 into branch-1.2

File size: 2.9 KB
Line 
1#include "service.h"
2
3extern "C" {
4
5#ifdef WIN32
6__declspec(dllexport)
7#endif
8  int Multiply(maps*& conf,maps*& inputs,maps*& outputs){
9        fprintf(stderr,"\nService internal print\n");
10        maps* cursor=inputs;
11        int A,B,res;
12        A=0;B=0;
13        if(cursor!=NULL){
14                fprintf(stderr,"\nService internal print\n");
15                dumpMaps(cursor);
16                maps* tmp=getMaps(inputs,"A");
17                if(tmp==NULL)
18                        return SERVICE_FAILED;
19                fprintf(stderr,"\nService internal print\n");
20                dumpMap(tmp->content);
21                map* tmpv=getMap(tmp->content,"value");
22                fprintf(stderr,"\nService internal print\n");
23                A=atoi(tmpv->value);
24                fprintf(stderr,"\nService internal print (A value: %i)\n",A);
25                cursor=cursor->next;
26        }
27        if(cursor!=NULL){
28                maps* tmp=getMaps(cursor,"B");
29                map* tmpv=getMap(tmp->content,"value");
30                if(tmpv==NULL)
31                        return SERVICE_FAILED;
32                B=atoi(tmpv->value);
33                fprintf(stderr,"\nService internal print (B value: %i)\n",B);
34        }
35        res=A*B;
36        outputs=(maps*)malloc(sizeof(maps*));
37        outputs->name="Result";
38        char tmp[256];
39        sprintf(tmp,"%i",res);
40        outputs->content=createMap("value",tmp);
41        addMapToMap(&outputs->content,createMap("datatype","float"));
42        addMapToMap(&outputs->content,createMap("uom","meter"));
43        outputs->next=NULL;
44        dumpMaps(outputs);
45        fprintf(stderr,"\nService internal print\n===\n");
46        return SERVICE_SUCCEEDED;
47  }
48
49  int helloworld1(maps*& conf,maps*& inputs,maps*& outputs){
50    outputs=(maps*)malloc(sizeof(maps*));
51    outputs->name="Result";
52    outputs->content=createMap("value","Hello World");
53    addMapToMap(&outputs->content,createMap("datatype","string"));
54    return SERVICE_SUCCEEDED; 
55  }
56
57  int helloworld(map*& inputs,map*& outputs){
58    outputs=createMap("output_0","Hello World\n");
59    return SERVICE_SUCCEEDED; 
60  }
61
62  int printArguments(map*& inputs,map*& outputs){
63    char *res=(char *)malloc(sizeof(char));
64    map* tmp=inputs;
65    while(tmp!=NULL){
66      res=(char *)realloc(res,strlen(res)+strlen(tmp->value)+strlen(tmp->name)+6);
67      sprintf(res,"%s,\"%s\"=\"%s\"",res,tmp->name,tmp->value);
68      //sprintf(res,"%s,\"%s\"=\"%s\"",res,tmp->name,tmp->value);
69      tmp=tmp->next;
70    }
71    char *tmpVal=strdup(res+1);
72    outputs=createMap("output_0",tmpVal);
73    addToMap(outputs,"output_1",tmpVal);
74
75    /*dumpMap(outputs);
76      dumpMap(inputs);*/
77    return SERVICE_SUCCEEDED; 
78  }
79
80  int buildJsonArrayOfArgs(map*& inputs,map*& outputs){
81    char *res=(char *)malloc(sizeof(char));
82    map* tmp=inputs;
83    while(tmp!=NULL){
84      res=(char *)realloc(res,strlen(res)+strlen(tmp->value)+3);
85      sprintf(res,"%s,\"%s\"",res,tmp->value);
86      tmp=tmp->next;
87    }
88    char *tmpVal;
89    if(strncmp(res,",",1)!=0){
90      free(tmpVal);
91      tmpVal=strdup(res+1);
92      //dumpMap(inputs);     
93    }else
94      tmpVal=strdup(res);
95    tmpVal=(char*)realloc(tmpVal,strlen(tmpVal)+2);
96    sprintf(tmpVal,"[%s]",tmpVal);
97    outputs=createMap("output_0",tmpVal+1);
98    //dumpMap(outputs);
99    //dumpMap(inputs);
100    return SERVICE_SUCCEEDED; 
101  }
102
103}
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