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 
00043 #ifndef _INTERFACE_UTIL_H
00044 #define _INTERFACE_UTIL_H
00045 
00046 #if defined (WIN32)
00047   #if defined (PLAYER_STATIC)
00048     #define PLAYERINTERFACE_EXPORT
00049   #elif defined (playerinterface_EXPORTS)
00050     #define PLAYERINTERFACE_EXPORT    __declspec (dllexport)
00051   #else
00052     #define PLAYERINTERFACE_EXPORT    __declspec (dllimport)
00053   #endif
00054 #else
00055   #define PLAYERINTERFACE_EXPORT
00056 #endif
00057 
00058 #include <playerconfig.h>  // for uint16_t type
00059 
00060 #ifdef __cplusplus
00061 extern "C" {
00062 #endif
00063 
00064 // available interfaces are stored in an array of these, defined in
00065 // interface_util.c
00066 typedef struct
00067 {
00068   uint16_t interf;
00069   char* name;
00070 } player_interface_t;
00071 
00072 /*
00073  * Initialises the interface names/codes table.
00074  */
00075 PLAYERINTERFACE_EXPORT int itable_init (void);
00076 
00077 /*
00078  * Grows the interface table to newSize, filling each interface between the
00079  * old end and the new end with (0xFFFF, "nointerfXX").
00080  */
00081 PLAYERINTERFACE_EXPORT int itable_grow (int newSize);
00082 
00083 /*
00084  * Destroys the interface names/codes table.
00085  */
00086 PLAYERINTERFACE_EXPORT void itable_destroy (void);
00087 
00088 /*
00089  * Add a new interface to the interface table.
00090  */
00091 PLAYERINTERFACE_EXPORT int itable_add (const char *name, unsigned int code, int replace);
00092 
00093 /*
00094  * looks through the array of available interfaces for one which the given
00095  * name.  if found, interface is filled out (the caller must provide storage)
00096  * and zero is returned.  otherwise, -1 is returned.
00097  */
00098 PLAYERINTERFACE_EXPORT int lookup_interface(const char* name, player_interface_t* interf);
00099 
00100 /*
00101  * looks through the array of available interfaces for one which the given
00102  * code.  if found, interface is filled out (the caller must provide storage)
00103  * and zero is returned.  otherwise, -1 is returned.
00104  */
00105 PLAYERINTERFACE_EXPORT int
00106 lookup_interface_code(int code, player_interface_t* interf);
00107 
00108 /*
00109  * looks through the array of interfaces, starting at startpos, for the first
00110  * entry that has the given code, and returns the name.
00111  * returns 0 if the device is not found.
00112  */
00113 PLAYERINTERFACE_EXPORT const char*
00114 lookup_interface_name(unsigned int startpos, int code);
00115 
00116 /*
00117  * Returns the name of an interface given its code. The result string must
00118  * not be altered.
00119  */
00120 PLAYERINTERFACE_EXPORT const char*
00121 interf_to_str(uint16_t code);
00122 
00123 /*
00124  * Returns the code for an interface, given a string. If the name is not found,
00125  * 0xFFFF is returned.
00126  */
00127 PLAYERINTERFACE_EXPORT uint16_t
00128 str_to_interf(const char *name);
00129 
00130 /*
00131  * Returns the name of a message type given its code. The result string must
00132  * not be altered.
00133  */
00134 PLAYERINTERFACE_EXPORT const char*
00135 msgtype_to_str(uint8_t code);
00136 
00137 /*
00138  * Returns the code for a message type, given a string. If the name is not
00139  * found, 0xFF is returned.
00140  */
00141 PLAYERINTERFACE_EXPORT uint8_t
00142 str_to_msgtype(const char *name);
00143 
00144 #ifdef __cplusplus
00145 }
00146 #endif
00147 
00150 #endif