grassroots_server.h
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  * grassroots_server.h
18  *
19  * Created on: 26 Jul 2019
20  * Author: billy
21  */
22 
23 #ifndef CORE_SERVER_SERVER_INCLUDE_GRASSROOTS_SERVER_H_
24 #define CORE_SERVER_SERVER_INCLUDE_GRASSROOTS_SERVER_H_
25 
27 
28 #include "jansson.h"
29 
30 
31 #include "servers_manager.h"
32 #include "schema_version.h"
33 
34 
35 /*
36  * forward declarations
37  */
38 struct JobsManager;
39 struct ServersManager;
40 struct MongoClientManager;
41 
42 
43 
44 typedef struct GrassrootsServer
45 {
46  char *gs_path_s;
47 
53 
59 
60 
66 
67 
68  struct JobsManager *gs_jobs_manager_p;
69 
70  MEM_FLAG gs_jobs_manager_mem;
71 
72  struct ServersManager *gs_servers_manager_p;
73 
74  MEM_FLAG gs_servers_manager_mem;
75 
76  json_t *gs_config_p;
77 
78  SchemaVersion *gs_schema_version_p;
79 
80  struct MongoClientManager *gs_mongo_manager_p;
82 
83 
84 
85 #ifdef __cplusplus
86 extern "C"
87 {
88 #endif
89 
90 
98 GRASSROOTS_SERVICE_MANAGER_API GrassrootsServer *AllocateGrassrootsServer (const char *grassroots_path_s, const char *config_filename_s, const char *service_config_path_s, const char *references_path_s, struct JobsManager *external_jobs_manager_p, MEM_FLAG jobs_manager_flag, struct ServersManager *external_servers_manager_p, MEM_FLAG servers_manager_flag);
99 
100 
108 GRASSROOTS_SERVICE_MANAGER_API void FreeGrassrootsServer (GrassrootsServer *server_p);
109 
110 
111 
118 GRASSROOTS_SERVICE_MANAGER_API struct JobsManager *GetJobsManager (GrassrootsServer *grassroots_p);
119 
120 
121 
122 GRASSROOTS_SERVICE_MANAGER_API bool SetGrassrootsServerConfig (GrassrootsServer *server_p, const char *config_filename_s);
123 
124 
125 
126 GRASSROOTS_SERVICE_MANAGER_API bool InitGrassrootsServer (GrassrootsServer *server_p);
127 
128 
133 GRASSROOTS_SERVICE_MANAGER_API void ConnectToExternalServers (GrassrootsServer *server_p);
134 
135 
140 GRASSROOTS_SERVICE_MANAGER_LOCAL void DisconnectFromExternalServers (GrassrootsServer *server_p);
141 
142 
143 
158 GRASSROOTS_SERVICE_MANAGER_API json_t *ProcessServerRawMessage (GrassrootsServer *server_p, const char * const request_s, const char **error_ss);
159 
160 
161 
162 
173 GRASSROOTS_SERVICE_MANAGER_API json_t *ProcessServerJSONMessage (GrassrootsServer *server_p, json_t *req_p, const char **error_ss);
174 
175 
176 
177 
192 GRASSROOTS_SERVICE_MANAGER_API json_t *GetInitialisedResponseOnServer (GrassrootsServer *server_p, const json_t *req_p, const char *key_s, json_t *value_p);
193 
194 
195 
205 GRASSROOTS_SERVICE_MANAGER_API json_t *GetGlobalConfigValue (const GrassrootsServer *grassroots_p, const char *key_s);
206 
207 
214 GRASSROOTS_SERVICE_MANAGER_API const char *GetServerProviderName (const GrassrootsServer *grassroots_p);
215 
216 
223 GRASSROOTS_SERVICE_MANAGER_API const char *GetServerProviderDescription (const GrassrootsServer *grassroots_p);
224 
225 
232 GRASSROOTS_SERVICE_MANAGER_API const char *GetServerProviderURI (const GrassrootsServer *grassroots_p);
233 
234 
243 GRASSROOTS_SERVICE_MANAGER_API const json_t *GetProviderAsJSON (const GrassrootsServer *grassroots_p);
244 
245 
253 GRASSROOTS_SERVICE_MANAGER_API bool IsServiceEnabled (const GrassrootsServer *grassroots_p, const char *service_name_s);
254 
255 
256 
263 GRASSROOTS_SERVICE_MANAGER_API const char *GetJobLoggingURI (const GrassrootsServer *grassroots_p);
264 
265 
266 GRASSROOTS_SERVICE_MANAGER_API const SchemaVersion *GetSchemaVersion (GrassrootsServer *server_p);
267 
268 
277 GRASSROOTS_SERVICE_MANAGER_API struct ServersManager *GetServersManager (GrassrootsServer *server_p);
278 
279 
280 
281 
282 
283 GRASSROOTS_SERVICE_MANAGER_API const char *GetServerRootDirectory (const GrassrootsServer * const grassroots_p);
284 
285 
306 GRASSROOTS_SERVICE_MANAGER_API json_t *GetGlobalServiceConfig (GrassrootsServer *grassroots_p, const char * const service_name_s, bool *alloc_flag_p);
307 
308 
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 
314 #endif /* CORE_SERVER_SERVER_INCLUDE_GRASSROOTS_SERVER_H_ */
const char * GetServerProviderDescription(const GrassrootsServer *grassroots_p)
Get the Provider description for this Grassroots Server.
char * gs_references_path_s
The relative path from gs_path_s to the folder containing the reference services.
Definition: grassroots_server.h:65
char * gs_config_path_s
The relative path from gs_path_s to the folder containing the individual service config files.
Definition: grassroots_server.h:58
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:36
bool IsServiceEnabled(const GrassrootsServer *grassroots_p, const char *service_name_s)
Check if a named Service is enabled upon this Grassroots server.
json_t * GetGlobalServiceConfig(GrassrootsServer *grassroots_p, const char *const service_name_s, bool *alloc_flag_p)
Get a configuration value for a named Service.
GRASSROOTS_SERVICE_MANAGER_LOCAL void DisconnectFromExternalServers(GrassrootsServer *server_p)
Disconnect to any defined separate Grassroots servers.
json_t * GetGlobalConfigValue(const GrassrootsServer *grassroots_p, const char *key_s)
Get a configuration value from the global Grassroots configuration file.
const char * GetServerProviderName(const GrassrootsServer *grassroots_p)
Get the Provider name for this Grassroots Server.
This is a datatype to store the versioning details for the Grassroots JSON schema that is being used.
Definition: schema_version.h:44
json_t * GetInitialisedResponseOnServer(GrassrootsServer *server_p, const json_t *req_p, const char *key_s, json_t *value_p)
Create a response object with a valid header and a given key and value.
struct ServersManager * GetServersManager(GrassrootsServer *server_p)
Get the ServersManager for a given GrassrootsServer.
json_t * ProcessServerJSONMessage(GrassrootsServer *server_p, json_t *req_p, const char **error_ss)
Process a given JSON request and produce the server response.
A datatype for monitoring ServiceJobs.
Definition: jobs_manager.h:99
const char * GetJobLoggingURI(const GrassrootsServer *grassroots_p)
Get the job logging URI for this Grassroots Server.
const json_t * GetProviderAsJSON(const GrassrootsServer *grassroots_p)
Get the JSON fragment with all of the details of the Provider for this Grassroots Server.
struct JobsManager * GetJobsManager(GrassrootsServer *grassroots_p)
Get the current Server-wide JobsManager.
void FreeGrassrootsServer(GrassrootsServer *server_p)
Free a GrassrootsServer.
json_t * ProcessServerRawMessage(GrassrootsServer *server_p, const char *const request_s, const char **error_ss)
Construct a response message based upon a client's message.
const char * GetServerProviderURI(const GrassrootsServer *grassroots_p)
Get the Provider URI for this Grassroots Server.
char * gs_config_filename_s
The path to the global grassroots config file for this GrassrootsServer.
Definition: grassroots_server.h:52
Definition: grassroots_server.h:44
GrassrootsServer * AllocateGrassrootsServer(const char *grassroots_path_s, const char *config_filename_s, const char *service_config_path_s, const char *references_path_s, struct JobsManager *external_jobs_manager_p, MEM_FLAG jobs_manager_flag, struct ServersManager *external_servers_manager_p, MEM_FLAG servers_manager_flag)
Allocate a GrassrootsServer.
void ConnectToExternalServers(GrassrootsServer *server_p)
Connect to any defined separate Grassroots servers.
A datatype for monitoring ExternalServers.
Definition: servers_manager.h:141