The Winamp Remote Control suite
a remote control client and plugin for Winamp 2.x, 5.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RPCFuncsU.cpp
Go to the documentation of this file.
1 /*
2 winamp remote control suite ŠPatrick Michael Martin 2000 - 2011
3 
4 Copyright (C) 2000,2001,2002 Patrick M. Martin
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 Patrick M. Martin may be reached by email at patrickmmartin@gmail.com.
21 */
22 
23 
24 #pragma hdrstop
25 
26 #include "RPCFuncsU.h" // for unit declarations
27 #include "RPCException.h" // for ERPCException
28 #include "RPCBind.h" // global Bind/UnBind
29 
30 // global string binding information
31 unsigned char * StringBinding = NULL;
32 
33 void __stdcall MIDL_user_free( void * mem)
34 {
35  free(mem);
36 }
37 
38 void * __stdcall MIDL_user_allocate(size_t size)
39 {
40  return malloc(size);
41 }
42 
43 
44 extern "C"
45 {
46 
47  void __stdcall ClientFree(void * mem)
48  {
49  MIDL_user_free(mem);
50  }
51 
52  // this binds to the interface , and assigns to the interface handle
53  void __stdcall Bind(const char * NetworkAddress, const char * EndPoint, const char * protocolSequence)
54  {
55  // avoid leaking handles ?
56  if (StringBinding)
57  UnBind();
58 
59  RpcStringBindingCompose(NULL,
60  (unsigned char *) protocolSequence,
61  (unsigned char *) NetworkAddress,
62  (unsigned char *) EndPoint,
63  NULL,
64  &StringBinding);
65  RpcBindingFromStringBinding(StringBinding, &winamp_IfHandle);
66 
67  }
68 
69  // this unbinds to the interface after the RPC call
70  void __stdcall UnBind()
71  {
72  RpcStringFree(&StringBinding);
73  StringBinding = NULL;
74  RpcBindingFree(&winamp_IfHandle);
75  }
76 
77 
78  // send a string
79  void __stdcall SendString(char * pszString)
80  {
81  RpcTryExcept
82  {
83  WAMessageProc( (unsigned char *) pszString);
84  }
85  RpcExcept(1)
86  {
87  throw ERPCException(RpcExceptionCode());
88  }
89  RpcEndExcept;
90 
91  }
92 
93  // execute a message
94  void __stdcall ExecuteMessage(char * pszString, int command)
95  {
96 
97  RpcTryExcept
98  {
99  WAExecuteMessage((unsigned char *) pszString, command);
100  }
101  RpcExcept(1)
102  {
103  throw ERPCException(RpcExceptionCode());
104  }
105  RpcEndExcept
106 
107  }
108 
109  // execute a string message
110  void __stdcall ExecuteStringMessage(char * pszString, char * pszParam, int command)
111  {
112 
113  RpcTryExcept
114  {
115  WAExecuteMessageString((unsigned char *) pszString, (unsigned char *) pszParam, command);
116  }
117  RpcExcept(1)
118  {
119  throw ERPCException(RpcExceptionCode());
120  }
121  RpcEndExcept
122  }
123 
124  // get the result of a string command
125  int __stdcall StringResult(char pszString[WA_RETURN_STRING_SIZE], int command, int data)
126  {
127 
128  int result = 0;
129 
130  RpcTryExcept
131  {
132  result = WAStringResult( (unsigned char *) pszString, command, data);
133  }
134  RpcExcept(1)
135  {
136  throw ERPCException(RpcExceptionCode());
137  }
138  RpcEndExcept
139  return result;
140  }
141 
142  // get result of a command
143  int __stdcall IntegerResult(char * pszString, int command, int data)
144  {
145 
146  int result = 0;
147 
148  RpcTryExcept
149  {
150  result = WAIntegerResult((unsigned char *) pszString, command, data);
151  }
152  RpcExcept(1)
153  {
154  throw ERPCException(RpcExceptionCode());
155  }
156  RpcEndExcept
157  return result;
158  }
159 
160  // shutdown server
161  void __stdcall Shutdown(void)
162  {
163 
164  RpcTryExcept
165  {
166  WAShutdown();
167  }
168  RpcExcept(1)
169  {
170  throw ERPCException(RpcExceptionCode());
171  }
172  RpcEndExcept
173  }
174 
175 
176  void __stdcall SetStringList(char * pszString, void * Buffer, int Size, int Command)
177  {
178  RpcTryExcept
179  {
180  WASetStringList( (unsigned char *) pszString, (unsigned char *) Buffer, Size, Command);
181  }
182  RpcExcept(1)
183  {
184  throw ERPCException(RpcExceptionCode());
185  }
186  RpcEndExcept
187  }
188 
189 
190  void __stdcall GetStringList(char * pszString, void ** Buffer, int& Size, int Command)
191  {
192 
193  RpcTryExcept
194  {
195 
196  BUFFER InBuffer;
197  InBuffer.BufferLength = 0;
198  InBuffer.Buffer = NULL;
199 
200  WAGetStringList( ( unsigned char *) pszString, &InBuffer, Command);
201 
202  *Buffer = (void *) InBuffer.Buffer;
203  Size = InBuffer.BufferLength;
204 
205  }
206  RpcExcept(1)
207  {
208  throw ERPCException(RpcExceptionCode());
209  }
210  RpcEndExcept
211  }
212 
213 
214  void __stdcall GetStringDataList(char * pszString, void ** Buffer, int& Size,
215  int stringcommand, int datacommand, int datadata)
216  {
217  RpcTryExcept
218  {
219 
220  BUFFER InBuffer;
221  InBuffer.BufferLength = 0;
222  InBuffer.Buffer = NULL;
223 
224  WAGetStringDataList( ( unsigned char *) pszString, &InBuffer, stringcommand,
225  datacommand, datadata);
226 
227  *Buffer = (void *) InBuffer.Buffer;
228  Size = InBuffer.BufferLength;
229 
230  }
231  RpcExcept(1)
232  {
233  throw ERPCException(RpcExceptionCode());
234  }
235  RpcEndExcept
236  }
237 
238  int __stdcall SafeSendString(char * pszString)
239  {
240  RpcTryExcept
241  {
242  WAMessageProc( (unsigned char *) pszString);
243  }
244  RpcExcept(1)
245  {
246  return RpcExceptionCode();
247  }
248  RpcEndExcept
249  return ERROR_SUCCESS;
250  }
251 
252  int __stdcall SafeExecuteMessage(char * pszString, int command)
253  {
254  RpcTryExcept
255  {
256  WAExecuteMessage( (unsigned char *) pszString, command);
257  }
258  RpcExcept(1)
259  {
260  return RpcExceptionCode();
261  }
262  RpcEndExcept
263  return ERROR_SUCCESS;
264  }
265 
266  int __stdcall SafeExecuteStringMessage(char * pszString, char * pszParam, int command)
267  {
268  RpcTryExcept
269  {
270  WAExecuteMessageString((unsigned char *) pszString, (unsigned char *) pszParam, command);
271  }
272  RpcExcept(1)
273  {
274  return RpcExceptionCode();
275  }
276  RpcEndExcept
277  return ERROR_SUCCESS;
278  }
279 
280  int __stdcall SafeStringResult(char * pszString, int command, int data, int * Result)
281  {
282  RpcTryExcept
283  {
284  *Result = WAStringResult((unsigned char *) pszString, command, data);
285  }
286  RpcExcept(1)
287  {
288  return RpcExceptionCode();
289  }
290  RpcEndExcept
291  return ERROR_SUCCESS;
292  }
293 
294  int __stdcall SafeIntegerResult(char * pszString, int command, int data, int * Result)
295  {
296  RpcTryExcept
297  {
298  *Result = WAIntegerResult((unsigned char *) pszString, command, data);
299  }
300  RpcExcept(1)
301  {
302  return RpcExceptionCode();
303  }
304  RpcEndExcept
305  return ERROR_SUCCESS;
306  }
307 
308  int __stdcall SafeSetStringList(char * pszString, void * Buffer, int Size, int Command)
309  {
310 
311  RpcTryExcept
312  {
313  WASetStringList( (unsigned char *) pszString, (unsigned char *) Buffer, Size, Command);
314  }
315  RpcExcept(1)
316  {
317  return RpcExceptionCode();
318  }
319  RpcEndExcept
320  return ERROR_SUCCESS;
321 
322  }
323 
324 
325  int __stdcall SafeGetStringList(char * pszString, void ** Buffer, int& Size, int Command)
326  {
327  RpcTryExcept
328  {
329 
330  BUFFER InBuffer;
331  InBuffer.BufferLength = 0;
332  InBuffer.Buffer = NULL;
333 
334  WAGetStringList( ( unsigned char *) pszString, &InBuffer, Command);
335 
336  *Buffer = (void *) InBuffer.Buffer;
337  Size = InBuffer.BufferLength;
338 
339  }
340  RpcExcept(1)
341  {
342  return RpcExceptionCode();
343  }
344  RpcEndExcept
345  return ERROR_SUCCESS;
346 
347  }
348 
349 // TODO need to implement or remove this
350 /*
351 
352  int __stdcall SafeGetStringList(char * pszString, BSTR * Str, int Command)
353  {
354  RpcTryExcept
355  {
356 
357  BUFFER InBuffer;
358  bstr_t retval;
359  InBuffer.BufferLength = 0;
360  InBuffer.Buffer = NULL;
361 
362  WAGetStringList( ( unsigned char *) pszString, &InBuffer, Command);
363 
364  retval = (char *) InBuffer.Buffer;
365  *Str = retval;
366  return ERROR_SUCCESS;
367 
368  }
369  RpcExcept(1)
370  {
371  return RpcExceptionCode();
372  }
373  RpcEndExcept
374 
375  }
376 
377 */
378 }// extern "c"
379 
380