ARB
trackers.hxx
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : trackers.hxx //
4 // Purpose : action trackers //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in March 2013 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // ============================================================= //
11 
12 #ifndef TRACKERS_HXX
13 #define TRACKERS_HXX
14 
15 #ifndef AW_ROOT_HXX
16 #include <aw_root.hxx>
17 #endif
18 #ifndef ARB_STRING_H
19 #include <arb_string.h>
20 #endif
21 #ifndef MACROS_LOCAL_HXX
22 #include "macros_local.hxx"
23 #endif
24 
25 #define ma_assert(bed) arb_assert(bed)
26 
28  // RequiresActionTracker is a failing placeholder for the explicit tracker,
29  // that has to be added later (when DB is available)
30  //
31  // Always "records", i.e. fails instantly on first GUI-action-callback
32  __ATTR__NORETURN inline void needs_to_be_replaced() {
33  // this tracker needs to be replaced before any UI action is performed
34  GBK_terminate("Broken macro recording ability (no valid tracker)");
35  }
36 public:
38  set_tracking(true); // always track
39  }
40  __ATTR__NORETURN void track_action(const char *) OVERRIDE { needs_to_be_replaced(); }
41  __ATTR__NORETURN void track_awar_change(AW_awar *) OVERRIDE { needs_to_be_replaced(); }
42  bool is_replaceable() const OVERRIDE { return true; }
43 };
44 
46  char *id; // application id (e.g. "ARB_NT", "ARB_EDIT4", ...)
47  GBDATA *gbmain; // DB used to record/playback macros
48 
49  void set_tracking(bool track) { UserActionTracker::set_tracking(track); }
50 
51 protected:
52  void set_recording(bool recording);
53 
54 public:
55  BoundActionTracker(const char *application_id, GBDATA *gb_main)
56  : id(ARB_strdup(application_id)),
57  gbmain(gb_main)
58  {}
60  free(id);
61  }
62 
63  bool is_replaceable() const OVERRIDE { return false; }
64  bool reconfigure(const char *application_id, GBDATA *gb_main);
65 
66  GBDATA *get_gbmain() { ma_assert(gbmain); return gbmain; }
67  bool is_bound_to(GBDATA *this_gbmain) { return gbmain == this_gbmain; }
68  void forgetDatabase() { gbmain = NULp; }
69 
70  const char *get_application_id() const { return id; }
71 
72  virtual void release() = 0;
73 };
74 
75 
76 class RecordingMacro;
77 
78 class MacroRecorder : public BoundActionTracker { // derived from Noncopyable
79  RecordingMacro *recording;
80 
81 public:
82  MacroRecorder(const char *application_id, GBDATA *gb_main_)
83  : BoundActionTracker(application_id, gb_main_),
84  recording(NULp)
85  {}
87  ma_assert(!recording);
88  }
89 
90  GB_ERROR start_recording(const char *file, const char *stop_action_name, bool expand_existing);
92  GB_ERROR execute(const char *macroFile, bool loop_marked, const RootCallback& execution_done_cb);
93 
94  bool is_executing_macro() const;
95 
96  void track_action(const char *action_id) OVERRIDE;
98 
99  void add_planned_interruption(const char *displayed_text);
100 
101  GB_ERROR handle_tracked_client_action(char *&tracked); // dont use
102  void release() OVERRIDE {
103  if (is_tracking()) {
105  if (error) fprintf(stderr, "Error in stop_recording: %s (while exiting server)\n", error);
106  }
108  }
109 };
110 
112  bool released;
113 
114  void bind_callbacks(bool install);
115  void send_client_action(const char *action);
116  void ungrant_client_and_confirm_quit_action();
117 public:
118  ClientActionTracker(const char *application_id, GBDATA *gb_main_)
119  : BoundActionTracker(application_id, gb_main_),
120  released(false)
121  {
122  bind_callbacks(true);
123  }
125  ma_assert(released); // you have to call release() before the dtor is called
126  }
127 
128  void release() OVERRIDE {
129  if (!released) {
130  bind_callbacks(false);
131  ungrant_client_and_confirm_quit_action();
133  released = true;
134  }
135  }
136 
137  void track_action(const char *action_id) OVERRIDE;
138  void track_awar_change(AW_awar *awar) OVERRIDE;
139 
140  void set_tracking_according_to(GBDATA *gb_recording); // dont use
141 };
142 
143 // --------------------------------------------------------------------------------
144 
146  UserActionTracker *tracker = aw_root->getTracker();
147  return tracker ? dynamic_cast<BoundActionTracker*>(tracker) : NULp;
148 }
149 
151  // getMacroRecorder may only be used, if got_macro_ability() == true
152 
154  ma_assert(tracker); // application is not able to handle macros
155  return dynamic_cast<MacroRecorder*>(tracker);
156 }
157 
158 // --------------------------------------------------------------------------------
159 
160 #else
161 #error trackers.hxx included twice
162 #endif // TRACKERS_HXX
const char * GB_ERROR
Definition: arb_core.h:25
GB_ERROR start_recording(const char *file, const char *stop_action_name, bool expand_existing)
Definition: trackers.cxx:74
bool is_executing_macro() const
Definition: trackers.cxx:326
void release() OVERRIDE
Definition: trackers.hxx:102
bool is_tracking() const
Definition: aw_root.hxx:70
MacroRecorder(const char *application_id, GBDATA *gb_main_)
Definition: trackers.hxx:82
GB_ERROR execute(const char *macroFile, bool loop_marked, const RootCallback &execution_done_cb)
Definition: trackers.cxx:232
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
void track_awar_change(AW_awar *awar) OVERRIDE
Definition: trackers.cxx:282
void track_awar_change(AW_awar *awar) OVERRIDE
Definition: trackers.cxx:376
MacroRecorder * getMacroRecorder(AW_root *aw_root)
Definition: trackers.hxx:150
void track_action(const char *action_id) OVERRIDE
Definition: trackers.cxx:277
ClientActionTracker(const char *application_id, GBDATA *gb_main_)
Definition: trackers.hxx:118
bool is_bound_to(GBDATA *this_gbmain)
Definition: trackers.hxx:67
virtual void release()=0
void add_planned_interruption(const char *displayed_text)
Definition: trackers.cxx:321
void track_action(const char *action_id) OVERRIDE
Definition: trackers.cxx:366
void release() OVERRIDE
Definition: trackers.hxx:128
void set_tracking_according_to(GBDATA *gb_recording)
Definition: trackers.cxx:333
void GBK_terminate(const char *error) __ATTR__NORETURN
Definition: arb_msg.cxx:509
#define false
Definition: ureadseq.h:13
static void error(const char *msg)
Definition: mkptypes.cxx:96
bool is_replaceable() const OVERRIDE
Definition: trackers.hxx:42
bool reconfigure(const char *application_id, GBDATA *gb_main)
Definition: trackers.cxx:24
BoundActionTracker(const char *application_id, GBDATA *gb_main)
Definition: trackers.hxx:55
void set_tracking(bool track)
Definition: aw_root.hxx:64
__ATTR__NORETURN void track_awar_change(AW_awar *) OVERRIDE
Definition: trackers.hxx:41
void set_recording(bool recording)
Definition: trackers.cxx:31
#define ma_assert(bed)
Definition: trackers.hxx:25
const char * get_application_id() const
Definition: trackers.hxx:70
#define OVERRIDE
Definition: cxxforward.h:112
GB_ERROR handle_tracked_client_action(char *&tracked)
Definition: trackers.cxx:287
BoundActionTracker * get_active_macro_recording_tracker(AW_root *aw_root)
Definition: trackers.hxx:145
~BoundActionTracker() OVERRIDE
Definition: trackers.hxx:59
void forgetDatabase()
Definition: trackers.hxx:68
#define NULp
Definition: cxxforward.h:116
UserActionTracker * getTracker()
Definition: aw_root.hxx:135
__ATTR__NORETURN void track_action(const char *) OVERRIDE
Definition: trackers.hxx:40
GB_ERROR stop_recording()
Definition: trackers.cxx:91
#define __ATTR__NORETURN
Definition: attributes.h:56
GBDATA * get_gbmain()
Definition: trackers.hxx:66
GBDATA * gb_main
Definition: adname.cxx:32
bool is_replaceable() const OVERRIDE
Definition: trackers.hxx:63