Code

5d11c09975277ded9c43d1425a02d3ac387a207a
[sysdb.git] / src / include / core / store.h
1 /*
2  * syscollector - src/include/core/store.h
3  * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 #ifndef SC_CORE_STORE_H
29 #define SC_CORE_STORE_H 1
31 #include "syscollector.h"
32 #include "core/object.h"
33 #include "utils/time.h"
34 #include "utils/llist.h"
36 #include <stdio.h>
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 typedef struct {
43         sc_object_t parent;
45         sc_time_t last_update;
46         char *name;
47 } sc_store_obj_t;
48 #define SC_STORE_OBJ_INIT { SC_OBJECT_INIT, 0, NULL }
49 #define SC_STORE_OBJ(obj) ((sc_store_obj_t *)(obj))
51 typedef struct {
52         sc_store_obj_t parent;
53 #define svc_last_update parent.last_update
54 #define svc_name parent.name
56         char *hostname;
57 } sc_service_t;
58 #define SC_SVC_INIT { SC_STORE_OBJ_INIT, NULL }
59 #define SC_SVC(obj) ((sc_service_t *)(obj))
61 typedef struct {
62         sc_store_obj_t parent;
63 #define host_last_update parent.last_update
64 #define host_name parent.name
66         sc_llist_t *services;
67 } sc_host_t;
68 #define SC_HOST_INIT { SC_STORE_OBJ_INIT, NULL }
69 #define SC_HOST(obj) ((sc_host_t *)(obj))
71 sc_host_t *
72 sc_host_create(char *name);
74 sc_host_t *
75 sc_host_clone(const sc_host_t *host);
77 /*
78  * sc_store_host:
79  * Add/update a host in the store. If the host, identified by its name,
80  * already exists, it will be updated according to the specified 'host'
81  * object. Else, a new entry will be created in the store. Any memory required
82  * for storing the entry will be allocated an managed by the store itself. The
83  * specified host-object will not be referenced or further accessed.
84  *
85  * Returns:
86  *  - 0 on success
87  *  - a positive value if the new entry is older than the currently stored
88  *    entry (in this case, no update will happen)
89  *  - a negative value on error
90  */
91 int
92 sc_store_host(const sc_host_t *host);
94 const sc_host_t *
95 sc_store_get_host(char *name);
97 sc_service_t *
98 sc_service_create(char *hostname, char *name);
100 sc_service_t *
101 sc_service_clone(const sc_service_t *svc);
103 /*
104  * sc_store_service:
105  * Add/update a store in the store. If the service, identified by its name,
106  * already exists for the specified host, it will be updated according to the
107  * specified 'service' object. If the referenced host does not exist, an error
108  * will be reported. Else, a new entry will be created in the store. Any
109  * memory required for storing the entry will be allocated an managed by the
110  * store itself. The specified service-object will not be referenced or
111  * further accessed.
112  *
113  * Returns:
114  *  - 0 on success
115  *  - a positive value if the new entry is older than the currently stored
116  *    entry (in this case, no update will happen)
117  *  - a negative value on error
118  */
119 int
120 sc_store_service(const sc_service_t *svc);
122 const sc_service_t *
123 sc_store_get_service(const sc_host_t *host, char *name);
125 int
126 sc_store_dump(FILE *fh);
128 #ifdef __cplusplus
129 } /* extern "C" */
130 #endif
132 #endif /* ! SC_CORE_STORE_H */
134 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */