From 75fab830c45add2af4cad608fbe2b73c78eb8563 Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Thu, 23 Apr 2020 08:16:48 +0200
Subject: [PATCH] Implement new attribute val lookup infrastucture

---
 attributes/maestro-schema.h     | 22 ++++++++++++++++++++++
 include/maestro/attributes.h    |  4 ++--
 include/maestro/i_attributes.h  |  2 +-
 maestro/attributes.c            |  2 +-
 maestro/cdo.c                   |  4 ++--
 maestro/cdo_attributes_schema.c |  4 ++--
 maestro/cdoid.c                 |  2 +-
 maestro/ofi.c                   |  2 +-
 tests/check_declaration_seal.c  |  2 +-
 tests/check_pool_mamba.c        |  2 +-
 tests/check_transport_gfs.c     |  4 ++--
 tests/demo_mvp_d3_2.c           |  4 ++--
 transport/gfs.c                 |  2 +-
 transport/transport.c           |  6 +++---
 14 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/attributes/maestro-schema.h b/attributes/maestro-schema.h
index eb0264b8..51ce6f3a 100644
--- a/attributes/maestro-schema.h
+++ b/attributes/maestro-schema.h
@@ -151,5 +151,27 @@ mstro_attributes_default(mstro_schema schema,
                          mstro_attribute_dict *result);
 
 
+/** Look up maestro attribute in dictionary.
+ *
+ * On successful lookup return MSTRO_OK, *valtype set appropriately,
+ * and *val_p set to a (read-only) reference of the value that can be
+ * cast to the type documented for the respective kind of @ref
+ * mstro_cdo_attr_value_type.
+ *
+ * The reference stays alive at least until the dictionary is
+ * deallocated, or until the value is replaced by a call to @ref
+ * mstro_attribute_dict_set().
+ *
+ * If key is unknown return MSTRO_NOENT and *valtype==MSTRO_CDO_ATTTR_VALUE_NA.
+ *
+ * If key is known but has no value, return MSTRO_NOENT, and *valtype==MSTRO_CDO_ATTTR_VALUE_INVALID
+ *
+ * otherwise returns other error code
+ */
+mstro_status
+mstro_attribute_dict_get(mstro_attribute_dict dict,
+                         const char *key,
+                         enum mstro_cdo_attr_value_type *valtype,
+                         const void **val_p);
 
 #endif
diff --git a/include/maestro/attributes.h b/include/maestro/attributes.h
index ac9e34e7..46ebbfd7 100644
--- a/include/maestro/attributes.h
+++ b/include/maestro/attributes.h
@@ -202,7 +202,7 @@ mstro_timestamp_to_tm_local(const mstro_timestamp *tsp, struct tm *tmp);
 
 
 /** Built-in Maestro attribute data types */
