libGizmod/GizmoEventLIRC.cpp

Go to the documentation of this file.
00001 
00012 /*
00013   
00014   Copyright (c) 2007, Tim Burrell
00015   Licensed under the Apache License, Version 2.0 (the "License");
00016   you may not use this file except in compliance with the License.
00017   You may obtain a copy of the License at 
00018 
00019         http://www.apache.org/licenses/LICENSE-2.0
00020 
00021   Unless required by applicable law or agreed to in writing, software
00022   distributed under the License is distributed on an "AS IS" BASIS,
00023   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00024   See the License for the specific language governing permissions and 
00025   limitations under the License. 
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 // Type Defs
00049 
00051 // Construction
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 // Class Body
00080 
00086 void GizmoEventLIRC::buildEventsVectorFromBuffer(std::vector< boost::shared_ptr<GizmoEventLIRC> > & EventVector, H::DynamicBuffer<char> const & Buffer) {
00087         // create some data structures for parsing the info
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                         // get the code
00103                         Code = *iter;
00104                         break;
00105                 case 1:
00106                         // get the repeats
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                         // get the button
00116                         Button = *iter;
00117                         break;
00118                 case 3:
00119                         // get the button
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 }

Generated on Wed Nov 7 10:04:16 2007 for gizmod by  doxygen 1.5.3