@@ -63,6 +63,29 @@ enum adaptived_attr {
6363 ADAPTIVED_ATTR_CNT
6464};
6565
66+ enum adaptived_sdata_type {
67+ /*
68+ * Custom data. Can be used by registered functions without forcing a recompile
69+ * of adaptived
70+ */
71+ ADAPTIVED_SDATA_CUSTOM = 0 ,
72+ ADAPTIVED_SDATA_STR ,
73+ ADAPTIVED_SDATA_CGROUP ,
74+ ADAPTIVED_SDATA_NAME_VALUE ,
75+
76+ ADAPTIVED_SDATA_CNT
77+ };
78+
79+ enum adaptived_sdata_flags {
80+ ADAPTIVED_SDATAF_PERSIST = 0x1
81+ };
82+
83+ /**
84+ * Function to free a custom shared data structure. Not needed for any other
85+ * shared data type, as adaptived knows how to free built-in data types.
86+ */
87+ typedef void (* adaptived_sdata_free )(void * const data );
88+
6689enum adaptived_cgroup_value_type {
6790 ADAPTIVED_CGVAL_STR = 0 ,
6891 ADAPTIVED_CGVAL_LONG_LONG ,
@@ -89,6 +112,11 @@ struct adaptived_cgroup_value {
89112 } value ;
90113};
91114
115+ struct adaptived_name_and_value {
116+ char * name ;
117+ struct adaptived_cgroup_value * value ;
118+ };
119+
92120struct adaptived_rule_stats {
93121 int cause_cnt ;
94122 int effect_cnt ;
@@ -459,6 +487,66 @@ int adaptived_load_rule(struct adaptived_ctx * const ctx, struct adaptived_rule
459487 */
460488int adaptived_unload_rule (struct adaptived_ctx * const ctx , const char * const name );
461489
490+ /**
491+ * Method to write shared data to a cause. Data can be used by downstream effect(s)
492+ * @param cse adaptived cause structure
493+ * @param type shared data enumeration describing the type of data being store
494+ * @param data pointer to the data to be stored
495+ * @param free_fn Function to free the shared data. Only needed for custom data types
496+ * @param flags See enum adaptived_sdata_flags
497+ *
498+ * @note - shared data is deleted/freed at the end of each adaptive main loop unless
499+ * the persist flag is set
500+ * @note - freeing of data is done by free(), so the *data pointer must be created
501+ * via malloc. It would be possible to avoid this by creating a new type,
502+ * e.g. ADAPTIVED_SDATA_INT, and adding handling for it in free_shared_data().
503+ * @note - persist can be used to share data bidirectionally between a cause and some
504+ * effect(s). Use with caution, as this tightly couples these causes and
505+ * effect(s).
506+ */
507+ int adaptived_write_shared_data (struct adaptived_cause * const cse ,
508+ enum adaptived_sdata_type type , void * data ,
509+ adaptived_sdata_free free_fn ,
510+ uint32_t flags );
511+
512+ /**
513+ * Update shared data
514+ * @param cse adaptived cause structure
515+ * @param index shared data object index
516+ * @param type shared data enumeration describing the type of data being store
517+ * @param data pointer to the data to be stored
518+ * @param flags See enum adaptived_sdata_flags
519+ *
520+ * @note - If the data pointer is changed, it's up to the caller of this function
521+ * to ensure that the previous *data pointer is freed.
522+ */
523+ int adaptived_update_shared_data (struct adaptived_cause * const cse , int index ,
524+ enum adaptived_sdata_type type , void * data ,
525+ uint32_t flags );
526+
527+ /**
528+ * Get the number of shared data objects in this cause
529+ * @param cse adaptived cause
530+ *
531+ * @return number of shared data objects
532+ */
533+ int adaptived_get_shared_data_cnt (const struct adaptived_cause * const cse );
534+
535+ /**
536+ * Retrieve one shared data object from the cause
537+ * @param cse adaptived cause
538+ * @param index shared data object index
539+ * @param type Output parameter that tells what type of data is stored in this object
540+ * @param data Output parameter that contains the stored data
541+ * @param flags See enum adaptived_sdata_flags
542+ *
543+ * @note You do not need to free the data in the shared data object. adaptived will
544+ * automatically do that at the end of each main processing loop
545+ */
546+ int adaptived_get_shared_data (const struct adaptived_cause * const cse , int index ,
547+ enum adaptived_sdata_type * const type , void * * data ,
548+ uint32_t * const flags );
549+
462550#ifdef __cplusplus
463551} /* extern "C" */
464552#endif
0 commit comments