RegistrationAPI.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 
39 #include "rexx.h"
40 #include "LocalAPIManager.hpp"
42 #include "RexxAPI.h"
43 #include "LocalAPIContext.hpp"
44 #include "RexxInternalApis.h"
45 #include "ClientMessage.hpp"
46 #include "SysLocalAPIManager.hpp"
47 
48 
49 /*********************************************************************/
50 /* */
51 /* Function Name: RexxRegisterSubcomDll */
52 /* */
53 /* Description: Registration function for the subcommand */
54 /* interface. All programs wishing to act as */
55 /* subcommand environments for REXX must first */
56 /* register through this function. */
57 /* */
58 /* The function adds new registration blocks to the */
59 /* subcommand registration table. Uses functions in */
60 /* REXXAPI for memory allocation functions. */
61 /* */
62 /* Parameter(s): EnvName - name of the registered subcommand */
63 /* handler */
64 /* */
65 /* ModuleName - name of the module containing */
66 /* the subcommand handler */
67 /* */
68 /* EntryPoint - name of the routine for the */
69 /* handler */
70 /* */
71 /* UserArea - Area for any user data */
72 /* */
73 /* DropAuth - Drop authority flag */
74 /* */
75 /* Return Value: Valid RXSUBCOM return codes */
76 /* */
77 /*********************************************************************/
78 
80  const char * envName, // Subcom name
81  const char * moduleName, // Name of DLL
82  const char * procedureName, // DLL routine name
83  const char * userArea, // User data
84  size_t dropAuthority) // Drop Authority
85 {
87  {
88  return lam->registrationManager.registerCallback(SubcomAPI,
89  envName, moduleName, procedureName, userArea, dropAuthority == RXSUBCOM_NONDROP);
90  }
91  EXIT_REXX_API();
92 }
93 
94 /*********************************************************************/
95 /* */
96 /* Function Name: RexxRegisterSubcomExe */
97 /* */
98 /* Description: Registration function for the subcommand */
99 /* interface. All programs wishing to act as */
100 /* subcommand environments for REXX must first */
101 /* register through this function. */
102 /* */
103 /* The function adds new registration blocks to the */
104 /* subcommand registration table. Uses functions in */
105 /* REXXAPI for memory allocation functions. */
106 /* */
107 /* Parameter(s): EnvName - name of the registered subcommand */
108 /* handler */
109 /* */
110 /* EntryPoint - address of the subcommand handler */
111 /* */
112 /* UserArea - Area for any user data */
113 /* */
114 /* Return Value: Valid RXSUBCOM return codes */
115 /* */
116 /*********************************************************************/
117 
119  const char * envName, // Subcom name
120  REXXPFN entryPoint, // callback address
121  const char * userArea) // User data
122 {
124  {
125  return lam->registrationManager.registerCallback(SubcomAPI, envName, entryPoint, userArea);
126  }
127  EXIT_REXX_API();
128 }
129 
130 /*********************************************************************/
131 /* */
132 /* Function Name: RexxDeregisterSubcom */
133 /* */
134 /* Description: drops a block from the subcommand registration */
135 /* table. Uses functions in rexxapi to free memory.*/
136 /* */
137 /* Entry Point: RexxDeregisterSubcom */
138 /* */
139 /* Parameter(s): name - The environment name to be dropped. */
140 /* dllname - The associated dllname to be */
141 /* dropped, if appropiate. */
142 /* */
143 /* Return Value: Valid RXSUBCOM return codes */
144 /* */
145 /*********************************************************************/
146 
148  const char * name, /* Environment Name */
149  const char * moduleName ) /* Associated library name */
150 {
152  {
153  return lam->registrationManager.dropCallback(SubcomAPI, name, moduleName);
154  }
155  EXIT_REXX_API();
156 }
157 
158 /*********************************************************************/
159 /* */
160 /* Function Name: RexxQuerySubcom */
161 /* */
162 /* Description: Queries the subcommand registration table. */
163 /* Allows user to tell if a subcommand is */
164 /* registered. */
165 /* */
166 /* Entry Point: RexxQuerySubcom */
167 /* */
168 /* Parameter(s): name - The environment name to be dropped. */
169 /* dll - The associated dllname to be */
170 /* dropped, if appropiate. */
171 /* exist - Existence flag. */
172 /* userword - 8 bytes of user data. */
173 /* */
174 /* Return Value: RXSUBCOM_OK - Subcommand is registered */
175 /* RXSUBCOM_NOTREG - Subcommand not registered */
176 /* RXSUBCOM_BADTYPE - Internal error. Should not */
177 /* occur. */
178 /* */
179 /*********************************************************************/
180 
182  const char *name, /* Environment Name */
183  const char *module, /* Associated library name */
184  unsigned short *flags, /* existence information */
185  char *userWord) /* data from registration */
186 {
187  *flags = 0;
189  {
190  RexxReturnCode ret = lam->registrationManager.queryCallback(SubcomAPI, name, module, userWord);
191  *flags = (ret == RXSUBCOM_OK);
192  return ret;
193  }
194  EXIT_REXX_API();
195 }
196 
197 
198 /*********************************************************************/
199 /* */
200 /* Function Name: RexxResolveSubcom */
201 /* */
202 /* Description: Query and return information about a resolved */
203 /* Subcom handler */
204 /* */
205 /* Entry Point: ooRexxResolveSubcom */
206 /* */
207 /* Parameter(s): name - Name of the desired system exit */
208 /* entryPoint - Pointer to the resolved handler */
209 /* style - The subcom call style info */
210 /* */
211 /* Return Value: Return code from subcommand handler processing */
212 /* */
213 /*********************************************************************/
214 
216  const char *name, // Exit name.
217  REXXPFN *entryPoint) // the entry point of the exit
218 {
220  {
221  return lam->registrationManager.resolveCallback(SubcomAPI, name, NULL, *entryPoint);
222  }
223  EXIT_REXX_API();
224 }
225 
226 
227 /*********************************************************************/
228 /* */
229 /* Function Name: RexxLoadSubcom */
230 /* */
231 /* Description: Force a subcommand handler to the resolved and */
232 /* loaded. */
233 /* */
234 /* Entry Point: RexxLoadSubcom */
235 /* */
236 /* Parameter(s): name - Name of the desired system exit */
237 /* entryPoint - Pointer to the resolved handler */
238 /* style - The subcom call style info */
239 /* */
240 /* Return Value: Return code from subcommand handler processing */
241 /* */
242 /*********************************************************************/
243 
245  const char *name, // handler name
246  const char *lib) // handler library
247 {
249  {
250  REXXPFN entryPoint;
251 
252  return lam->registrationManager.resolveCallback(SubcomAPI, name, lib, entryPoint);
253  }
254  EXIT_REXX_API();
255 }
256 
257 
258 /*********************************************************************/
259 /* */
260 /* Function Name: RexxRegisterExitDll */
261 /* */
262 /* Description: Registration function for the exit */
263 /* interface. All programs wishing to act as */
264 /* exit handlers for REXX must first */
265 /* register through this function. */
266 /* */
267 /* The function adds new registration blocks to the */
268 /* exit registration table. Uses functions in */
269 /* REXXAPI for memory allocation functions. */
270 /* */
271 /* Entry Point: RexxRegisterLibraryExit */
272 /* */
273 /* Return Value: Valid RXSUBCOM return codes */
274 /* */
275 /*********************************************************************/
276 
278  const char * envName, // Exit name
279  const char * moduleName, // Name of DLL
280  const char * procedureName, // DLL routine name
281  const char * userArea, // User data
282  size_t dropAuthority) // Drop Authority
283 {
285  {
286  return lam->registrationManager.registerCallback(ExitAPI, envName, moduleName, procedureName, userArea, dropAuthority == RXSUBCOM_NONDROP);
287  }
288  EXIT_REXX_API();
289 }
290 
291 /*********************************************************************/
292 /* */
293 /* Function Name: RexxRegisterExitExe */
294 /* */
295 /* Description: Registration function for the exit */
296 /* interface. All programs wishing to act as */
297 /* exit handlers for REXX must first */
298 /* register through this function. */
299 /* */
300 /* The function adds new registration blocks to the */
301 /* subcommand registration table. Uses functions in */
302 /* REXXAPI for memory allocation functions. */
303 /* */
304 /* Return Value: Valid RXSUBCOM return codes */
305 /* */
306 /*********************************************************************/
307 
309  const char * envName, /* exit name */
310  REXXPFN entryPoint, /* Entry point address */
311  const char * userArea) /* User data */
312 {
314  {
315  return lam->registrationManager.registerCallback(ExitAPI, envName, entryPoint, userArea);
316  }
317  EXIT_REXX_API();
318 }
319 
320 /*********************************************************************/
321 /* */
322 /* Function Name: RexxDeregisterExit */
323 /* */
324 /* Description: drops a block from the exit registration */
325 /* table. Uses functions in rexxapi to free memory.*/
326 /* */
327 /* Entry Point: RexxDeregisterExit */
328 /* */
329 /* Parameter(s): name - The environment name to be dropped. */
330 /* dllname - The associated dllname to be */
331 /* dropped, if appropiate. */
332 /* */
333 /* Return Value: Valid RXSUBCOM return codes */
334 /* */
335 /*********************************************************************/
336 
338  const char * name, /* Environment Name */
339  const char * moduleName) /* Associated library name */
340 {
342  {
343  return lam->registrationManager.dropCallback(ExitAPI, name, moduleName);
344  }
345  EXIT_REXX_API();
346 }
347 
348 /*********************************************************************/
349 /* */
350 /* Function Name: RexxQueryExit */
351 /* */
352 /* Description: Querys the exit registration table. */
353 /* Allows user to tell if an exit is */
354 /* registered. */
355 /* */
356 /* Entry Point: RexxQueryExit */
357 /* */
358 /* Parameter(s): name - The environment name to be dropped. */
359 /* dll - The associated dllname to be */
360 /* dropped, if appropiate. */
361 /* exist - Existence flag. */
362 /* userword - 8 bytes of user data. */
363 /* */
364 /* Return Value: RXSUBCOM_OK - Exit is registered */
365 /* RXSUBCOM_NOTREG - Exit not registered */
366 /* RXSUBCOM_BADTYPE - Internal error. Should not */
367 /* occur. */
368 /* */
369 /*********************************************************************/
370 
372  const char * name, /* Environment Name */
373  const char * module, /* Associated Name (of DLL) */
374  unsigned short *exist, /* existence information */
375  char *userWord) /* data from registration */
376 {
377  *exist = 0;
379  {
380  RexxReturnCode ret = lam->registrationManager.queryCallback(ExitAPI, name, module, userWord);
381  *exist = (ret == RXQUEUE_OK);
382  return ret;
383  }
384  EXIT_REXX_API();
385 }
386 
387 
388 /*********************************************************************/
389 /* */
390 /* Function Name: RexxResolveExit */
391 /* */
392 /* Description: Resolves a system exit entrypoint address */
393 /* */
394 /* Entry Point: ooRexxResolveExit */
395 /* */
396 /* Parameter(s): name - Name of the desired system exit */
397 /* entrypoint - returned entry point address */
398 /* legacyStyle - style of the call */
399 /* */
400 /* Return Value: Return code from exit if the exit ran */
401 /* -1 otherwise */
402 /* */
403 /*********************************************************************/
404 
406  const char * name, // Exit name.
407  REXXPFN *entryPoint) // the entry point of the exit
408 {
410  {
411  return lam->registrationManager.resolveCallback(ExitAPI, name, NULL, *entryPoint);
412  }
413  EXIT_REXX_API();
414 }
415 
416 /*********************************************************************/
417 /* */
418 /* Function Name: RexxRegisterFunctionDll */
419 /* */
420 /* Description: Registration function for the external function */
421 /* interface. All programs wishing to act as */
422 /* external functions for REXX must first */
423 /* register through this function. */
424 /* */
425 /* The function adds new registration blocks to the */
426 /* function registration table. Uses functions in */
427 /* REXXAPI for memory allocation functions. */
428 /* */
429 /* Return Value: Valid RXSUBCOM return codes */
430 /* */
431 /*********************************************************************/
432 
434  const char * name, // Subcom name
435  const char * moduleName, // Name of library
436  const char * procedureName) // library routine name
437 {
439  {
440  return lam->registrationManager.registerCallback(FunctionAPI, name, moduleName, procedureName, NULL, true);
441  }
442  EXIT_REXX_API();
443 }
444 
445 /*********************************************************************/
446 /* */
447 /* Function Name: RexxRegisterFunctionExe */
448 /* */
449 /* Description: Registration function for the external function */
450 /* interface. All programs wishing to act as */
451 /* external functions for REXX must first */
452 /* register through this function. */
453 /* */
454 /* The function adds new registration blocks to the */
455 /* function registration table. Uses functions in */
456 /* REXXAPI for memory allocation functions. */
457 /* */
458 /* Return Value: Valid RXSUBCOM return codes */
459 /* */
460 /*********************************************************************/
461 
463  const char * name, // Function name
464  REXXPFN entryPoint) // Entry point address
465 {
467  {
468  return lam->registrationManager.registerCallback(FunctionAPI, name, entryPoint, NULL);
469  }
470  EXIT_REXX_API();
471 }
472 
473 /*********************************************************************/
474 /* */
475 /* Function Name: RexxDeregisterFunction */
476 /* */
477 /* Description: drops a block from the function registration */
478 /* table. Uses functions in rexxapi to free memory.*/
479 /* */
480 /* Entry Point: RexxDeregisterFunction */
481 /* */
482 /* Parameter(s): name - The function name to be dropped. */
483 /* */
484 /* Return Value: Valid RXSUBCOM return codes */
485 /* */
486 /*********************************************************************/
487 
489  const char * name) /* Function Name */
490 {
492  {
493  return lam->registrationManager.dropCallback(FunctionAPI, name, NULL);
494  }
495  EXIT_REXX_API();
496 }
497 
498 /*********************************************************************/
499 /* */
500 /* Function Name: RexxQueryFunction */
501 /* */
502 /* Description: Querys the function registration table. */
503 /* Allows user to tell if a function is */
504 /* registered. */
505 /* */
506 /* Entry Point: RexxQueryFunction */
507 /* */
508 /* Parameter(s): name - The function name to be queried. */
509 /* */
510 /* Return Value: RXSUBCOM_OK - Function is registered */
511 /* RXSUBCOM_NOTREG - Function not registered */
512 /* */
513 /*********************************************************************/
514 
516  const char * name) /* Function Name */
517 {
519  {
520  return lam->registrationManager.queryCallback(FunctionAPI, name, NULL, NULL);
521  }
522  EXIT_REXX_API();
523 }
524 
525 
526 RexxReturnCode RexxEntry RexxResolveRoutine(const char *name, REXXPFN *entryPoint)
527 {
529  {
530  return lam->registrationManager.resolveCallback(FunctionAPI, name, NULL, *entryPoint);
531  }
532  EXIT_REXX_API();
533 }
534 
535 
536 /*********************************************************************/
537 /* */
538 /* Function Name: RexxAllocateMemory */
539 /* */
540 /* Description: Operating system independant method to */
541 /* allocate memory. The function is a wrapper */
542 /* for appropriate compiler or operating system */
543 /* memory function. */
544 /* */
545 /* */
546 /* Entry Point: RexxAllocateMemory */
547 /* */
548 /* Parameter(s): size of memory to allocate (ULONG) */
549 /* */
550 /* Return Value: The allocated Block of memory (PVOID) */
551 /* */
552 /*********************************************************************/
553 void *REXXENTRY RexxAllocateMemory(size_t size)
554 {
555  return SysAPIManager::allocateMemory(size);
556 }
557 
558 /*********************************************************************/
559 /* */
560 /* Function Name: RexxFreeMemory */
561 /* */
562 /* Description: Operating system independant method to */
563 /* free memory. The function is a wrapper */
564 /* for appropriate compiler or operating system */
565 /* memory function. */
566 /* */
567 /* */
568 /* Entry Point: RexxFreeMemory */
569 /* */
570 /* Parameter(s): size of memory to allocate (ULONG) */
571 /* */
572 /* Return Value: The allocated Block of memory (PVOID) */
573 /* */
574 /*********************************************************************/
576 {
578  return 0;
579 }
580 
581 
582 /**
583  * Shutdown the API subsystem. This is a nop in 4.0. This is
584  * maintained solely for binary compatibility.
585  *
586  * @return always returns true
587  */
589 {
590  return true;
591 }
592 
593 
RexxReturnCode RexxEntry RexxResolveSubcom(const char *name, REXXPFN *entryPoint)
RexxReturnCode REXXENTRY RexxFreeMemory(void *ptr)
RexxReturnCode RexxEntry RexxRegisterSubcomExe(const char *envName, REXXPFN entryPoint, const char *userArea)
RexxReturnCode RexxEntry RexxQueryFunction(const char *name)
RexxReturnCode REXXENTRY RexxShutDownAPI()
RexxReturnCode RexxEntry RexxRegisterSubcomDll(const char *envName, const char *moduleName, const char *procedureName, const char *userArea, size_t dropAuthority)
RexxReturnCode RexxEntry RexxDeregisterExit(const char *name, const char *moduleName)
RexxReturnCode RexxEntry RexxQuerySubcom(const char *name, const char *module, unsigned short *flags, char *userWord)
RexxReturnCode RexxEntry RexxLoadSubcom(const char *name, const char *lib)
RexxReturnCode RexxEntry RexxRegisterExitDll(const char *envName, const char *moduleName, const char *procedureName, const char *userArea, size_t dropAuthority)
RexxReturnCode RexxEntry RexxRegisterFunctionDll(const char *name, const char *moduleName, const char *procedureName)
RexxReturnCode RexxEntry RexxResolveRoutine(const char *name, REXXPFN *entryPoint)
RexxReturnCode RexxEntry RexxResolveExit(const char *name, REXXPFN *entryPoint)
RexxReturnCode RexxEntry RexxRegisterExitExe(const char *envName, REXXPFN entryPoint, const char *userArea)
RexxReturnCode RexxEntry RexxDeregisterFunction(const char *name)
RexxReturnCode RexxEntry RexxQueryExit(const char *name, const char *module, unsigned short *exist, char *userWord)
RexxReturnCode RexxEntry RexxDeregisterSubcom(const char *name, const char *moduleName)
void *REXXENTRY RexxAllocateMemory(size_t size)
RexxReturnCode RexxEntry RexxRegisterFunctionExe(const char *name, REXXPFN entryPoint)
#define ENTER_REXX_API(target)
Definition: RexxAPI.h:49
#define EXIT_REXX_API()
Definition: RexxAPI.h:55
@ ExitAPI
@ SubcomAPI
@ FunctionAPI
@ RegistrationManager
static void * allocateMemory(size_t length)
static void releaseMemory(void *p)
int RexxReturnCode
Definition: rexx.h:73
#define RexxEntry
Definition: rexx.h:235
#define RXSUBCOM_NONDROP
Definition: rexxapidefs.h:73
#define RXSUBCOM_OK
Definition: rexxapidefs.h:85
#define RXQUEUE_OK
Definition: rexxapidefs.h:248
void * REXXPFN
#define REXXENTRY