mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
syslog: Added multi device support in syslog_device.
This commit is contained in:
committed by
Xiang Xiao
parent
a21d6b884e
commit
1dee243e29
@@ -27,6 +27,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "nvic.h"
|
||||
#include "itm.h"
|
||||
@@ -61,22 +62,29 @@
|
||||
|
||||
/* SYSLOG channel methods */
|
||||
|
||||
static int itm_putc(int ch);
|
||||
static int itm_flush(void);
|
||||
static int itm_putc(FAR struct syslog_channel_s *channel, int ch);
|
||||
static int itm_flush(FAR struct syslog_channel_s *channel);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the ITM SYSLOG channel */
|
||||
/* This structure describes the ITM SYSLOG channel operations */
|
||||
|
||||
static const struct syslog_channel_s g_itm_channel =
|
||||
static const struct syslog_channel_ops_s g_itm_channel_ops =
|
||||
{
|
||||
.sc_putc = itm_putc,
|
||||
.sc_force = itm_putc,
|
||||
.sc_flush = itm_flush,
|
||||
};
|
||||
|
||||
/* This structure describes the ITM SYSLOG channel */
|
||||
|
||||
static const struct syslog_channel_s g_itm_channel =
|
||||
{
|
||||
.sc_ops = &g_itm_channel_ops
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -89,8 +97,10 @@ static const struct syslog_channel_s g_itm_channel =
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int itm_putc(int ch)
|
||||
static int itm_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
UNUSED(channel);
|
||||
|
||||
/* ITM enabled */
|
||||
|
||||
if ((getreg32(ITM_TCR) & ITM_TCR_ITMENA_MASK) == 0)
|
||||
@@ -117,8 +127,9 @@ static int itm_putc(int ch)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int itm_flush(void)
|
||||
static int itm_flush(FAR struct syslog_channel_s *channel)
|
||||
{
|
||||
UNUSED(channel);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "nvic.h"
|
||||
#include "itm.h"
|
||||
@@ -61,22 +62,29 @@
|
||||
|
||||
/* SYSLOG channel methods */
|
||||
|
||||
static int itm_putc(int ch);
|
||||
static int itm_flush(void);
|
||||
static int itm_putc(FAR struct syslog_channel_s *channel, int ch);
|
||||
static int itm_flush(FAR struct syslog_channel_s *channel);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the ITM SYSLOG channel */
|
||||
/* This structure describes the ITM SYSLOG channel operations */
|
||||
|
||||
static const struct syslog_channel_s g_itm_channel =
|
||||
static const struct syslog_channel_ops_s g_itm_channel_ops =
|
||||
{
|
||||
.sc_putc = itm_putc,
|
||||
.sc_force = itm_putc,
|
||||
.sc_flush = itm_flush,
|
||||
};
|
||||
|
||||
/* This structure describes the ITM SYSLOG channel */
|
||||
|
||||
static const struct syslog_channel_s g_itm_channel =
|
||||
{
|
||||
.sc_ops = &g_itm_channel_ops
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -89,8 +97,10 @@ static const struct syslog_channel_s g_itm_channel =
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int itm_putc(int ch)
|
||||
static int itm_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
UNUSED(channel);
|
||||
|
||||
/* ITM enabled */
|
||||
|
||||
if ((getreg32(ITM_TCR) & ITM_TCR_ITMENA_MASK) == 0)
|
||||
@@ -117,8 +127,9 @@ static int itm_putc(int ch)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int itm_flush(void)
|
||||
static int itm_flush(FAR struct syslog_channel_s *channel)
|
||||
{
|
||||
UNUSED(channel);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/syslog/ramlog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
@@ -719,12 +720,14 @@ void ramlog_syslog_register(void)
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
int ramlog_putc(int ch)
|
||||
int ramlog_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
FAR struct ramlog_dev_s *priv = &g_sysdev;
|
||||
int readers_waken = 0;
|
||||
int ret;
|
||||
|
||||
UNUSED(channel);
|
||||
|
||||
#ifdef CONFIG_RAMLOG_CRLF
|
||||
/* Ignore carriage returns. But return success. */
|
||||
|
||||
|
||||
+18
-17
@@ -48,7 +48,7 @@ extern "C"
|
||||
*/
|
||||
|
||||
struct syslog_channel_s; /* Forward reference */
|
||||
EXTERN FAR const struct syslog_channel_s *g_syslog_channel
|
||||
EXTERN FAR struct syslog_channel_s *g_syslog_channel
|
||||
[CONFIG_SYSLOG_MAX_CHANNELS];
|
||||
|
||||
/****************************************************************************
|
||||
@@ -73,16 +73,16 @@ EXTERN FAR const struct syslog_channel_s *g_syslog_channel
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the character device to be used.
|
||||
* oflags - File open flags
|
||||
* mode - File open mode (only if oflags include O_CREAT)
|
||||
* oflags - File open flags.
|
||||
* mode - File open mode (only if oflags include O_CREAT).
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* any failure.
|
||||
* Returns a newly created SYSLOG channel, or NULL in case of any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_dev_initialize(FAR const char *devpath, int oflags, int mode);
|
||||
FAR struct syslog_channel_s *syslog_dev_initialize(FAR const char *devpath,
|
||||
int oflags, int mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_uninitialize
|
||||
@@ -92,7 +92,7 @@ int syslog_dev_initialize(FAR const char *devpath, int oflags, int mode);
|
||||
* a different SYSLOG device. Currently only used for CONFIG_SYSLOG_FILE.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* channel - Handle to syslog channel to be used.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
@@ -104,9 +104,7 @@ int syslog_dev_initialize(FAR const char *devpath, int oflags, int mode);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SYSLOG_FILE
|
||||
void syslog_dev_uninitialize(void);
|
||||
#endif /* CONFIG_SYSLOG_FILE */
|
||||
void syslog_dev_uninitialize(FAR struct syslog_channel_s *channel);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_channel
|
||||
@@ -294,8 +292,9 @@ int syslog_force(int ch);
|
||||
* for the character driver interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* buffer - The buffer containing the data to be output
|
||||
* buflen - The number of bytes in the buffer
|
||||
* channel - Handle to syslog channel to be used.
|
||||
* buffer - The buffer containing the data to be output.
|
||||
* buflen - The number of bytes in the buffer.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the character is echoed back to the caller. A negated errno
|
||||
@@ -303,7 +302,8 @@ int syslog_force(int ch);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen);
|
||||
ssize_t syslog_dev_write(FAR struct syslog_channel_s *channel,
|
||||
FAR const char *buffer, size_t buflen);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_putc
|
||||
@@ -313,7 +313,8 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen);
|
||||
* character driver interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ch - The character to add to the SYSLOG (must be positive).
|
||||
* channel - Handle to syslog channel to be used.
|
||||
* ch - The character to add to the SYSLOG (must be positive).
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the character is echoed back to the caller. A negated
|
||||
@@ -321,7 +322,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_dev_putc(int ch);
|
||||
int syslog_dev_putc(FAR struct syslog_channel_s *channel, int ch);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_dev_flush
|
||||
@@ -330,14 +331,14 @@ int syslog_dev_putc(int ch);
|
||||
* Flush any buffer data in the file system to media.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* channel - Handle to syslog channel to be used.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value is returned on any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_dev_flush(void);
|
||||
int syslog_dev_flush(FAR struct syslog_channel_s *channel);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
# include <nuttx/syslog/ramlog.h>
|
||||
@@ -44,9 +45,7 @@
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ARCH_LOWPUTC)
|
||||
# define HAVE_LOWPUTC
|
||||
#elif !defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_SYSLOG_RPMSG)
|
||||
#if !defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_SYSLOG_RPMSG)
|
||||
# define NEED_LOWPUTC
|
||||
#endif
|
||||
|
||||
@@ -55,7 +54,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef NEED_LOWPUTC
|
||||
static int syslog_default_putc(int ch);
|
||||
static int syslog_default_putc(FAR struct syslog_channel_s *channel,
|
||||
int ch);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -63,36 +63,35 @@ static int syslog_default_putc(int ch);
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_RAMLOG_SYSLOG)
|
||||
static const struct syslog_channel_s g_default_channel =
|
||||
static const struct syslog_channel_ops_s g_default_channel_ops =
|
||||
{
|
||||
ramlog_putc,
|
||||
ramlog_putc,
|
||||
ramlog_putc
|
||||
};
|
||||
#elif defined(CONFIG_SYSLOG_RPMSG)
|
||||
static const struct syslog_channel_s g_default_channel =
|
||||
static const struct syslog_channel_ops_s g_default_channel_ops =
|
||||
{
|
||||
syslog_rpmsg_putc,
|
||||
syslog_rpmsg_putc,
|
||||
syslog_rpmsg_flush,
|
||||
syslog_rpmsg_write
|
||||
};
|
||||
#elif defined(HAVE_LOWPUTC)
|
||||
static const struct syslog_channel_s g_default_channel =
|
||||
{
|
||||
up_putc,
|
||||
up_putc,
|
||||
};
|
||||
#else
|
||||
static const struct syslog_channel_s g_default_channel =
|
||||
static const struct syslog_channel_ops_s g_default_channel_ops =
|
||||
{
|
||||
syslog_default_putc,
|
||||
syslog_default_putc,
|
||||
syslog_default_putc
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct syslog_channel_s g_default_channel =
|
||||
{
|
||||
&g_default_channel_ops
|
||||
};
|
||||
|
||||
/* This is the current syslog channel in use */
|
||||
|
||||
FAR const struct syslog_channel_s
|
||||
FAR struct syslog_channel_s
|
||||
*g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS] =
|
||||
{
|
||||
&g_default_channel
|
||||
@@ -106,13 +105,20 @@ FAR const struct syslog_channel_s
|
||||
* Name: syslog_default_putc and syslog_default_flush
|
||||
*
|
||||
* Description:
|
||||
* Dummy, no-nothing channel interface methods
|
||||
* If the arch supports a low-level putc function, output will be
|
||||
* redirected there. Else acts as a dummy, no-nothing channel.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef NEED_LOWPUTC
|
||||
static int syslog_default_putc(int ch)
|
||||
static int syslog_default_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
UNUSED(channel);
|
||||
|
||||
#if defined(CONFIG_ARCH_LOWPUTC)
|
||||
return up_putc(ch);
|
||||
#endif
|
||||
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
@@ -137,7 +143,7 @@ static int syslog_default_putc(int ch)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_channel(FAR const struct syslog_channel_s *channel)
|
||||
int syslog_channel(FAR struct syslog_channel_s *channel)
|
||||
{
|
||||
#if (CONFIG_SYSLOG_MAX_CHANNELS != 1)
|
||||
int i;
|
||||
@@ -147,7 +153,8 @@ int syslog_channel(FAR const struct syslog_channel_s *channel)
|
||||
|
||||
if (channel != NULL)
|
||||
{
|
||||
DEBUGASSERT(channel->sc_putc != NULL && channel->sc_force != NULL);
|
||||
DEBUGASSERT(channel->sc_ops->sc_putc != NULL &&
|
||||
channel->sc_ops->sc_force != NULL);
|
||||
|
||||
#if (CONFIG_SYSLOG_MAX_CHANNELS == 1)
|
||||
g_syslog_channel[0] = channel;
|
||||
@@ -187,7 +194,7 @@ int syslog_channel(FAR const struct syslog_channel_s *channel)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_channel_remove(FAR const struct syslog_channel_s *channel)
|
||||
int syslog_channel_remove(FAR struct syslog_channel_s *channel)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "syslog.h"
|
||||
|
||||
@@ -56,30 +58,29 @@
|
||||
|
||||
/* SYSLOG channel methods */
|
||||
|
||||
#ifndef HAVE_LOWPUTC
|
||||
static int syslog_console_force(int ch);
|
||||
#endif
|
||||
static int syslog_console_force(FAR struct syslog_channel_s *channel,
|
||||
int ch);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the SYSLOG channel */
|
||||
/* This structure describes the channel's operations. */
|
||||
|
||||
static const struct syslog_channel_s g_syslog_console_channel =
|
||||
static const struct syslog_channel_ops_s g_syslog_ops =
|
||||
{
|
||||
syslog_dev_putc,
|
||||
#ifdef HAVE_LOWPUTC
|
||||
up_putc,
|
||||
#else
|
||||
syslog_console_force,
|
||||
#endif
|
||||
syslog_dev_flush,
|
||||
#ifdef CONFIG_SYSLOG_WRITE
|
||||
syslog_dev_write,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Handle to the SYSLOG channel */
|
||||
|
||||
FAR static struct syslog_channel_s *g_syslog_console_channel;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -92,12 +93,17 @@ static const struct syslog_channel_s g_syslog_console_channel =
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef HAVE_LOWPUTC
|
||||
static int syslog_console_force(int ch)
|
||||
static int syslog_console_force(FAR struct syslog_channel_s *channel,
|
||||
int ch)
|
||||
{
|
||||
UNUSED(channel);
|
||||
|
||||
#ifdef HAVE_LOWPUTC
|
||||
return up_putc(ch);
|
||||
#endif
|
||||
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@@ -132,19 +138,22 @@ static int syslog_console_force(int ch)
|
||||
|
||||
int syslog_console_channel(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Initialize the character driver interface */
|
||||
|
||||
ret = syslog_dev_initialize("/dev/console", OPEN_FLAGS, OPEN_MODE);
|
||||
if (ret < 0)
|
||||
g_syslog_console_channel = syslog_dev_initialize("/dev/console",
|
||||
OPEN_FLAGS, OPEN_MODE);
|
||||
if (g_syslog_console_channel == NULL)
|
||||
{
|
||||
return ret;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Register the channel operations */
|
||||
|
||||
g_syslog_console_channel->sc_ops = &g_syslog_ops;
|
||||
|
||||
/* Use the character driver as the SYSLOG channel */
|
||||
|
||||
return syslog_channel(&g_syslog_console_channel);
|
||||
return syslog_channel(g_syslog_console_channel);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SYSLOG_CONSOLE */
|
||||
|
||||
@@ -26,8 +26,10 @@
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "syslog.h"
|
||||
|
||||
@@ -47,17 +49,19 @@
|
||||
/* SYSLOG channel methods */
|
||||
|
||||
#ifdef CONFIG_SYSLOG_CHAR_CRLF
|
||||
static int syslog_devchan_putc(int ch);
|
||||
static int syslog_devchan_putc(FAR struct syslog_channel_s *channel,
|
||||
int ch);
|
||||
#endif
|
||||
static int syslog_devchan_force(int ch);
|
||||
static int syslog_devchan_force(FAR struct syslog_channel_s *channel,
|
||||
int ch);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the SYSLOG channel */
|
||||
/* This structure describes the channel's operations. */
|
||||
|
||||
static const struct syslog_channel_s g_syslog_dev_channel =
|
||||
static const struct syslog_channel_ops_s g_syslog_ops =
|
||||
{
|
||||
#ifdef CONFIG_SYSLOG_CHAR_CRLF
|
||||
syslog_devchan_putc,
|
||||
@@ -71,6 +75,10 @@ static const struct syslog_channel_s g_syslog_dev_channel =
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Handle to the SYSLOG channel */
|
||||
|
||||
FAR static struct syslog_channel_s *g_syslog_dev_channel;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -84,7 +92,7 @@ static const struct syslog_channel_s g_syslog_dev_channel =
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SYSLOG_CHAR_CRLF
|
||||
static int syslog_devchan_putc(int ch)
|
||||
static int syslog_devchan_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -94,7 +102,7 @@ static int syslog_devchan_putc(int ch)
|
||||
{
|
||||
/* Pre-pend a carriage return */
|
||||
|
||||
ret = syslog_dev_putc('\r');
|
||||
ret = syslog_dev_putc(channel, '\r');
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@@ -103,7 +111,7 @@ static int syslog_devchan_putc(int ch)
|
||||
|
||||
/* Output the provided character */
|
||||
|
||||
return syslog_dev_putc(ch);
|
||||
return syslog_dev_putc(channel, ch);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -115,8 +123,10 @@ static int syslog_devchan_putc(int ch)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int syslog_devchan_force(int ch)
|
||||
static int syslog_devchan_force(FAR struct syslog_channel_s *channel,
|
||||
int ch)
|
||||
{
|
||||
UNUSED(channel);
|
||||
return ch;
|
||||
}
|
||||
|
||||
@@ -150,19 +160,22 @@ static int syslog_devchan_force(int ch)
|
||||
|
||||
int syslog_dev_channel(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Initialize the character driver interface */
|
||||
|
||||
ret = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH, OPEN_FLAGS, OPEN_MODE);
|
||||
if (ret < 0)
|
||||
g_syslog_dev_channel = syslog_dev_initialize(CONFIG_SYSLOG_DEVPATH,
|
||||
OPEN_FLAGS, OPEN_MODE);
|
||||
if (g_syslog_dev_channel == NULL)
|
||||
{
|
||||
return ret;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Register the channel operations */
|
||||
|
||||
g_syslog_dev_channel->sc_ops = &g_syslog_ops;
|
||||
|
||||
/* Use the character driver as the SYSLOG channel */
|
||||
|
||||
return syslog_channel(&g_syslog_dev_channel);
|
||||
return syslog_channel(g_syslog_dev_channel);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SYSLOG_CHAR */
|
||||
|
||||
+173
-131
File diff suppressed because it is too large
Load Diff
@@ -27,8 +27,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sched.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "syslog.h"
|
||||
|
||||
@@ -47,15 +49,15 @@
|
||||
|
||||
/* SYSLOG channel methods */
|
||||
|
||||
static int syslog_file_force(int ch);
|
||||
static int syslog_file_force(FAR struct syslog_channel_s *channel, int ch);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the SYSLOG channel */
|
||||
/* This structure describes the channel's operations. */
|
||||
|
||||
static const struct syslog_channel_s g_syslog_file_channel =
|
||||
static const struct syslog_channel_ops_s g_syslog_ops =
|
||||
{
|
||||
syslog_dev_putc,
|
||||
syslog_file_force,
|
||||
@@ -65,6 +67,10 @@ static const struct syslog_channel_s g_syslog_file_channel =
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Handle to the SYSLOG channel */
|
||||
|
||||
FAR static struct syslog_channel_s *g_syslog_file_channel;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -77,8 +83,9 @@ static const struct syslog_channel_s g_syslog_file_channel =
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int syslog_file_force(int ch)
|
||||
static int syslog_file_force(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
UNUSED(channel);
|
||||
return ch;
|
||||
}
|
||||
|
||||
@@ -138,21 +145,30 @@ int syslog_file_channel(FAR const char *devpath)
|
||||
|
||||
/* Uninitialize any driver interface that may have been in place */
|
||||
|
||||
syslog_dev_uninitialize();
|
||||
if (g_syslog_file_channel != NULL)
|
||||
{
|
||||
syslog_dev_uninitialize(g_syslog_file_channel);
|
||||
}
|
||||
|
||||
/* Then initialize the file interface */
|
||||
|
||||
ret = syslog_dev_initialize(devpath, OPEN_FLAGS, OPEN_MODE);
|
||||
if (ret < 0)
|
||||
g_syslog_file_channel = syslog_dev_initialize(devpath, OPEN_FLAGS,
|
||||
OPEN_MODE);
|
||||
if (g_syslog_file_channel == NULL)
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Register the channel operations */
|
||||
|
||||
g_syslog_file_channel->sc_ops = &g_syslog_ops;
|
||||
|
||||
/* Use the file as the SYSLOG channel. If this fails we are pretty much
|
||||
* screwed.
|
||||
*/
|
||||
|
||||
ret = syslog_channel(&g_syslog_file_channel);
|
||||
ret = syslog_channel(g_syslog_file_channel);
|
||||
|
||||
errout_with_lock:
|
||||
sched_unlock();
|
||||
|
||||
@@ -83,9 +83,9 @@ int syslog_flush(void)
|
||||
|
||||
/* Then flush all of the buffered output to the SYSLOG device */
|
||||
|
||||
if (g_syslog_channel[i]->sc_flush != NULL)
|
||||
if (g_syslog_channel[i]->sc_ops->sc_flush != NULL)
|
||||
{
|
||||
g_syslog_channel[i]->sc_flush();
|
||||
g_syslog_channel[i]->sc_ops->sc_flush(g_syslog_channel[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ int syslog_force(int ch)
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_force != NULL);
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_force != NULL);
|
||||
|
||||
/* Then send the character to the emergency channel */
|
||||
|
||||
g_syslog_channel[i]->sc_force(ch);
|
||||
g_syslog_channel[i]->sc_ops->sc_force(g_syslog_channel[i], ch);
|
||||
}
|
||||
|
||||
return ch;
|
||||
|
||||
@@ -307,10 +307,10 @@ int syslog_flush_intbuffer(bool force)
|
||||
|
||||
/* Select which putc function to use for this flush */
|
||||
|
||||
putfunc = force ? g_syslog_channel[i]->sc_putc :
|
||||
g_syslog_channel[i]->sc_force;
|
||||
putfunc = force ? g_syslog_channel[i]->sc_ops->sc_putc :
|
||||
g_syslog_channel[i]->sc_ops->sc_force;
|
||||
|
||||
putfunc(ch);
|
||||
putfunc(g_syslog_channel[i], ch);
|
||||
}
|
||||
}
|
||||
while (ch != EOF);
|
||||
|
||||
@@ -88,9 +88,10 @@ int syslog_putc(int ch)
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_force != NULL);
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_force != NULL);
|
||||
|
||||
g_syslog_channel[i]->sc_force(ch);
|
||||
g_syslog_channel[i]->sc_ops->sc_force(g_syslog_channel[i],
|
||||
ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,9 +112,9 @@ int syslog_putc(int ch)
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_putc != NULL);
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_putc != NULL);
|
||||
|
||||
g_syslog_channel[i]->sc_putc(ch);
|
||||
g_syslog_channel[i]->sc_ops->sc_putc(g_syslog_channel[i], ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <nuttx/syslog/syslog.h>
|
||||
#include <nuttx/syslog/syslog_rpmsg.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "syslog.h"
|
||||
#include "syslog_rpmsg.h"
|
||||
@@ -298,11 +299,13 @@ static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_rpmsg_putc(int ch)
|
||||
int syslog_rpmsg_putc(FAR struct syslog_channel_s *channel, int ch)
|
||||
{
|
||||
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
||||
irqstate_t flags;
|
||||
|
||||
UNUSED(channel);
|
||||
|
||||
flags = enter_critical_section();
|
||||
syslog_rpmsg_putchar(priv, ch, true);
|
||||
leave_critical_section(flags);
|
||||
@@ -310,20 +313,25 @@ int syslog_rpmsg_putc(int ch)
|
||||
return ch;
|
||||
}
|
||||
|
||||
int syslog_rpmsg_flush(void)
|
||||
int syslog_rpmsg_flush(FAR struct syslog_channel_s *channel)
|
||||
{
|
||||
UNUSED(channel);
|
||||
|
||||
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
||||
|
||||
work_queue(HPWORK, &priv->work, syslog_rpmsg_work, priv, 0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
ssize_t syslog_rpmsg_write(FAR const char *buffer, size_t buflen)
|
||||
ssize_t syslog_rpmsg_write(FAR struct syslog_channel_s *channel,
|
||||
FAR const char *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct syslog_rpmsg_s *priv = &g_syslog_rpmsg;
|
||||
irqstate_t flags;
|
||||
size_t nwritten;
|
||||
|
||||
UNUSED(channel);
|
||||
|
||||
flags = enter_critical_section();
|
||||
for (nwritten = 1; nwritten <= buflen; nwritten++)
|
||||
{
|
||||
|
||||
@@ -78,8 +78,9 @@ static ssize_t syslog_default_write(FAR const char *buffer, size_t buflen)
|
||||
break;
|
||||
}
|
||||
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_force != NULL);
|
||||
g_syslog_channel[i]->sc_force(*buffer++);
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_force != NULL);
|
||||
g_syslog_channel[i]->sc_ops->sc_force(g_syslog_channel[i],
|
||||
*buffer++);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,18 +95,21 @@ static ssize_t syslog_default_write(FAR const char *buffer, size_t buflen)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SYSLOG_WRITE
|
||||
if (g_syslog_channel[i]->sc_write)
|
||||
if (g_syslog_channel[i]->sc_ops->sc_write)
|
||||
{
|
||||
nwritten = g_syslog_channel[i]->sc_write(buffer, buflen);
|
||||
nwritten =
|
||||
g_syslog_channel[i]->sc_ops->sc_write(g_syslog_channel[i],
|
||||
buffer, buflen);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_putc != NULL);
|
||||
DEBUGASSERT(g_syslog_channel[i]->sc_ops->sc_putc != NULL);
|
||||
|
||||
for (nwritten = 0; nwritten < buflen; nwritten++)
|
||||
{
|
||||
g_syslog_channel[i]->sc_putc(*buffer++);
|
||||
g_syslog_channel[i]->sc_ops->sc_putc(g_syslog_channel[i],
|
||||
*buffer++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ void ramlog_syslog_register(void);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RAMLOG_SYSLOG
|
||||
int ramlog_putc(int ch);
|
||||
int ramlog_putc(FAR struct syslog_channel_s *channel, int ch);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
|
||||
@@ -82,22 +82,37 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure provides the interface to a SYSLOG device */
|
||||
/* Forward declaration */
|
||||
|
||||
typedef CODE ssize_t (*syslog_write_t)(FAR const char *buf, size_t buflen);
|
||||
typedef CODE int (*syslog_putc_t)(int ch);
|
||||
typedef CODE int (*syslog_flush_t)(void);
|
||||
struct syslog_channel_s;
|
||||
|
||||
struct syslog_channel_s
|
||||
/* SYSLOG I/O redirection methods */
|
||||
|
||||
typedef CODE ssize_t (*syslog_write_t)(FAR struct syslog_channel_s *channel,
|
||||
FAR const char *buf, size_t buflen);
|
||||
typedef CODE int (*syslog_putc_t)(FAR struct syslog_channel_s *channel,
|
||||
int ch);
|
||||
typedef CODE int (*syslog_flush_t)(FAR struct syslog_channel_s *channel);
|
||||
|
||||
/* SYSLOG device operations */
|
||||
|
||||
struct syslog_channel_ops_s
|
||||
{
|
||||
/* I/O redirection methods */
|
||||
|
||||
syslog_putc_t sc_putc; /* Normal buffered output */
|
||||
syslog_putc_t sc_force; /* Low-level output for interrupt handlers */
|
||||
syslog_flush_t sc_flush; /* Flush buffered output (on crash) */
|
||||
#ifdef CONFIG_SYSLOG_WRITE
|
||||
syslog_write_t sc_write; /* Write multiple bytes */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* This structure provides the interface to a SYSLOG channel */
|
||||
|
||||
struct syslog_channel_s
|
||||
{
|
||||
/* Channel operations */
|
||||
|
||||
FAR const struct syslog_channel_ops_s *sc_ops;
|
||||
|
||||
/* Implementation specific logic may follow */
|
||||
};
|
||||
@@ -136,7 +151,7 @@ extern "C"
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_channel(FAR const struct syslog_channel_s *channel);
|
||||
int syslog_channel(FAR struct syslog_channel_s *channel);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_channel_remove
|
||||
@@ -154,7 +169,7 @@ int syslog_channel(FAR const struct syslog_channel_s *channel);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syslog_channel_remove(FAR const struct syslog_channel_s *channel);
|
||||
int syslog_channel_remove(FAR struct syslog_channel_s *channel);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syslog_initialize
|
||||
|
||||
@@ -44,9 +44,10 @@ void syslog_rpmsg_init_early(FAR const char *cpu_name, FAR void *buffer,
|
||||
size_t size);
|
||||
int syslog_rpmsg_init(void);
|
||||
|
||||
int syslog_rpmsg_putc(int ch);
|
||||
int syslog_rpmsg_flush(void);
|
||||
ssize_t syslog_rpmsg_write(FAR const char *buffer, size_t buflen);
|
||||
int syslog_rpmsg_putc(FAR struct syslog_channel_s *channel, int ch);
|
||||
int syslog_rpmsg_flush(FAR struct syslog_channel_s *channel);
|
||||
ssize_t syslog_rpmsg_write(FAR struct syslog_channel_s *channel,
|
||||
FAR const char *buffer, size_t buflen);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYSLOG_RPMSG_SERVER
|
||||
|
||||
Reference in New Issue
Block a user