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_DEBUGGER_CLIENTIMPL_H
17 #define ZORBA_DEBUGGER_CLIENTIMPL_H
18 
19 #include <string>
20 #include <zorba/debugger_client.h>
21 #include "debugger/socket.h"
22 #include "zorbautils/runnable.h"
23 
24 namespace zorba {
25   class SocketStreambuf;
26   class DebuggerEventHandler;
27   class DebuggerListener;
28   class DebuggerClientImpl;
29 
30   class DebuggerListener : public Runnable {
31   public:
32     DebuggerListener(DebuggerClientImpl* aClient);
33   public:
34     virtual void run();
35     virtual void finish();
36     void stopLooping();
37   private:
38     DebuggerClientImpl* theClient;
39     bool theStopLooping;
40   };
41 
42   class DebuggerClientImpl : public DebuggerClient {
43     friend class DebuggerListener;
44   public:
45     DebuggerClientImpl(const std::string& aHost,
46                        unsigned short aPort,
47                        DebuggerEventHandler* aHandler);
48     ~DebuggerClientImpl();
49   public: // API
50     virtual void accept();
51     virtual std::size_t status();
52     virtual std::size_t variables();
53     virtual std::size_t feature_get(const std::string& aFeatureName);
54     virtual std::size_t feature_set(const std::string& aFeatureName,
55                                     const std::string& aValue);
56     virtual std::size_t run();
57     virtual std::size_t step_into();
58     virtual std::size_t step_out();
59     virtual std::size_t step_over();
60     virtual std::size_t stop(bool withQuit = true);
61     virtual std::size_t detach();
62     virtual std::size_t breakpoint_set(BreakpointType aType,
63                                        bool aEnabled = true,
64                                        const std::string& aFilename = "",
65                                        int aLinenumber = -1,
66                                        const std::string& aFunctionName = "",
67                                        const std::string& aExceptionName = "",
68                                        unsigned hit_value = 0,
69                                        HitCondition aCondition = BiggerEqual,
70                                        bool aIsTemporary = false,
71                                        const std::string& aExpression = "");
72     virtual std::size_t breakpoint_get(std::size_t aBreakpointId);
73     virtual std::size_t breakpoint_update(std::size_t aBreakpointId,
74                                        bool aEnabled = true,
75                                        int aLinenumber = -1,
76                                        unsigned hit_value = 0,
77                                        HitCondition aCondition = BiggerEqual);
78     virtual std::size_t breakpoint_remove(std::size_t aBreakpointId);
79     virtual std::size_t breakpoint_list();
80     virtual std::size_t stack_depth();
81     virtual std::size_t stack_get(int depth = -1);
82     virtual std::size_t context_names(int depth = -1);
83     virtual std::size_t context_get(int depth = -1, int contextId = -1);
84     virtual std::size_t typemap_get();
85     virtual std::size_t property_get(const std::string& aPropertyLongName,
86                                      int aStackDepth = -1,
87                                      int aContextId = -1,
88                                      std::size_t aMaxDataSize = 0,
89                                      int aDatapage = -1,
90                                      const std::string& aPropertyKey = "");
91     virtual std::size_t property_set(const std::string& aPropertyLongName,
92                                      int aStackDepth = -1,
93                                      int aContextId = -1,
94                                      std::size_t aMaxDataSize = 0,
95                                      const std::string& aPropertyAddress = "");
96     virtual std::size_t property_value(const std::string& aPropertyLongName,
97                                        int aStackDepth = -1,
98                                        int aContextId = -1,
99                                        std::size_t aMaxDataSize = 0,
100                                        int aDatapage = -1,
101                                        const std::string& aPropertyKey = "",
102                                        const std::string& aPropertyAddress = "");
103     virtual std::size_t source(const std::string& aFile, unsigned aBeginLine = 0, unsigned aEndLine = 0);
104     virtual std::size_t stream_option(OutputStream aStream, StreamBehaviour aBehaviour);
105     virtual std::size_t do_break();
106     virtual std::size_t eval(const std::string& aExpr);
107     virtual void quit();
108   private:
109     std::size_t property_x(const std::string& aCommand,
110                            const std::string& aPropertyLongName,
111                            int aStackDepth = -1,
112                            int aContextId = -1,
113                            std::size_t aMaxDataSize = 0);
114   private:
115     TCPServerSocket       theServerSocket;
116     TCPSocket*            theSocket;
117     SocketStreambuf*      theInStreamBuffer;
118     SocketStreambuf*      theOutStreamBuffer;
119     std::istream*         theInStream;
120     std::ostream*         theOutStream;
121     DebuggerEventHandler* theHandler;
122     DebuggerListener*     theListener;
123     std::size_t           theLastId;
124   };
125 
126 } // namespace zorba
127 
128 #endif // ZORBA_DEBUGGER_CLIENTIMPL_H
129