parent
							
								
									02f654a87b
								
							
						
					
					
						commit
						93ed9b7a94
					
				@ -0,0 +1,51 @@ | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Created by MightyPork on 2017/12/19.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "gex_helpers.h" | 
				
			||||||
 | 
					#include "gex_client_internal.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Delete recursively all GEX callsign look-up table entries */ | 
				
			||||||
 | 
					void destroy_unit_lookup(GexClient *gex) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					    struct gex_unit_lu *next = gex->ulu_head; | 
				
			||||||
 | 
					    while (next != NULL) { | 
				
			||||||
 | 
					        struct gex_unit_lu *cur = next; | 
				
			||||||
 | 
					        next = next->next; | 
				
			||||||
 | 
					        free(cur); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    gex->ulu_head = NULL; | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Get lookup entry for unit name */ | 
				
			||||||
 | 
					struct gex_unit_lu *find_unit_by_callsign(GexClient *gex, uint8_t callsign) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					    struct gex_unit_lu *next = gex->ulu_head; | 
				
			||||||
 | 
					    while (next != NULL) { | 
				
			||||||
 | 
					        if (next->callsign == callsign) { | 
				
			||||||
 | 
					            return next; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					        next = next->next; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    return NULL; | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Get lookup entry for unit name */ | 
				
			||||||
 | 
					struct gex_unit_lu *find_unit_by_name(GexClient *gex, const char *name) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					    struct gex_unit_lu *next = gex->ulu_head; | 
				
			||||||
 | 
					    while (next != NULL) { | 
				
			||||||
 | 
					        if (strcmp(next->name, name) == 0) { | 
				
			||||||
 | 
					            return next; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					        next = next->next; | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					    return NULL; | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Get callsign for unit name */ | 
				
			||||||
 | 
					uint8_t find_callsign_by_name(GexClient *gex, const char *name) | 
				
			||||||
 | 
					{ | 
				
			||||||
 | 
					    struct gex_unit_lu *lu = find_unit_by_name(gex, name); | 
				
			||||||
 | 
					    return (uint8_t) ((lu == NULL) ? 0 : lu->callsign); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,23 @@ | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Created by MightyPork on 2017/12/19.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef GEX_CLIENT_GEX_HELPERS_H | 
				
			||||||
 | 
					#define GEX_CLIENT_GEX_HELPERS_H | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "gex_client_internal.h" | 
				
			||||||
 | 
					#include "gex_client.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Delete recursively all GEX callsign look-up table entries */ | 
				
			||||||
 | 
					void destroy_unit_lookup(GexClient *gex); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Get lookup entry for unit name */ | 
				
			||||||
 | 
					struct gex_unit_lu *find_unit_by_callsign(GexClient *gex, uint8_t callsign); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Get lookup entry for unit name */ | 
				
			||||||
 | 
					struct gex_unit_lu *find_unit_by_name(GexClient *gex, const char *name); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Get callsign for unit name */ | 
				
			||||||
 | 
					uint8_t find_callsign_by_name(GexClient *gex, const char *name); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //GEX_CLIENT_GEX_HELPERS_H
 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue