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.
data_resource.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 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 
21 #ifndef GRASSROOTS_RESOURCE_H
22 #define GRASSROOTS_RESOURCE_H
23 
24 #include "jansson.h"
25 
27 #include "typedefs.h"
28 
40 typedef struct DataResource
41 {
54 
58  char *re_value_s;
59 
63  char *re_title_s;
64 
69  json_t *re_data_p;
70 } DataResource;
71 
72 /*
73  * The following preprocessor macros allow us to declare
74  * and define the variables in the same place. By default,
75  * they will expand to
76  *
77  * extern const char *SERVICE_NAME_S;
78  *
79  * however if ALLOCATE_JSON_TAGS is defined then it will
80  * become
81  *
82  * const char *SERVICE_NAME_S = "path";
83  *
84  * ALLOCATE_RESOURCE_TAGS must be defined only once prior to
85  * including this header file. Currently this happens in
86  * resource.c.
87  */
88 #ifndef DOXYGEN_SHOULD_SKIP_THIS
89 
90 #ifdef ALLOCATE_DATA_RESOURCE_TAGS
91  #define RESOURCE_PREFIX GRASSROOTS_UTIL_API
92  #define RESOURCE_VAL(x) = x
93 #else
94  #define RESOURCE_PREFIX extern GRASSROOTS_UTIL_API
95  #define RESOURCE_VAL(x)
96 #endif
97 
98 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
99 
100 #ifdef __cplusplus
101 extern "C" {
102 #endif
103 
104 
105 
112 RESOURCE_PREFIX const char *RESOURCE_DELIMITER_S RESOURCE_VAL("://");
113 
118 RESOURCE_PREFIX const char *PROTOCOL_IRODS_S RESOURCE_VAL("irods");
119 
124 RESOURCE_PREFIX const char *PROTOCOL_FILE_S RESOURCE_VAL("file");
125 
130 RESOURCE_PREFIX const char *PROTOCOL_HTTP_S RESOURCE_VAL("http");
131 
136 RESOURCE_PREFIX const char *PROTOCOL_HTTPS_S RESOURCE_VAL("https");
137 
142 RESOURCE_PREFIX const char* PROTOCOL_INLINE_S RESOURCE_VAL ("inline");
143 
144 
149 RESOURCE_PREFIX const char *PROTOCOL_TEXT_S RESOURCE_VAL("text");
150 
151 
156 RESOURCE_PREFIX const char *PROTOCOL_SERVICE_S RESOURCE_VAL("service");
157 
158 
159 
160 
173 GRASSROOTS_UTIL_API DataResource *AllocateDataResource (const char *protocol_s, const char *value_s, const char *title_s);
174 
175 
182 GRASSROOTS_UTIL_API void InitDataResource (DataResource *resource_p);
183 
184 
191 GRASSROOTS_UTIL_API void FreeDataResource (DataResource *resource_p);
192 
193 
202 GRASSROOTS_UTIL_API void ClearDataResource (DataResource *resource_p);
203 
204 
218 GRASSROOTS_UTIL_API bool SetDataResourceValue (DataResource *resource_p, const char *protocol_s, const char *value_s, const char *title_s);
219 
220 
231 GRASSROOTS_UTIL_API bool SetDataResourceData (DataResource *resource_p, json_t *data_p, const bool owns_data_flag);
232 
233 
245 GRASSROOTS_UTIL_API bool CopyDataResource (const DataResource * const src_p, DataResource * const dest_p);
246 
247 
258 GRASSROOTS_UTIL_API DataResource *CloneDataResource (const DataResource * const src_p);
259 
260 
278 GRASSROOTS_UTIL_API DataResource *ParseStringToDataResource (const char * const resource_s);
279 
280 
294 GRASSROOTS_UTIL_API bool GetDataResourceProtocolAndPath (const char * const resource_s, char ** const path_ss, char ** const protocol_ss);
295 
296 
308 GRASSROOTS_UTIL_API json_t *GetDataResourceAsJSONByParts (const char * const protocol_s, const char * const path_s, const char * const title_s, json_t *data_p);
309 
310 
319 GRASSROOTS_UTIL_API json_t *GetDataResourceAsJSON (const DataResource *resource_p);
320 
321 
330 GRASSROOTS_UTIL_API DataResource *GetDataResourceFromJSON (const json_t *json_p);
331 
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 
338 
339 #endif /* #ifndef GRASSROOTS_RESOURCE_H */
PROTOCOL_FILE_S
const char * PROTOCOL_FILE_S
The protocol for a data object for a mounted file.
Definition: data_resource.h:124
grassroots_util_library.h
PROTOCOL_HTTP_S
const char * PROTOCOL_HTTP_S
The protocol for a data object for a web address.
Definition: data_resource.h:130
DataResource
A datatype representing a URI.
Definition: data_resource.h:40
PROTOCOL_HTTPS_S
const char * PROTOCOL_HTTPS_S
The protocol for a data object for a secure web address.
Definition: data_resource.h:136
DataResource::re_value_s
char * re_value_s
The protocol-specific path to the data object.
Definition: data_resource.h:58
RESOURCE_DELIMITER_S
const char * RESOURCE_DELIMITER_S
The string used to separate the protocol and values of a Resource.
Definition: data_resource.h:112
typedefs.h
DataResource::re_protocol_s
char * re_protocol_s
The protocol of this Resource.
Definition: data_resource.h:53
PROTOCOL_TEXT_S
const char * PROTOCOL_TEXT_S
The protocol for a data object stored within the Grassroots system inline.
Definition: data_resource.h:149
PROTOCOL_INLINE_S
const char * PROTOCOL_INLINE_S
The protocol for a data object stored within the Grassroots system inline.
Definition: data_resource.h:142
DataResource::re_data_p
json_t * re_data_p
An optional set of json-based data for any application-specific configuration details.
Definition: data_resource.h:69
DataResource::re_title_s
char * re_title_s
An optional user-friendly name for this Resource.
Definition: data_resource.h:63
PROTOCOL_IRODS_S
const char * PROTOCOL_IRODS_S
The protocol for a data object on an iRODS system.
Definition: data_resource.h:118
PROTOCOL_SERVICE_S
const char * PROTOCOL_SERVICE_S
The protocol for a data object for a Grassroots Service.
Definition: data_resource.h:156
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47