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  const char *get_application_id() const { return id; }
68 
69  void forgetDatabase() { gbmain = NULp; }
70  virtual void release() = 0;
71 };
72 
73 
74 class RecordingMacro;
75 
76 class MacroRecorder : public BoundActionTracker { // derived from Noncopyable
77  RecordingMacro *recording;
78 
79 public:
80  MacroRecorder(const char *application_id, GBDATA *gb_main_)
81  : BoundActionTracker(application_id, gb_main_),
82  recording(NULp)
83  {}
85  ma_assert(!recording);
86  }
87 
88  GB_ERROR start_recording(const char *file, const char *stop_action_name, bool expand_existing);
90  GB_ERROR execute(const char *macroFile, bool loop_marked, const RootCallback& execution_done_cb);
91 
92  void track_action(const char *action_id) OVERRIDE;
94 
95  void add_planned_interruption(const char *displayed_text);
96 
97  GB_ERROR handle_tracked_client_action(char *&tracked); // dont use
98  void release() OVERRIDE {
99  if (is_tracking()) {
101  if (error) fprintf(stderr, "Error in stop_recording: %s (while exiting server)\n", error);
102  }
104  }
105 };
106 
108  bool released;
109 
110  void bind_callbacks(bool install);
111  void send_client_action(const char *action);
112  void ungrant_client_and_confirm_quit_action();
113 public:
114  ClientActionTracker(const char *application_id, GBDATA *gb_main_)
115  : BoundActionTracker(application_id, gb_main_),
116  released(false)
117  {
118  bind_callbacks(true);
119  }
121  ma_assert(released); // you have to call release() before the dtor is called
122  }
123 
124  void release() OVERRIDE {
125  if (!released) {
126  bind_callbacks(false);
127  ungrant_client_and_confirm_quit_action();
129  released = true;
130  }
131  }
132 
133  void track_action(const char *action_id) OVERRIDE;
134  void track_awar_change(AW_awar *awar) OVERRIDE;
135 
136  void set_tracking_according_to(GBDATA *gb_recording); // dont use
137 };
138 
139 // --------------------------------------------------------------------------------
140 
142  UserActionTracker *tracker = aw_root->getTracker();
143  return tracker ? dynamic_cast<BoundActionTracker*>(tracker) : NULp;
144 }
145 
148  ma_assert(tracker); // application is not able to handle macros
149  return dynamic_cast<MacroRecorder*>(tracker);
150 }
151 
152 // --------------------------------------------------------------------------------
153 
154 #else
155 #error trackers.hxx included twice
156 #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
void release() OVERRIDE
Definition: trackers.hxx:98
bool is_tracking() const
Definition: aw_root.hxx:70
MacroRecorder(const char *application_id, GBDATA *gb_main_)
Definition: trackers.hxx:80
GB_ERROR execute(const char *macroFile, bool loop_marked, const RootCallback &execution_done_cb)
Definition: trackers.cxx:210
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
void track_awar_change(AW_awar *awar) OVERRIDE
Definition: trackers.cxx:243
void track_awar_change(AW_awar *awar) OVERRIDE
Definition: trackers.cxx:333
MacroRecorder * getMacroRecorder(AW_root *aw_root)
Definition: trackers.hxx:146
void track_action(const char *action_id) OVERRIDE
Definition: trackers.cxx:238
ClientActionTracker(const char *application_id, GBDATA *gb_main_)
Definition: trackers.hxx:114
virtual void release()=0
void add_planned_interruption(const char *displayed_text)
Definition: trackers.cxx:282
void track_action(const char *action_id) OVERRIDE
Definition: trackers.cxx:323
void release() OVERRIDE
Definition: trackers.hxx:124
void set_tracking_according_to(GBDATA *gb_recording)
Definition: trackers.cxx:290
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:67
#define OVERRIDE
Definition: cxxforward.h:112
GB_ERROR handle_tracked_client_action(char *&tracked)
Definition: trackers.cxx:248
BoundActionTracker * get_active_macro_recording_tracker(AW_root *aw_root)
Definition: trackers.hxx:141
~BoundActionTracker() OVERRIDE
Definition: trackers.hxx:59
void forgetDatabase()
Definition: trackers.hxx:69
#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