InterpreterInstance.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
4 /* */
5 /* This program and the accompanying materials are made available under */
6 /* the terms of the Common Public License v1.0 which accompanies this */
7 /* distribution. A copy is also available at the following address: */
8 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
9 /* */
10 /* Redistribution and use in source and binary forms, with or */
11 /* without modification, are permitted provided that the following */
12 /* conditions are met: */
13 /* */
14 /* Redistributions of source code must retain the above copyright */
15 /* notice, this list of conditions and the following disclaimer. */
16 /* Redistributions in binary form must reproduce the above copyright */
17 /* notice, this list of conditions and the following disclaimer in */
18 /* the documentation and/or other materials provided with the distribution. */
19 /* */
20 /* Neither the name of Rexx Language Association nor the names */
21 /* of its contributors may be used to endorse or promote products */
22 /* derived from this software without specific prior written permission. */
23 /* */
24 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
25 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
26 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
27 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
28 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
29 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
30 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
31 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
32 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
33 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
34 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
35 /* */
36 /*----------------------------------------------------------------------------*/
37 /******************************************************************************/
38 /* REXX Kernel */
39 /* */
40 /* Manage a created instance of the interpreter */
41 /* */
42 /******************************************************************************/
43 #ifndef Included_InterpreterInstance_hpp
44 #define Included_InterpreterInstance_hpp
45 
46 #include "RexxCore.h"
47 #include "ExitHandler.hpp"
49 #include "SysInterpreterInstance.hpp"
50 
51 class RexxDirectory;
52 class CommandHandler;
53 class PackageClass;
54 
56 {
57 // the SysInterpreterInstance is essentially an extension of this class,
58 // so it is given full access to the interpreter instance fields.
60 public:
61 
62  // methods associated with actual interpreter instances
63  inline InterpreterInstance(RESTORETYPE restoreType) : terminationSem("InterpreterInstance::terminationSem") { ; }
65 
66  inline void *operator new(size_t, void *ptr) {return ptr;}
67  inline void operator delete(void *, void *) {;}
68  void *operator new(size_t);
69  inline void operator delete(void *) {;}
70  void live(size_t);
71  void liveGeneral(int);
72 
75 
79  void initialize(RexxActivity *activity, RexxOption *options);
80  bool terminate();
85  int attachThread(RexxThreadContext *&attachedContext);
86  bool detachThread();
87  bool detachThread(RexxActivity *activity);
89  void exitCurrentThread();
92  void copyExits(ExitHandler *target);
96  bool poolActivity(RexxActivity *activity);
97  ExitHandler &getExitHandler(int exitNum) { return exits[exitNum - 1]; }
98  void setExitHandler(int exitNum, REXXPFN e) { getExitHandler(exitNum).setEntryPoint(e); }
99  void setExitHandler(int exitNum, const char *e) { getExitHandler(exitNum).resolve(e); }
104  void traceAllActivities(bool on);
105  inline RexxString *resolveProgramName(RexxString *name, RexxString *dir, RexxString *ext) { return sysInstance.resolveProgramName(name, dir, ext); }
112  void addCommandHandler(const char *name, const char *registeredName);
113  void addCommandHandler(const char *name, REXXPFN entryPoint);
116  PackageClass *loadRequires(RexxActivity *activity, RexxString *shortName, const char *data, size_t length);
117  PackageClass *loadRequires(RexxActivity *activity, RexxString *shortName, RexxArray *source);
118  PackageClass *loadRequires(RexxActivity *activity, RexxString *shortName, RexxString *fullName);
119  void runRequires(RexxActivity *activity, RexxString *name, RoutineClass *code);
120  void addRequiresFile(RexxString *shortName, RexxString *fullName, PackageClass *package);
121  inline void setupProgram(RexxActivation *activation)
122  {
123  sysInstance.setupProgram(activation);
124  }
125 
126 protected:
127 
128  bool processOptions(RexxOption *options);
129 
130 
131  InstanceContext context; // our externalizied instance context
132  SysInterpreterInstance sysInstance; // our platform specific helper
133 
134  RexxActivity *rootActivity; // the initial activity
135  SecurityManager *securityManager; // the security manager for our instance
136  RexxList *allActivities; // all activities associated with this instance
137  RexxIdentityTable *globalReferences; // our global reference table
138  RexxString *defaultEnvironment; // the default address environment
139  RexxString *searchPath; // additional Rexx search path
140  RexxList *searchExtensions; // extensions to search on for external calls
141  void *applicationData; // application specific data
142  RexxDirectory *localEnvironment; // the current local environment
143  RexxDirectory *commandHandlers; // our list of command environment handlers
144  RexxDirectory *requiresFiles; // our list of requires files used by this instance
145 
146  bool terminating; // shutdown indicator
147  bool terminated; // last thread cleared indicator
148  SysSemaphore terminationSem; // used to signal that everything has shutdown
149 
150  // array of system exits
152 
153  static RexxInstanceInterface interfaceVector; // single interface vector instance
154 };
155 
156 #endif
157 
RESTORETYPE
Definition: ObjectClass.hpp:82
void resolve(const char *name)
Definition: ExitHandler.cpp:86
void setEntryPoint(REXXPFN e)
Definition: ExitHandler.hpp:56
SecurityManager * securityManager
bool poolActivity(RexxActivity *activity)
void removeActivity(RexxActivity *)
RexxObject * getLocalEnvironment(RexxString *)
void setSecurityManager(RexxObject *m)
void addGlobalReference(RexxObject *o)
ExitHandler exits[RXNOOFEXITS+1]
RexxActivity * enterOnCurrentThread()
RexxActivity * findActivity()
RexxInstance * getInstanceContext()
SysInterpreterInstance sysInstance
RexxActivity * attachThread()
RexxDirectory * localEnvironment
RexxIdentityTable * globalReferences
RexxActivity * getRootActivity()
InterpreterInstance(ExitHandler *handlers)
void setExitHandler(RexxContextExit &e)
void addRequiresFile(RexxString *shortName, RexxString *fullName, PackageClass *package)
bool haltAllActivities(RexxString *)
static RexxInstanceInterface interfaceVector
void setupProgram(RexxActivation *activation)
void removeGlobalReference(RexxObject *o)
PackageClass * getRequiresFile(RexxActivity *activity, RexxString *name)
PackageClass * loadRequires(RexxActivity *activity, RexxString *shortName, const char *data, size_t length)
ExitHandler & getExitHandler(int exitNum)
void setExitHandler(int exitNum, const char *e)
void addCommandHandler(const char *name, const char *registeredName)
InterpreterInstance(RESTORETYPE restoreType)
void addActivity(RexxActivity *)
void traceAllActivities(bool on)
SecurityManager * getSecurityManager()
void setExitHandler(int exitNum, REXXPFN e)
RexxDirectory * getLocal()
void setExitHandler(RXSYSEXIT &e)
void copyExits(ExitHandler *target)
void runRequires(RexxActivity *activity, RexxString *name, RoutineClass *code)
void initialize(RexxActivity *activity, RexxOption *options)
void activityDeactivated(RexxActivity *activity)
RexxActivity * spawnActivity(RexxActivity *parent)
RexxThreadContext * getRootThreadContext()
RexxDirectory * requiresFiles
RexxString * getDefaultEnvironment()
bool processOptions(RexxOption *options)
RexxString * resolveProgramName(RexxString *name, RexxString *dir, RexxString *ext)
CommandHandler * resolveCommandHandler(RexxString *name)
RexxDirectory * commandHandlers
RexxString * resolveProgramName(RexxString *_name, RexxString *_parentDir, RexxString *_parentExtension)
void setupProgram(RexxActivation *activation)
#define RXNOOFEXITS
Definition: rexxapidefs.h:206
CONSTANT_STRING sysexit_name
Definition: rexx.h:191
int sysexit_code
Definition: rexx.h:192
RexxContextExitHandler * handler
Definition: oorexxapi.h:171
RexxInstance instanceContext
void * REXXPFN
pthread_t thread_id_t