2016-06-19 17:48:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/syslog/syslog_channel.c
|
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-06-19 17:48:42 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-19 17:48:42 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-06-19 17:48:42 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-18 20:54:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-06-20 15:35:38 +02:00
|
|
|
#include <sys/types.h>
|
2016-06-18 20:54:55 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/syslog/syslog.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_RAMLOG_SYSLOG
|
|
|
|
# include <nuttx/syslog/ramlog.h>
|
2020-02-22 21:47:40 +01:00
|
|
|
#elif defined(CONFIG_SYSLOG_RPMSG)
|
|
|
|
# include <nuttx/syslog/syslog_rpmsg.h>
|
2016-06-18 20:54:55 +02:00
|
|
|
#elif defined(CONFIG_ARCH_LOWPUTC)
|
|
|
|
# include <nuttx/arch.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "syslog.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-26 14:49:35 +02:00
|
|
|
#if defined(CONFIG_ARCH_LOWPUTC)
|
2016-06-21 23:08:09 +02:00
|
|
|
# define HAVE_LOWPUTC
|
2020-02-22 21:47:40 +01:00
|
|
|
#elif !defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_SYSLOG_RPMSG)
|
2016-06-21 23:08:09 +02:00
|
|
|
# define NEED_LOWPUTC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef NEED_LOWPUTC
|
2016-06-18 20:54:55 +02:00
|
|
|
static int syslog_default_putc(int ch);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-06-21 20:25:15 +02:00
|
|
|
* Public Data
|
2016-06-18 20:54:55 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_RAMLOG_SYSLOG)
|
2020-02-24 04:10:49 +01:00
|
|
|
static const struct syslog_channel_s g_default_channel =
|
2016-06-18 20:54:55 +02:00
|
|
|
{
|
|
|
|
ramlog_putc,
|
|
|
|
ramlog_putc,
|
|
|
|
};
|
2020-02-22 21:47:40 +01:00
|
|
|
#elif defined(CONFIG_SYSLOG_RPMSG)
|
2020-02-24 04:10:49 +01:00
|
|
|
static const struct syslog_channel_s g_default_channel =
|
2020-02-22 21:47:40 +01:00
|
|
|
{
|
|
|
|
syslog_rpmsg_putc,
|
|
|
|
syslog_rpmsg_putc,
|
2020-04-27 06:15:11 +02:00
|
|
|
syslog_rpmsg_flush,
|
|
|
|
syslog_rpmsg_write
|
2020-02-22 21:47:40 +01:00
|
|
|
};
|
2016-06-21 23:08:09 +02:00
|
|
|
#elif defined(HAVE_LOWPUTC)
|
2020-02-24 04:10:49 +01:00
|
|
|
static const struct syslog_channel_s g_default_channel =
|
2016-06-18 20:54:55 +02:00
|
|
|
{
|
|
|
|
up_putc,
|
|
|
|
up_putc,
|
|
|
|
};
|
|
|
|
#else
|
2020-02-24 04:10:49 +01:00
|
|
|
static const struct syslog_channel_s g_default_channel =
|
2016-06-18 20:54:55 +02:00
|
|
|
{
|
|
|
|
syslog_default_putc,
|
|
|
|
syslog_default_putc,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This is the current syslog channel in use */
|
|
|
|
|
2016-06-21 01:10:52 +02:00
|
|
|
FAR const struct syslog_channel_s *g_syslog_channel = &g_default_channel;
|
2016-06-18 20:54:55 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-20 15:35:38 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_default_putc and syslog_default_flush
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dummy, no-nothing channel interface methods
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-21 23:08:09 +02:00
|
|
|
#ifdef NEED_LOWPUTC
|
2016-06-18 20:54:55 +02:00
|
|
|
static int syslog_default_putc(int ch)
|
|
|
|
{
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslog_channel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the SYSLOGging function to use the provided channel to
|
|
|
|
* generate SYSLOG output.
|
|
|
|
*
|
2016-06-20 15:35:38 +02:00
|
|
|
* Input Parameters:
|
2016-06-18 20:54:55 +02:00
|
|
|
* channel - Provides the interface to the channel to be used.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2019-09-17 18:46:23 +02:00
|
|
|
* Zero (OK) is returned on success. A negated errno value is returned
|
2016-06-18 20:54:55 +02:00
|
|
|
* on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int syslog_channel(FAR const struct syslog_channel_s *channel)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(channel != NULL);
|
|
|
|
|
|
|
|
if (channel != NULL)
|
|
|
|
{
|
2020-04-27 06:23:42 +02:00
|
|
|
DEBUGASSERT(channel->sc_putc != NULL && channel->sc_force != NULL);
|
2016-06-18 20:54:55 +02:00
|
|
|
|
|
|
|
g_syslog_channel = channel;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|