File: teamdctl_private.h

package info (click to toggle)
libteam 1.31-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,344 kB
  • sloc: ansic: 17,494; sh: 1,242; python: 613; makefile: 102
file content (108 lines) | stat: -rw-r--r-- 3,427 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 *   teamdctl_private.h - Teamd daemon control library private header
 *   Copyright (C) 2013-2015 Jiri Pirko <jiri@resnulli.us>
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2.1 of the License, or (at your option) any later version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _TEAMDCTL_PRIVATE_H_
#define _TEAMDCTL_PRIVATE_H_

#include <stdbool.h>
#include <syslog.h>
#include <private/list.h>
#include <teamdctl.h>

#include "config.h"

#define TEAMDCTL_EXPORT __attribute__ ((visibility("default")))

/**
 * SECTION: teamdctl
 * @short_description: libteamdctl context
 */

struct teamdctl_cli;

struct teamdctl {
	void (*log_fn)(struct teamdctl *tdc, int priority,
		       const char *file, int line, const char *fn,
		       const char *format, va_list args);
	int log_priority;
	char *addr;
	const struct teamdctl_cli *cli;
	void *cli_priv;
	struct list_item reply_cache_list;
};

struct teamdctl_reply_cache_item {
	struct list_item list;
	char *reply;
	char id[0];
};

/**
 * SECTION: logging
 * @short_description: libteamdctl logging facility
 */

void teamdctl_log(struct teamdctl *tdc, int priority,
		  const char *file, int line, const char *fn,
		  const char *format, ...);

static inline void __attribute__((always_inline, format(printf, 2, 3)))
teamdctl_log_null(struct teamdctl *tdc, const char *format, ...) {}

#define teamdctl_log_cond(tdc, prio, arg...)				\
	do {								\
		if (teamdctl_get_log_priority(tdc) >= prio)		\
			teamdctl_log(tdc, prio, __FILE__, __LINE__,	\
				  __FUNCTION__, ## arg);		\
	} while (0)

#ifdef ENABLE_LOGGING
#  ifdef ENABLE_DEBUG
#    define dbg(tdc, arg...) teamdctl_log_cond(tdc, LOG_DEBUG, ## arg)
#  else
#    define dbg(tdc, arg...) teamdctl_log_null(tdc, ## arg)
#  endif
#  define info(tdc, arg...) teamdctl_log_cond(tdc, LOG_INFO, ## arg)
#  define warn(tdc, arg...) teamdctl_log_cond(tdc, LOG_WARNING, ## arg)
#  define err(tdc, arg...) teamdctl_log_cond(tdc, LOG_ERR, ## arg)
#else
#  define dbg(tdc, arg...) teamdctl_log_null(tdc, ## arg)
#  define info(tdc, arg...) teamdctl_log_null(tdc, ## arg)
#  define warn(tdc, arg...) teamdctl_log_null(tdc, ## arg)
#  define err(tdc, arg...) teamdctl_log_null(tdc, ## arg)
#endif

struct teamdctl_cli {
	const char *name;
	size_t priv_size;
	int (*init)(struct teamdctl *tdc, const char *team_name, void *priv);
	void (*fini)(struct teamdctl *tdc, void *priv);
	bool test_method_call_required;
	int (*method_call)(struct teamdctl *tdc, const char *method_name,
			   char **p_reply, void *priv,
			   const char *fmt, va_list ap);
};

const struct teamdctl_cli *teamdctl_cli_usock_get(void);
const struct teamdctl_cli *teamdctl_cli_dbus_get(void);
const struct teamdctl_cli *teamdctl_cli_zmq_get(void);

#define TEAMDCTL_REPLY_TIMEOUT 5000 /* ms */

#endif /* _TEAMDCTL_PRIVATE_H_ */