automotive-dlt
dlt-logstorage-ctrl.c File Reference
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <getopt.h>
#include <sys/epoll.h>
#include "sd-daemon.h"
#include "dlt_protocol.h"
#include "dlt_client.h"
#include "dlt-control-common.h"
#include "dlt-logstorage-common.h"
#include "dlt-logstorage-ctrl.h"
Include dependency graph for dlt-logstorage-ctrl.c:

Go to the source code of this file.

Macros

#define pr_fmt(fmt)   "Logstorage control: "fmt
 
#define EPOLL_MAX_EVENTS   10
 
#define EPOLL_TIME_OUT   500
 
#define DLT_LOGSTORAGE_CTRL_EXIT   1
 
#define MAX_RESPONSE_LENGTH   32
 

Functions

void dlt_logstorage_exit (void)
 Triggers the application exit. More...
 
int dlt_logstorage_must_exit (void)
 Check if the application must exit. More...
 
static void catch_signal (int signo)
 Signal handler. More...
 
static void install_signal_handler (void)
 Install a handler for some signals. More...
 
static int analyze_response (char *data, void *payload, int len)
 Analyze the daemon answer to a request. More...
 
static int dlt_logstorage_ctrl_add_event (int fd, void *cb)
 Add a new event to watch to the epoll instance. More...
 
static int dlt_logstorage_ctrl_execute_event_loop (int efd)
 Main execution loop. More...
 
static int dlt_logstorage_ctrl_setup_event_loop (void)
 Start event loop and receive messages from DLT. More...
 
static int dlt_logstorage_ctrl_single_request ()
 Send a single command to DLT daemon and wait for response. More...
 
static void usage (void)
 Print out the application help. More...
 
static int parse_args (int argc, char *argv[])
 Parses the application arguments. More...
 
int main (int argc, char *argv[])
 Entry point. More...
 

Variables

static int must_exit
 
static int efd
 
static struct option long_options []
 

Detailed Description

app begin@ Copyright (C) 2013 - 2015 Advanced Driver Information Technology. This code is developed by Advanced Driver Information Technology. Copyright of Advanced Driver Information Technology, Bosch and DENSO. * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.

Author
Syed Hameed shame.nosp@m.ed@j.nosp@m.p.adi.nosp@m.t-jv.nosp@m..com ADIT 2013 - 2015
Christoph Lipka clipk.nosp@m.a@jp.nosp@m..adit.nosp@m.-jv..nosp@m.com ADIT 2015
Frederic Berat fbera.nosp@m.t@de.nosp@m..adit.nosp@m.-jv..nosp@m.com ADIT 2015

For further information see http://www.genivi.org/. end@

Definition in file dlt-logstorage-ctrl.c.

Macro Definition Documentation

#define DLT_LOGSTORAGE_CTRL_EXIT   1

Definition at line 79 of file dlt-logstorage-ctrl.c.

Referenced by dlt_logstorage_exit().

#define EPOLL_MAX_EVENTS   10

Definition at line 76 of file dlt-logstorage-ctrl.c.

Referenced by dlt_logstorage_ctrl_execute_event_loop().

#define EPOLL_TIME_OUT   500

Definition at line 77 of file dlt-logstorage-ctrl.c.

Referenced by dlt_logstorage_ctrl_execute_event_loop().

#define MAX_RESPONSE_LENGTH   32

Definition at line 143 of file dlt-logstorage-ctrl.c.

Referenced by analyze_response().

#define pr_fmt (   fmt)    "Logstorage control: "fmt

Definition at line 56 of file dlt-logstorage-ctrl.c.

Function Documentation

static int analyze_response ( char *  data,
void *  payload,
int  len 
)
static

Analyze the daemon answer to a request.

This function checks whether if the daemon answered positively to the request or not.

Parameters
dataThe textual answer
payloadThe answer payload
lenThe answer payload length
Returns
0 on success, -1 otherwise.

Definition at line 154 of file dlt-logstorage-ctrl.c.

References DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, MAX_RESPONSE_LENGTH, NULL, and pr_verbose.

Referenced by dlt_logstorage_ctrl_setup_event_loop(), and dlt_logstorage_ctrl_single_request().

static void catch_signal ( int  signo)
static

Signal handler.

Triggers the exit of the application in case of specific signals

Parameters
signoThe value of the signal received.

Definition at line 107 of file dlt-logstorage-ctrl.c.

References dlt_logstorage_exit(), and pr_error.

Referenced by install_signal_handler().

static int dlt_logstorage_ctrl_add_event ( int  fd,
void *  cb 
)
static

Add a new event to watch to the epoll instance.

This function could be exported to be used by udev/prop so that they can register several events. There is no remove function as the removal is done on efd closure.

Parameters
fdThe file descriptor to watch
cbThe callback to be called on event.
Returns
epoll_ctrl return value, or -1 on earlier failure.

Definition at line 195 of file dlt-logstorage-ctrl.c.

