Commit 82de2e3a authored by Alessandro Rubini's avatar Alessandro Rubini

general: network operations are now per-instance

This commit moves the network operations inside the instance.  It
allows to have different operations for each instance, which will be
useful in the future. For example, one ethernet card may have hardware
timestamping and another may not.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 4220b51a
......@@ -50,7 +50,7 @@ void posix_main_loop(struct pp_instance *ppi)
* We got a packet. If it's not ours, continue consuming
* the pending timeout
*/
i = pp_net_ops.recv(ppi, payload, sizeof(packet) - 16,
i = ppi->n_ops->recv(ppi, payload, sizeof(packet) - 16,
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
......
......@@ -475,7 +475,7 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
return ret;
}
struct pp_network_operations pp_net_ops = {
struct pp_network_operations posix_net_ops = {
.init = posix_net_init,
.exit = posix_net_exit,
.recv = posix_net_recv,
......
......@@ -46,6 +46,8 @@ int main(int argc, char **argv)
ppi->frgn_master = calloc(1, sizeof(*ppi->frgn_master));
ppi->arch_data = calloc(1, sizeof(struct posix_arch_data));
ppi->n_ops = &posix_net_ops;
if ((!ppi->defaultDS) || (!ppi->currentDS) || (!ppi->parentDS)
|| (!ppi->portDS) || (!ppi->timePropertiesDS)
|| (!ppi->net_path) || (!ppi->frgn_master) || (!ppi->arch_data)
......
......@@ -15,3 +15,5 @@ struct posix_arch_data {
extern int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms);
extern void posix_main_loop(struct pp_instance *ppi);
extern struct pp_network_operations posix_net_ops;
......@@ -122,7 +122,7 @@ static int wrpc_net_exit(struct pp_instance *ppi)
return 0;
}
struct pp_network_operations pp_net_ops = {
struct pp_network_operations wrpc_net_ops = {
.init = wrpc_net_init,
.exit = wrpc_net_exit,
.recv = wrpc_net_recv,
......
......@@ -149,6 +149,9 @@ struct pp_instance {
struct pp_servo *servo;
unsigned long flags; /* ppi-specific flags (diag mainly) */
/* Operations that may be different in each instance */
struct pp_network_operations *n_ops;
/* Data sets */
DSDefault *defaultDS; /* page 65 */
DSCurrent *currentDS; /* page 67 */
......@@ -277,8 +280,6 @@ struct pp_network_operations {
TimeInternal *t, int chtype, int use_pdelay_addr);
};
extern struct pp_network_operations pp_net_ops;
/*
* Time operations, like network operations above, are encapsulated.
......
......@@ -8,6 +8,8 @@
extern void bare_main_loop(struct pp_instance *ppi);
extern struct pp_network_operations bare_net_ops;
/* syscalls */
struct bare_sockaddr;
......
......@@ -146,7 +146,7 @@ static int bare_net_exit(struct pp_instance *ppi)
return sys_shutdown(NP(ppi)->ch[PP_NP_GEN].fd, SHUT_RDWR);
}
struct pp_network_operations pp_net_ops = {
struct pp_network_operations bare_net_ops = {
.init = bare_net_init,
.exit = bare_net_exit,
.recv = bare_net_recv,
......
......@@ -48,6 +48,7 @@ int ppsi_main(int argc, char **argv)
ppi->servo = &servo;
ppi->frgn_master = &frgn_master;
ppi->arch_data = NULL;
ppi->n_ops = &bare_net_ops;
/* This just llocates the stuff */
pp_open_instance(ppi, NULL);
......
......@@ -66,7 +66,7 @@ void bare_main_loop(struct pp_instance *ppi)
*
* FIXME: we don't know which socket to receive from
*/
i = pp_net_ops.recv(ppi, payload, sizeof(packet) - 16,
i = ppi->n_ops->recv(ppi, payload, sizeof(packet) - 16,
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
......
......@@ -40,7 +40,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static inline int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype)
{
if (pp_net_ops.send(ppi, ppi->buf_out, msglen,
if (ppi->n_ops->send(ppi, ppi->buf_out, msglen,
&ppi->last_snt_time, chtype, 0) < msglen) {
if (pp_verbose_frames)
PP_PRINTF("%s(%d) Message can't be sent\n",
......
......@@ -19,9 +19,9 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
int ret = 0;
if (NP(ppi)->inited)
pp_net_ops.exit(ppi);
ppi->n_ops->exit(ppi);
if (pp_net_ops.init(ppi) < 0)
if (ppi->n_ops->init(ppi) < 0)
goto failure;
NP(ppi)->inited = 1;
......
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