TranslateDispatcher.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.oorexx.org/license.html */
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 "RexxCore.h"
40 #include "TranslateDispatcher.hpp"
41 #include "RoutineClass.hpp"
42 #include "ProtectedObject.hpp"
43 #include "RexxNativeActivation.hpp"
44 
45 
46 /**
47  * Default virtual method for handling a run() methods on
48  * an activity dispatcher.
49  */
51 {
52  ProtectedSet savedObjects;
53 
54  RoutineClass *program;
55 
56  RexxString *name = OREF_NULLSTRING; // name of the invoked program
57  if (programName != NULL) /* have an actual name? */
58  {
59  /* get string version of the name */
60  name = new_string(programName);
61  }
62 
63  savedObjects.add(name); /* protect from garbage collect */
64 
65  if (instore == NULL) /* no instore request? */
66  {
67  /* go resolve the name */
69  if (fullname == OREF_NULL) /* not found? */
70  {
71  /* got an error here */
73  }
74  savedObjects.add(fullname);
75  /* go translate the image */
76  program = new RoutineClass(fullname);
77  savedObjects.add(program);
78  }
79  else /* have an instore program */
80  {
81  /* go handle instore parms */
82  program = RoutineClass::processInstore(instore, name);
83  if (program == OREF_NULL) /* couldn't get it? */
84  {
85  /* got an error here */
87  }
88  savedObjects.add(program);
89  }
90  if (outputName != NULL) /* want to save this to a file? */
91  {
92  /* go save this method */
93  program->save(outputName);
94  }
95 }
96 
97 
98 /**
99  * Default handler for any error conditions. This just sets the
100  * condition information in the dispatch unit.
101  *
102  * @param c The condition information for the error.
103  */
105 {
106  // use the base error handling and set our return code to the negated error code.
108  rc = -r;
109  // process the error to display the error message.
111 }
112 
113 
114 /**
115  * Default virtual method for handling a run() methods on
116  * an activity dispatcher.
117  */
119 {
120  ProtectedSet savedObjects;
121  RexxString *name = OREF_NULLSTRING; // name of the invoked program
122  if (programName != NULL) /* have an actual name? */
123  {
124  /* get string version of the name */
125  name = new_string(programName);
126  }
127 
128  savedObjects.add(name); /* protect from garbage collect */
129 
130  RXSTRING instore[2];
131 
132  MAKERXSTRING(instore[0], const_cast<char *>(source->strptr), source->strlength);
133  MAKERXSTRING(instore[1], NULL, 0);
134 
135  /* go handle instore parms */
136  RoutineClass *program = RoutineClass::processInstore(instore, name);
137  if (program == OREF_NULL) /* couldn't get it? */
138  {
139  /* got an error here */
141  }
142  // copy the image information back
143  image->strptr = instore[1].strptr;
144  image->strlength = instore[1].strlength;
145 }
146 
147 
148 /**
149  * Default handler for any error conditions. This just sets the
150  * condition information in the dispatch unit.
151  *
152  * @param c The condition information for the error.
153  */
155 {
156  // use the base error handling and set our return code to the negated error code.
158  rc = -r;
159 }
160 
void reportException(wholenumber_t error)
#define OREF_NULL
Definition: RexxCore.h:61
#define Error_Program_unreadable_name
#define Error_Program_unreadable_notfound
RexxString * new_string(const char *s, stringsize_t l)
virtual void handleError(wholenumber_t, RexxDirectory *)
RexxNativeActivation * activation
RexxDirectory * conditionData
void add(RexxObject *)
wholenumber_t error()
RexxString * resolveProgramName(RexxString *, RexxString *, RexxString *)
RexxBuffer * save()
static RoutineClass * processInstore(PRXSTRING instore, RexxString *name)
virtual void handleError(wholenumber_t, RexxDirectory *)
virtual void handleError(wholenumber_t, RexxDirectory *)
ssize_t wholenumber_t
Definition: rexx.h:230
#define MAKERXSTRING(r, p, l)
Definition: rexx.h:182
const char * strptr
Definition: rexx.h:163
size_t strlength
Definition: rexx.h:162
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158