00001 /*************************************************************************** 00002 ** 00003 ** This file is part of GeopsySLink. 00004 ** 00005 ** This file may be distributed and/or modified under the terms of the 00006 ** GNU General Public License version 2 or 3 as published by the Free 00007 ** Software Foundation and appearing in the file LICENSE.GPL included 00008 ** in the packaging of this file. 00009 ** 00010 ** This file is distributed in the hope that it will be useful, but WITHOUT 00011 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 ** more details. 00014 ** 00015 ** You should have received a copy of the GNU General Public License 00016 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 ** 00018 ** See http://www.geopsy.org for more information. 00019 ** 00020 ** Created : 2007-04-23 00021 ** Authors: 00022 ** Marc Wathelet 00023 ** Marc Wathelet (LGIT, Grenoble, France) 00024 ** 00025 ***************************************************************************/ 00026 00027 #ifndef SEEDLINK_H 00028 #define SEEDLINK_H 00029 00030 #include <GeopsyCore.h> 00031 00032 #include "GeopsySLinkDLLExport.h" 00033 #include "SeedLinkServer.h" 00034 #include "SeedLinkStream.h" 00035 00036 namespace GeopsySLink { 00037 00038 class SeedLinkPrivate; 00039 00040 class GEOPSYSLINK_EXPORT SeedLink : public QThread 00041 { 00042 Q_OBJECT 00043 public: 00044 SeedLink(QObject * parent=0); 00045 ~SeedLink(); 00046 00047 void setServer(QByteArray address, qint16 port); 00048 QString serverName() const {return _serverName;} 00049 quint16 serverPort() const {return _serverPort;} 00050 const SeedLinkServer& serverInfo() const {return _serverInfo;} 00051 00052 void start(); 00053 void stop(); 00054 void streams(); 00055 void stations(); 00056 void addStation(SeedLinkStation * station) {_serverInfo.addStation(station);} 00057 bool addStream(SeedLinkStream * str); 00058 bool removeStream(SeedLinkStream * str); 00059 00060 int listeningStreamCount() {return _listeningStreams.count();} 00061 SubSignalPool subPool() const; 00062 00063 void setFromTime(QDateTime f) {_fromTime=f;} 00064 void setBufferType(SeedLinkStream::BufferType bt) {_bufferType=bt;} 00065 void setMaximumDuration(double d) {_maximumDuration=d;} 00066 00067 enum Error {NoError, StationsNotAvailable, StreamsNotAvailable, FromTimeNotAvailable}; 00068 Error error() const {return _error;} 00069 protected: 00070 virtual void run(); 00071 signals: 00072 void infoAvailable(); 00073 void dataChanged(Signal * sig, TimeRange tw); 00074 void error(GeopsySLink::SeedLink::Error e); 00075 private: 00076 static SeedLink * _instance; 00077 static void log(const char * msg); 00078 void packetReceived(); 00079 void setError(Error e); 00080 00081 enum Request {Streams, Stations, Data, Dns}; 00082 Request _request; 00083 QMutex _mutex; 00084 Error _error; 00085 00086 QByteArray _serverName; 00087 qint16 _serverPort; 00088 QByteArray _serverAddress; 00089 SeedLinkPrivate * _internals; 00090 00091 QString _xmlInfos; 00092 SeedLinkServer _serverInfo; 00093 00094 QMap<QByteArray,SeedLinkStream *> _listeningStreams; 00095 00096 QDateTime _fromTime; 00097 double _maximumDuration; 00098 SeedLinkStream::BufferType _bufferType; 00099 }; 00100 00101 } // namespace GeopsySLink 00102 00103 // Allow passing SeedLink::Error as a QVariant or through SIGNAL/SLOT 00104 Q_DECLARE_METATYPE(GeopsySLink::SeedLink::Error); 00105 00106 #endif // SEEDLINK_H