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  GB_ERROR handle_tracked_client_action(char *&tracked); // dont use
96  void release() OVERRIDE {
97  if (is_tracking()) {
99  if (error) fprintf(stderr, "Error in stop_recording: %s (while exiting server)\n", error);
100  }
102  }
103 };
104 
106  bool released;
107 
108  void bind_callbacks(bool install);
109  void send_client_action(const char *action);
110  void ungrant_client_and_confirm_quit_action();
111 public:
112  ClientActionTracker(const char *application_id, GBDATA *gb_main_)
113  : BoundActionTracker(application_id, gb_main_),
114  released(false)
115  {
116  bind_callbacks(true);
117  }
119  ma_assert(released); // you have to call release() before the dtor is called
120  }
121 
122  void release() OVERRIDE {
123  if (!released) {
124  bind_callbacks(false);
125  ungrant_client_and_confirm_quit_action();
127  released = true;
128  }
129  }
130 
131  void track_action(const char *action_id) OVERRIDE;
132  void track_awar_change(AW_awar *awar) OVERRIDE;
133 
134  void set_tracking_according_to(GBDATA *gb_recording); // dont use
135 };
136 
137 // --------------------------------------------------------------------------------
138 
140  UserActionTracker *tracker = aw_root->getTracker();
141  return tracker ? dynamic_cast<BoundActionTracker*>(tracker) : NULp;
142 }
143 
146  ma_assert(tracker); // application is not able to handle macros
147  return dynamic_cast<MacroRecorder*>(tracker);
148 }
149 
150 // --------------------------------------------------------------------------------
151 
152 #else
153 #error trackers.hxx included twice
154 #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:96
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:328
MacroRecorder * getMacroRecorder(AW_root *aw_root)
Definition: trackers.hxx:144
void track_action(const char *action_id) OVERRIDE
Definition: trackers.cxx:238
ClientActionTracker(const char *application_id, GBDATA *gb_main_)
Definition: trackers.hxx:112
virtual void release()=0
void track_action(const char *action_id) OVERRIDE
Definition: trackers.cxx:318
void release() OVERRIDE
Definition: trackers.hxx:122
void set_tracking_according_to(GBDATA *gb_recording)
Definition: trackers.cxx:285
void GBK_terminate(const char *error) __ATTR__NORETURN
Definition: arb_msg.cxx:463
#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:93
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:139
~BoundActionTracker() OVERRIDE
Definition: trackers.hxx:59
void forgetDatabase()
Definition: trackers.hxx:69
#define NULp
Definition: cxxforward.h:97
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:33
bool is_replaceable() const OVERRIDE
Definition: trackers.hxx:63