ContextApi.hpp
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 /* REXX API support */
40 /* */
41 /* Stub functions for all APIs accessed via the NativeFunctionContext */
42 /* */
43 /******************************************************************************/
44 
45 #ifndef ContextApi_Included
46 #define ContextApi_Included
47 
48 #include "RexxCore.h"
49 #include "RexxNativeActivation.hpp"
51 #include "RexxActivity.hpp"
52 
53 /**
54  * A stack-based API context object used for API stubs.
55  */
57 {
58 public:
59  /**
60  * Initialize an API context from a thread context.
61  *
62  * @param c The source context.
63  */
65  {
66  // we need to cleanup on exit
67  releaseLock = true;
71  // go acquire the kernel lock and take care of nesting
73  // we need to validate the thread call context to ensure this
74  // is the correct thread
76  }
77 
78 
79  /**
80  * Initialize an API context from a thread context.
81  * this is a nonblocking context. The extra argument allows
82  * the overloads to work
83  *
84  * @param c The source context.
85  */
86  inline ApiContext(RexxThreadContext *c, bool blocking)
87  {
88 
89  // we need to cleanup on exit
90  releaseLock = blocking;
94  }
95 
96  /**
97  * Initialize an API context from a call context.
98  *
99  * @param c The source context.
100  */
102  {
103  // we need to cleanup on exit
104  releaseLock = true;
108  // go acquire the kernel lock and take care of nesting
110  // we need to validate the thread call context to ensure this
111  // is the correct thread
113  }
114 
115  /**
116  * Initialize an API context from an exit context.
117  *
118  * @param c The source context.
119  */
121  {
122  // we need to cleanup on exit
123  releaseLock = true;
127  // go acquire the kernel lock and take care of nesting
129  // we need to validate the thread call context to ensure this
130  // is the correct thread
132  }
133 
134  /**
135  * Initialize an API context from a method context.
136  *
137  * @param c The source context.
138  */
140  {
141  // we need to cleanup on exit
142  releaseLock = true;
146  // go acquire the kernel lock and take care of nesting
148  // we need to validate the thread call context to ensure this
149  // is the correct thread
151  }
152 
153  /**
154  * Destructor for an API context. Releases the interpreter
155  * access lock on exit.
156  */
157  inline ~ApiContext()
158  {
159  // we only do this sort of cleanup if we really entered on the
160  // activity
161  if (releaseLock)
162  {
165  }
166  }
167 
169  {
171  return (RexxObjectPtr)o;
172  }
173 
174  /**
175  * The activity used for the API callback.
176  */
178  /**
179  * The top-level API context.
180  */
182 
183  /**
184  * Indicates whether we need to release the lock on return.
185  */
187 };
188 
189 
190 /**
191  * A stack-based API context object used for instance stubs.
192  */
194 {
195 public:
196  /**
197  * Initialize an API context from an instance context.
198  *
199  * @param c The source context.
200  */
202  {
203  instance = ((InstanceContext *)c)->instance;
204  }
205 
206  /**
207  * Destructor for an API context. Releases the interpreter
208  * access lock on exit.
209  */
211  {
212  }
213 
214  /**
215  * The top-level API context.
216  */
218 };
219 
220 #endif
RexxActivity * contextToActivity(RexxThreadContext *c)
RexxNativeActivation * contextToActivation(RexxThreadContext *c)
ApiContext(RexxCallContext *c)
Definition: ContextApi.hpp:101
bool releaseLock
Definition: ContextApi.hpp:186
ApiContext(RexxThreadContext *c)
Definition: ContextApi.hpp:64
ApiContext(RexxThreadContext *c, bool blocking)
Definition: ContextApi.hpp:86
ApiContext(RexxMethodContext *c)
Definition: ContextApi.hpp:139
ApiContext(RexxExitContext *c)
Definition: ContextApi.hpp:120
RexxActivity * activity
Definition: ContextApi.hpp:177
RexxNativeActivation * context
Definition: ContextApi.hpp:181
RexxObjectPtr ret(RexxObject *o)
Definition: ContextApi.hpp:168
InterpreterInstance * instance
Definition: ContextApi.hpp:217
InstanceApiContext(RexxInstance *c)
Definition: ContextApi.hpp:201
RexxNativeActivation * getApiContext()
void enterCurrentThread()
void validateThread()
void exitCurrentThread()
void createLocalReference(RexxObject *objr)
struct _RexxObjectPtr * RexxObjectPtr
Definition: rexx.h:127