root/opal/mca/pmix/pmix4x/pmix/src/mca/base/pmix_mca_base_component_compare.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pmix_mca_base_component_compare_priority
  2. pmix_mca_base_component_compare
  3. pmix_mca_base_component_compatible
  4. pmix_mca_base_component_to_string

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
  13  * $COPYRIGHT$
  14  *
  15  * Additional copyrights may follow
  16  *
  17  * $HEADER$
  18  */
  19 
  20 #include <src/include/pmix_config.h>
  21 
  22 #include <string.h>
  23 
  24 #include "src/mca/mca.h"
  25 #include "src/mca/base/base.h"
  26 
  27 
  28 /*
  29  * Function for comparing two pmix_mca_base_component_priority_t structs so
  30  * that we can build prioritized listss of them.  This assumed that
  31  * the types of the modules are the same.  Sort first by priority,
  32  * second by module name, third by module version.
  33  *
  34  * Note that we acutally want a *reverse* ordering here -- the al_*
  35  * functions will put "smaller" items at the head, and "larger" items
  36  * at the tail.  Since we want the highest priority at the head, it
  37  * may help the gentle reader to consider this an inverse comparison.
  38  * :-)
  39  */
  40 int
  41 pmix_mca_base_component_compare_priority(pmix_mca_base_component_priority_list_item_t *a,
  42                                          pmix_mca_base_component_priority_list_item_t *b)
  43 {
  44   /* First, compare the priorties */
  45 
  46   if (a->cpli_priority > b->cpli_priority) {
  47     return -1;
  48   } else if (a->cpli_priority < b->cpli_priority) {
  49     return 1;
  50   } else {
  51     return pmix_mca_base_component_compare(a->super.cli_component,
  52                                       b->super.cli_component);
  53   }
  54 }
  55 
  56 
  57 int pmix_mca_base_component_compare(const pmix_mca_base_component_t* aa,
  58                                     const pmix_mca_base_component_t* bb)
  59 {
  60     int val;
  61 
  62     val = strncmp(aa->pmix_mca_type_name, bb->pmix_mca_type_name,
  63                   PMIX_MCA_BASE_MAX_TYPE_NAME_LEN);
  64     if (val != 0) {
  65       return -val;
  66     }
  67 
  68     val = strncmp(aa->pmix_mca_component_name, bb->pmix_mca_component_name,
  69                       PMIX_MCA_BASE_MAX_COMPONENT_NAME_LEN);
  70     if (val != 0) {
  71       return -val;
  72     }
  73 
  74     /* The names were equal, so compare the versions */
  75 
  76     if (aa->pmix_mca_component_major_version >
  77         bb->pmix_mca_component_major_version) {
  78       return -1;
  79     } else if (aa->pmix_mca_component_major_version <
  80                bb->pmix_mca_component_major_version) {
  81       return 1;
  82     } else if (aa->pmix_mca_component_minor_version >
  83                bb->pmix_mca_component_minor_version) {
  84       return -1;
  85     } else if (aa->pmix_mca_component_minor_version <
  86                bb->pmix_mca_component_minor_version) {
  87       return 1;
  88     } else if (aa->pmix_mca_component_release_version >
  89                bb->pmix_mca_component_release_version) {
  90       return -1;
  91     } else if (aa->pmix_mca_component_release_version <
  92                bb->pmix_mca_component_release_version) {
  93       return 1;
  94     }
  95 
  96     return 0;
  97 }
  98 
  99 
 100 /**
 101  * compare but exclude the release version - declare compatible
 102  * if the major/minor version are the same.
 103  */
 104 int pmix_mca_base_component_compatible(const pmix_mca_base_component_t* aa,
 105                                        const pmix_mca_base_component_t* bb)
 106 {
 107     int val;
 108 
 109     val = strncmp(aa->pmix_mca_type_name, bb->pmix_mca_type_name,
 110                   PMIX_MCA_BASE_MAX_TYPE_NAME_LEN);
 111     if (val != 0) {
 112       return -val;
 113     }
 114 
 115     val = strncmp(aa->pmix_mca_component_name, bb->pmix_mca_component_name,
 116                   PMIX_MCA_BASE_MAX_COMPONENT_NAME_LEN);
 117     if (val != 0) {
 118       return -val;
 119     }
 120 
 121     /* The names were equal, so compare the versions */
 122 
 123     if (aa->pmix_mca_component_major_version >
 124         bb->pmix_mca_component_major_version) {
 125       return -1;
 126     } else if (aa->pmix_mca_component_major_version <
 127                bb->pmix_mca_component_major_version) {
 128       return 1;
 129     } else if (aa->pmix_mca_component_minor_version >
 130                bb->pmix_mca_component_minor_version) {
 131       return -1;
 132     } else if (aa->pmix_mca_component_minor_version <
 133                bb->pmix_mca_component_minor_version) {
 134       return 1;
 135     }
 136     return 0;
 137 }
 138 
 139 /**
 140  * Returns a string which represents the component name and version.
 141  * Has the form: comp_type.comp_name.major_version.minor_version
 142  */
 143 char * pmix_mca_base_component_to_string(const pmix_mca_base_component_t *a) {
 144     char * str = NULL;
 145     if(0 > asprintf(&str, "%s.%s.%d.%d", a->pmix_mca_type_name,
 146                     a->pmix_mca_component_name, a->pmix_mca_component_major_version,
 147                     a->pmix_mca_component_minor_version)) {
 148         return NULL;
 149     }
 150     return str;
 151 }

/* [<][>][^][v][top][bottom][index][help] */