source: trunk/zoo-services/arithmetics/test_service.c @ 1

Last change on this file since 1 was 1, checked in by djay, 10 years ago

Initial ZOO SVN Repository Import.

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