jobs_manager.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  * running_services_table.h
23  *
24  * Created on: 17 Apr 2015
25  * Author: tyrrells
26  */
27 
28 #ifndef JOBS_MANAGER_H
29 #define JOBS_MANAGER_H
30 
31 #include "hash_table.h"
32 #include "service.h"
33 #include "service_job.h"
35 #include "uuid/uuid.h"
36 
37 
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 
40 #ifdef ALLOCATE_JOBS_MANAGER_TAGS
41  #define JOBS_MANAGER_PREFIX GRASSROOTS_SERVICE_MANAGER_API
42  #define JOBS_MANAGER_VAL(x) = x
43 #else
44  #define JOBS_MANAGER_PREFIX extern
45  #define JOBS_MANAGER_VAL(x)
46 #endif
47 
48 #endif
49 
50 
51 
56 JOBS_MANAGER_PREFIX const char *JOBS_MANAGERS_PATH_S JOBS_MANAGER_VAL("jobs_managers");
57 
58 
59 
60 /* forward declaration */
61 struct JobsManager;
62 struct Plugin;
63 struct GrassrootsServer;
64 
65 
76 typedef unsigned char *(*ServiceJobSerialiser) (ServiceJob *job_p, uint32 *length_p);
77 
78 
89 typedef ServiceJob *(*ServiceJobDeserialiser) (unsigned char *input_data_p, void *config_p);
90 
91 
99 typedef struct JobsManager
100 {
103 
115  bool (*jm_add_job_fn) (struct JobsManager *manager_p, uuid_t job_key, ServiceJob *job_p);
116 
129  ServiceJob *(*jm_get_job_fn) (struct JobsManager *manager_p, const uuid_t key);
130 
131 
145  ServiceJob *(*jm_remove_job_fn) (struct JobsManager *manager_p, const uuid_t key, bool get_job_flag);
146 
147 
148 
158  LinkedList *(*jm_get_all_jobs_fn) (struct JobsManager *manager_p);
159 
166  bool (*jm_delete_manager_fn) (struct JobsManager *manager_p);
167 
168 } JobsManager;
169 
170 
171 #ifdef __cplusplus
172  extern "C" {
173 #endif
174 
175 
176 
177 
191 GRASSROOTS_SERVICE_MANAGER_API void InitJobsManager (JobsManager *manager_p,
192  bool (*add_job_fn) (JobsManager *manager_p, uuid_t job_key, ServiceJob *job_p),
193  ServiceJob *(*get_job_fn) (JobsManager *manager_p, const uuid_t key),
194  ServiceJob *(*remove_job_fn) (JobsManager *manager_p, const uuid_t key, bool get_job_flag),
195  LinkedList *(*get_all_jobs_fn) (struct JobsManager *manager_p),
196  bool (*delete_manager_fn) (struct JobsManager *manager_p));
197 
198 
199 
208 GRASSROOTS_SERVICE_MANAGER_API bool FreeJobsManager (JobsManager *manager_p);
209 
210 
225 GRASSROOTS_SERVICE_MANAGER_API bool AddServiceJobToJobsManager (JobsManager *manager_p, uuid_t job_key, ServiceJob *job_p);
226 
227 
241 GRASSROOTS_SERVICE_MANAGER_API ServiceJob *GetServiceJobFromJobsManager (JobsManager *manager_p, const uuid_t key);
242 
243 
262 GRASSROOTS_SERVICE_MANAGER_API ServiceJob *RemoveServiceJobFromJobsManager (JobsManager *manager_p, const uuid_t key, bool get_job_flag);
263 
264 
276 GRASSROOTS_SERVICE_MANAGER_API LinkedList *GetAllServiceJobsFromJobsManager (struct JobsManager *manager_p);
277 
278 
287 GRASSROOTS_SERVICE_MANAGER_API JobsManager *LoadJobsManager (const char *jobs_manager_s, struct GrassrootsServer *server_p);
288 
289 
290 GRASSROOTS_SERVICE_MANAGER_API struct GrassrootsServer *GetGrassrootsServerFromJobsManager (const JobsManager * const manager_p);
291 
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 
297 #endif /* JOBS_MANAGER_H */
ServiceJob * GetServiceJobFromJobsManager(JobsManager *manager_p, const uuid_t key)
Find a ServiceJob.
LinkedList * GetAllServiceJobsFromJobsManager(struct JobsManager *manager_p)
Get all ServiceJobs.
bool(* jm_add_job_fn)(struct JobsManager *manager_p, uuid_t job_key, ServiceJob *job_p)
Add a ServiceJob to the JobsManager.
Definition: jobs_manager.h:115
struct Plugin * jm_plugin_p
The plugin that thjis JobsManager was loaded from.
Definition: jobs_manager.h:102
void InitJobsManager(JobsManager *manager_p, bool(*add_job_fn)(JobsManager *manager_p, uuid_t job_key, ServiceJob *job_p), ServiceJob *(*get_job_fn)(JobsManager *manager_p, const uuid_t key), ServiceJob *(*remove_job_fn)(JobsManager *manager_p, const uuid_t key, bool get_job_flag), LinkedList *(*get_all_jobs_fn)(struct JobsManager *manager_p), bool(*delete_manager_fn)(struct JobsManager *manager_p))
Initialise a JobsManager.
A doubly-linked list that can be traversed in either direction.
Definition: linked_list.h:56
A Plugin is a dynamically-loaded component to provide a piece of functionality.
Definition: plugin.h:151
ServiceJob * RemoveServiceJobFromJobsManager(JobsManager *manager_p, const uuid_t key, bool get_job_flag)
Remove a ServiceJob.
A datatype for monitoring ServiceJobs.
Definition: jobs_manager.h:99
A datatype to represent a running task.
Definition: service_job.h:72
bool(* jm_delete_manager_fn)(struct JobsManager *manager_p)
The function to use to delete this JobsManager,.
Definition: jobs_manager.h:166
bool AddServiceJobToJobsManager(JobsManager *manager_p, uuid_t job_key, ServiceJob *job_p)
Add a ServiceJob to the JobsManager.
const char * JOBS_MANAGERS_PATH_S
This specifies the relative filesystem path to where the Service plugins are stored.
Definition: jobs_manager.h:56
Definition: grassroots_server.h:44
JobsManager * LoadJobsManager(const char *jobs_manager_s, struct GrassrootsServer *server_p)
Load and create a JobsManager from the named plugin.
bool FreeJobsManager(JobsManager *manager_p)
Free a JobsManager.