rk_remokon_qt.hpp

Go to the documentation of this file.
00001 /*
00002  !concept {:name => "QXmpp and Lua based remote control mechanism",
00003    :desc => "Accepting remote commands via XMPP and executing them using a Lua runtime."}
00004 */
00005 
00006 #ifndef __rk_remokon_qt_hpp__
00007 #define __rk_remokon_qt_hpp__
00008 
00009 #include "lua_cl2.h"
00010 
00011 // http://code.google.com/p/qxmpp/
00012 #include "QXmppClient.h"
00013 #include "QXmppMessage.h"
00014 
00015 #include <QObject>
00016 #include <QTimer>
00017 
00018 // We must use a QObject derived remote control state object so as to
00019 // allow us to implement slots for observing Qt signals.
00020 class _rk_Remokon :
00021   public QObject 
00022 {
00023   Q_OBJECT
00024 
00025   private:
00026 
00027   // Not sure if these must persist during session, but just in case.
00028   QXmppPresence iXmppPresence;
00029   QXmppConfiguration iXmppConfiguration;
00030   
00031   int iRunForSecs;
00032   QTimer iRunTimer;
00033 
00034   public:
00035 
00036   // These come mostly from the configuration file. There will be no
00037   // default values, and hence Remokon will be automatically disabled
00038   // when no configuration setting is available. We require that
00039   // "server", "password", and "jid" are all non-NULL. The dynamically
00040   // settable "iap_id" will be given some unlikely to work default
00041   // value.
00042   struct {
00043     const char* server;
00044     int port;
00045     const char* password;
00046     const char* jid;
00047     int iap_id;
00048   } params;
00049 
00050   // We should always have a Jabber session object after having been
00051   // initialized. The object creation itself requires nothing but
00052   // memory. Getting the connection is harder.
00053   QXmppClient iSession;
00054 
00055   // Indicates whether iSession has been asked to connect, but not
00056   // disconnect. If so, it should be connected or actively trying to
00057   // connect.
00058   bool iIsActive;
00059 
00060   // This indicates whether we have at least some kind of a value for
00061   // all the required configuration parameters. Leaving any of these
00062   // out is a simple way to disable the remote control facility.
00063   bool iHaveConfig;
00064 
00065   // This is just a hint for the controller as to whether to start
00066   // Remokon automatically at startup.
00067   bool iAutostartEnabled;
00068 
00069   // Here we have only one Lua instance per session, making for a
00070   // proper REPL. We might consider providing a way to reset the VM.
00071   lua_State* L;
00072 
00073   public:
00074 
00075   _rk_Remokon();
00076 
00077   ~_rk_Remokon();
00078 
00079   void start();
00080 
00081   void stop();
00082 
00083   void startTimed(int secs);
00084 
00085   void send(const QString& toJid, const QString& msgText);
00086 
00087   private:
00088 
00089   void resetRunTimer();
00090 
00091   private slots:
00092 
00093   void gotJabberError(QXmppClient::Error anError);
00094 
00095   void gotJabberMessage(const QXmppMessage& aMessage);
00096 
00097   void runTimeout();
00098 
00099 };
00100 
00101 #endif /* __rk_remokon_qt_hpp__ */
00102 
00103 /**
00104 
00105 Copyright 2011 Helsinki Institute for Information Technology (HIIT)
00106 and the authors. All rights reserved.
00107 
00108 Authors: Tero Hasu <tero.hasu@hut.fi>
00109 
00110 Permission is hereby granted, free of charge, to any person
00111 obtaining a copy of this software and associated documentation files
00112 (the "Software"), to deal in the Software without restriction,
00113 including without limitation the rights to use, copy, modify, merge,
00114 publish, distribute, sublicense, and/or sell copies of the Software,
00115 and to permit persons to whom the Software is furnished to do so,
00116 subject to the following conditions:
00117 
00118 The above copyright notice and this permission notice shall be
00119 included in all copies or substantial portions of the Software.
00120 
00121 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00122 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00123 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00124 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00125 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00126 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00127 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00128 SOFTWARE.
00129 
00130  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:56 2011 by Doxygen 1.6.1