Refactor to use new protocol module and sipo.
[bertos.git] / bertos / net / syslog.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2012 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief SYSLOG log all debug message in the BeRTOS code, with the
34  * respective log level, to one syslog server on the udp protocol.
35  *
36  * The usage pattern is as follows:
37  * \code
38  *  // Init the network, es using dhcp:
39  *
40  *      // Initialize TCP/IP stack
41  *      tcpip_init(NULL, NULL);
42  *
43  *      // Bring up the network interface
44  *      netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);
45  *      netif_set_default(&netif);
46  *      netif_set_up(&netif);
47  *
48  *      dhcp_start(&netif);
49  *      while (!netif.ip_addr.addr)
50  *      timer_delay(DHCP_FINE_TIMER_MSECS);
51  *
52  *  // lwip address struct
53  *      struct ip_addr server_addr;
54  *  // convert address to ip_address
55  *      IP4_ADDR(&server_addr, 192, 168, 0, 2);
56  *
57  *  // init the syslog module
58  *      syslog_init(&syslog, server_addr);
59  *
60  * // now all LOG_*(message) are logged on
61  * // syslog server.
62  * // see the cfg_syslog.h for all settings.
63  * \endcode
64  *
65  *
66  * \author Daniele Basile <asterix@develer.com>
67  *
68  * $WIZ$ module_name = "syslog"
69  * $WIZ$ module_configuration = "bertos/cfg/cfg_syslog.h"
70  * $WIZ$ module_depends = "lwip", "debug"
71  */
72
73 #ifndef NET_SYSLOG_H
74 #define NET_SYSLOG_H
75
76 #include <lwip/netif.h>
77 #include <lwip/ip_addr.h>
78
79 typedef struct SysLog
80 {
81         struct netconn *syslog_server;
82         struct netbuf *send_buf;
83         struct ip_addr server_addr;
84
85         uint32_t syslog_cnt;
86 } SysLog;
87
88
89 uint32_t syslog_count(void);
90 struct ip_addr syslog_ip(void);
91 void syslog_setIp(struct ip_addr addr);
92
93 int syslog_printf(const char *fmt, ...);
94
95 void syslog_init(SysLog *syslog_ctx, struct ip_addr addr);
96
97 #endif /* NET_SYSLOG_H */