interface_util.h

00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000
00004  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00005  *
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 /********************************************************************
00023  *
00024  *  This library is free software; you can redistribute it and/or
00025  *  modify it under the terms of the GNU Lesser General Public
00026  *  License as published by the Free Software Foundation; either
00027  *  version 2.1 of the License, or (at your option) any later version.
00028  *
00029  *  This library is distributed in the hope that it will be useful,
00030  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00031  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00032  *  Lesser General Public License for more details.
00033  *
00034  *  You should have received a copy of the GNU Lesser General Public
00035  *  License along with this library; if not, write to the Free Software
00036  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00037  *
00038  ********************************************************************/
00039 
00049 #ifndef _INTERFACE_UTIL_H
00050 #define _INTERFACE_UTIL_H
00051 
00052 #include <libplayercore/playerconfig.h>  // for uint16_t type
00053 
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
00057 
00058 // available interfaces are stored in an array of these, defined in
00059 // interface_util.c
00060 typedef struct
00061 {
00062   uint16_t interf;
00063   char* name;
00064 } player_interface_t;
00065 
00066 /*
00067  * Initialises the interface names/codes table.
00068  */
00069 int itable_init (void);
00070 
00071 /*
00072  * Grows the interface table to newSize, filling each interface between the
00073  * old end and the new end with (0xFFFF, "nointerfXX").
00074  */
00075 int itable_grow (int newSize);
00076 
00077 /*
00078  * Destroys the interface names/codes table.
00079  */
00080 void itable_destroy (void);
00081 
00082 /*
00083  * Add a new interface to the interface table.
00084  */
00085 int itable_add (const char *name, int code, int replace);
00086 
00087 /*
00088  * looks through the array of available interfaces for one which the given
00089  * name.  if found, interface is filled out (the caller must provide storage)
00090  * and zero is returned.  otherwise, -1 is returned.
00091  */
00092 int lookup_interface(const char* name, player_interface_t* interface);
00093 
00094 /*
00095  * looks through the array of available interfaces for one which the given
00096  * code.  if found, interface is filled out (the caller must provide storage)
00097  * and zero is returned.  otherwise, -1 is returned.
00098  */
00099 int
00100 lookup_interface_code(int code, player_interface_t* interface);
00101 
00102 /*
00103  * looks through the array of interfaces, starting at startpos, for the first
00104  * entry that has the given code, and returns the name.
00105  * returns 0 if the device is not found.
00106  */
00107 const char*
00108 lookup_interface_name(unsigned int startpos, int code);
00109 
00110 /*
00111  * Returns the name of an interface given its code. The result string must
00112  * not be altered.
00113  */
00114 const char*
00115 interf_to_str(uint16_t code);
00116 
00117 /*
00118  * Returns the code for an interface, given a string. If the name is not found,
00119  * 0xFFFF is returned.
00120  */
00121 uint16_t
00122 str_to_interf(const char *name);
00123 
00124 /*
00125  * Returns the name of a message type given its code. The result string must
00126  * not be altered.
00127  */
00128 const char*
00129 msgtype_to_str(uint8_t code);
00130 
00131 /*
00132  * Returns the code for a message type, given a string. If the name is not
00133  * found, 0xFF is returned.
00134  */
00135 uint8_t
00136 str_to_msgtype(const char *name);
00137 
00138 #ifdef __cplusplus
00139 }
00140 #endif
00141 
00144 #endif

Last updated 12 September 2005 21:38:45