File indexing completed on 2024-12-01 06:51:47
0001 // 0002 // C++ Interface: cnotifymanager 0003 // 0004 // Description: Notification manager for the /notify macro 0005 // 0006 /* 0007 Copyright 2005-2011 Tomas Mecir <kmuddy@kmuddy.com> 0008 Copyright 2005 Alex Bache <alexbache@ntlworld.com> 0009 0010 This program is free software; you can redistribute it and/or 0011 modify it under the terms of the GNU General Public License as 0012 published by the Free Software Foundation; either version 2 of 0013 the License, or (at your option) any later version. 0014 0015 This program is distributed in the hope that it will be useful, 0016 but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 GNU General Public License for more details. 0019 0020 You should have received a copy of the GNU General Public License 0021 along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 */ 0023 0024 #ifndef CNOTIFYMANAGER_H 0025 #define CNOTIFYMANAGER_H 0026 0027 #include <qobject.h> 0028 0029 #include <list> 0030 0031 class cEventNotification; 0032 class QTcpSocket; 0033 0034 /** 0035 Notification manager. Used by the /notify macro. 0036 0037 @author Tomas Mecir 0038 */ 0039 class cNotifyManager : public QObject 0040 { 0041 Q_OBJECT 0042 public: 0043 cNotifyManager (); 0044 0045 ~cNotifyManager(); 0046 0047 /** send information to external IP port */ 0048 void doNotify(const int port, QString &ip_data); 0049 0050 public slots: 0051 /** information sent to external IP port */ 0052 void portNotified (cEventNotification *event_notify); 0053 0054 protected: 0055 0056 std::list<cEventNotification *> notifications; 0057 }; 0058 0059 /** 0060 class cEventNotification is used to send notification data to externally running scripts using 0061 the non-blocking TCP/IP functionality of QSocket 0062 0063 *@author Alex Bache 0064 */ 0065 0066 class cEventNotification: public QObject 0067 { 0068 Q_OBJECT 0069 0070 private: 0071 QTcpSocket *sock; 0072 int port; 0073 std::list<QString> data_list; 0074 0075 public slots: 0076 // Connected to IP port successfully 0077 void connected(); 0078 0079 // Wrote some data to the IP port 0080 void wroteAll(); 0081 0082 // Connection closed 0083 void connectionClosed(); 0084 0085 // An error occured 0086 void error(); 0087 0088 signals: 0089 // Communication with IP port finished 0090 void finished(cEventNotification *item); 0091 0092 public: 0093 cEventNotification(const int ip_port, 0094 const QString &ip_data); 0095 0096 ~cEventNotification(); 0097 0098 // Send the information to the specified IP port 0099 void send(); 0100 0101 // Which port are we sending information to? 0102 int port_num() const { return port; } 0103 0104 // Queue data for sending at next opportunity 0105 void queue(const QString &ip_data); 0106 private: 0107 void writeNext (); 0108 0109 }; // cEventNotification 0110 0111 0112 0113 #endif