Changeset 578 for trunk/zoo-project


Ignore:
Timestamp:
Feb 12, 2015, 12:35:20 PM (7 years ago)
Author:
knut
Message:

Added function getLastErrorMessage() (service_internal.c). Fixed problems caused by differing return types for GetLastError?() (unsigned int) and dlerror() (char*). Added DEBUG-conditional macros for diagnostic output in zoo_service_loader.c.

Location:
trunk/zoo-project/zoo-kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r577 r578  
    3737#endif
    3838
     39#ifndef WIN32
     40#include <dlfcn.h>
     41#endif
     42
     43#define ERROR_MSG_MAX_LENGTH 1024
     44
    3945int isValidLang(maps* conf,const char *str){
    4046  map *tmpMap=getMapFromMaps(conf,"main","lang");
     
    152158
    153159#ifdef DEBUG
    154       fprintf(stderr,"Semaphore failed to create ! %s\n",GetLastError());
     160      fprintf(stderr,"Semaphore failed to create: %s\n", getLastErrorMessage());
    155161#endif
    156162      return NULL;
     
    166172  semid sem_id=getShmLockId(conf,1);
    167173  if (CloseHandle(sem_id) == 0) {
    168     fprintf(stderr,"Unable to remove semaphore %s",GetLastError());
     174    fprintf(stderr,"Unable to remove semaphore: %s\n", getLastErrorMessage());
    169175    return -1;
    170176  }
     
    232238  if (hMapObjectG == NULL){
    233239#ifdef DEBUG
    234     fprintf(stderr,"Unable to create shared memory segment %d !! \n",GetLastError());
     240    fprintf(stderr,"Unable to create shared memory segment: %s\n", getLastErrorMessage());
    235241#endif
    236242    return -2;
     
    292298#ifdef DEBUG
    293299    fprintf(stderr,"ERROR on line %d\n",__LINE__);
    294     fprintf(stderr,"READING STRING S %s\n",GetLastError());
     300    fprintf(stderr,"READING STRING S %s\n", getLastErrorMessage());
    295301#endif
    296302    fIgnore = UnmapViewOfFile(lpvMem);
     
    309315#ifdef DEBUG
    310316    fprintf(stderr,"READING STRING S %d\n",__LINE__);
    311     fprintf(stderr,"READING STRING S %s\n",GetLastError());
     317    fprintf(stderr,"READING STRING S %s\n", getLastErrorMessage());
    312318#endif
    313319    return "-1";
     
    37333739  }
    37343740}
     3741
     3742/*
     3743 * The character string returned from getLastErrorMessage resides
     3744 * in a static buffer. The application should not write to this
     3745 * buffer or attempt to free() it.
     3746 */
     3747char* getLastErrorMessage() {                                                                                                                                                   
     3748#ifdef WIN32   
     3749        LPVOID lpMsgBuf;
     3750        DWORD errCode = GetLastError();
     3751        static char msg[ERROR_MSG_MAX_LENGTH];
     3752        size_t i;
     3753
     3754        DWORD length = FormatMessage(
     3755                                         FORMAT_MESSAGE_ALLOCATE_BUFFER |
     3756                                         FORMAT_MESSAGE_FROM_SYSTEM |
     3757                                         FORMAT_MESSAGE_IGNORE_INSERTS,
     3758                                         NULL,
     3759                                         errCode,
     3760                                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
     3761                                         (LPTSTR) &lpMsgBuf,
     3762                                         0, NULL );     
     3763       
     3764        #ifdef UNICODE         
     3765                wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH,
     3766                                        (wchar_t*) lpMsgBuf, _TRUNCATE );
     3767        #else
     3768                strcpy_s( msg, ERROR_MSG_MAX_LENGTH,
     3769                      (char *) lpMsgBuf );             
     3770        #endif 
     3771        LocalFree(lpMsgBuf);
     3772       
     3773        return msg;
     3774#else
     3775        return dlerror();
     3776#endif
     3777}
  • trunk/zoo-project/zoo-kernel/service_internal.h

    r576 r578  
    174174  char* getInputValue( maps*,const char*,size_t*);
    175175  int  setOutputValue( maps*, const char*, char*, size_t);
    176 
     176 
     177  char* getLastErrorMessage();
    177178#ifdef __cplusplus
    178179}
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r576 r578  
    455455#endif
    456456#ifdef WIN32
    457       DWORD errstr;
    458       errstr = GetLastError ();
     457      char* errstr = getLastErrorMessage();
    459458#else
    460459      char *errstr;
     
    462461#endif
    463462#ifdef DEBUG
    464       fprintf (stderr, "%s loaded (%d) \n", tmps1, errstr);
     463          fprintf (stderr, "%s loaded (%s) \n", tmps1, errstr);
    465464#endif
    466465      if (so != NULL)
     
    494493#ifdef DEBUG
    495494#ifdef WIN32
    496               errstr = GetLastError ();
     495                          errstr = getLastErrorMessage();
    497496#else
    498497              errstr = dlerror ();
     
    529528#ifdef DEBUG
    530529#ifdef WIN32
    531               errstr = GetLastError ();
    532               fprintf (stderr, "Function %s failed to load because of %d\n",
     530                          errstr = getLastErrorMessage();
     531              fprintf (stderr, "Function %s failed to load because of %s\n",
    533532                       r_inputs->value, errstr);
    534533#endif
     
    549548                {
    550549#ifdef WIN32
    551                   errstr = GetLastError ();
     550                                  errstr = getLastErrorMessage();
    552551#else
    553552                  errstr = dlerror ();
     
    571570#ifdef DEBUG
    572571#ifdef WIN32
    573               errstr = GetLastError ();
     572                          errstr = getLastErrorMessage();
    574573#else
    575574              errstr = dlerror ();
     
    604603          char tmps[1024];
    605604#ifdef WIN32
    606           DWORD errstr = GetLastError ();
     605                  errstr = getLastErrorMessage();
    607606#else
    608           char *errstr = dlerror ();
     607              errstr = dlerror ();
    609608#endif
    610609          sprintf (tmps, _("C Library can't be loaded %s"), errstr);
     
    28432842   */
    28442843  map* errI=NULL;
     2844#ifdef DEBUG 
    28452845  dumpMaps(request_input_real_format);
     2846#endif 
    28462847  char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0,&errI);
     2848#ifdef DEBUG 
    28472849  dumpMaps(request_input_real_format);
     2850#endif 
    28482851  maps *ptr = request_input_real_format;
    28492852  while (ptr != NULL)
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