Ignore:
Timestamp:
Mar 12, 2015, 3:14:52 AM (9 years ago)
Author:
djay
Message:

Introduce the Process Profiles Registry with its documentation.

File:
1 edited

Legend:

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

    r605 r607  
    1 /**
     1/*
    22 * Author : Gérald FENOY
    33 *
     
    120120#endif
    121121
     122/**
     123 * Translation function for zoo-kernel
     124 */
    122125#define _(String) dgettext ("zoo-kernel",String)
     126/**
     127 * Translation function for zoo-service
     128 */
    123129#define __(String) dgettext ("zoo-service",String)
    124130
     
    131137extern int getServiceFromFile (maps *, const char *, service **);
    132138
     139/**
     140 * Parse the service file using getServiceFromFile or use getServiceFromYAML
     141 * if YAML support was activated.
     142 *
     143 * @param conf the conf maps containing the main.cfg settings
     144 * @param file the file name to parse
     145 * @param service the service to update witht the file content
     146 * @param name the service name
     147 * @return true if the file can be parsed or false
     148 * @see getServiceFromFile, getServiceFromYAML
     149 */
    133150int
    134151readServiceFile (maps * conf, char *file, service ** service, char *name)
     
    144161}
    145162
     163/**
     164 * Replace a char by another one in a string
     165 *
     166 * @param str the string to update
     167 * @param toReplace the char to replace
     168 * @param toReplaceBy the char that will be used
     169 */
    146170void
    147171translateChar (char *str, char toReplace, char toReplaceBy)
     
    156180
    157181/**
    158  * Create (or append to) an array valued maps
    159  * value = "["",""]"
     182 * Create (or append to) an array valued maps value = "["",""]"
     183 *
     184 * @param m the conf maps containing the main.cfg settings
     185 * @param mo the map to update
     186 * @param mi the map to append
     187 * @param elem the elements containing default definitions
     188 * @return 0 on success, -1 on failure
    160189 */
    161190int
     
    237266}
    238267
     268/**
     269 * Create the profile registry.
     270 *
     271 * The profile registry is optional (created only if the registry key is
     272 * available in the [main] section of the main.cfg file) and can be used to
     273 * store the profiles hierarchy. The registry is a directory which should
     274 * contain the following sub-directories:
     275 *  * concept: direcotry containing .html files describing concept
     276 *  * generic: directory containing .zcfg files for wps:GenericProcess
     277 *  * implementation: directory containing .zcfg files for wps:Process
     278 *
     279 * @param m the conf maps containing the main.cfg settings
     280 * @param r the registry to update
     281 * @param reg_dir the resgitry
     282 * @param saved_stdout the saved stdout identifier
     283 * @return 0 if the resgitry is null or was correctly updated, -1 on failure
     284 */
    239285int
    240 recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix,
     286createRegistry (maps* m,registry ** r, char *reg_dir, int saved_stdout)
     287{
     288  struct dirent *dp;
     289  int scount = 0;
     290
     291  if (reg_dir == NULL)
     292    return 0;
     293  DIR *dirp = opendir (reg_dir);
     294  if (dirp == NULL)
     295    {
     296      return -1;
     297    }
     298  while ((dp = readdir (dirp)) != NULL){
     299    if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.')
     300      {
     301
     302        char * tmpName =
     303          (char *) malloc ((strlen (reg_dir) + strlen (dp->d_name) + 2) *
     304                           sizeof (char));
     305        sprintf (tmpName, "%s/%s", reg_dir, dp->d_name);
     306       
     307        DIR *dirp1 = opendir (tmpName);
     308        struct dirent *dp1;
     309        while ((dp1 = readdir (dirp1)) != NULL){
     310          char* extn = strstr(dp1->d_name, ".zcfg");
     311          if(dp1->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)
     312            {
     313              int t;
     314              char *tmps1=
     315                (char *) malloc ((strlen (tmpName) + strlen (dp1->d_name) + 2) *
     316                                 sizeof (char));
     317              sprintf (tmps1, "%s/%s", tmpName, dp1->d_name);
     318              char *tmpsn = zStrdup (dp1->d_name);
     319              tmpsn[strlen (tmpsn) - 5] = 0;
     320              service* s1 = (service *) malloc (SERVICE_SIZE);
     321              if (s1 == NULL)
     322                {
     323                  dup2 (saved_stdout, fileno (stdout));
     324                  errorException (m, _("Unable to allocate memory."),
     325                                  "InternalError", NULL);
     326                  return -1;
     327                }
     328              t = readServiceFile (m, tmps1, &s1, tmpsn);
     329              free (tmpsn);
     330              if (t < 0)
     331                {
     332                  map *tmp00 = getMapFromMaps (m, "lenv", "message");
     333                  char tmp01[1024];
     334                  if (tmp00 != NULL)
     335                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
     336                             dp1->d_name, tmp00->value);
     337                  else
     338                    sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
     339                             dp1->d_name);
     340                  dup2 (saved_stdout, fileno (stdout));
     341                  errorException (m, tmp01, "InternalError", NULL);
     342                  return -1;
     343                }
     344#ifdef DEBUG
     345              dumpService (s1);
     346              fflush (stdout);
     347              fflush (stderr);
     348#endif
     349              if(strncasecmp(dp->d_name,"implementation",14)==0){
     350                inheritance(*r,&s1);
     351              }
     352              addServiceToRegistry(r,dp->d_name,s1);
     353              freeService (&s1);
     354              free (s1);
     355              scount++;
     356            }
     357        }
     358        (void) closedir (dirp1);
     359      }
     360  }
     361  (void) closedir (dirp);
     362  return 0;
     363}
     364
     365/**
     366 * Recursivelly parse zcfg starting from the ZOO-Kernel cwd.
     367 * Call the func function given in arguments after parsing the ZCFG file.
     368 *
     369 * @param m the conf maps containing the main.cfg settings
     370 * @param r the registry containing profiles hierarchy
     371 * @param n the root XML Node to add the sub-elements
     372 * @param conf_dir the location of the main.cfg file (basically cwd)
     373 * @param prefix the current prefix if any, or NULL
     374 * @param saved_stdout the saved stdout identifier
     375 * @param level the current level (number of sub-directories to reach the
     376 * current path)
     377 * @see inheritance, readServiceFile
     378 */
     379int
     380recursReaddirF (maps * m, registry *r, xmlNodePtr n, char *conf_dir, char *prefix,
    241381                int saved_stdout, int level, void (func) (maps *, xmlNodePtr,
    242382                                                          service *))
     
    287427            setMapInMaps (m, "lenv", "level", levels1);
    288428            res =
    289               recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1,
     429              recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,
    290430                              func);
    291431            sprintf (levels1, "%d", level);
     
    346486            fflush (stderr);
    347487#endif
     488            inheritance(r,&s1);
    348489            func (m, n, s1);
    349490            freeService (&s1);
     
    356497}
    357498
     499/**
     500 * Apply XPath Expression on XML document.
     501 *
     502 * @param doc the XML Document
     503 * @param search the XPath expression
     504 * @return xmlXPathObjectPtr containing the resulting nodes set
     505 */
    358506xmlXPathObjectPtr
    359507extractFromDoc (xmlDocPtr doc, const char *search)
     
    367515}
    368516
     517/**
     518 * Signal handling function which simply call exit(0).
     519 *
     520 * @param sig the signal number
     521 */
    369522void
    370523donothing (int sig)
     
    376529}
    377530
     531/**
     532 * Signal handling function which create an ExceptionReport node containing the
     533 * information message corresponding to the signal number.
     534 *
     535 * @param sig the signal number
     536 */
    378537void
    379538sig_handler (int sig)
     
    416575}
    417576
     577/**
     578 * Load a service provider and run the service function.
     579 *
     580 * @param myMap the conf maps containing the main.cfg settings
     581 * @param s1 the service structure
     582 * @param request_inputs map storing all the request parameters
     583 * @param inputs the inputs maps
     584 * @param ioutputs the outputs maps
     585 * @param eres the result returned by the service execution
     586 */
    418587void
    419588loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
     
    8761045#endif
    8771046
     1047/**
     1048 * Process the request.
     1049 *
     1050 * @param inputs the request parameters map
     1051 * @return 0 on sucess, other value on failure
     1052 * @see conf_read,recursReaddirF
     1053 */
    8781054int
    8791055runRequest (map ** inputs)
     
    11131289    SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL);
    11141290
     1291
     1292
    11151293  service *s1;
    11161294  int scount = 0;
     
    11291307  else
    11301308    snprintf (conf_dir, 1024, "%s", ntmp);
     1309
     1310  map* reg = getMapFromMaps (m, "main", "registry");
     1311  registry* zooRegistry=NULL;
     1312  if(reg!=NULL){
     1313    int saved_stdout = dup (fileno (stdout));
     1314    dup2 (fileno (stderr), fileno (stdout));
     1315    createRegistry (m,&zooRegistry,reg->value,saved_stdout);
     1316    dup2 (saved_stdout, fileno (stdout));
     1317  }
    11311318
    11321319  if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0)
     
    11461333      dup2 (fileno (stderr), fileno (stdout));
    11471334      if (int res =               
    1148           recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
     1335          recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
    11491336                          printGetCapabilitiesForProcess) < 0)
    11501337        {
    11511338          freeMaps (&m);
    11521339          free (m);
     1340          if(zooRegistry!=NULL){
     1341            freeRegistry(&zooRegistry);
     1342            free(zooRegistry);
     1343          }
    11531344          free (REQUEST);
    11541345          free (SERVICE_URL);
     
    11601351      freeMaps (&m);
    11611352      free (m);
     1353      if(zooRegistry!=NULL){
     1354        freeRegistry(&zooRegistry);
     1355        free(zooRegistry);
     1356      }
    11621357      free (REQUEST);
    11631358      free (SERVICE_URL);
     
    11771372          freeMaps (&m);
    11781373          free (m);
     1374          if(zooRegistry!=NULL){
     1375            freeRegistry(&zooRegistry);
     1376            free(zooRegistry);
     1377          }
    11791378          free (REQUEST);
    11801379          free (SERVICE_URL);
     
    12001399            {
    12011400              if (int res =
    1202                   recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
     1401                  recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
    12031402                                  printDescribeProcessForProcess) < 0)
    12041403                return res;
     
    12451444                          freeMaps (&m);
    12461445                          free (m);
     1446                          if(zooRegistry!=NULL){
     1447                            freeRegistry(&zooRegistry);
     1448                            free(zooRegistry);
     1449                          }
    12471450                          free (REQUEST);
    12481451                          free (corig);
     
    12591462                      dumpService (s1);
    12601463#endif
     1464                      inheritance(zooRegistry,&s1);
    12611465                      printDescribeProcessForProcess (m, n, s1);
    12621466                      freeService (&s1);
     
    13211525                                  freeMaps (&m);
    13221526                                  free (m);
     1527                                  if(zooRegistry!=NULL){
     1528                                    freeRegistry(&zooRegistry);
     1529                                    free(zooRegistry);
     1530                                  }
    13231531                                  free (orig);
    13241532                                  free (REQUEST);
     
    13321540                              dumpService (s1);
    13331541#endif
     1542                              inheritance(zooRegistry,&s1);
    13341543                              printDescribeProcessForProcess (m, n, s1);
    13351544                              freeService (&s1);
     
    13581567                      freeMaps (&m);
    13591568                      free (m);
     1569                      if(zooRegistry!=NULL){
     1570                        freeRegistry(&zooRegistry);
     1571                        free(zooRegistry);
     1572                      }
    13601573                      free (orig);
    13611574                      free (REQUEST);
     
    13791592          freeMaps (&m);
    13801593          free (m);
     1594          if(zooRegistry!=NULL){
     1595            freeRegistry(&zooRegistry);
     1596            free(zooRegistry);
     1597          }
    13811598          free (REQUEST);
    13821599          free (SERVICE_URL);
     
    13961613          freeMaps (&m);
    13971614          free (m);
     1615          if(zooRegistry!=NULL){
     1616            freeRegistry(&zooRegistry);
     1617            free(zooRegistry);
     1618          }
    13981619          free (REQUEST);
    13991620          free (SERVICE_URL);
     
    14101631      freeMaps (&m);
    14111632      free (m);
     1633      if(zooRegistry!=NULL){
     1634        freeRegistry(&zooRegistry);
     1635        free(zooRegistry);
     1636      }
    14121637      free (REQUEST);
    14131638      free (SERVICE_URL);
     
    14471672  dup2 (fileno (stderr), fileno (stdout));
    14481673  t = readServiceFile (m, tmps1, &s1, r_inputs->value);
     1674  inheritance(zooRegistry,&s1);
     1675  if(zooRegistry!=NULL){
     1676    freeRegistry(&zooRegistry);
     1677    free(zooRegistry);
     1678  }
    14491679  fflush (stdout);
    14501680  dup2 (saved_stdout, fileno (stdout));
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