Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / libs / Module.h
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef MODULE_H
9 #define MODULE_H
10
11 // See : http://smoothieware.org/listofevents
12 // When adding a new event the virtual method needs to be defined in class Module and the method pointer need to be defined in
13 // Module.cpp:16 in the same order
14 enum _EVENT_ENUM {
15 ON_MAIN_LOOP,
16 ON_CONSOLE_LINE_RECEIVED,
17 ON_GCODE_RECEIVED,
18 ON_GCODE_EXECUTE,
19 ON_SPEED_CHANGE,
20 ON_BLOCK_BEGIN,
21 ON_BLOCK_END,
22 ON_IDLE,
23 ON_SECOND_TICK,
24 ON_GET_PUBLIC_DATA,
25 ON_SET_PUBLIC_DATA,
26 ON_HALT,
27 ON_ENABLE,
28 NUMBER_OF_DEFINED_EVENTS
29 };
30
31 class Module;
32 typedef void (Module::*ModuleCallback)(void *argument);
33 extern const ModuleCallback kernel_callback_functions[NUMBER_OF_DEFINED_EVENTS];
34
35 // Module base class
36 // All modules must extend this class, see http://smoothieware.org/moduleexample
37 class Module
38 {
39 public:
40 Module();
41 virtual ~Module();
42 virtual void on_module_loaded() {};
43
44 void register_for_event(_EVENT_ENUM event_id);
45
46 // event callbacks, not every module will implement all of these
47 // there should be one for each _EVENT_ENUM
48 virtual void on_main_loop(void *) {};
49 virtual void on_console_line_received(void *) {};
50 virtual void on_gcode_received(void *) {};
51 virtual void on_gcode_execute(void *) {};
52 virtual void on_speed_change(void *) {};
53 virtual void on_block_begin(void *) {};
54 virtual void on_block_end(void *) {};
55 virtual void on_idle(void *) {};
56 virtual void on_second_tick(void *) {};
57 virtual void on_get_public_data(void *) {};
58 virtual void on_set_public_data(void *) {};
59 virtual void on_halt(void *) {};
60 virtual void on_enable(void *) {};
61
62 };
63
64 #endif