port: make the dispatch and event methods variable based on clock type.
This paves the way to allow different implementations for the upcoming Transparent Clock code. Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This commit is contained in:
		
							parent
							
								
									dc1b7c66c6
								
							
						
					
					
						commit
						c170405822
					
				
							
								
								
									
										27
									
								
								port.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								port.c
									
									
									
									
									
								
							@ -82,6 +82,10 @@ struct port {
 | 
				
			|||||||
	struct fdarray fda;
 | 
						struct fdarray fda;
 | 
				
			||||||
	int fault_fd;
 | 
						int fault_fd;
 | 
				
			||||||
	int phc_index;
 | 
						int phc_index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void (*dispatch)(struct port *p, enum fsm_event event, int mdiff);
 | 
				
			||||||
 | 
						enum fsm_event (*event)(struct port *p, int fd_index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int jbod;
 | 
						int jbod;
 | 
				
			||||||
	struct foreign_clock *best;
 | 
						struct foreign_clock *best;
 | 
				
			||||||
	enum syfu_state syfu;
 | 
						enum syfu_state syfu;
 | 
				
			||||||
@ -2372,6 +2376,11 @@ static void port_p2p_transition(struct port *p, enum port_state next)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void port_dispatch(struct port *p, enum fsm_event event, int mdiff)
 | 
					void port_dispatch(struct port *p, enum fsm_event event, int mdiff)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						p->dispatch(p, event, mdiff);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void bc_dispatch(struct port *p, enum fsm_event event, int mdiff)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	enum port_state next;
 | 
						enum port_state next;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2488,6 +2497,11 @@ static void port_link_status(void *ctx, int linkup, int ts_index)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum fsm_event port_event(struct port *p, int fd_index)
 | 
					enum fsm_event port_event(struct port *p, int fd_index)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return p->event(p, fd_index);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static enum fsm_event bc_event(struct port *p, int fd_index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	enum fsm_event event = EV_NONE;
 | 
						enum fsm_event event = EV_NONE;
 | 
				
			||||||
	struct ptp_message *msg;
 | 
						struct ptp_message *msg;
 | 
				
			||||||
@ -2850,6 +2864,7 @@ struct port *port_open(int phc_index,
 | 
				
			|||||||
		       struct interface *interface,
 | 
							       struct interface *interface,
 | 
				
			||||||
		       struct clock *clock)
 | 
							       struct clock *clock)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						enum clock_type type = clock_type(clock);
 | 
				
			||||||
	struct config *cfg = clock_config(clock);
 | 
						struct config *cfg = clock_config(clock);
 | 
				
			||||||
	struct port *p = malloc(sizeof(*p));
 | 
						struct port *p = malloc(sizeof(*p));
 | 
				
			||||||
	enum transport_type transport;
 | 
						enum transport_type transport;
 | 
				
			||||||
@ -2860,6 +2875,18 @@ struct port *port_open(int phc_index,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	memset(p, 0, sizeof(*p));
 | 
						memset(p, 0, sizeof(*p));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (type) {
 | 
				
			||||||
 | 
						case CLOCK_TYPE_ORDINARY:
 | 
				
			||||||
 | 
						case CLOCK_TYPE_BOUNDARY:
 | 
				
			||||||
 | 
							p->dispatch = bc_dispatch;
 | 
				
			||||||
 | 
							p->event = bc_event;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case CLOCK_TYPE_P2P:
 | 
				
			||||||
 | 
						case CLOCK_TYPE_E2E:
 | 
				
			||||||
 | 
						case CLOCK_TYPE_MANAGEMENT:
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p->state_machine = clock_slave_only(clock) ? ptp_slave_fsm : ptp_fsm;
 | 
						p->state_machine = clock_slave_only(clock) ? ptp_slave_fsm : ptp_fsm;
 | 
				
			||||||
	p->dscmp = dscmp;
 | 
						p->dscmp = dscmp;
 | 
				
			||||||
	p->phc_index = phc_index;
 | 
						p->phc_index = phc_index;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user