mmlib/mmat: replace some variables by literal constants
[mmondor.git] / mmsoftware / mmlib / mmstat.h
CommitLineData
b232bd02 1/* $Id: mmstat.h,v 1.12 2007/12/05 23:47:56 mmondor Exp $ */
47071c2b
MM
2
3/*
d4aaa170 4 * Copyright (C) 2002-2004, Matthew Mondor
47071c2b
MM
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
d4aaa170 17 * This product includes software developed by Matthew Mondor.
47071c2b
MM
18 * 4. The name of Matthew Mondor may not be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission.
d4aaa170
MM
21 * 5. Redistribution of source code may not be released under the terms of
22 * any GNU Public License derivate.
47071c2b
MM
23 *
24 * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36
37
38
904cd663
MM
39#ifndef MMSTAT_H
40#define MMSTAT_H
47071c2b
MM
41
42
43
44
b232bd02
MM
45#include <stdbool.h>
46#include <stdint.h>
47071c2b
MM
47
48#include <mmtypes.h>
49#include <mmlist.h>
7a56f31f 50#include <mmpool.h>
904cd663 51#include <mmhash.h>
47071c2b
MM
52
53
54
55
dd417763 56#define MAX_TRANSACT 32
0b0f75cd 57#define KEY_SIZE 256
47071c2b 58
4fd4b499
MM
59typedef struct mmstat_entry mmstatent_t;
60typedef struct mmstat_handle mmstat_t;
61typedef struct mmstat_report mmstatres_t;
62
47071c2b
MM
63
64
65
47071c2b
MM
66enum stat_type {
67 STAT_TRANSACT = 1,
68 STAT_NEWFILE = 2,
69 STAT_UPDATE = 3,
70 STAT_RESET = 4,
71 STAT_DELETE = 5
72};
73
6ac2cab3
MM
74/* This structure is always in host byte order for now, since remote operation
75 * is not currently allowed.
76 */
4fd4b499 77struct mmstat_entry {
47071c2b
MM
78 int64_t value;
79 time_t created, modified;
80 uid_t uid;
81 char key[KEY_SIZE];
c55da4e1 82 bool persistent;
4fd4b499 83};
47071c2b 84
6ac2cab3
MM
85/* Note: elements of the following structure have been explicitely set to
86 * bit-fixed types, so that it can be architecture and platform independent.
87 * BYTEORDER_*() macros from mmarch(3) are used to achieve this.
88 */
47071c2b 89struct log_entry {
6ac2cab3 90 int32_t type; /* enum stat_type */
b232bd02
MM
91 uint32_t uid; /* uid_t */
92 uint32_t time; /* time_t */
93 uint16_t persistent, autoflush; /* booleans */
47071c2b
MM
94 char key[KEY_SIZE];
95 union {
96 struct {
b232bd02 97 uint32_t begin; /* boolean */
47071c2b
MM
98 } transact;
99 struct {
b232bd02 100 uint32_t lognum;
47071c2b
MM
101 } newfile;
102 struct {
103 int64_t modifier;
104 } update;
105 struct {
106 int64_t value;
107 } reset;
108 struct {
109 } del;
110 } un;
111};
112
4fd4b499 113struct mmstat_handle {
c55da4e1 114 bool persistent, transaction, autoflush;
47071c2b
MM
115 int transact_pos;
116 struct log_entry entries[MAX_TRANSACT];
4fd4b499 117};
47071c2b 118
4fd4b499 119struct mmstat_report {
47071c2b 120 int fd;
4fd4b499
MM
121 mmstatent_t entry;
122};
47071c2b
MM
123
124struct mmstat_config {
125 char USER[32], GROUPS[256], LOG_FACILITY[32], PID_FILE[256],
904cd663
MM
126 LOCK_FILE[256], LOG_SOCKET[256], STAT_SOCKET[256], ENV_DIR[128],
127 LOG_GROUP[32], STAT_GROUP[32];
47071c2b
MM
128 long SYNC_INTERVAL, SYNC_BYTES, MAX_LOGSIZE, STATS_RATE, STATS_TIME;
129 gid_t log_group, stat_group;
130 off_t max_logsize;
131};
132
133
134
135
c0d58fca
MM
136extern bool mmstat_initialize(void);
137extern bool mmstat_init(mmstat_t *, bool, bool);
138extern bool mmstat(mmstat_t *, enum stat_type, int64_t,
139 const char *, ...);
140extern bool mmstat_transact(mmstat_t *, bool);
141extern mmstatres_t * mmstat_report(const char *, ...);
142extern mmstatent_t * mmstat_nextres(mmstatres_t *);
143extern mmstatres_t * mmstat_freeres(mmstatres_t *);
144extern bool mmstat_rotate(const char *, const char *);
47071c2b
MM
145
146
147
148
149#endif