schema_version.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 /*
22  * schema_version.h
23  *
24  * Created on: 6 May 2016
25  * Author: tyrrells
26  */
27 
28 #ifndef SRC_UTIL_INCLUDE_SCHEMA_VERSION_H_
29 #define SRC_UTIL_INCLUDE_SCHEMA_VERSION_H_
30 
32 #include "typedefs.h"
33 #include "jansson.h"
34 
35 
44 typedef struct SchemaVersion
45 {
47  uint32 sv_major;
48 
50  uint32 sv_minor;
51 
57  char *sv_version_s;
59 
60 
61 
62 /*
63  * The following preprocessor macros allow us to declare
64  * and define the variables in the same place. By default,
65  * they will expand to
66  *
67  * extern const char *SERVICE_NAME_S;
68  *
69  * however if ALLOCATE_SCHEMA_VERSION_TAGS is defined then it will
70  * become
71  *
72  * const char *ALLOCATE_SCHEMA_VERSION_TAGS = "path";
73  *
74  * ALLOCATE_SCHEMA_VERSION_TAGS must be defined only once prior to
75  * including this header file. Currently this happens in
76  * schema_version.c.
77  */
78 
79 #ifndef DOXYGEN_SHOULD_SKIP_THIS
80 
81 #ifdef ALLOCATE_SCHEMA_VERSION_TAGS
82  #define SV_PREFIX GRASSROOTS_UTIL_API
83  #define SV_VAL(x) = x
84 #else
85  #define SV_PREFIX extern
86  #define SV_VAL(x)
87 #endif
88 
89 #endif /* ifndef DOXYGEN_SHOULD_SKIP_THIS */
90 
96 SV_PREFIX const uint32 CURRENT_SCHEMA_VERSION_MAJOR SV_VAL(0);
97 
98 
104 SV_PREFIX const uint32 CURRENT_SCHEMA_VERSION_MINOR SV_VAL(10);
105 
106 #ifdef __cplusplus
107 extern "C"
108 {
109 #endif
110 
111 
122 GRASSROOTS_UTIL_API SchemaVersion *AllocateSchemaVersion (const int major, const int minor);
123 
124 
135 GRASSROOTS_UTIL_API bool SetSchemaVersionDetails (SchemaVersion *sv_p, const int major, const int minor);
136 
137 
144 GRASSROOTS_UTIL_API void FreeSchemaVersion (SchemaVersion *sv_p);
145 
146 
153 GRASSROOTS_UTIL_API void ClearSchemaVersion (SchemaVersion *sv_p);
154 
155 
163 GRASSROOTS_UTIL_API json_t *GetSchemaVersionAsJSON (const SchemaVersion * const sv_p);
164 
165 
175 GRASSROOTS_UTIL_API SchemaVersion *GetSchemaVersionFromJSON (const json_t * const json_p);
176 
177 
178 
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 
185 #endif /* SRC_UTIL_INCLUDE_SCHEMA_VERSION_H_ */
uint32 sv_major
The major revision of the schema.
Definition: schema_version.h:47
void FreeSchemaVersion(SchemaVersion *sv_p)
Free the memory and resources for a given SchemaVersion.
bool SetSchemaVersionDetails(SchemaVersion *sv_p, const int major, const int minor)
Set the details for a given SchemaVersion.
This is a datatype to store the versioning details for the Grassroots JSON schema that is being used.
Definition: schema_version.h:44
char * sv_version_s
The version as a string this will be of the form.
Definition: schema_version.h:57
SchemaVersion * AllocateSchemaVersion(const int major, const int minor)
Create a new SchemaVersion.
SchemaVersion * GetSchemaVersionFromJSON(const json_t *const json_p)
Create a SchemaVersion from a JSON representation.
uint32 sv_minor
The minor revision of the schema.
Definition: schema_version.h:50
const uint32 CURRENT_SCHEMA_VERSION_MINOR
The current minor revision of the Grassroots schema.
Definition: schema_version.h:104
json_t * GetSchemaVersionAsJSON(const SchemaVersion *const sv_p)
Get the JSON representation for a SchemaVersion.
const uint32 CURRENT_SCHEMA_VERSION_MAJOR
The current major revision of the Grassroots schema.
Definition: schema_version.h:96
void ClearSchemaVersion(SchemaVersion *sv_p)
Clear the memory and resources for a given SchemaVersion.