-
-
Notifications
You must be signed in to change notification settings - Fork 336
/
CliContext.h
121 lines (90 loc) · 2.87 KB
/
CliContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef CLI_CONTEXT_H
#define CLI_CONTEXT_H
#include <sys/cdefs.h>
// Needed in histedit.h.
#include <histedit.h>
#include <Locker.h>
#include "Team.h"
class StackFrame;
class StackTrace;
class Team;
class UserInterfaceListener;
class ValueNodeManager;
class CliContext : private Team::Listener {
public:
enum {
EVENT_QUIT = 0x01,
EVENT_USER_INTERRUPT = 0x02,
EVENT_THREAD_ADDED = 0x04,
EVENT_THREAD_REMOVED = 0x08,
EVENT_THREAD_STOPPED = 0x10,
EVENT_THREAD_STACK_TRACE_CHANGED = 0x20
};
public:
CliContext();
~CliContext();
status_t Init(Team* team,
UserInterfaceListener* listener);
void Cleanup();
void Terminating();
bool IsTerminating() const { return fTerminating; }
// service methods for the input loop thread follow
Team* GetTeam() const { return fTeam; }
UserInterfaceListener* GetUserInterfaceListener() const
{ return fListener; }
ValueNodeManager* GetValueNodeManager() const
{ return fNodeManager; }
StackTrace* GetStackTrace() const
{ return fCurrentStackTrace; }
Thread* CurrentThread() const { return fCurrentThread; }
thread_id CurrentThreadID() const;
void SetCurrentThread(Thread* thread);
void PrintCurrentThread();
int32 CurrentStackFrameIndex() const
{ return fCurrentStackFrameIndex; }
void SetCurrentStackFrameIndex(int32 index);
const char* PromptUser(const char* prompt);
void AddLineToInputHistory(const char* line);
void QuitSession(bool killTeam);
void WaitForThreadOrUser();
void ProcessPendingEvents();
private:
struct Event;
typedef DoublyLinkedList<Event> EventList;
private:
// Team::Listener
virtual void ThreadAdded(const Team::ThreadEvent& event);
virtual void ThreadRemoved(const Team::ThreadEvent& event);
virtual void ThreadStateChanged(
const Team::ThreadEvent& event);
virtual void ThreadStackTraceChanged(
const Team::ThreadEvent& event);
private:
void _QueueEvent(Event* event);
void _PrepareToWaitForEvents(uint32 eventMask);
uint32 _WaitForEvents();
void _SignalInputLoop(uint32 events);
static const char* _GetPrompt(EditLine* editLine);
private:
BLocker fLock;
Team* fTeam;
UserInterfaceListener* fListener;
ValueNodeManager* fNodeManager;
EditLine* fEditLine;
History* fHistory;
const char* fPrompt;
sem_id fBlockingSemaphore;
uint32 fInputLoopWaitingForEvents;
uint32 fEventsOccurred;
bool fInputLoopWaiting;
volatile bool fTerminating;
Thread* fCurrentThread;
StackTrace* fCurrentStackTrace;
int32 fCurrentStackFrameIndex;
EventList fPendingEvents;
};
#endif // CLI_CONTEXT_H