Commit 42ba921c authored by Federico Vaga's avatar Federico Vaga

wrtd:lib: always share logging interface

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 7f974a1b
......@@ -83,24 +83,41 @@ void wrtd_exit()
/**
* Open a WRTD node device using FMC ID
* @param[in] device_id FMC device identificator
* It opens and initialize the configuration for the given device
* @param[in] device_id device identifier
* @param[in] is_lun 1 if device_id is a LUN
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
struct wrtd_node *wrtd_open_by_fmc(uint32_t device_id)
static struct wrtd_node *wrtd_open(uint32_t device_id, unsigned int is_lun)
{
struct wrtd_desc *wrtd;
int err;
wrtd = malloc(sizeof(struct wrtd_desc));
if (!wrtd)
return NULL;
wrtd->wrnc = wrnc_open_by_fmc(device_id);
if (is_lun)
wrtd->wrnc = wrnc_open_by_lun(device_id);
else
wrtd->wrnc = wrnc_open_by_fmc(device_id);
if (!wrtd->wrnc)
goto out;
wrtd->dev_id = device_id;
/* Logging interface is always in share mode */
err = wrnc_hmq_share_set(wrtd->wrnc, WRNC_HMQ_OUTCOMING,
WRTD_OUT_FD_LOGGING, 1);
if (err)
goto out;
err = wrnc_hmq_share_set(wrtd->wrnc, WRNC_HMQ_OUTCOMING,
WRTD_OUT_TDC_LOGGING, 1);
if (err)
goto out;
return (struct wrtd_node *)wrtd;
out:
......@@ -108,6 +125,17 @@ out:
return NULL;
}
/**
* Open a WRTD node device using FMC ID
* @param[in] device_id FMC device identificator
* @return It returns an anonymous wrtd_node structure on success.
* On error, NULL is returned, and errno is set appropriately.
*/
struct wrtd_node *wrtd_open_by_fmc(uint32_t device_id)
{
return wrtd_open(device_id, 0);
}
/**
* Open a WRTD node device using LUN
......@@ -118,23 +146,7 @@ out:
*/
struct wrtd_node *wrtd_open_by_lun(int lun)
{
struct wrtd_desc *wrtd;
wrtd = malloc(sizeof(struct wrtd_desc));
if (!wrtd)
return NULL;
wrtd->wrnc = wrnc_open_by_lun(lun);
if (!wrtd->wrnc)
goto out;
wrtd->dev_id = lun;
return (struct wrtd_node *)wrtd;
out:
free(wrtd);
return NULL;
return wrtd_open(lun, 1);
}
......
......@@ -241,41 +241,6 @@ int wrtd_out_log_level_set(struct wrtd_node *dev, unsigned int output,
}
/**
* It sets the logging interface shared mode. When the logging interface
* is shared all users will receive the same messages.
* Rembember that the logging interface is not "per-channel" but "per-core".
* Even if it is possible to fake a per-channel behaviour
* for wrtd_in_log_open(); there is no way to set the shared mode for
* single channel
* @param[in] dev device token
* @param[in] shared 1 share, 0 not share
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_log_share_set(struct wrtd_node *dev, unsigned int shared)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return wrnc_hmq_share_set(wrtd->wrnc, WRNC_HMQ_OUTCOMING,
WRTD_OUT_FD_LOGGING, shared);
}
/**
* It gets the current shared mode status for the logging interface
* @param[in] dev device token
* @param[out] shared 1 share, 0 not share
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_out_log_share_get(struct wrtd_node *dev, unsigned int *shared)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return wrnc_hmq_share_get(wrtd->wrnc, WRNC_HMQ_OUTCOMING,
WRTD_OUT_FD_LOGGING, shared);
}
/**
* It opens the logging interface for device a given divice. The default
* logging level will be applied to all device channels. You can change it
......@@ -306,38 +271,3 @@ int wrtd_in_log_level_set(struct wrtd_node *dev, unsigned int input,
{
return wrtd_log_level_set(dev, input, log_level, WRTD_CORE_IN);
}
/**
* It sets the logging interface shared mode. When the logging interface
* is shared all users will receive the same messages.
* Rembember that the logging interface is not "per-channel" but "per-core".
* Even if it is possible to fake a per-channel behaviour
* for wrtd_in_log_open(); there is no way to set the shared mode for
* single channel
* @param[in] dev device token
* @param[in] shared 1 share, 0 not share
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_log_share_set(struct wrtd_node *dev, unsigned int shared)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return wrnc_hmq_share_set(wrtd->wrnc, WRNC_HMQ_OUTCOMING,
WRTD_OUT_TDC_LOGGING, shared);
}
/**
* It gets the current shared mode status for the logging interface
* @param[in] dev device token
* @param[out] shared 1 share, 0 not share
* @return 0 on success, -1 on error and errno is set appropriately
*/
int wrtd_in_log_share_get(struct wrtd_node *dev, unsigned int *shared)
{
struct wrtd_desc *wrtd = (struct wrtd_desc *)dev;
return wrnc_hmq_share_get(wrtd->wrnc, WRNC_HMQ_OUTCOMING,
WRTD_OUT_TDC_LOGGING, shared);
}
......@@ -197,12 +197,8 @@ extern struct wrnc_hmq *wrtd_in_log_open(struct wrtd_node *dev,
int input);
extern int wrtd_in_log_level_set(struct wrtd_node *dev, unsigned int input,
uint32_t log_level);
extern int wrtd_in_log_share_set(struct wrtd_node *dev, unsigned int shared);
extern int wrtd_in_log_share_get(struct wrtd_node *dev, unsigned int *shared);
extern int wrtd_out_log_level_set(struct wrtd_node *dev, unsigned int output,
uint32_t log_level);
extern int wrtd_out_log_share_set(struct wrtd_node *dev, unsigned int shared);
extern int wrtd_out_log_share_get(struct wrtd_node *dev, unsigned int *shared);
extern struct wrnc_hmq *wrtd_out_log_open(struct wrtd_node *dev,
uint32_t lvl,
int output);
......
......@@ -21,7 +21,6 @@ static void help()
fprintf(stderr, "It shows logging information coming from Real-Time applications\n");
fprintf(stderr, "-D device id\n");
fprintf(stderr, "-n number of messages to read (0 means infinite)\n");
fprintf(stderr, "-s share the logging device with other processes\n");
exit(1);
}
......@@ -55,7 +54,7 @@ int main(int argc, char *argv[])
{
struct wrnc_hmq *log[N_LOG];
struct pollfd p[N_LOG]; /* each node has 2 logging channels (in, out) */
int n = 0, i = 0, ret, k, err, share = 0, chan = -1;
int n = 0, i = 0, ret, k, err, chan = -1;
struct wrtd_node *wrtd;
uint32_t dev_id = 0;
char c;
......@@ -71,9 +70,6 @@ int main(int argc, char *argv[])
case 'n':
sscanf(optarg, "0x%x", &n);
break;
case 's':
share = 1;
break;
}
}
......@@ -94,15 +90,6 @@ int main(int argc, char *argv[])
exit(1);
}
if (share) {
err = wrtd_in_log_share_set(wrtd, 1);
if (err)
fprintf(stderr, "Cannot set share mode: %s\n", wrtd_strerror(errno));
err = wrtd_out_log_share_set(wrtd, 1);
if (err)
fprintf(stderr, "Cannot set share mode: %s\n", wrtd_strerror(errno));
}
/* Open logging interfaces */
log[0] = wrtd_in_log_open(wrtd, WRTD_LOG_ALL, chan);
if (!log[0]) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment