diff options
author | Tobias Markmann <tm@ayena.de> | 2015-10-29 10:12:03 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-10-30 12:49:14 (GMT) |
commit | cb62de17d1e17fd3049a6bc8155a100574a42a85 (patch) | |
tree | ddbabd81818f1dd16ba2ebc96b45267a1d2e4bf2 | |
parent | 1d921f3d39ed134ca7f1d40011c1a07a5835b73c (diff) | |
download | swift-cb62de17d1e17fd3049a6bc8155a100574a42a85.zip swift-cb62de17d1e17fd3049a6bc8155a100574a42a85.tar.bz2 |
Add FileTransfer::getState() method
In addition, this adds the file-transfer classes to the
Doxygen documentation.
Test-Information:
Unit and integration tests still pass.
Change-Id: Ib6c16078c90ed56fae835cb2abfea8a564c3afa3
-rw-r--r-- | Documentation/API/Doxyfile | 7 | ||||
-rw-r--r-- | Swiften/FileTransfer/FileTransfer.cpp | 13 | ||||
-rw-r--r-- | Swiften/FileTransfer/FileTransfer.h | 20 | ||||
-rw-r--r-- | Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp | 24 | ||||
-rw-r--r-- | Swiften/FileTransfer/OutgoingJingleFileTransfer.h | 18 |
5 files changed, 50 insertions, 32 deletions
diff --git a/Documentation/API/Doxyfile b/Documentation/API/Doxyfile index 84fdaac..0634800 100644 --- a/Documentation/API/Doxyfile +++ b/Documentation/API/Doxyfile @@ -86,23 +86,24 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- INPUT = \ Swiften/Avatars \ Swiften/Base \ Swiften/Chat \ Swiften/Client/Client.h \ - Swiften/Client/CoreClient.h \ Swiften/Client/ClientError.h \ - Swiften/Client/StanzaChannel.h \ + Swiften/Client/CoreClient.h \ + Swiften/Client/MemoryStorages.h \ Swiften/Client/NickResolver.h \ + Swiften/Client/StanzaChannel.h \ Swiften/Client/Storages.h \ - Swiften/Client/MemoryStorages.h \ Swiften/Component/Component.h \ Swiften/Component/CoreComponent.h \ Swiften/Disco \ Swiften/Elements \ Swiften/EventLoop \ + Swiften/FileTransfer \ Swiften/JID \ Swiften/MUC \ Swiften/Presence \ Swiften/Queries \ Swiften/Roster/XMPPRoster.h \ Swiften/StringCodecs \ diff --git a/Swiften/FileTransfer/FileTransfer.cpp b/Swiften/FileTransfer/FileTransfer.cpp index 6b594aa..f63a4e8 100644 --- a/Swiften/FileTransfer/FileTransfer.cpp +++ b/Swiften/FileTransfer/FileTransfer.cpp @@ -1,20 +1,25 @@ /* - * Copyright (c) 2013-2014 Isode Limited. + * Copyright (c) 2013-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/FileTransfer.h> using namespace Swift; -FileTransfer::FileTransfer() : fileSizeInBytes(0) { +FileTransfer::FileTransfer() : fileSizeInBytes_(0), state_(State::Initial) { } FileTransfer::~FileTransfer() { } +void FileTransfer::setState(const State& state) { + state_ = state; + onStateChanged(state); +} + void FileTransfer::setFileInfo(const std::string& name, boost::uintmax_t size) { - filename = name; - fileSizeInBytes = size; + filename_ = name; + fileSizeInBytes_ = size; } diff --git a/Swiften/FileTransfer/FileTransfer.h b/Swiften/FileTransfer/FileTransfer.h index 01c8295..afb3f7b 100644 --- a/Swiften/FileTransfer/FileTransfer.h +++ b/Swiften/FileTransfer/FileTransfer.h @@ -18,12 +18,18 @@ #include <Swiften/Base/API.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/FileTransfer/FileTransferError.h> namespace Swift { + /** + * The FileTransfer class provides a general interface for file-transfer + * implmenetations. Currently, only Jingle File Transfer based on XEP-0234 is + * implementated in the \ref OutgoingJingleFileTransfer and + * \ref IncomingJingleFileTransfer classes. + */ class SWIFTEN_API FileTransfer { public: struct State { enum Type { Initial, WaitingForStart, @@ -46,26 +52,32 @@ namespace Swift { FileTransfer(); virtual ~FileTransfer(); virtual void cancel() = 0; const std::string& getFileName() const { - return filename; + return filename_; } boost::uintmax_t getFileSizeInBytes() const { - return fileSizeInBytes; + return fileSizeInBytes_; + } + + const State& getState() const { + return state_; } public: boost::signal<void (size_t /* proccessedBytes */)> onProcessedBytes; boost::signal<void (const State&)> onStateChanged; boost::signal<void (boost::optional<FileTransferError>)> onFinished; protected: + void setState(const State& state); void setFileInfo(const std::string& name, boost::uintmax_t size); private: - boost::uintmax_t fileSizeInBytes; - std::string filename; + boost::uintmax_t fileSizeInBytes_; + std::string filename_; + State state_; }; } diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index f9441cd..6369581 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp @@ -86,13 +86,13 @@ void OutgoingJingleFileTransfer::start() { if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } setTransporter(transporterFactory->createInitiatorTransporter(getInitiator(), getResponder(), options)); - setState(GeneratingInitialLocalCandidates); + setInternalState(GeneratingInitialLocalCandidates); transporter->startGeneratingLocalCandidates(); } void OutgoingJingleFileTransfer::cancel() { terminate(JinglePayload::Reason::Cancel); } @@ -113,13 +113,13 @@ void OutgoingJingleFileTransfer::handleSessionAcceptReceived( JingleTransportPayload::ref transportPayload) { SWIFT_LOG(debug) << std::endl; if (state != WaitingForAccept) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) { transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr()); - setState(TryingCandidates); + setInternalState(TryingCandidates); transporter->startTryingRemoteCandidates(); } else { SWIFT_LOG(debug) << "Unknown transport payload. Falling back." << std::endl; fallback(); } @@ -175,13 +175,13 @@ void OutgoingJingleFileTransfer::sendSessionInfoHash() { session->sendInfo(hashElement); } void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { SWIFT_LOG(debug) << std::endl; - if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } + if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } fillCandidateMap(localCandidates, candidates); JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>(); fileInfo.addHash(HashElement("sha-1", ByteArray())); fileInfo.addHash(HashElement("md5", ByteArray())); @@ -192,23 +192,23 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( transport->setMode(JingleS5BTransportPayload::TCPMode); transport->setDstAddr(dstAddr); foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { transport->addCandidate(candidate); SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl; } - setState(WaitingForAccept); + setInternalState(WaitingForAccept); session->sendInitiate(contentID, description, transport); } void OutgoingJingleFileTransfer::fallback() { if (options.isInBandAllowed()) { SWIFT_LOG(debug) << "Trying to fallback to IBB transport." << std::endl; JingleIBBTransportPayload::ref ibbTransport = boost::make_shared<JingleIBBTransportPayload>(); ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); ibbTransport->setSessionID(idGenerator->generateID()); - setState(FallbackRequested); + setInternalState(FallbackRequested); session->sendTransportReplace(contentID, ibbTransport); } else { SWIFT_LOG(debug) << "Fallback to IBB transport not allowed." << std::endl; terminate(JinglePayload::Reason::ConnectivityError); } @@ -222,34 +222,34 @@ void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTran terminate(JinglePayload::Reason::ConnectivityError); } else { sendSessionInfoHash(); // wait for other party to terminate session after they have verified the hash - setState(WaitForTermination); + setInternalState(WaitForTermination); waitForRemoteTermination->start(); } } void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSession> transportSession) { SWIFT_LOG(debug) << std::endl; this->transportSession = transportSession; processedBytesConnection = transportSession->onBytesSent.connect( boost::bind(boost::ref(onProcessedBytes), _1)); transferFinishedConnection = transportSession->onFinished.connect( boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1)); - setState(Transferring); + setInternalState(Transferring); transportSession->start(); } -void OutgoingJingleFileTransfer::setState(State state) { +void OutgoingJingleFileTransfer::setInternalState(State state) { SWIFT_LOG(debug) << state << std::endl; this->state = state; - onStateChanged(FileTransfer::State(getExternalState(state))); + setState(FileTransfer::State(getExternalState(state))); } void OutgoingJingleFileTransfer::setFinishedState( FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) { SWIFT_LOG(debug) << std::endl; this->state = Finished; @@ -303,25 +303,25 @@ void OutgoingJingleFileTransfer::stopAll() { } void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { SWIFT_LOG(debug) << std::endl; if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { - setState(WaitingForPeerProxyActivate); + setInternalState(WaitingForPeerProxyActivate); } else { transportSession = createRemoteCandidateSession(); startTransferringIfCandidateAcknowledged(); } } void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { SWIFT_LOG(debug) << std::endl; if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { - setState(WaitingForLocalProxyActivate); + setInternalState(WaitingForLocalProxyActivate); transporter->startActivatingProxy(theirCandidateChoice->jid); } else { transportSession = createLocalCandidateSession(); startTransferringIfCandidateAcknowledged(); } @@ -329,13 +329,13 @@ void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { void OutgoingJingleFileTransfer::startTransferringIfCandidateAcknowledged() { if (candidateAcknowledged) { startTransferring(transportSession); } else { - setState(WaitingForCandidateAcknowledge); + setInternalState(WaitingForCandidateAcknowledge); } } void OutgoingJingleFileTransfer::handleTransportInfoAcknowledged(const std::string& id) { if (id == candidateSelectRequestID) { candidateAcknowledged = true; diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h index 4cb2685..96b465b 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h @@ -9,33 +9,33 @@ * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> #include <boost/optional/optional.hpp> +#include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Base/Override.h> -#include <Swiften/Jingle/JingleContentID.h> #include <Swiften/Elements/JingleFileTransferFileInfo.h> -#include <Swiften/FileTransfer/OutgoingFileTransfer.h> -#include <Swiften/FileTransfer/JingleFileTransfer.h> #include <Swiften/FileTransfer/FileTransferOptions.h> +#include <Swiften/FileTransfer/JingleFileTransfer.h> +#include <Swiften/FileTransfer/OutgoingFileTransfer.h> +#include <Swiften/Jingle/JingleContentID.h> #include <Swiften/Network/Timer.h> namespace Swift { - class ReadBytestream; - class IDGenerator; - class IncrementalBytestreamHashCalculator; class CryptoProvider; class FileTransferTransporter; class FileTransferTransporterFactory; - class TransportSession; + class IDGenerator; + class IncrementalBytestreamHashCalculator; + class ReadBytestream; class TimerFactory; + class TransportSession; class SWIFTEN_API OutgoingJingleFileTransfer : public OutgoingFileTransfer, public JingleFileTransfer { public: OutgoingJingleFileTransfer( const JID& to, boost::shared_ptr<JingleSession>, @@ -95,13 +95,13 @@ namespace Swift { virtual boost::shared_ptr<TransportSession> createLocalCandidateSession() SWIFTEN_OVERRIDE; virtual boost::shared_ptr<TransportSession> createRemoteCandidateSession() SWIFTEN_OVERRIDE; void handleWaitForRemoteTerminationTimeout(); void stopAll(); - void setState(State state); + void setInternalState(State state); void setFinishedState(FileTransfer::State::Type, const boost::optional<FileTransferError>& error); static FileTransfer::State::Type getExternalState(State state); private: IDGenerator* idGenerator; |