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 Resource
41 {
54 
58  char *re_value_s;
59 
63  char *re_title_s;
64 
69  json_t *re_data_p;
70 } Resource;
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_RESOURCE_TAGS
91  #define RESOURCE_PREFIX GRASSROOTS_UTIL_API
92  #define RESOURCE_VAL(x) = x
93 #else
94  #define RESOURCE_PREFIX extern
95  #define RESOURCE_VAL(x)
96 #endif
97 
98 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
99 
106 RESOURCE_PREFIX const char *RESOURCE_DELIMITER_S RESOURCE_VAL("://");
107 
112 RESOURCE_PREFIX const char *PROTOCOL_IRODS_S RESOURCE_VAL("irods");
113 
118 RESOURCE_PREFIX const char *PROTOCOL_FILE_S RESOURCE_VAL("file");
119 
124 RESOURCE_PREFIX const char *PROTOCOL_HTTP_S RESOURCE_VAL("http");
125 
130 RESOURCE_PREFIX const char *PROTOCOL_HTTPS_S RESOURCE_VAL("https");
131 
136 RESOURCE_PREFIX const char *PROTOCOL_INLINE_S RESOURCE_VAL("inline");
137 
138 
143 RESOURCE_PREFIX const char *PROTOCOL_TEXT_S RESOURCE_VAL("text");
144 
145 
150 RESOURCE_PREFIX const char *PROTOCOL_SERVICE_S RESOURCE_VAL("service");
151 
152 
153 
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157 
158 
171 GRASSROOTS_UTIL_API Resource *AllocateResource (const char *protocol_s, const char *value_s, const char *title_s);
172 
173 
180 GRASSROOTS_UTIL_API void InitResource (Resource *resource_p);
181 
182 
189 GRASSROOTS_UTIL_API void FreeResource (Resource *resource_p);
190 
191 
200 GRASSROOTS_UTIL_API void ClearResource (Resource *resource_p);
201 
202 
216 GRASSROOTS_UTIL_API bool SetResourceValue (Resource *resource_p, const char *protocol_s, const char *value_s, const char *title_s);
217 
218 
229 GRASSROOTS_UTIL_API bool SetResourceData (Resource *resource_p, json_t *data_p, const bool owns_data_flag);
230 
231 
243 GRASSROOTS_UTIL_API bool CopyResource (const Resource * const src_p, Resource * const dest_p);
244 
245 
256 GRASSROOTS_UTIL_API Resource *CloneResource (const Resource * const src_p);
257 
258 
276 GRASSROOTS_UTIL_API Resource *ParseStringToResource (const char * const resource_s);
277 
278 
292 GRASSROOTS_UTIL_API bool GetResourceProtocolAndPath (const char * const resource_s, char ** const path_ss, char ** const protocol_ss);
293 
294 
306 GRASSROOTS_UTIL_API json_t *GetResourceAsJSONByParts (const char * const protocol_s, const char * const path_s, const char * const title_s, json_t *data_p);
307 
308 
317 GRASSROOTS_UTIL_API json_t *GetResourceAsJSON (const Resource *resource_p);
318 
319 
328 GRASSROOTS_UTIL_API Resource *GetResourceFromJSON (const json_t *json_p);
329 
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 
336 
337 #endif /* #ifndef GRASSROOTS_RESOURCE_H */
const char * PROTOCOL_IRODS_S
The protocol for a data object on an iRODS system.
Definition: data_resource.h:112
bool GetResourceProtocolAndPath(const char *const resource_s, char **const path_ss, char **const protocol_ss)
Get the protocol and path parts of a Resource.
const char * PROTOCOL_SERVICE_S
The protocol for a data object for a Grassroots Service.
Definition: data_resource.h:150
Resource * AllocateResource(const char *protocol_s, const char *value_s, const char *title_s)
Allocate a Resource.
void FreeResource(Resource *resource_p)
Free a Resource and its associated data.
const char * PROTOCOL_INLINE_S
The protocol for a data object stored within the Grassroots system inline.
Definition: data_resource.h:136
const char * PROTOCOL_FILE_S
The protocol for a data object for a mounted file.
Definition: data_resource.h:118
const char * PROTOCOL_TEXT_S
The protocol for a data object stored within the Grassroots system inline.
Definition: data_resource.h:143
Resource * ParseStringToResource(const char *const resource_s)
Create a Resource from a given string.
Resource * CloneResource(const Resource *const src_p)
Clone the data from one Resource to another.
char * re_title_s
An optional user-friendly name for this Resource.
Definition: data_resource.h:63
char * re_value_s
The protocol-specific path to the data object.
Definition: data_resource.h:58
json_t * re_data_p
An optional set of json-based data for any application-specific configuration details.
Definition: data_resource.h:69
bool SetResourceData(Resource *resource_p, json_t *data_p, const bool owns_data_flag)
Set the json_t object of a Resource.
Resource * GetResourceFromJSON(const json_t *json_p)
Create a new Resource from a JSON fragment.
bool CopyResource(const Resource *const src_p, Resource *const dest_p)
Copy the data from one Resource to another.
json_t * GetResourceAsJSON(const Resource *resource_p)
Get the json representation of a Resource.
void InitResource(Resource *resource_p)
Initialise a Resource ready for use.
json_t * GetResourceAsJSONByParts(const char *const protocol_s, const char *const path_s, const char *const title_s, json_t *data_p)
Get the json representation of a Resource's fields.
void ClearResource(Resource *resource_p)
Clear a Resource.
const char * PROTOCOL_HTTPS_S
The protocol for a data object for a secure web address.
Definition: data_resource.h:130
const char * RESOURCE_DELIMITER_S
The string used to separate the protocol and values of a Resource.
Definition: data_resource.h:106
char * re_protocol_s
The protocol of this Resource.
Definition: data_resource.h:53
bool SetResourceValue(Resource *resource_p, const char *protocol_s, const char *value_s, const char *title_s)
Set the fields of a Resource.
A datatype representing a URI.
Definition: data_resource.h:40
const char * PROTOCOL_HTTP_S
The protocol for a data object for a web address.
Definition: data_resource.h:124