00001 // ===================================================================================== 00002 // Filename: InputSequencer.h 00003 // Description: 00004 // Created: 02/15/2007 08:47:46 PM EST 00005 // Revision: none 00006 // Compiler: gcc 3.4.6 00007 // 00008 // Author: John P. Feltz 00009 // Email: jfeltz@gmail.com 00010 // License: Copyright (c) 2006-2007, John P. Feltz 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of the GNU General Public License as 00013 // published by the Free Software Foundation, version 2 of the 00014 // License. 00015 // This program is distributed in the hope that it will be 00016 // useful, but WITHOUT ANY WARRANTY; without even the implied 00017 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00018 // PURPOSE. 00019 // See the GNU General Public License version 2 for more details. 00020 // 00021 // ===================================================================================== 00022 00026 00027 namespace cmil { 00028 class InputSequencer : public Logger { 00029 public: 00030 InputSequencer() : m_mode(Trigger), m_stop_capture_action(NULL), m_captured(NULL) {} 00031 00032 enum Mode { 00035 Trigger, 00036 00040 Capture 00041 }; 00042 00043 virtual ~InputSequencer() { 00044 if(m_captured) 00045 delete m_captured; 00046 }; 00047 00051 00052 void captureNormal( ModAction* stop_action ) { 00053 if(m_mode == Capture) 00054 log_error("captureSeq() already in capture mode."); 00055 else { 00056 m_stop_capture_action = stop_action; 00057 m_mode = Capture; 00058 00060 if(m_captured) { 00061 delete m_captured; 00062 m_captured = NULL; 00063 } 00064 } 00065 } 00066 00067 Ev::Sequence* getCaptured() const { 00068 return m_captured; 00069 }; 00070 00071 bool handle(const InputData& input) { 00072 return imp_handle(input); 00073 }; 00074 00075 00078 bool handle(const ModData& input) { 00079 if(m_mode == Capture) { 00080 if(capture(input)) 00081 m_mode = Trigger; 00082 } 00083 00084 return imp_handle(input); 00085 }; 00086 00088 virtual bool isCombo(const Ev::Sequence& seq) const = 0; 00089 00091 virtual bool isNormal(const Ev::Sequence& seq) const = 0; 00092 00093 virtual std::string getName() const { return "InputSequencer"; } 00094 00095 bool addNormal(const Ev& event) { 00096 Ev::Sequence* sequence; 00097 if((sequence = event.getSequence()) != NULL) { 00098 log_debug("addNormal validating.."); 00099 if(isNormal(*sequence)) { 00100 return imp_addNormal(*sequence); 00101 } 00102 } 00103 return false; 00104 } 00105 00106 bool removeNormal(const Ev& event) { 00107 Ev::Sequence* sequence; 00108 if((sequence = event.getSequence()) != NULL) { 00109 log_debug("removeNormal validating.."); 00110 if(isNormal(*sequence)) { 00111 return imp_removeNormal(*sequence); 00112 } 00113 } 00114 return false; 00115 } 00116 00117 bool addCombo(const Ev& event) { 00118 Ev::Sequence* sequence; 00119 if((sequence = event.getSequence()) != NULL) { 00120 log_debug("addCombo validating.."); 00121 if(isCombo(*sequence)) { 00122 return imp_addCombo(*sequence); 00123 } 00124 } 00125 return false; 00126 } 00127 protected: 00128 Mode m_mode; 00129 InputAction* m_stop_capture_action; 00130 Ev::Sequence* m_captured; 00131 00132 private: 00134 virtual Ev::Sequence* capture(const ModData& input) = 0; 00135 00136 virtual bool imp_handle(const ModData& input) = 0; 00137 virtual bool imp_handle(const InputData& input) = 0; 00138 00139 virtual bool imp_addNormal(const Ev::Sequence& seq) = 0; 00140 virtual bool imp_removeNormal(const Ev::Sequence& seq) = 0; 00141 00142 virtual bool imp_addCombo(const Ev::Sequence& seq) = 0; 00143 00144 }; 00145 }