Ignore:
Timestamp:
May 7, 2019, 2:17:08 PM (5 years ago)
Author:
djay
Message:

Merge prototype-v0 branch in trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/zoo-project/zoo-kernel/service.c

    r889 r917  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2015 GeoLabs SARL
     4 * Copyright (c) 2015-2019 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2828#include <ctime>
    2929#include <chrono>
     30#ifdef WIN32
    3031#include <process.h>
     32#endif
    3133
    3234#if defined(_MSC_VER) && _MSC_VER < 1800
     
    102104    fprintf(stderr," * CONTENT [%s] \n",tmp->name);
    103105    dumpMap(tmp->content);
    104     fprintf(stderr," * CHILD [%s] \n",tmp->name);
    105     dumpMaps(tmp->child);
     106    if(tmp->child!=NULL){
     107      fprintf(stderr," * CHILD [%s] \n",tmp->name);
     108      dumpMaps(tmp->child);
     109      fprintf(stderr," * /CHILD [%s] \n",tmp->name);
     110    }
    106111    tmp=tmp->next;
    107112  }
     
    125130    fflush(file);
    126131    tmp=tmp->next;
    127     cnt++;
    128132    if(limit>=0 && cnt==limit)
    129133      tmp=NULL;
     134    cnt++;
    130135  }
    131136  fflush(file);
     
    144149  fflush(file);
    145150  fclose(file);
     151}
     152
     153/**
     154 * Create a new iotype*
     155 *
     156 * @return a pointer to the allocated iotype
     157 */
     158iotype* createIoType(){
     159  iotype* io=(iotype*)malloc(IOTYPE_SIZE);
     160  io->content=NULL;
     161  io->next=NULL;
     162  return io;
    146163}
    147164
     
    179196 * Count number of map in a map
    180197 *
    181  * @param m the maps to count
     198 * @param m the map to count
    182199 * @return number of map in a map
    183200 */
    184201int count(map* m){
    185202  map* tmp=m;
     203  int c=0;
     204  while(tmp!=NULL){
     205    c++;
     206    tmp=tmp->next;
     207  }
     208  return c;
     209}
     210
     211/**
     212 * Count number of maps in a maps
     213 *
     214 * @param m the maps to count
     215 * @return number of maps in a maps
     216 */
     217int maps_length(maps* m){
     218  maps* tmp=m;
    186219  int c=0;
    187220  while(tmp!=NULL){
     
    401434    if(tmp->metadata!=NULL)
    402435      free(tmp->metadata);
     436    freeMap(&tmp->additional_parameters);
     437    if(tmp->additional_parameters!=NULL)
     438      free(tmp->additional_parameters);
    403439    if(tmp->format!=NULL)
    404440      free(tmp->format);
     441    freeElements(&tmp->child);
    405442    if(tmp->child!=NULL){
    406       freeElements(&tmp->child);
    407443      free(tmp->child);
    408444    }
    409     freeIOType(&tmp->defaults);
    410     if(tmp->defaults!=NULL)
     445    if(tmp->defaults!=NULL){
     446      freeIOType(&tmp->defaults);
    411447      free(tmp->defaults);
    412     freeIOType(&tmp->supported);
     448    }
    413449    if(tmp->supported!=NULL){
     450      freeIOType(&tmp->supported);
    414451      free(tmp->supported);
    415452    }
    416     freeElements(&tmp->next);
    417     if(tmp->next!=NULL)
     453    if(tmp->next!=NULL){
     454      freeElements(&tmp->next);
    418455      free(tmp->next);
    419   }
     456    }
     457  }
     458}
     459
     460
     461/**
     462 * Allocate memory for a service.
     463 * Require to call free after calling this function.
     464 *
     465 * @return the service
     466 */
     467service* createService(){
     468  service *s1 = (service *) malloc (SERVICE_SIZE);
     469  s1->name=NULL;
     470  s1->content=NULL;
     471  s1->metadata=NULL;
     472  s1->additional_parameters=NULL;
     473  s1->inputs=NULL;
     474  s1->outputs=NULL;
     475  return s1;
    420476}
    421477
    422478/**
    423479 * Free allocated memory of a service.
    424  * Require to call free on e after calling this function.
     480 * Require to be invoked for every createService call.
    425481 *
    426482 * @param s the service to free
     
    437493    if(tmp->metadata!=NULL)
    438494      free(tmp->metadata);
     495    freeMap(&tmp->additional_parameters);
     496    if(tmp->additional_parameters!=NULL)
     497      free(tmp->additional_parameters);
    439498    freeElements(&tmp->inputs);
    440499    if(tmp->inputs!=NULL)
     
    454513 */
    455514void addToMap(map* m,const char* n,const char* v){
    456   if (m != NULL) { // knut: add NULL-pointer check
    457     if(hasKey(m,n)==false){
    458       map* _cursor=m;
    459       while(_cursor->next!=NULL){
    460         _cursor=_cursor->next;
    461       }
    462       _cursor->next=createMap(n,v);
    463     }
    464     else{
    465       map *tmp=getMap(m,n);
    466       if(tmp->value!=NULL)
    467         free(tmp->value);
    468       tmp->value=zStrdup(v);
    469     }
    470   }
     515    if (m != NULL) { // knut: add NULL-pointer check
     516        if (hasKey(m, n) == false) {
     517            map* _cursor = m;
     518            while (_cursor->next != NULL) {
     519                _cursor = _cursor->next;
     520            }
     521            _cursor->next = createMap(n, v);
     522        }
     523        else {
     524            map *tmp = getMap(m, n);
     525            if (tmp->value != NULL)
     526                free(tmp->value);
     527            tmp->value = zStrdup(v);
     528        }
     529    }
    471530}
    472531
     
    506565 */
    507566map* addToMapWithSize(map* m,const char* n,const char* v,int size){
     567  char sin[128];
     568  char sname[10]="size";
     569  map *tmp;
    508570  if(hasKey(m,n)==false){
    509571    map* _cursor=m;
     
    514576    }
    515577  }
    516   char sname[10]="size";
    517578  if(strlen(n)>5)
    518579    sprintf(sname,"size_%s",n+6);
    519   map *tmp=getMap(m,n);
     580  tmp=getMap(m,n);
    520581  if(tmp->value!=NULL)
    521582    free(tmp->value);
     
    524585    memmove(tmp->value,v,size*sizeof(char));
    525586  tmp->value[size]=0;
    526   char sin[128];
    527587  sprintf(sin,"%d",size);
    528588  addToMap(m,sname,sin);
     
    545605    }
    546606    else{
    547 #ifdef DEBUG
    548       fprintf(stderr,"_CURSOR\n");
    549       dumpMap(_cursor);
    550 #endif
    551       while(_cursor->next!=NULL)
    552         _cursor=_cursor->next;
    553607      map* tmp1=getMap(*mo,tmp->name);
    554608      if(tmp1==NULL){
     609        while(_cursor->next!=NULL)
     610          _cursor=_cursor->next;
    555611        _cursor->next=createMap(tmp->name,tmp->value);
    556612      }
     
    561617    _cursor=*mo;
    562618    tmp=tmp->next;
    563 #ifdef DEBUG
    564     fprintf(stderr,"MO\n");
    565     dumpMap(*mo);
    566 #endif
    567619  }
    568620}
     
    678730  map* size=getMap(in,"size");
    679731  map *lout=*out;
     732  map *tmpVin,*tmpVout;
    680733  if(size!=NULL && pos>0){
    681734    char tmp[11];
     
    683736    size=getMap(in,tmp);
    684737    sprintf(tmp,"value_%d",pos);
    685     map* tmpVin=getMap(in,tmp);
    686     map* tmpVout=getMap(lout,tmp);
     738    tmpVin=getMap(in,tmp);
     739    tmpVout=getMap(lout,tmp);
    687740    free(tmpVout->value);
    688741    tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
     
    691744  }else{
    692745    if(size!=NULL){
    693       map* tmpVin=getMap(in,"value");
    694       map* tmpVout=getMap(lout,"value");
     746      tmpVin=getMap(in,"value");
     747      tmpVout=getMap(lout,"value");
    695748      free(tmpVout->value);
    696749      tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
     
    712765  map* size=getMap(in,"size");
    713766  map* length=getMap(in,"length");
     767  map* toload=getMap(in,"to_load");
     768  if(toload!=NULL && strcasecmp(toload->value,"false")==0){
     769#ifdef DEBUG
     770    fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__);
     771#endif
     772    return ;
     773  }
    714774  if(length!=NULL){
    715775    int len=atoi(length->value);
     
    734794  maps* res=NULL;
    735795  if(_cursor!=NULL){
     796    map* mc=_cursor->content;
     797    maps* mcs=_cursor->child;
    736798    res=createMaps(_cursor->name);
    737     map* mc=_cursor->content;
    738799    if(mc!=NULL){
    739800      addMapToMap(&res->content,mc);
    740801      loadMapBinaries(&res->content,mc);
    741802    }
    742     maps* mcs=_cursor->child;
    743803    if(mcs!=NULL){
    744804      res->child=dupMaps(&mcs);
     
    764824    }
    765825    else{
     826      maps* tmp1=getMaps(*mo,tmp->name);
    766827      while(_cursor->next!=NULL)
    767828        _cursor=_cursor->next;
    768       maps* tmp1=getMaps(*mo,tmp->name);
    769829      if(tmp1==NULL){
    770830        _cursor->next=dupMaps(&tmp);
     
    797857map* getMapArray(map* m,const char* key,int index){
    798858  char tmp[1024];
     859  map* tmpMap;
    799860  if(index>0)
    800861    sprintf(tmp,"%s_%d",key,index);
     
    804865  fprintf(stderr,"** KEY %s\n",tmp);
    805866#endif
    806   map* tmpMap=getMap(m,tmp);
     867  tmpMap=getMap(m,tmp);
    807868#ifdef DEBUG
    808869  if(tmpMap!=NULL)
     
    823884void setMapArray(map* m,const char* key,int index,const char* value){
    824885  char tmp[1024];
     886  map* tmpSize;
    825887  if(index>0){
     888    map* len=getMap(m,"length");
    826889    sprintf(tmp,"%s_%d",key,index);
    827     map* len=getMap(m,"length");
    828890    if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
    829891      char tmp0[5];
     
    832894    }
    833895  }
    834   else
     896  else{
    835897    sprintf(tmp,"%s",key);
    836   map* tmpSize=getMapArray(m,"size",index);
     898    addToMap(m,"length","1");
     899  }
     900  tmpSize=getMapArray(m,"size",index);
    837901  if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
     902    map* ptr=getMapOrFill(&m,tmp,(char *)"");
    838903#ifdef DEBUG
    839904    fprintf(stderr,"%s\n",tmpSize->value);
    840905#endif
    841     map* ptr=getMapOrFill(&m,tmp,(char *)"");
    842906    free(ptr->value);
    843907    ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
     
    846910  else
    847911    addToMap(m,tmp,value);
     912}
     913
     914/**
     915 * Add a key and an integer value to an existing map array.
     916 *
     917 * @param m the map to add the KVP
     918 * @param n the key to add
     919 * @param index the index of the MapArray
     920 * @param v the corresponding value to add
     921 */
     922void addIntToMapArray(map* m,const char* n,int index,const int v){
     923  char svalue[10];
     924  sprintf(svalue,"%d",v);
     925  setMapArray(m,n,index,svalue);
    848926}
    849927
     
    881959  maps* tmp=mi;   
    882960  maps* _cursor=getMaps(*mo,tmp->name);
    883 
    884   if(_cursor==NULL)
    885     return -1;
    886 
    887   map* tmpLength=getMap(_cursor->content,"length");
    888961  char tmpLen[10];
    889962  int len=1;
    890   if(tmpLength!=NULL){
    891     len=atoi(tmpLength->value);
    892   }
    893 
    894963  char *tmpV[14]={
    895964    (char*)"size",
     
    906975    (char*)"isCached",
    907976    (char*)"LowerCorner",
    908     (char*)"UpperCorner"   
     977    (char*)"UpperCorner"
    909978  };
     979  int i=0;
     980  map* tmpLength;
     981 
     982  if(_cursor==NULL)
     983    return -1;
     984
     985  tmpLength=getMap(_cursor->content,"length");
     986  if(tmpLength!=NULL){
     987    len=atoi(tmpLength->value);
     988  }
     989
    910990  sprintf(tmpLen,"%d",len+1);
    911991  addToMap(_cursor->content,"length",tmpLen);
    912   int i=0;
    913992  for(i=0;i<14;i++){
    914993    map* tmpVI=getMap(tmp->content,tmpV[i]);
     
    9671046  res->content=NULL;
    9681047  res->metadata=NULL;
     1048  res->additional_parameters=NULL; 
    9691049  res->format=NULL;
    9701050  res->defaults=NULL;
     
    9811061 * @return a pointer to the allocated elements
    9821062 */
    983 elements* createElements(char* name){
     1063elements* createElements(const char* name){
    9841064  elements* res=(elements*)malloc(ELEMENTS_SIZE);
    9851065  res->name=zStrdup(name);
    9861066  res->content=NULL;
    9871067  res->metadata=NULL;
     1068  res->additional_parameters=NULL;
    9881069  res->format=NULL;
    9891070  res->defaults=NULL;
     
    10201101  elements* tmp=e;
    10211102  while(tmp!=NULL){
     1103    iotype* tmpio=tmp->defaults;
     1104    int ioc=0;
    10221105    fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
    10231106    fprintf(stderr," > CONTENT [%s]\n",tmp->name);
     
    10251108    fprintf(stderr," > METADATA [%s]\n",tmp->name);
    10261109    dumpMap(tmp->metadata);
     1110    fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name);
     1111    dumpMap(tmp->additional_parameters);
    10271112    fprintf(stderr," > FORMAT [%s]\n",tmp->format);
    1028     iotype* tmpio=tmp->defaults;
    1029     int ioc=0;
    10301113    while(tmpio!=NULL){
    10311114      fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
     
    10601143  int i;
    10611144  while(tmp!=NULL){
     1145    map* mcurs=tmp->content;
     1146    int ioc=0;
     1147    iotype* tmpio;
    10621148    for(i=0;i<2+(4*level);i++)
    10631149      fprintf(stderr," ");
    10641150    fprintf(stderr,"%s:\n",tmp->name);
    1065     map* mcurs=tmp->content;
    10661151    while(mcurs!=NULL){
    10671152      for(i=0;i<4+(4*level);i++)
     
    10911176        dumpElementsAsYAML(tmp->child,level+1);
    10921177    }
    1093     iotype* tmpio=tmp->defaults;
    1094     int ioc=0;
     1178    tmpio=tmp->defaults;
    10951179    while(tmpio!=NULL){
    10961180      for(i=0;i<6+(4*level);i++)
     
    11421226  elements* cursor=e;
    11431227  elements* tmp=NULL;
    1144   if(cursor!=NULL){
     1228  if(cursor!=NULL && cursor->name!=NULL){
    11451229#ifdef DEBUG
    11461230    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
     
    11491233#endif
    11501234    tmp=(elements*)malloc(ELEMENTS_SIZE);
    1151     tmp->name=zStrdup(e->name);
     1235    tmp->name=zStrdup(cursor->name);
    11521236    tmp->content=NULL;
    1153     addMapToMap(&tmp->content,e->content);
     1237    addMapToMap(&tmp->content,cursor->content);
    11541238    tmp->metadata=NULL;
    1155     addMapToMap(&tmp->metadata,e->metadata);
    1156     if(e->format!=NULL)
    1157       tmp->format=zStrdup(e->format);
     1239    addMapToMap(&tmp->metadata,cursor->metadata);
     1240    tmp->additional_parameters=NULL;
     1241    addMapToMap(&tmp->additional_parameters,cursor->additional_parameters);
     1242    if(cursor->format!=NULL)
     1243      tmp->format=zStrdup(cursor->format);
    11581244    else
    11591245      tmp->format=NULL;
    1160     if(e->defaults!=NULL){
     1246    if(cursor->defaults!=NULL){
    11611247      tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
    11621248      tmp->defaults->content=NULL;
    1163       addMapToMap(&tmp->defaults->content,e->defaults->content);
     1249      addMapToMap(&tmp->defaults->content,cursor->defaults->content);
    11641250      tmp->defaults->next=NULL;
    11651251#ifdef DEBUG
     
    11691255    }else
    11701256      tmp->defaults=NULL;
    1171     if(e->supported!=NULL){
     1257    if(cursor->supported!=NULL && cursor->supported->content!=NULL){
     1258      iotype *tmp2=cursor->supported->next;
    11721259      tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
    11731260      tmp->supported->content=NULL;
    1174       addMapToMap(&tmp->supported->content,e->supported->content);
     1261      addMapToMap(&tmp->supported->content,cursor->supported->content);
    11751262      tmp->supported->next=NULL;
    1176       iotype *tmp2=e->supported->next;
    1177       while(tmp2!=NULL){
     1263            while(tmp2!=NULL){
    11781264        addMapToIoType(&tmp->supported,tmp2->content);
    11791265#ifdef DEBUG
     
    11901276    else
    11911277      tmp->child=NULL;
    1192     tmp->next=dupElements(cursor->next);
     1278    if(cursor->next!=NULL)
     1279      tmp->next=dupElements(cursor->next);
     1280    else
     1281      tmp->next=NULL;
    11931282  }
    11941283  return tmp;
     
    12051294  elements* tmp=e;
    12061295  if(*m==NULL){
    1207     *m=dupElements(tmp);
     1296    (*m)=dupElements(tmp);
    12081297  }else{
    12091298    addToElements(&(*m)->next,tmp);
     
    12371326    fprintf(stderr,"CONTENT MAP\n");
    12381327    dumpMap(s->content);
    1239     fprintf(stderr,"CONTENT METADATA\n");
     1328    if(s->metadata!=NULL)
     1329      fprintf(stderr,"CONTENT METADATA\n");
    12401330    dumpMap(s->metadata);
     1331    if(s->additional_parameters!=NULL)
     1332      fprintf(stderr,"CONTENT AdditionalParameters\n");
     1333    dumpMap(s->additional_parameters);
    12411334  }
    12421335  if(s->inputs!=NULL){
     
    12961389  res->metadata=NULL;
    12971390  addMapToMap(&res->metadata,s->metadata);
     1391  res->additional_parameters=NULL;
     1392  addMapToMap(&res->additional_parameters,s->additional_parameters);
    12981393  res->inputs=dupElements(s->inputs);
    12991394  res->outputs=dupElements(s->outputs);
     
    13091404  registry* p=r;
    13101405  while(p!=NULL){
     1406    services* s=p->content;
    13111407    fprintf(stderr,"%s \n",p->name);
    1312     services* s=p->content;
    13131408    s=p->content;
    13141409    while(s!=NULL){
     
    15091604 */
    15101605void inheritance(registry *r,service** s){
     1606  service* ls=*s;
     1607  map *profile,*level;
    15111608  if(r==NULL)
    15121609    return;
    1513   service* ls=*s;
    1514   if(ls->content==NULL)
     1610  if(ls==NULL || ls->content==NULL)
    15151611    return;
    1516   map* profile=getMap(ls->content,"extend");
    1517   map* level=getMap(ls->content,"level");
     1612  profile=getMap(ls->content,"extend");
     1613  level=getMap(ls->content,"level");
    15181614  if(profile!=NULL&&level!=NULL){
    15191615    service* s1;
     
    15501646  memset(tmp,0,1024*10*10);
    15511647  while(tm!=NULL){
     1648    map* tc=tm->content;
    15521649    if(i>=10)
    15531650      break;
     
    15561653    strcpy(tmp[i][j],tm->name);
    15571654    j++;
    1558     map* tc=tm->content;
    15591655    while(tc!=NULL){
    15601656      if(j>=30)
     
    16091705 * @return true if map has a value or false if value is missing/empty/NULL
    16101706 */
    1611 bool nonempty( map* map ) {
    1612     return ( map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0 );
    1613 }
    1614 
    1615 /**
    1616  * Verify that a particular map value exists in a maps 
     1707bool nonempty(map* map) {
     1708        return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);
     1709}
     1710
     1711/**
     1712 * Verify that a particular map value exists in a maps
    16171713 * data structure, and obtain that value
    16181714 *
     
    16201716 * @param node name of maps node to search
    16211717 * @param key name of map node to find
    1622  * @param address to the map* if it exists, otherwise NULL
     1718 * @param kvp address to the map* if it exists, otherwise NULL
    16231719 * @return true if map has a value or false if value is missing/NULL
    1624  */
    1625 bool hasvalue( maps* source, const char* node, const char* key, map** kvp ) {
    1626     *kvp = getMapFromMaps(source, node, key);
    1627     return ( *kvp != NULL && (*kvp)->value != NULL &&
    1628              strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0 );
     1720 *
     1721 * @note The map assigned to kvp is owned by the source maps
     1722 */
     1723bool hasvalue(maps* source, const char* node, const char* key, map** kvp) {
     1724        *kvp = getMapFromMaps(source, node, key);
     1725        return (*kvp != NULL && (*kvp)->value != NULL &&
     1726                strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0);
    16291727}
    16301728
     
    16331731 *
    16341732 * @param conf reference to configuration maps
    1635  * @param service name of service 
     1733 * @param service name of service
    16361734 * @param exc WPSException code
    16371735 * @param message exception text (default: exception text in WPS specification)
    16381736 */
    1639 void setErrorMessage( maps*& conf, const char* service, WPSException exc, const char* message ) {
    1640  
    1641   if (message == NULL) {
    1642     message = WPSExceptionText[exc];
    1643   }
    1644 
    1645         size_t len = strlen( service ) + strlen(": ") + strlen( message ) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;
    1646         char* msg = (char*) malloc( len * sizeof(char) );
     1737void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message) {
     1738
     1739        if (message == NULL) {
     1740                message = WPSExceptionText[exc];
     1741        }
     1742
     1743        size_t len = strlen(service) + strlen(": ") + strlen(message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;
     1744        char* msg = (char*)malloc(len * sizeof(char));
    16471745
    16481746        if (msg != NULL) {
    1649                 snprintf( msg, len*sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc] );
    1650                 setMapInMaps( conf, "lenv", "message", msg );
    1651                 free( msg );
    1652         }       
     1747                snprintf(msg, len * sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]);
     1748                setMapInMaps(conf, "lenv", "message", msg);
     1749                free(msg);
     1750        }
    16531751}
    16541752
    16551753void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) {
    1656  
    1657   size_t msglen = 512;
    1658   const char empty[] = "";
    1659  
    1660   FILE* log;
    1661  
    1662   // system time, process time [nanoseconds]   
    1663   unsigned long long sys_t, proc_t;
    1664  
    1665   // processor time consumed by the program:
    1666   clock_t t = clock();
    1667    
    1668   // system time:
    1669   std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
    1670  
    1671   std::time_t now_t = std::chrono::system_clock::to_time_t( now );
    1672   std::tm* tm = localtime( &now_t );
     1754
     1755        size_t msglen = 512;
     1756        const char empty[] = "";
     1757
     1758        FILE* log;
     1759
     1760        // system time, process time [nanoseconds]   
     1761        unsigned long long sys_t, proc_t;
     1762
     1763        // processor time consumed by the program:
     1764        clock_t t = clock();
     1765
     1766        // system time:
     1767        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
     1768
     1769        std::time_t now_t = std::chrono::system_clock::to_time_t(now);
     1770        std::tm* tm = localtime(&now_t);
    16731771        char* str = asctime(tm);
    1674   str[strlen(str)-1] = '\0'; // remove newline
    1675  
    1676   sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
    1677   //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
    1678   proc_t = t;
    1679  
    1680   if ( message != NULL ) {
    1681      msglen += strlen(message);
    1682   } 
    1683   else {
    1684     message = empty;
    1685   }
    1686   //getLastErrorMessage(); // cgiScriptName 
    1687   char* text = (char*) malloc( sizeof(char)*msglen );
    1688  
    1689   snprintf( text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
    1690     _getpid(), source, line, function, str, sys_t, proc_t, message ); // __FILE__ __LINE__ __func__ //
    1691  
    1692   if ( file != NULL && (log = fopen( file, "a+" )) != NULL ) {
    1693     fputs( text, log );
    1694     fclose( log );
    1695   }
    1696   else {
    1697     #ifdef MSG_LOG_FILE
    1698     if ( (log = fopen( MSG_LOG_FILE, "a+" )) != NULL ) {
    1699       fputs( text, log );
    1700       fclose( log );
    1701     }     
    1702     #endif
    1703   }
    1704  
    1705   if ( text != NULL ) free( text );
     1772        str[strlen(str) - 1] = '\0'; // remove newline
     1773
     1774        sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
     1775        //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
     1776        proc_t = t;
     1777
     1778        if (message != NULL) {
     1779                msglen += strlen(message);
     1780        }
     1781        else {
     1782                message = empty;
     1783        }
     1784        //getLastErrorMessage(); // cgiScriptName 
     1785        char* text = (char*)malloc(sizeof(char)*msglen);
     1786
     1787        snprintf(text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
     1788                zGetpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ //
     1789
     1790        if (file != NULL && (log = fopen(file, "a+")) != NULL) {
     1791                fputs(text, log);
     1792                fclose(log);
     1793        }
     1794        else {
     1795#ifdef MSG_LOG_FILE
     1796                if ((log = fopen(MSG_LOG_FILE, "a+")) != NULL) {
     1797                        fputs(text, log);
     1798                        fclose(log);
     1799                }
     1800#endif
     1801        }
     1802
     1803        if (text != NULL) free(text);
    17061804}
    17071805
     
    17101808// zooLog;
    17111809// zooLogMsg(NULL, getLastErrorMessage());
    1712 // zooLogMsg(log.txt, getLastErrorMessage());
    1713 
    1714 #ifdef WIN32
    1715 #ifndef USE_MS
    1716 char *strcasestr (char const *a, char const *b)
    1717   {
    1718     char *x = zStrdup (a);
    1719     char *y = zStrdup (b);
    1720  
    1721       x = _strlwr (x);
    1722       y = _strlwr (y);
    1723     char *pos = strstr (x, y);
    1724     char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
    1725       free (x);
    1726       free (y);
    1727       return ret;
    1728   };
    1729 #else
    1730    ;
    1731 #endif
    1732 #endif
     1810// zooLogMsg("log.txt", getLastErrorMessage());
Note: See TracChangeset for help on using the changeset viewer.

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