Ignore:
Timestamp:
Jun 19, 2015, 3:58:00 PM (9 years ago)
Author:
djay
Message:

Move createRegistry function to server_internal. Add the utils/registry service.

File:
1 edited

Legend:

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

    r673 r676  
    141141#endif
    142142
    143 extern int getServiceFromFile (maps *, const char *, service **);
    144 
    145 /**
    146  * Parse the service file using getServiceFromFile or use getServiceFromYAML
    147  * if YAML support was activated.
    148  *
    149  * @param conf the conf maps containing the main.cfg settings
    150  * @param file the file name to parse
    151  * @param service the service to update witht the file content
    152  * @param name the service name
    153  * @return true if the file can be parsed or false
    154  * @see getServiceFromFile, getServiceFromYAML
    155  */
    156 int
    157 readServiceFile (maps * conf, char *file, service ** service, char *name)
    158 {
    159   int t = getServiceFromFile (conf, file, service);
    160 #ifdef YAML
    161   if (t < 0)
    162     {
    163       t = getServiceFromYAML (conf, file, service, name);
    164     }
    165 #endif
    166   return t;
    167 }
    168143
    169144/**
     
    185160}
    186161
    187 
    188 /**
    189  * Create the profile registry.
    190  *
    191  * The profile registry is optional (created only if the registry key is
    192  * available in the [main] section of the main.cfg file) and can be used to
    193  * store the profiles hierarchy. The registry is a directory which should
    194  * contain the following sub-directories:
    195  *  * concept: direcotry containing .html files describing concept
    196  *  * generic: directory containing .zcfg files for wps:GenericProcess
    197  *  * implementation: directory containing .zcfg files for wps:Process
    198  *
    199  * @param m the conf maps containing the main.cfg settings
    200  * @param r the registry to update
    201  * @param reg_dir the resgitry
    202  * @param saved_stdout the saved stdout identifier
    203  * @return 0 if the resgitry is null or was correctly updated, -1 on failure
    204  */
    205 int
    206 createRegistry (maps* m,registry ** r, char *reg_dir, int saved_stdout)
    207 {
    208   char registryKeys[3][15]={
    209     "concept",
    210     "generic",
    211     "implementation"
    212   };
    213   int scount = 0,i=0;
    214   if (reg_dir == NULL)
    215     return 0;
    216   for(i=0;i<3;i++){
    217     char * tmpName =
    218       (char *) malloc ((strlen (reg_dir) + strlen (registryKeys[i]) + 2) *
    219                        sizeof (char));
    220     sprintf (tmpName, "%s/%s", reg_dir, registryKeys[i]);
    221    
    222     DIR *dirp1 = opendir (tmpName);
    223     struct dirent *dp1;
    224     while ((dp1 = readdir (dirp1)) != NULL){
    225       char* extn = strstr(dp1->d_name, ".zcfg");
    226       if(dp1->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)
    227         {
    228           int t;
    229           char *tmps1=
    230             (char *) malloc ((strlen (tmpName) + strlen (dp1->d_name) + 2) *
    231                              sizeof (char));
    232           sprintf (tmps1, "%s/%s", tmpName, dp1->d_name);
    233           char *tmpsn = zStrdup (dp1->d_name);
    234           tmpsn[strlen (tmpsn) - 5] = 0;
    235           service* s1 = (service *) malloc (SERVICE_SIZE);
    236           if (s1 == NULL)
    237             {
    238               dup2 (saved_stdout, fileno (stdout));
    239               errorException (m, _("Unable to allocate memory."),
    240                               "InternalError", NULL);
    241               return -1;
    242             }
    243           t = readServiceFile (m, tmps1, &s1, tmpsn);
    244           free (tmpsn);
    245           if (t < 0)
    246             {
    247               map *tmp00 = getMapFromMaps (m, "lenv", "message");
    248               char tmp01[1024];
    249               if (tmp00 != NULL)
    250                 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
    251                          dp1->d_name, tmp00->value);
    252               else
    253                 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
    254                          dp1->d_name);
    255               dup2 (saved_stdout, fileno (stdout));
    256               errorException (m, tmp01, "InternalError", NULL);
    257               return -1;
    258             }
    259 #ifdef DEBUG
    260           dumpService (s1);
    261           fflush (stdout);
    262           fflush (stderr);
    263 #endif
    264           if(strncasecmp(registryKeys[i],"implementation",14)==0){
    265             inheritance(*r,&s1);
    266           }
    267           addServiceToRegistry(r,registryKeys[i],s1);
    268           freeService (&s1);
    269           free (s1);
    270           scount++;
    271         }
    272     }
    273     (void) closedir (dirp1);
    274   }
    275   return 0;
    276 }
    277 
    278162/**
    279163 * Recursivelly parse zcfg starting from the ZOO-Kernel cwd.
     
    288172 * @param level the current level (number of sub-directories to reach the
    289173 * current path)
     174 * @param func a pointer to a function having 4 parameters
     175 *  (registry*, maps*, xmlNodePtr and service*).
    290176 * @see inheritance, readServiceFile
    291177 */
    292178int
    293 recursReaddirF (maps * m, registry *r, xmlNodePtr n, char *conf_dir, char *prefix,
    294                 int saved_stdout, int level, void (func) (maps *, xmlNodePtr,
    295                                                           service *))
     179recursReaddirF ( maps * m, registry *r, xmlNodePtr n, char *conf_dir,
     180                 char *prefix, int saved_stdout, int level,
     181                 void (func) (registry *, maps *, xmlNodePtr, service *) )
    296182{
    297183  struct dirent *dp;
     
    400286#endif
    401287            inheritance(r,&s1);
    402             func (m, n, s1);
     288            func (r, m, n, s1);
    403289            freeService (&s1);
    404290            free (s1);
     
    12511137    int saved_stdout = dup (fileno (stdout));
    12521138    dup2 (fileno (stderr), fileno (stdout));
    1253     createRegistry (m,&zooRegistry,reg->value,saved_stdout);
     1139    if(createRegistry (m,&zooRegistry,reg->value)<0){
     1140      map *message=getMapFromMaps(m,"lenv","message");
     1141      map *type=getMapFromMaps(m,"lenv","type");
     1142      dup2 (saved_stdout, fileno (stdout));
     1143      errorException (m, message->value,
     1144                      type->value, NULL);
     1145      return 0;
     1146    }
    12541147    dup2 (saved_stdout, fileno (stdout));
     1148    close(saved_stdout);
    12551149  }
    12561150
     
    14331327#endif
    14341328                        inheritance(zooRegistry,&s1);
    1435                         printDescribeProcessForProcess (m, n, s1);
     1329                        printDescribeProcessForProcess (zooRegistry,m, n, s1);
    14361330                        freeService (&s1);
    14371331                        free (s1);
     
    15111405#endif
    15121406                                inheritance(zooRegistry,&s1);
    1513                                 printDescribeProcessForProcess (m, n, s1);
     1407                                printDescribeProcessForProcess (zooRegistry,m, n, s1);
    15141408                                freeService (&s1);
    15151409                                free (s1);
     
    21772071          fclose (stdin);
    21782072#endif
    2179 
     2073          fprintf(stderr,"DEBUG START %s %d \n",__FILE__,__LINE__);
    21802074#ifdef RELY_ON_DB
    21812075          init_sql(m);
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