00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "GizmoEventLIRC.hpp"
00030 #include "GizmoLinuxInputDevice.hpp"
00031 #include "../libH/Debug.hpp"
00032 #include "../libH/Exception.hpp"
00033 #include "../libH/Util.hpp"
00034 #include "../libH/stringconverter.hpp"
00035 #include <boost/shared_ptr.hpp>
00036 #include <boost/bind.hpp>
00037 #include <boost/lexical_cast.hpp>
00038 #include <boost/tokenizer.hpp>
00039 #include <boost/algorithm/string/replace.hpp>
00040
00041 using namespace std;
00042 using namespace boost;
00043 using namespace H;
00044 using namespace Gizmod;
00045
00047
00049
00051
00053
00057 GizmoEventLIRC::GizmoEventLIRC() : GizmoEvent(GIZMO_EVENTCLASS_LIRC, false) {
00058 Repeat = 0;
00059 }
00060
00064 GizmoEventLIRC::GizmoEventLIRC(std::string code, int repeat, std::string button, std::string remote, bool IsRemote) : GizmoEvent(GIZMO_EVENTCLASS_LIRC, IsRemote) {
00065 Code = code;
00066 Repeat = repeat;
00067 Button = button;
00068 Remote = remote;
00069 }
00070
00074 GizmoEventLIRC::~GizmoEventLIRC() {
00075 }
00076
00078
00080
00086 void GizmoEventLIRC::buildEventsVectorFromBuffer(std::vector< boost::shared_ptr<GizmoEventLIRC> > & EventVector, H::DynamicBuffer<char> const & Buffer) {
00087
00088 typedef boost::tokenizer< boost::char_separator<char> > tokenizer;
00089 char_separator<char> Separators(" ");
00090 string Code;
00091 int Repeat = 0;
00092 string Button;
00093 string Remote;
00094
00095 string LIRCData(Buffer.getBuffer(), Buffer.length());
00096 replace_all(LIRCData, "\n", "");
00097 tokenizer tok(LIRCData, Separators);
00098 int count = 0;
00099 for(tokenizer::iterator iter = tok.begin(); iter!= tok.end(); iter ++, count ++) {
00100 switch (count) {
00101 case 0:
00102
00103 Code = *iter;
00104 break;
00105 case 1:
00106
00107 try {
00108 Repeat = lexical_cast<int>(*iter);
00109 } catch (bad_lexical_cast const & e) {
00110 cdbg1 << "Bad LIRC Data Packet <Repeat> [" << LIRCData << "]" << endl;
00111 return;
00112 }
00113 break;
00114 case 2:
00115
00116 Button = *iter;
00117 break;
00118 case 3:
00119
00120 Remote = *iter;
00121 EventVector.push_back(boost::shared_ptr<GizmoEventLIRC>(new GizmoEventLIRC(Code, Repeat, Button, Remote)));
00122 count = 0;
00123 break;
00124 }
00125 }
00126 }