-enum mstro_cdo_attr_value_types {
+enum mstro_cdo_attr_value_type {
   /** Invalid value */
   MSTRO_CDO_ATTR_VALUE_INVALID = 0,
 
@@ -275,7 +275,7 @@ mstro_cdo_attribute_set(mstro_cdo cdo, const char* key, void* val);
  **/
 mstro_status
 mstro_cdo_attribute_get(mstro_cdo cdo, const char*key,
-                        enum mstro_cdo_attr_value_types *valtype,
+                        enum mstro_cdo_attr_value_type *valtype,
                         const void * * val_p);
 
 /**
diff --git a/include/maestro/i_attributes.h b/include/maestro/i_attributes.h
index 23286d51..36d5af9b 100644
--- a/include/maestro/i_attributes.h
+++ b/include/maestro/i_attributes.h
@@ -135,7 +135,7 @@ mstro_cdo_attr_table__destroy(mstro_cdo_attr_table tab);
 mstro_status
 mstro_cdo_attr_table__lookup(const mstro_cdo cdo,
                              const char *key,
-                             enum mstro_cdo_attr_value_types *valtype,
+                             enum mstro_cdo_attr_value_type *valtype,
                              void **value_dst);
 
 /**@brief Insert an attribute, based on YAML string (key,value) pair
diff --git a/maestro/attributes.c b/maestro/attributes.c
index 08e78230..caf509ea 100644
--- a/maestro/attributes.c
+++ b/maestro/attributes.c
@@ -171,7 +171,7 @@ SUCCESS:
 
 mstro_status
 mstro_cdo_attribute_get(mstro_cdo cdo, const char* key,
-                        enum mstro_cdo_attr_value_types *type,
+                        enum mstro_cdo_attr_value_type *type,
                         const void ** val_p)
 {
   if (key == NULL || cdo == NULL)
diff --git a/maestro/cdo.c b/maestro/cdo.c
index ae349093..3ee65835 100644
--- a/maestro/cdo.c
+++ b/maestro/cdo.c
@@ -398,7 +398,7 @@ mstro_cdo_declaration_seal(mstro_cdo cdo)
   } else if(cdo->raw_ptr!=NULL) {
     uint64_t raw_ptr_size; /* size_t is not portable enough, so the schema says '64 bit' */
     void * val;
-    enum mstro_cdo_attr_value_types type;
+    enum mstro_cdo_attr_value_type type;
     status = mstro_cdo_attr_table__lookup(
         cdo,
         /* FIXME: should use the well-defined one FQAN */
@@ -599,7 +599,7 @@ mstro_cdo_offer(mstro_cdo cdo)
 
           {
             void* val;
-            enum mstro_cdo_attr_value_types type;
+            enum mstro_cdo_attr_value_type type;
             status = mstro_cdo_attr_table__lookup(
                 cdo,
                 /* FIXME: should use the well-defined one FQAN */
diff --git a/maestro/cdo_attributes_schema.c b/maestro/cdo_attributes_schema.c
index 151ebbcc..bb83d96b 100644
--- a/maestro/cdo_attributes_schema.c
+++ b/maestro/cdo_attributes_schema.c
@@ -135,7 +135,7 @@ mstro_cdo_attributes_parse_string(mstro_cdo cdo)
   return MSTRO_OK;
 }
 
-enum mstro_cdo_attr_value_types
+enum mstro_cdo_attr_value_type
 mstro_cdo_attr__match_type_cyaml(enum cyaml_type t, uint32_t size)
 {
   switch (t) {
@@ -197,7 +197,7 @@ mstro_cdo_attr__match_key_schema(const cyaml_schema_field_t s[], size_t len, con
 mstro_status
 mstro_cdo_attr_table__lookup(mstro_cdo cdo,
                              const char *key,
-                             enum mstro_cdo_attr_value_types *valtype,
+                             enum mstro_cdo_attr_value_type *valtype,
                              void **value_dst)
 {
 // XXX how to navigate through the attribute table levels using the schema table?
diff --git a/maestro/cdoid.c b/maestro/cdoid.c
index db57eef2..f8986967 100644
--- a/maestro/cdoid.c
+++ b/maestro/cdoid.c
@@ -54,7 +54,7 @@
 static inline
 uint32_t udj__ntohl(uint32_t const net)
 {
-  uint8_t data[4] = {};
+  uint8_t data[4] = {0,0,0,0};
   memcpy(&data, &net, sizeof(data));
   return ((uint32_t) data[3] <<0)
       |  ((uint32_t) data[2] <<8)
diff --git a/maestro/ofi.c b/maestro/ofi.c
index fbf28929..6851c21e 100644
--- a/maestro/ofi.c
+++ b/maestro/ofi.c
@@ -2092,7 +2092,7 @@ mstro_pc__handle_initiate_transfer(const Mstro__Pool__InitiateTransfer* init)
   ticket.cdoid = &id;
 
 	const void *size;
-	  enum mstro_cdo_attr_value_types type;
+	  enum mstro_cdo_attr_value_type type;
 	  if (! (MSTRO_OK == mstro_cdo_attribute_get(src_cdo, "local_size", &type, &size))) {
 	    ERR("Couldn't retrieve CDO %s local_size needed for transport\n", src_cdo->name);
 	    return MSTRO_FAIL;
diff --git a/tests/check_declaration_seal.c b/tests/check_declaration_seal.c
index e670c18a..117e5f19 100644
--- a/tests/check_declaration_seal.c
+++ b/tests/check_declaration_seal.c
@@ -46,7 +46,7 @@ CHEAT_TEST(cdo_declaration_seal_works,
            cheat_assert(MSTRO_OK == mstro_init("Tests","DECLARE",0));
            char name[] = "my_cdo_1";
            mstro_cdo cdo=NULL;
-           enum mstro_cdo_attr_value_types type;
+           enum mstro_cdo_attr_value_type type;
            const void* val;
            uint64_t size;
            size = 16000;
diff --git a/tests/check_pool_mamba.c b/tests/check_pool_mamba.c
index b7026173..ed21aff9 100644
--- a/tests/check_pool_mamba.c
+++ b/tests/check_pool_mamba.c
@@ -48,7 +48,7 @@ CHEAT_TEST(cdo_local_pool_mamba_works,
            mstro_cdo cdo=NULL;
            cheat_assert(MSTRO_OK == mstro_cdo_declare(name, MSTRO_ATTR_DEFAULT, &cdo));
            uint64_t size = 4096;
-           enum mstro_cdo_attr_value_types type;
+           enum mstro_cdo_attr_value_type type;
            float* buf;
            void *rec;
            buf = malloc(sizeof(float)*size);
diff --git a/tests/check_transport_gfs.c b/tests/check_transport_gfs.c
index 0369281a..87bc1ff2 100644
--- a/tests/check_transport_gfs.c
+++ b/tests/check_transport_gfs.c
@@ -84,7 +84,7 @@ CHEAT_DECLARE (
                cheat_assert(MSTRO_OK == mstro_cdo_attribute_set(cdo_src,
                                                                 MSTRO_ATTR_CORE_CDO_SCOPE_LOCAL_SIZE,
                                                                 &bytes));
-               enum mstro_cdo_attr_value_types ttype;
+               enum mstro_cdo_attr_value_type ttype;
                const void* tval;
 
                cheat_assert(MSTRO_OK == mstro_cdo_attribute_get(cdo_src,
@@ -130,7 +130,7 @@ CHEAT_DECLARE (
                
                double* data;
                size_t len;
-               enum mstro_cdo_attr_value_types type;
+               enum mstro_cdo_attr_value_type type;
                const void* val;
                
                cheat_assert(MSTRO_OK == mstro_cdo_access_ptr(cdo_dst, (void**)&data, NULL));
diff --git a/tests/demo_mvp_d3_2.c b/tests/demo_mvp_d3_2.c
index 31605efe..f0049091 100644
--- a/tests/demo_mvp_d3_2.c
+++ b/tests/demo_mvp_d3_2.c
@@ -574,7 +574,7 @@ archiver_thread_fun(void *closure)
 
       /* extract mamba pointer */
       mmbArray *mamba_array;
-      enum mstro_cdo_attr_value_types type;      
+      enum mstro_cdo_attr_value_type type;
 
       s = mstro_cdo_access_mamba_array(incoming[i], &mamba_array);
       if(s!=MSTRO_OK) {
@@ -832,7 +832,7 @@ consumer_thread_fun(void *closure)
 
       /* extract raw ptr */
       void* rawptr;
-      enum mstro_cdo_attr_value_types type;      
+      enum mstro_cdo_attr_value_type type;
       const void* size;
       s = mstro_cdo_access_ptr(incoming[i], &rawptr, NULL);
       if(s!=MSTRO_OK) {
diff --git a/transport/gfs.c b/transport/gfs.c
index 1fed4c6d..5359b292 100644
--- a/transport/gfs.c
+++ b/transport/gfs.c
@@ -84,7 +84,7 @@ mstro_transport_gfs_dst_execute(mstro_cdo dst,
     }
   } else {
     const void *available_size;
-    enum mstro_cdo_attr_value_types type;
+    enum mstro_cdo_attr_value_type type;
     status = mstro_cdo_attribute_get(
         dst, MSTRO_ATTR_CORE_CDO_SCOPE_LOCAL_SIZE, &type, &available_size);
     if(status!=MSTRO_OK) {
diff --git a/transport/transport.c b/transport/transport.c
index 62311aa8..4334d465 100644
--- a/transport/transport.c
+++ b/transport/transport.c
@@ -74,7 +74,7 @@ mstro_transport_get_dst_buffer(mstro_cdo dst, size_t len, void** data)
     }
   } else {
     const void *available_size;
-    enum mstro_cdo_attr_value_types type;
+    enum mstro_cdo_attr_value_type type;
     status = mstro_cdo_attribute_get(
         dst, MSTRO_ATTR_CORE_CDO_SCOPE_LOCAL_SIZE, &type, &available_size);
     if(status!=MSTRO_OK) {
@@ -98,7 +98,7 @@ mstro_transport_get_dst_buffer(mstro_cdo dst, size_t len, void** data)
 mstro_status
 mstro_transport_get_datalen(mstro_cdo src, struct mstro_transport_datalen* dl)
 {
-	enum mstro_cdo_attr_value_types type;
+	enum mstro_cdo_attr_value_type type;
 	const void* val;
 
 	if (src->raw_ptr != NULL ) {
@@ -195,7 +195,7 @@ mstro_transport_ticket_issue(
 
   mstro_status status;
 
-	enum mstro_cdo_attr_value_types type;
+	enum mstro_cdo_attr_value_type type;
         const void* val;
         if (! (MSTRO_OK == mstro_cdo_attribute_get(src_cdo, "local_size", &type, &val))) {
           ERR("Couldn't retrieve CDO %s local_size needed for transport\n", src_cdo->name);
-- 
GitLab