interface_util.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000
4  * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 /********************************************************************
23  *
24  * This library is free software; you can redistribute it and/or
25  * modify it under the terms of the GNU Lesser General Public
26  * License as published by the Free Software Foundation; either
27  * version 2.1 of the License, or (at your option) any later version.
28  *
29  * This library is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32  * Lesser General Public License for more details.
33  *
34  * You should have received a copy of the GNU Lesser General Public
35  * License along with this library; if not, write to the Free Software
36  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37  *
38  ********************************************************************/
39 
43 #ifndef _INTERFACE_UTIL_H
44 #define _INTERFACE_UTIL_H
45 
46 #if defined (WIN32)
47  #if defined (PLAYER_STATIC)
48  #define PLAYERINTERFACE_EXPORT
49  #elif defined (playerinterface_EXPORTS)
50  #define PLAYERINTERFACE_EXPORT __declspec (dllexport)
51  #else
52  #define PLAYERINTERFACE_EXPORT __declspec (dllimport)
53  #endif
54 #else
55  #define PLAYERINTERFACE_EXPORT
56 #endif
57 
58 #include <playerconfig.h> // for uint16_t type
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 // available interfaces are stored in an array of these, defined in
65 // interface_util.c
66 typedef struct
67 {
68  uint16_t interf;
69  char* name;
71 
72 /*
73  * Initialises the interface names/codes table.
74  */
75 PLAYERINTERFACE_EXPORT int itable_init (void);
76 
77 /*
78  * Grows the interface table to newSize, filling each interface between the
79  * old end and the new end with (0xFFFF, "nointerfXX").
80  */
81 PLAYERINTERFACE_EXPORT int itable_grow (int newSize);
82 
83 /*
84  * Destroys the interface names/codes table.
85  */
86 PLAYERINTERFACE_EXPORT void itable_destroy (void);
87 
88 /*
89  * Add a new interface to the interface table.
90  */
91 PLAYERINTERFACE_EXPORT int itable_add (const char *name, unsigned int code, int replace);
92 
93 /*
94  * looks through the array of available interfaces for one which the given
95  * name. if found, interface is filled out (the caller must provide storage)
96  * and zero is returned. otherwise, -1 is returned.
97  */
98 PLAYERINTERFACE_EXPORT int lookup_interface(const char* name, player_interface_t* interf);
99 
100 /*
101  * looks through the array of available interfaces for one which the given
102  * code. if found, interface is filled out (the caller must provide storage)
103  * and zero is returned. otherwise, -1 is returned.
104  */
105 PLAYERINTERFACE_EXPORT int
106 lookup_interface_code(int code, player_interface_t* interf);
107 
108 /*
109  * looks through the array of interfaces, starting at startpos, for the first
110  * entry that has the given code, and returns the name.
111  * returns 0 if the device is not found.
112  */
113 PLAYERINTERFACE_EXPORT const char*
114 lookup_interface_name(unsigned int startpos, int code);
115 
116 /*
117  * Returns the name of an interface given its code. The result string must
118  * not be altered.
119  */
120 PLAYERINTERFACE_EXPORT const char*
121 interf_to_str(uint16_t code);
122 
123 /*
124  * Returns the code for an interface, given a string. If the name is not found,
125  * 0xFFFF is returned.
126  */
127 PLAYERINTERFACE_EXPORT uint16_t
128 str_to_interf(const char *name);
129 
130 /*
131  * Returns the name of a message type given its code. The result string must
132  * not be altered.
133  */
134 PLAYERINTERFACE_EXPORT const char*
135 msgtype_to_str(uint8_t code);
136 
137 /*
138  * Returns the code for a message type, given a string. If the name is not
139  * found, 0xFF is returned.
140  */
141 PLAYERINTERFACE_EXPORT uint8_t
142 str_to_msgtype(const char *name);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
150 #endif

Last updated 12 September 2005 21:38:45