Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
string_parameter.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2020 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 /*
17  * char_parameter.h
18  *
19  * Created on: 30 Jan 2020
20  * Author: billy
21  */
22 
23 #ifndef CORE_SHARED_PARAMETERS_INCLUDE_STRING_PARAMETER_H_
24 #define CORE_SHARED_PARAMETERS_INCLUDE_STRING_PARAMETER_H_
25 
26 
27 #include "parameter.h"
28 #include "parameter_set.h"
30 
31 
32 typedef struct StringParameter
33 {
35 
37 
39 
41 
43 
45 
46 
47 
48 typedef struct StringParameterOption
49 {
51  char *spo_value_s;
52 
55 
57 
58 
60 {
62 
64 
66 
67 
68 #ifdef __cplusplus
69 extern "C"
70 {
71 #endif
72 
73 /*
74  * Allocate a StringParameter
75  *
76  * @param service_data_p The ServiceData for the Service that is allocating this Parameter.
77  * @param name_s The name of the Parameter. The Parameter will store a copy of this string so this value does not need to remain in scope.
78  * @param display_name_s An optional name to display for the Parameter for use in Clients. The Parameter will store a copy of this string so this value does not need to remain in scope.
79  * This can be <code>NULL</code>.
80  * @param description_s The description of the Parameter. The Parameter will store a copy of this string so this value does not need to remain in scope.
81  * @param options_p This can be used to constrain the Parameter to a fixed set of values. If this is <code>NULL</code> then the Parameter can be set to any value.
82  * @param default_value_p The default value for this Parameter.
83  * @param current_value_p If this is not <code>NULL</code>, then copy this value as the current value of the Parameter. If this is <code>NULL</code>, then current value for this Parameter
84  * will be set to be a copy of its default value.
85  * @param bounds_p If this is not <code>NULL</code>, then this will be used to specify the minimum and maximum values that this Parameter can take. If this is <code>NULL</code>,
86  * then the Parameter can take any value.
87  * @param level The ParameterLevel for this Parameter. This determines when the Client should display this Parameter to the user.
88  * @param check_value_fn If this is not <code>NULL</code>, then this will be used to check whether the Parameter has been set to a valid value.
89  * @return A newly-allocated Parameter or <code>NULL</code> upon error.
90  * @memberof BooleanParameter
91  */
92 GRASSROOTS_SERVICE_API StringParameter *AllocateStringParameter (const struct ServiceData *service_data_p, const ParameterType pt, const char * const name_s, const char * const display_name_s, const char * const description_s, const char *default_value_p, const char *current_value_p, ParameterLevel level);
93 
94 
95 GRASSROOTS_SERVICE_API StringParameter *AllocateStringParameterFromJSON (const json_t *param_json_p, const struct Service *service_p, const bool concise_flag, const ParameterType *pt_p);
96 
97 
99  const char * const name_s, const char * const display_name_s, const char * const description_s,
100  const char *default_value_s, uint8 level);
101 
102 
104  const char * const name_s, const char * const display_name_s, const char * const description_s,
105  const char *default_value_s, const char *current_value_s, uint8 level);
106 
107 
108 
110 
111 
113 
114 
115 GRASSROOTS_SERVICE_API bool SetStringParameterCurrentValue (StringParameter *param_p, const char *value_p);
116 
117 
119 
120 
121 GRASSROOTS_SERVICE_API bool SetStringParameterDefaultValue (StringParameter *param_p, const char *value_p);
122 
123 
124 GRASSROOTS_SERVICE_API bool SetStringParameterBounds (StringParameter *param_p, const char *min_value_s, const char *max_value_s);
125 
126 
128 
129 
130 GRASSROOTS_SERVICE_API bool GetStringParameterBounds (const StringParameter *param_p, const char **min_pp, const char **max_pp);
131 
132 
133 GRASSROOTS_SERVICE_API bool CreateAndAddStringParameterOption (Parameter *param_p, const char *value_s, const char *description_s);
134 
135 
136 GRASSROOTS_SERVICE_API StringParameterOption *AllocateStringParameterOption (const char *value_s, const char *description_s);
137 
138 
140 
141 
143 
144 
146 
147 
158 GRASSROOTS_SERVICE_API bool GetCurrentStringParameterValueFromParameterSet (const ParameterSet * const params_p, const char * const name_s, const char **value_pp);
159 
160 
161 
162 GRASSROOTS_SERVICE_API bool GetCurrentStringParameterValueFromParameterGroup (const ParameterGroup * const params_p, const char * const name_s, const char **value_pp);
163 
164 
166 
167 
168 GRASSROOTS_SERVICE_API bool AddStringParameterOptionsToJSON (const Parameter *param_p, json_t *param_json_p);
169 
170 
171 GRASSROOTS_SERVICE_API bool GetStringParameterOptionsFromJSON (Parameter *param_p, const json_t * const json_p);
172 
173 
174 GRASSROOTS_SERVICE_API bool CopyStringParameterOptions (const Parameter *src_p, Parameter *dest_p, const bool clear_existing_dest_options_flag);
175 
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif /* CORE_SHARED_PARAMETERS_INCLUDE_STRING_PARAMETER_H_ */
IsStringParameter
bool IsStringParameter(const Parameter *param_p)
Parameter
The datatype that stores all of the information about a Parameter.
Definition: parameter.h:121
ParameterSet::GetCurrentStringParameterValueFromParameterSet
bool GetCurrentStringParameterValueFromParameterSet(const ParameterSet *const params_p, const char *const name_s, const char **value_pp)
Get the value of a StringParameter within a ParameterSet.
ParameterGroup
A datatype to tell the system that certain parameters should be grouped together in the client's user...
Definition: parameter_group.h:85
StringParameter::sp_default_value_s
char * sp_default_value_s
Definition: string_parameter.h:38
StringParameterOption
Definition: string_parameter.h:48
ParameterType
ParameterType
The different types that a Parameter can take.
Definition: parameter_type.h:35
grassroots_service_library.h
parameter_set.h
FreeStringParameter
void FreeStringParameter(StringParameter *param_p)
EasyCreateAndAddStringParameterToParameterSet
Parameter * EasyCreateAndAddStringParameterToParameterSet(const struct ServiceData *service_data_p, ParameterSet *params_p, ParameterGroup *group_p, ParameterType type, const char *const name_s, const char *const display_name_s, const char *const description_s, const char *default_value_s, uint8 level)
GRASSROOTS_SERVICE_API
#define GRASSROOTS_SERVICE_API
Definition: grassroots_service_library.h:49
AddStringParameterOptionsToJSON
bool AddStringParameterOptionsToJSON(const Parameter *param_p, json_t *param_json_p)
parameter.h
StringParameter::sp_base_param
Parameter sp_base_param
Definition: string_parameter.h:34
StringParameterOptionNode::spon_option_p
StringParameterOption * spon_option_p
Definition: string_parameter.h:63
AllocateStringParameterFromJSON
StringParameter * AllocateStringParameterFromJSON(const json_t *param_json_p, const struct Service *service_p, const bool concise_flag, const ParameterType *pt_p)
SetStringParameterBounds
bool SetStringParameterBounds(StringParameter *param_p, const char *min_value_s, const char *max_value_s)
Service
A datatype which defines an available service, its capabilities and its parameters.
Definition: service.h:153
StringParameter
Definition: string_parameter.h:32
AllocateStringParameterOptionNode
StringParameterOptionNode * AllocateStringParameterOptionNode(StringParameterOption *option_p)
ParameterLevel
ParameterLevel
The ParameterLevel defines the level that a user should be to adjust the Parameter.
Definition: parameter.h:52
StringParameterOption::spo_value_s
char * spo_value_s
The internal value for this option.
Definition: string_parameter.h:51
AllocateStringParameter
StringParameter * AllocateStringParameter(const struct ServiceData *service_data_p, const ParameterType pt, const char *const name_s, const char *const display_name_s, const char *const description_s, const char *default_value_p, const char *current_value_p, ParameterLevel level)
StringParameter::sp_max_value_s
char * sp_max_value_s
Definition: string_parameter.h:42
IsStringParameterBounded
bool IsStringParameterBounded(const StringParameter *param_p)
StringParameter::sp_min_value_s
char * sp_min_value_s
Definition: string_parameter.h:40
GetStringParameterBounds
bool GetStringParameterBounds(const StringParameter *param_p, const char **min_pp, const char **max_pp)
SetStringParameterCurrentValueFromJSON
bool SetStringParameterCurrentValueFromJSON(StringParameter *param_p, const json_t *value_p)
SetStringParameterDefaultValue
bool SetStringParameterDefaultValue(StringParameter *param_p, const char *value_p)
AllocateStringParameterOption
StringParameterOption * AllocateStringParameterOption(const char *value_s, const char *description_s)
SetStringParameterCurrentValue
bool SetStringParameterCurrentValue(StringParameter *param_p, const char *value_p)
ServiceData
A datatype for holding the configuration data for a Service.
Definition: service.h:126
StringParameterOptionNode
Definition: string_parameter.h:59
GetStringParameterDefaultValue
const char * GetStringParameterDefaultValue(const StringParameter *param_p)
StringParameter::sp_current_value_s
char * sp_current_value_s
Definition: string_parameter.h:36
GetStringParameterOptionsFromJSON
bool GetStringParameterOptionsFromJSON(Parameter *param_p, const json_t *const json_p)
FreeStringParameterOption
void FreeStringParameterOption(StringParameterOption *option_p)
ParameterSet
A set of Parameters along with an optional name and description.
Definition: parameter_set.h:46
GetStringParameterCurrentValue
const char * GetStringParameterCurrentValue(const StringParameter *param_p)
CreateAndAddStringParameterToParameterSet
Parameter * CreateAndAddStringParameterToParameterSet(const struct ServiceData *service_data_p, ParameterSet *params_p, ParameterGroup *group_p, ParameterType type, const char *const name_s, const char *const display_name_s, const char *const description_s, const char *default_value_s, const char *current_value_s, uint8 level)
StringParameterOptionNode::spon_node
ListItem spon_node
Definition: string_parameter.h:61
CopyStringParameterOptions
bool CopyStringParameterOptions(const Parameter *src_p, Parameter *dest_p, const bool clear_existing_dest_options_flag)
StringParameterOption::spo_description_s
char * spo_description_s
The user-friendly description for this value.
Definition: string_parameter.h:54
GetCurrentStringParameterValueFromParameterGroup
bool GetCurrentStringParameterValueFromParameterGroup(const ParameterGroup *const params_p, const char *const name_s, const char **value_pp)
ListItem
A doubly-linked node that points to its predecessor and successor.
Definition: linked_list.h:43
CreateAndAddStringParameterOption
bool CreateAndAddStringParameterOption(Parameter *param_p, const char *value_s, const char *description_s)