debugger_client.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef ZORBA_DEBUGGER_CLIENT_H
00017 #define ZORBA_DEBUGGER_CLIENT_H
00018 
00019 #include <map>
00020 #include <list>
00021 #include <zorba/api_shared_types.h>
00022 #include <zorba/debugger_event_handler.h>
00023 
00024 namespace zorba{ 
00025 
00026   /**
00027    * zorba::Variable is the debugger representation of a variable on 
00028    * from the remote server to the client.
00029    */
00030   class ZORBA_EXTERN_DECL Variable
00031   {
00032     private:
00033       String theName;
00034       String theType;
00035     public:
00036       Variable( String &aName, String &aType ): theName(aName), theType(aType){}
00037       
00038       virtual ~Variable(){}
00039 
00040       String getName() const { return theName; }
00041 
00042       String getType() const { return theType; }
00043   };
00044 
00045   /** 
00046    * Client instance of Zorba debugger.
00047    * ZorbaDebuggerClient API provides to send commands to a
00048    * remote debugger and to handle events from it.
00049    */
00050   class ZORBA_EXTERN_DECL ZorbaDebuggerClient
00051   {
00052 
00053     public:
00054 
00055       virtual ~ZorbaDebuggerClient(){}
00056 
00057       /** \brief Gets a new instance of Zorba debugger client.
00058        *
00059        * This factory method create a new instance of the debugger.
00060        * The parameters are the network ports for the request and event connection
00061        * (by default: 8000 for commands and 9000 for events):
00062        * <pre>
00063        * ZorbaDebuggerClient* lClient = ZorbaDebuggerClient::createClient(8000, 9000);
00064        * </pre>
00065        *
00066        * @param unsigned short aRequestPortno Network port number for debugging commands
00067        * @param unsigned short aEventPortno
00068        * @return ZorbaDebuggerClient the newly created debugger client instance.
00069        */
00070       static ZorbaDebuggerClient*
00071       createClient( unsigned short aRequestPortno, unsigned short aEventPortno );
00072 
00073       /** \brief Register a debuggere vent handler to which runtime events on the remote 
00074        * debugger server are reported.
00075        *
00076        * @param aDebuggerEventHandler DebuggerEventHandler Handler for runtime events comming
00077        * from the remote debugger server.
00078        */
00079       virtual void
00080       registerEventHandler( DebuggerEventHandler *aDebuggerEventHandler ) = 0;
00081      
00082       /** \brief Indicates if the query is running.
00083        *
00084        * @return true if the query is running, false otherwise.
00085        */
00086       virtual bool
00087       isQueryRunning() const = 0;
00088 
00089       /** \brief Indicates if the query is idle.
00090        *
00091        * @return true if the query is idle, false otherwise.
00092        */
00093       virtual bool
00094       isQueryIdle() const = 0;
00095 
00096       /** \brief Indicates if the query is suspended.
00097        *
00098        * @return true if the query is suspended, false otherwise.
00099        */
00100       virtual bool
00101       isQuerySuspended() const = 0;
00102 
00103       /** \brief Indicates if the query is terminated.
00104        *
00105        * @return true if the query is terminated, false otherwise.
00106        */
00107       virtual bool
00108       isQueryTerminated() const = 0;
00109 
00110       /** \brief Request the remote query to run.
00111        *
00112        */
00113       virtual void
00114       run() = 0;
00115 
00116       /** \brief Request the remote query to suspend.
00117        *
00118        */
00119       virtual void
00120       suspend() = 0;
00121 
00122       /** \brief Request the remote query to resume.
00123        *
00124        */
00125       virtual void
00126       resume() = 0;
00127       
00128       /** \brief Request the remote query to terminate.
00129        *
00130        */
00131       virtual void
00132       terminate() = 0;
00133 
00134       
00135       /** \brief Request the remote query quit and the debugger server to shutdown.
00136        *
00137        */virtual void
00138       quit() = 0;
00139 
00140       /** \brief Set a new breakpoint.
00141        *
00142        * @param aFileName String Filename of the query or module.
00143        * @param aLineNo unsigned int Line number in the file.
00144        */
00145       virtual void
00146       addBreakpoint( const String &aFileName, const unsigned int aLineNo ) = 0;
00147 
00148       /** \brief Set a new breakpoint in the main query.
00149        *
00150        * @param aLineNo unsigned int Line number in the main query.
00151        */
00152       virtual void
00153       addBreakpoint( const unsigned int aLineNo ) = 0;
00154 
00155       /** \brief Set a new watchpoint.
00156        * 
00157        * A watchpoint suspend the query execution when the return 
00158        * value of its XQuery expression is true.
00159        *
00160        * @param anExpr String XQuery expression to be evaluated.
00161        */
00162       virtual void
00163       addBreakpoint( const String &anExpr ) = 0;
00164 
00165       /** \brief Remove a breakpoint or watchpoint of the given id
00166        *
00167        * @param anId unsigned int the breakpoint/watchpoint id
00168        * @return true if the breakpoint id is correct.
00169        */
00170       virtual bool
00171       clearBreakpoint( unsigned int anId ) = 0;
00172 
00173       /** \brief Remove a breakpoint or watchpoint of the given collection of ids
00174        *
00175        * @param Ids std::list<unsigned int> List of the breakpoint/watchpoint ids
00176        * @return true if all breakpoint ids are correct.
00177        */
00178       virtual void
00179       clearBreakpoints( std::list<unsigned int> &Ids ) = 0;
00180       
00181       /** \brief Get all breakpoints set on the remote query.
00182        *
00183        * @return a map of all breakpoints with their associated id.
00184        */
00185       virtual std::map<unsigned int, String>
00186       getBreakpoints() const = 0;
00187 
00188       /** \brief Remove all breakpoints on the remote query.
00189        *
00190        */
00191       virtual void
00192       clearBreakpoints() = 0;
00193 
00194       /** \brief Get the current location of the remote query.
00195        *
00196        * return the current location of the query or null is the query didn't start yet.
00197        */
00198       virtual QueryLocation*
00199       getLocation() const = 0;
00200 
00201       /** \brief Evaluate an XQuery expression on the remote debugger server.
00202        *
00203        * eval() sends an XQuery expression to the remote debugger server for evaluation.
00204        * This expression can use debugee query global and locals variables.
00205        * Because eval() can eventually compute very complex expression, the evaluation is
00206        * done in a separate thread. Once the expression computed, the server fires an event to
00207        * the client with the result or an error description if an error happened during evaluation.
00208        */
00209       virtual void
00210       eval( String &anExpr ) = 0;
00211 
00212       /** \brief Get all variables that are in scope in the remote query.
00213        *
00214        * @return a list of all variables that are in scope in the remote query.
00215        */
00216       virtual std::list<Variable>
00217       getAllVariables() = 0;
00218 
00219       /** \brief Get all local variables that are in scope in the remote query.
00220        *
00221        * @return a list of all local variables that are in scope in the remote query.
00222        */
00223       virtual std::list<Variable>
00224       getLocalVariables() = 0;
00225 
00226       /** \brief Get all global variables that are in scope in the remote query.
00227        *
00228        * @return a list of all global variables that are in scope in the remote query.
00229        */
00230       virtual std::list<Variable>
00231       getGlobalVariables() = 0;
00232   };
00233 }//end of namespace
00234 #endif