1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef ZORBA_RUNTIME_API_PLAN_WRAPPER 17 #define ZORBA_RUNTIME_API_PLAN_WRAPPER 18 19 #include "common/shared_types.h" 20 21 #include "store/api/iterator.h" 22 23 #include "zorbautils/mutex.h" 24 25 #include <zorba/item.h> 26 #include <api/serialization/serializable.h> 27 28 29 namespace zorba 30 { 31 32 class PlanState; 33 class DebuggerRuntime; 34 class Timeout; 35 class XQueryImpl; 36 class dynamic_context; 37 38 39 /******************************************************************************* 40 Wrapper used to drive the evaluation of an iterator (sub)tree. 41 42 The wrapper wraps the root iterator of the (sub)tree. It is responsible 43 for allocating and deallocating the plan state that is shared by all 44 iterators in the (sub)tree. In general, it hides internal functionality 45 like separation of code and execution, or garabage collection, and it 46 provides a simple interface that the application can use. 47 48 - theIterator : 49 Pointer to the root iterator of the plan to be executed by this PlanWrapper. 50 NOTE: theIterator MUST be a RAW pointer, NOT an rchandle. This is because 51 several PlanWrappers (created from different clones of the same query) may 52 be accessing the same plan iterator, but PlanIterator does not do sunchronized 53 ref counting. It is the responsibility of the user of a plan wrapper to do 54 memory management for the actual plan (the plan wrapper does not assume 55 ownership of the plan). 56 57 - theDynamicContext : 58 Most of the time this is NULL. It is non-NULL if a NULL dctx is given to the 59 constructor of "this", in which case the constructor will allocate a dctx and 60 store a pointer to it in theDynamicContext, so that it will be deallocated by 61 the destructor of "this". 62 ********************************************************************************/ 63 class PlanWrapper : public store::Iterator 64 { 65 friend class DynamicFunctionInvocationIterator; 66 friend class DebuggerRuntime; 67 68 protected: 69 70 PlanIterator * theIterator; 71 72 dynamic_context * theDynamicContext; 73 74 PlanState * thePlanState; 75 76 bool theIsOpen; 77 78 Timeout * theTimeout; 79 Mutex theTimeoutMutex; 80 81 store::Iterator_t theExitValue; 82 83 public: 84 85 PlanWrapper( 86 PlanIterator* iter, 87 CompilerCB* ccb, 88 dynamic_context* dynamicContext, 89 XQueryImpl* query, 90 uint32_t stackDepth, 91 bool haveTimeout, 92 unsigned long timeout); 93 94 ~PlanWrapper(); 95 96 void open(); 97 98 bool next(store::Item_t& item); 99 100 void reset(); 101 102 void close(); 103 104 void checkDepth(const QueryLoc& loc); 105 dctx()106 dynamic_context* dctx() { return theDynamicContext; } 107 108 }; 109 110 } /* namespace zorba */ 111 #endif 112 113 /* 114 * Local variables: 115 * mode: c++ 116 * End: 117 */ 118 /* vim:set et sw=2 ts=2: */ 119