References efd, pr_error, and pr_verbose.

Referenced by dlt_logstorage_ctrl_setup_event_loop().

static int dlt_logstorage_ctrl_execute_event_loop ( int  efd)
static

Main execution loop.

Waits on events from the epoll fd, and executes the callbacks retrieved back from the event structure.

Returns
0 on success, -1 otherwise.

Definition at line 220 of file dlt-logstorage-ctrl.c.

References data, dlt_logstorage_exit(), EPOLL_MAX_EVENTS, EPOLL_TIME_OUT, pr_error, and pr_verbose.

Referenced by dlt_logstorage_ctrl_setup_event_loop().

static int dlt_logstorage_ctrl_setup_event_loop ( void  )
static

Start event loop and receive messages from DLT.

The function will first install the signal handler, then create the epoll instance, initialize the communication controller, initialize the event handler and finally start the polling.

Returns
0 on success, -1 on error

Definition at line 301 of file dlt-logstorage-ctrl.c.

References analyze_response(), dlt_control_deinit(), dlt_control_init(), dlt_logstorage_ctrl_add_event(), dlt_logstorage_ctrl_execute_event_loop(), dlt_logstorage_deinit_handler(), dlt_logstorage_exit(), dlt_logstorage_get_handler_cb(), dlt_logstorage_get_handler_fd(), dlt_logstorage_init_handler(), dlt_logstorage_must_exit(), efd, get_ecuid(), get_timeout(), get_verbosity(), install_signal_handler(), pr_error, and pr_verbose.

Referenced by main().

static int dlt_logstorage_ctrl_single_request ( )
static
void dlt_logstorage_exit ( void  )

Triggers the application exit.

The application will exit on next epoll timeout.

Definition at line 87 of file dlt-logstorage-ctrl.c.

References DLT_LOGSTORAGE_CTRL_EXIT, and must_exit.

Referenced by catch_signal(), dlt_logstorage_ctrl_execute_event_loop(), and dlt_logstorage_ctrl_setup_event_loop().

int dlt_logstorage_must_exit ( void  )

Check if the application must exit.

The application will exit on next epoll timeout.

Definition at line 96 of file dlt-logstorage-ctrl.c.

References must_exit.

Referenced by dlt_logstorage_ctrl_setup_event_loop(), and dlt_logstorage_ctrl_single_request().

static void install_signal_handler ( void  )
static

Install a handler for some signals.

Handler are installed on exit related signals. That allows to exit from the main loop gracefully.

Definition at line 121 of file dlt-logstorage-ctrl.c.

References catch_signal(), NULL, pr_error, and pr_verbose.

Referenced by dlt_logstorage_ctrl_setup_event_loop().

int main ( int  argc,
char *  argv[] 
)

Entry point.

Execute the argument parser and call the main feature accordingly.

Parameters
argcThe amount of arguments
argvThe table of arguments
Returns
0 on success, -1 otherwise

Definition at line 551 of file dlt-logstorage-ctrl.c.

References CTRL_NOHANDLER, DLT_CTRL_TIMEOUT, dlt_logstorage_ctrl_setup_event_loop(), dlt_logstorage_ctrl_single_request(), get_handler_type(), NULL, parse_args(), pr_error, pr_verbose, set_ecuid(), and set_timeout().

static int parse_args ( int  argc,
char *  argv[] 
)
static

Parses the application arguments.

The arguments are parsed and saved in static structure for future use.

Parameters
argcThe amount of arguments
argvThe table of arguments
Returns
0 on success, -1 otherwise

Definition at line 454 of file dlt-logstorage-ctrl.c.

References CTRL_NOHANDLER, DLT_MOUNT_PATH_MAX, EVENT_SYNC_CACHE, get_default_event_type(), get_handler_type(), long_options, NULL, pr_error, pr_verbose, set_default_event_type(), set_default_path(), set_ecuid(), set_handler_type(), set_timeout(), set_verbosity(), and usage().

Referenced by main().

static void usage ( void  )
static

Print out the application help.

Definition at line 412 of file dlt-logstorage-ctrl.c.

References DLT_CTRL_DEFAULT_ECUID, DLT_CTRL_TIMEOUT, and get_verbosity().

Referenced by parse_args().

Variable Documentation

int efd
static
struct option long_options[]
static
Initial value:
= {
{"command", required_argument, 0, 'c'},
{"daemonize", optional_argument, 0, 'd'},
{"ecuid", required_argument, 0, 'e'},
{"help", no_argument, 0, 'h'},
{"path", required_argument, 0, 'p'},
{"snapshot", optional_argument, 0, 's'},
{"timeout", required_argument, 0, 't'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
}

Definition at line 433 of file dlt-logstorage-ctrl.c.

Referenced by parse_args().

int must_exit
static

Definition at line 80 of file dlt-logstorage-ctrl.c.

Referenced by dlt_logstorage_exit(), and dlt_logstorage_must_exit().