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.
dfw_util.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2018 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  * dfw_util.h
18  *
19  * Created on: 8 Oct 2018
20  * Author: billy
21  */
22 
23 
24 #ifndef DFW_FIELD_TRIAL_SERVICE_DFW_UTIL_H_
25 #define DFW_FIELD_TRIAL_SERVICE_DFW_UTIL_H_
26 
28 
29 #include "json_processor.h"
30 
31 
32 #include "parameter.h"
33 #include "string_parameter.h"
34 
35 
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 
38 #ifdef ALLOCATE_DFW_UTIL_TAGS
39  #define DFW_UTIL_PREFIX DFW_FIELD_TRIAL_SERVICE_API
40  #define DFW_UTIL_VAL(x) = x
41  #define DFW_UTIL_STRUCT_VAL(x,y) = { x, y}
42 #else
43  #define DFW_UTIL_PREFIX extern
44  #define DFW_UTIL_VAL(x)
45  #define DFW_UTIL_STRUCT_VAL(x,y)
46 #endif
47 
48 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
49 
50 
51 
52 
53 DFW_UTIL_PREFIX NamedParameterType FT_TIMESTAMP DFW_UTIL_STRUCT_VAL("PR Timestamp", PT_STRING);
54 
55 DFW_UTIL_PREFIX const char * const FT_DEFAULT_TIMESTAMP_S DFW_UTIL_VAL("current");
56 
57 
58 DFW_UTIL_PREFIX const char * const FT_EMPTY_LIST_OPTION_S DFW_UTIL_VAL("<empty>");
59 
60 DFW_UTIL_PREFIX const char * const FT_USER_S DFW_UTIL_VAL("user");
61 
62 DFW_UTIL_PREFIX const char * const FT_PERMISSIONS_S DFW_UTIL_VAL("permissions");
63 
64 
65 
66 #ifdef __cplusplus
67 extern "C"
68 {
69 #endif
70 
71 
72 
73 
74 DFW_FIELD_TRIAL_SERVICE_LOCAL void *GetDFWObjectById (const bson_oid_t *id_p, FieldTrialDatatype collection_type, void *(*get_obj_from_json_fn) (const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p);
75 
76 
77 DFW_FIELD_TRIAL_SERVICE_LOCAL void *GetDFWObjectByNamedId (const bson_oid_t *id_p, FieldTrialDatatype collection_type, const char *id_key_s, void *(*get_obj_from_json_fn) (const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p);
78 
79 
80 DFW_FIELD_TRIAL_SERVICE_LOCAL void *GetDFWObjectByIdString (const char *object_id_s, FieldTrialDatatype collection_type, void *(*get_obj_from_json_fn) (const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p);
81 
82 
83 DFW_FIELD_TRIAL_SERVICE_LOCAL void *GetDFWObjectByNamedIdString (const char *object_id_s, FieldTrialDatatype collection_type, const char *id_key_s, void *(*get_obj_from_json_fn) (const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p);
84 
85 
86 DFW_FIELD_TRIAL_SERVICE_LOCAL bool CopyValidDate (const struct tm *src_p, struct tm **dest_pp);
87 
88 
89 DFW_FIELD_TRIAL_SERVICE_LOCAL bool CopyValidReal (const double64 *src_p, double64 **dest_pp);
90 
91 DFW_FIELD_TRIAL_SERVICE_LOCAL bool CopyValidUnsignedInteger (const uint32 *src_p, uint32 **dest_pp);
92 
93 DFW_FIELD_TRIAL_SERVICE_LOCAL bool CopyValidInteger (const int32 *src_p, int32 **dest_pp);
94 
95 
96 DFW_FIELD_TRIAL_SERVICE_LOCAL bool CreateValidDateFromJSON (const json_t *json_p, const char *key_s, struct tm **time_pp);
97 
98 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddValidDateToJSON (struct tm *time_p, json_t *json_p, const char *key_s, const bool add_time_flag);
99 
100 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddValidDateAsEpochToJSON (struct tm *time_p, json_t *json_p, const char *key_s);
101 
102 
103 
104 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddContext (json_t *data_p);
105 
106 
107 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddImage (json_t *doc_p, const FieldTrialDatatype data_type, const FieldTrialServiceData *data_p);
108 
109 
110 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddDatatype (json_t *doc_p, const FieldTrialDatatype data_type);
111 
112 
113 DFW_FIELD_TRIAL_SERVICE_LOCAL LinkedList *SearchObjects (const FieldTrialServiceData *data_p, const FieldTrialDatatype collection_type, const char **keys_ss, const char **values_ss, void (*free_list_item_fn) (ListItem * const item_p), bool (*add_result_to_list_fn) (const json_t *result_p, LinkedList *list_p, const FieldTrialServiceData *service_data_p));
114 
115 
116 DFW_FIELD_TRIAL_SERVICE_LOCAL bool CacheStudy (const char *id_s, const json_t *study_json_p, const FieldTrialServiceData *data_p);
117 
118 
119 DFW_FIELD_TRIAL_SERVICE_LOCAL json_t *GetCachedStudy (const char *id_s, const FieldTrialServiceData *data_p);
120 
121 
122 DFW_FIELD_TRIAL_SERVICE_LOCAL bool ClearCachedStudy (const char *id_s, const FieldTrialServiceData *data_p);
123 
124 
125 DFW_FIELD_TRIAL_SERVICE_LOCAL bool FindAndAddResultToServiceJob (const char *id_s, const ViewFormat format, ServiceJob *job_p, JSONProcessor *processor_p,
126  json_t *(get_json_fn) (const char *id_s, const ViewFormat format, JSONProcessor *processor_p, char **name_ss, const FieldTrialServiceData *data_p),
127  const FieldTrialDatatype datatype, const FieldTrialServiceData *data_p);
128 
129 
130 
131 DFW_FIELD_TRIAL_SERVICE_LOCAL bool GetValidRealFromJSON (const json_t *study_json_p, const char *key_s, double64 **ph_pp);
132 
133 DFW_FIELD_TRIAL_SERVICE_LOCAL bool GetValidUnsignedIntFromJSON (const json_t *study_json_p, const char *key_s, uint32 **value_pp);
134 
135 
136 DFW_FIELD_TRIAL_SERVICE_LOCAL json_t *GetImageObject (const char *image_url_s, const char *thumbnail_url_s);
137 
138 
139 DFW_FIELD_TRIAL_SERVICE_LOCAL char *GetFrictionlessDataFilename (const char * const name_s, const FieldTrialServiceData *data_p);
140 
141 DFW_FIELD_TRIAL_SERVICE_LOCAL char *GetFrictionlessDataURL (const char *const name_s, const FieldTrialServiceData *data_p);
142 
143 
144 DFW_FIELD_TRIAL_SERVICE_LOCAL char *GetStudyHandbookURL (const char *const name_s, const FieldTrialServiceData *data_p);
145 
146 
147 DFW_FIELD_TRIAL_SERVICE_LOCAL char *GetBackupFilename (const char *id_s, const FieldTrialServiceData *data_p);
148 
149 DFW_FIELD_TRIAL_SERVICE_LOCAL char *GetPlotsUploadsFilename (const char *id_s, const FieldTrialServiceData *data_p);
150 
151 
152 DFW_FIELD_TRIAL_SERVICE_LOCAL bool SetFieldTrialServiceJobURL (ServiceJob *job_p, const char * const url_prefix_s, const char * const id_s);
153 
154 
155 DFW_FIELD_TRIAL_SERVICE_LOCAL const char *GetStringDefaultValueFromJSON (const char *param_s, const json_t *params_json_p);
156 
157 
158 DFW_FIELD_TRIAL_SERVICE_LOCAL json_t *GetAllJSONVersionsOfObject (const char *id_s, FieldTrialDatatype collection_type, const FieldTrialServiceData *data_p);
159 
160 
161 DFW_FIELD_TRIAL_SERVICE_LOCAL json_t *GetSpecificJSONVersionOfObject (const char *id_s, const char *timestamp_s, FieldTrialDatatype collection_type, const FieldTrialServiceData *data_p);
162 
163 
164 DFW_FIELD_TRIAL_SERVICE_LOCAL void *GetVersionedObject (const char *id_s, const char *timestamp_s, const ViewFormat format, const FieldTrialDatatype dt, const FieldTrialServiceData *data_p, void *(*callback_fn) (json_t *json_p, ViewFormat format, const FieldTrialServiceData *data_p));
165 
166 
167 DFW_FIELD_TRIAL_SERVICE_LOCAL void *GetVersionedObjectFromResource (DataResource *resource_p, const NamedParameterType param_type, const char **original_id_ss, FieldTrialServiceData *ft_data_p,
168  void *(*get_versioned_obj_fn) (const char *id_s, const char *timestamp_s, const ViewFormat vf, FieldTrialServiceData *ft_data_p),
169  void *(*get_obj_by_id_fn) (const char *id_s, const ViewFormat vf, FieldTrialServiceData *ft_data_p));
170 
171 
172 DFW_FIELD_TRIAL_SERVICE_LOCAL bool SetUpListParameterFromJSON (const FieldTrialServiceData *data_p, StringParameter *param_p, const char *active_id_s, const char *empty_option_s, const char *name_key_s, json_t *objects_p);
173 
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 
180 #endif /* #ifndef DFW_FIELD_TRIAL_SERVICE_DFW_UTIL_H_ */
CacheStudy
bool CacheStudy(const char *id_s, const json_t *study_json_p, const FieldTrialServiceData *data_p)
GetImageObject
json_t * GetImageObject(const char *image_url_s, const char *thumbnail_url_s)
CreateValidDateFromJSON
bool CreateValidDateFromJSON(const json_t *json_p, const char *key_s, struct tm **time_pp)
GetCachedStudy
json_t * GetCachedStudy(const char *id_s, const FieldTrialServiceData *data_p)
NamedParameterType
This is a datatype that stores a read-only c-style string along with a ParameterType.
Definition: parameter.h:85
ServiceJob
A datatype to represent a running task.
Definition: service_job.h:72
GetFrictionlessDataURL
char * GetFrictionlessDataURL(const char *const name_s, const FieldTrialServiceData *data_p)
FieldTrialDatatype
FieldTrialDatatype
Definition: dfw_field_trial_service_data.h:40
PT_STRING
A c-style string.
Definition: parameter_type.h:58
DataResource
A datatype representing a URI.
Definition: data_resource.h:40
AddValidDateToJSON
bool AddValidDateToJSON(struct tm *time_p, json_t *json_p, const char *key_s, const bool add_time_flag)
JSONProcessor
Definition: json_processor.h:21
parameter.h
SearchObjects
LinkedList * SearchObjects(const FieldTrialServiceData *data_p, const FieldTrialDatatype collection_type, const char **keys_ss, const char **values_ss, void(*free_list_item_fn)(ListItem *const item_p), bool(*add_result_to_list_fn)(const json_t *result_p, LinkedList *list_p, const FieldTrialServiceData *service_data_p))
GetDFWObjectById
void * GetDFWObjectById(const bson_oid_t *id_p, FieldTrialDatatype collection_type, void *(*get_obj_from_json_fn)(const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p)
AddContext
bool AddContext(json_t *data_p)
GetVersionedObject
void * GetVersionedObject(const char *id_s, const char *timestamp_s, const ViewFormat format, const FieldTrialDatatype dt, const FieldTrialServiceData *data_p, void *(*callback_fn)(json_t *json_p, ViewFormat format, const FieldTrialServiceData *data_p))
CopyValidInteger
bool CopyValidInteger(const int32 *src_p, int32 **dest_pp)
GetBackupFilename
char * GetBackupFilename(const char *id_s, const FieldTrialServiceData *data_p)
DFW_FIELD_TRIAL_SERVICE_LOCAL
#define DFW_FIELD_TRIAL_SERVICE_LOCAL
Definition: dfw_field_trial_service_library.h:43
AddValidDateAsEpochToJSON
bool AddValidDateAsEpochToJSON(struct tm *time_p, json_t *json_p, const char *key_s)
CopyValidReal
bool CopyValidReal(const double64 *src_p, double64 **dest_pp)
CopyValidUnsignedInteger
bool CopyValidUnsignedInteger(const uint32 *src_p, uint32 **dest_pp)
FindAndAddResultToServiceJob
bool FindAndAddResultToServiceJob(const char *id_s, const ViewFormat format, ServiceJob *job_p, JSONProcessor *processor_p, json_t *(get_json_fn)(const char *id_s, const ViewFormat format, JSONProcessor *processor_p, char **name_ss, const FieldTrialServiceData *data_p), const FieldTrialDatatype datatype, const FieldTrialServiceData *data_p)
StringParameter
Definition: string_parameter.h:32
GetAllJSONVersionsOfObject
json_t * GetAllJSONVersionsOfObject(const char *id_s, FieldTrialDatatype collection_type, const FieldTrialServiceData *data_p)
GetDFWObjectByNamedId
void * GetDFWObjectByNamedId(const bson_oid_t *id_p, FieldTrialDatatype collection_type, const char *id_key_s, void *(*get_obj_from_json_fn)(const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p)
LinkedList
A doubly-linked list that can be traversed in either direction.
Definition: linked_list.h:56
GetValidUnsignedIntFromJSON
bool GetValidUnsignedIntFromJSON(const json_t *study_json_p, const char *key_s, uint32 **value_pp)
DFW_UTIL_VAL
const DFW_UTIL_PREFIX char *const FT_DEFAULT_TIMESTAMP_S DFW_UTIL_VAL("current")
CopyValidDate
bool CopyValidDate(const struct tm *src_p, struct tm **dest_pp)
GetStudyHandbookURL
char * GetStudyHandbookURL(const char *const name_s, const FieldTrialServiceData *data_p)
GetFrictionlessDataFilename
char * GetFrictionlessDataFilename(const char *const name_s, const FieldTrialServiceData *data_p)
GetDFWObjectByNamedIdString
void * GetDFWObjectByNamedIdString(const char *object_id_s, FieldTrialDatatype collection_type, const char *id_key_s, void *(*get_obj_from_json_fn)(const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p)
GetDFWObjectByIdString
void * GetDFWObjectByIdString(const char *object_id_s, FieldTrialDatatype collection_type, void *(*get_obj_from_json_fn)(const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p), const ViewFormat format, const FieldTrialServiceData *data_p)
dfw_field_trial_service_data.h
AddImage
bool AddImage(json_t *doc_p, const FieldTrialDatatype data_type, const FieldTrialServiceData *data_p)
SetUpListParameterFromJSON
bool SetUpListParameterFromJSON(const FieldTrialServiceData *data_p, StringParameter *param_p, const char *active_id_s, const char *empty_option_s, const char *name_key_s, json_t *objects_p)
GetValidRealFromJSON
bool GetValidRealFromJSON(const json_t *study_json_p, const char *key_s, double64 **ph_pp)
AddDatatype
bool AddDatatype(json_t *doc_p, const FieldTrialDatatype data_type)
ClearCachedStudy
bool ClearCachedStudy(const char *id_s, const FieldTrialServiceData *data_p)
FieldTrialServiceData
The configuration data used by the DFW Field Trial Service.
Definition: dfw_field_trial_service_data.h:118
GetSpecificJSONVersionOfObject
json_t * GetSpecificJSONVersionOfObject(const char *id_s, const char *timestamp_s, FieldTrialDatatype collection_type, const FieldTrialServiceData *data_p)
ViewFormat
ViewFormat
An indicator of what the output destination is for the JSON data values.
Definition: view_format.h:19
GetPlotsUploadsFilename
char * GetPlotsUploadsFilename(const char *id_s, const FieldTrialServiceData *data_p)
json_processor.h
GetStringDefaultValueFromJSON
const char * GetStringDefaultValueFromJSON(const char *param_s, const json_t *params_json_p)
SetFieldTrialServiceJobURL
bool SetFieldTrialServiceJobURL(ServiceJob *job_p, const char *const url_prefix_s, const char *const id_s)
string_parameter.h
GetVersionedObjectFromResource
void * GetVersionedObjectFromResource(DataResource *resource_p, const NamedParameterType param_type, const char **original_id_ss, FieldTrialServiceData *ft_data_p, void *(*get_versioned_obj_fn)(const char *id_s, const char *timestamp_s, const ViewFormat vf, FieldTrialServiceData *ft_data_p), void *(*get_obj_by_id_fn)(const char *id_s, const ViewFormat vf, FieldTrialServiceData *ft_data_p))
DFW_UTIL_STRUCT_VAL
DFW_UTIL_PREFIX NamedParameterType FT_TIMESTAMP DFW_UTIL_STRUCT_VAL("PR Timestamp", PT_STRING)
ListItem
A doubly-linked node that points to its predecessor and successor.
Definition: linked_list.h:43