[1] | 1 | #include "service.h" |
---|
| 2 | |
---|
| 3 | extern "C" { |
---|
| 4 | |
---|
[217] | 5 | #ifdef WIN32 |
---|
| 6 | __declspec(dllexport) |
---|
| 7 | #endif |
---|
[1] | 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 | } |
---|