diff options
author | Christoph Lipka <clipka@jp.adit-jv.com> | 2015-11-18 19:19:22 +0900 |
---|---|---|
committer | Lutz Helwing <lutz_helwing@mentor.com> | 2015-11-24 09:48:41 +0100 |
commit | da4ac57d87108d8b2690979c273c000a798a59f5 (patch) | |
tree | 45f79c0c90d3b4c9a6804d6794da5485a5f05ed3 /src/lib | |
parent | 188772ea0b3479352ae93552014d45fd1bc8e804 (diff) | |
download | DLT-daemon-da4ac57d87108d8b2690979c273c000a798a59f5.tar.gz |
Unix socket control interface
Control applications running in the same Linux OS should be able to communicate
with the DLT Daemon via a socket connection.
To be able to do that, the DLT Client library need to be extended. DLT
Clients connected via this UNIX socket are not handled as normal DLT
Clients and no log messages will be forwarded to them. This avoids
problems in situations when a control application is connected to the
DLT Daemon before any other 'real' DLT Client (e.g. DLT Viewer) is
connected. In this situations, all already stored log messages are
flushed to the control application and therefore lost, because the
control application most likely ignore all incoming messages besides the
one in which it is interested in.
Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dlt_client.c | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c index 2bae2eb..3de3845 100644 --- a/src/lib/dlt_client.c +++ b/src/lib/dlt_client.c @@ -77,6 +77,7 @@ #include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ #include <netdb.h> #include <sys/stat.h> +#include <sys/un.h> #endif #if defined(_MSC_VER) @@ -116,7 +117,8 @@ DltReturnValue dlt_client_init(DltClient *client, int verbose) client->servIP = 0; client->serialDevice = 0; client->baudrate = DLT_CLIENT_INITIAL_BAUDRATE; - client->serial_mode = 0; + client->socketPath = 0; + client->mode=DLT_CLIENT_MODE_TCP; client->receiver.buffer = 0; return DLT_RETURN_OK; @@ -126,6 +128,7 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) { char portnumbuffer[33]; struct addrinfo hints, *servinfo, *p; + struct sockaddr_un addr; int rv; char *env_daemon_port; /* the port may be specified by an environment variable, defaults to DLT_DAEMON_TCP_PORT */ @@ -149,8 +152,9 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) servPort = DLT_DAEMON_TCP_PORT; } - if (client->serial_mode==0) + switch (client->mode) { + case DLT_CLIENT_MODE_TCP: snprintf(portnumbuffer, 32, "%d", servPort); if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); @@ -182,9 +186,8 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) { printf("Connected to DLT daemon (%s)\n",client->servIP); } - } - else - { + break; + case DLT_CLIENT_MODE_SERIAL: /* open serial connection */ client->sock=open(client->serialDevice,O_RDWR); if (client->sock<0) @@ -218,6 +221,39 @@ DltReturnValue dlt_client_connect(DltClient *client, int verbose) { printf("Connected to %s\n", client->serialDevice); } + break; + case DLT_CLIENT_MODE_UNIX: + if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) + { + fprintf(stderr, "ERROR: (unix) socket error: %s\n", strerror(errno)); + return DLT_RETURN_ERROR; + } + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + memcpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path)-1); + + if (connect(client->sock, + (struct sockaddr_un *)&addr, + sizeof(addr)) == -1) + { + fprintf(stderr, "ERROR: (unix) connect error: %s\n", strerror(errno)); + return DLT_RETURN_ERROR; + } + + if (client->sock < 0) + { + fprintf(stderr,"ERROR: Failed to open device %s\n", + client->socketPath); + return DLT_RETURN_ERROR; + } + break; + default: + if (verbose) + { + fprintf(stderr, "ERROR: Mode not supported: %d\n", client->mode); + } + return DLT_RETURN_ERROR; } if (dlt_receiver_init(&(client->receiver),client->sock,DLT_CLIENT_RCVBUFSIZE) != DLT_RETURN_OK) @@ -271,7 +307,7 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose) while (1) { - if (client->serial_mode==0) + if (client->mode==0) { /* wait for data from socket */ ret = dlt_receiver_receive_socket(&(client->receiver)); @@ -437,7 +473,7 @@ DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *cti msg.standardheader->len = DLT_HTOBE_16(len); /* Send data (without storage header) */ - if (client->serial_mode) + if (client->mode) { /* via FileDescriptor */ ret=write(client->sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader)); |