2011-11-06 15:16:19 +08:00
|
|
|
/**
|
|
|
|
* @file transport.c
|
|
|
|
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "transport.h"
|
2012-03-13 15:28:37 +08:00
|
|
|
#include "transport_private.h"
|
2012-03-18 02:12:20 +08:00
|
|
|
#include "raw.h"
|
2011-11-06 15:16:19 +08:00
|
|
|
#include "udp.h"
|
2012-04-20 22:30:01 +08:00
|
|
|
#include "udp6.h"
|
2012-08-24 21:22:40 +08:00
|
|
|
#include "uds.h"
|
2011-11-06 15:16:19 +08:00
|
|
|
|
2012-03-13 15:28:37 +08:00
|
|
|
int transport_close(struct transport *t, struct fdarray *fda)
|
|
|
|
{
|
|
|
|
return t->close(t, fda);
|
|
|
|
}
|
|
|
|
|
|
|
|
int transport_open(struct transport *t, char *name,
|
|
|
|
struct fdarray *fda, enum timestamp_type tt)
|
|
|
|
{
|
|
|
|
return t->open(t, name, fda, tt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int transport_recv(struct transport *t, int fd,
|
|
|
|
void *buf, int buflen, struct hw_timestamp *hwts)
|
|
|
|
{
|
|
|
|
return t->recv(t, fd, buf, buflen, hwts);
|
|
|
|
}
|
|
|
|
|
|
|
|
int transport_send(struct transport *t, struct fdarray *fda, int event,
|
|
|
|
void *buf, int buflen, struct hw_timestamp *hwts)
|
|
|
|
{
|
2012-04-05 23:15:32 +08:00
|
|
|
return t->send(t, fda, event, 0, buf, buflen, hwts);
|
|
|
|
}
|
|
|
|
|
|
|
|
int transport_peer(struct transport *t, struct fdarray *fda, int event,
|
|
|
|
void *buf, int buflen, struct hw_timestamp *hwts)
|
|
|
|
{
|
|
|
|
return t->send(t, fda, event, 1, buf, buflen, hwts);
|
2012-03-13 15:28:37 +08:00
|
|
|
}
|
2011-11-06 15:16:19 +08:00
|
|
|
|
2012-03-13 15:28:37 +08:00
|
|
|
struct transport *transport_create(enum transport_type type)
|
2011-11-06 15:16:19 +08:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case TRANS_UDP_IPV4:
|
2012-03-13 15:28:37 +08:00
|
|
|
return udp_transport_create();
|
2011-11-06 15:16:19 +08:00
|
|
|
case TRANS_UDP_IPV6:
|
2012-04-20 22:30:01 +08:00
|
|
|
return udp6_transport_create();
|
2011-11-06 15:16:19 +08:00
|
|
|
case TRANS_IEEE_802_3:
|
2012-03-18 02:12:20 +08:00
|
|
|
return raw_transport_create();
|
2011-11-06 15:16:19 +08:00
|
|
|
case TRANS_DEVICENET:
|
|
|
|
case TRANS_CONTROLNET:
|
|
|
|
case TRANS_PROFINET:
|
|
|
|
break;
|
2012-08-24 21:22:40 +08:00
|
|
|
case TRANS_UDS:
|
|
|
|
return uds_transport_create();
|
2011-11-06 15:16:19 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-03-13 15:28:37 +08:00
|
|
|
|
|
|
|
void transport_destroy(struct transport *t)
|
|
|
|
{
|
|
|
|
t->release(t);
|
|
|
|
}
|