diff options
author | Tobias Markmann <tm@ayena.de> | 2014-12-19 15:07:38 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2015-02-03 10:46:29 (GMT) |
commit | d7842c20dd3da47ca15fc102191881465fd23a91 (patch) | |
tree | 34a6df893a236f45379a9566405b7d81fc4e8a78 | |
parent | 33639a52730936a442070f6454920213f3350602 (diff) | |
download | swift-d7842c20dd3da47ca15fc102191881465fd23a91.zip swift-d7842c20dd3da47ca15fc102191881465fd23a91.tar.bz2 |
Cleaning up SendFile example.
Update SendFile.cpp to recent Jingle file-transfer changes and clean
up old code.
Test-Information:
Verified that a file-transfer between SendFile and ReceiveFile
examples works.
Change-Id: I342cfa2f4949ffcc1e227e6ebdd10de84e5d6a8a
-rw-r--r-- | Swiften/Examples/SendFile/SendFile.cpp | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp index febef22..d686387 100644 --- a/Swiften/Examples/SendFile/SendFile.cpp +++ b/Swiften/Examples/SendFile/SendFile.cpp @@ -39,12 +39,11 @@ static int exitCode = 2; class FileSender { public: - FileSender(const JID& jid, const std::string& password, const JID& recipient, const boost::filesystem::path& file) : jid(jid), password(password), recipient(recipient), file(file) { - + FileSender(const JID& jid, const std::string& password, const JID& recipient, const boost::filesystem::path& file) : jid(jid), password(password), recipient(recipient), file(file), tracer(NULL) { client = new Swift::Client(jid, password, &networkFactories); client->onConnected.connect(boost::bind(&FileSender::handleConnected, this)); client->onDisconnected.connect(boost::bind(&FileSender::handleDisconnected, this, _1)); - tracer = new ClientXMLTracer(client); + //tracer = new ClientXMLTracer(client); client->getEntityCapsProvider()->onCapsChanged.connect(boost::bind(&FileSender::handleCapsChanged, this, _1)); } @@ -61,24 +60,8 @@ class FileSender { private: void handleConnected() { + std::cout << "Connected. Awaiting presence from receipient." << std::endl; client->sendPresence(Presence::create()); - - //ByteArray fileData; - //readByteArrayFromFile(fileData, file); - - // gather file information - /*StreamInitiationFileInfo fileInfo; - - fileInfo.setName(file.filename()); - fileInfo.setSize(boost::filesystem::file_size(file)); - fileInfo.setDescription("Some file!"); - fileInfo.setDate(boost::posix_time::from_time_t(boost::filesystem::last_write_time(file)));*/ - //fileInfo.setHash(Hexify::hexify(MD5::getHash(fileData))); - /* - transfer = new OutgoingSIFileTransfer("myid", client->getJID(), recipient, file.filename(), boost::filesystem::file_size(file), "A file", boost::make_shared<FileReadBytestream>(file)), client->getIQRouter(), socksBytestreamServer); - transfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1)); - transfer->start(); - */ } void handleCapsChanged(JID jid) { @@ -89,27 +72,36 @@ class FileSender { outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream); if (outgoingFileTransfer) { - std::cout << "started FT" << std::endl; + outgoingFileTransfer->onFinished.connect(boost::bind(&FileSender::handleFileTransferFinished, this, _1)); + std::cout << "Starting file-transfer to " << recipient.toString() << "." << std::endl; outgoingFileTransfer->start(); // TODO: getting notified about FT status and end } else { - std::cout << "[ ERROR ] " << recipient << " doesn't support any kind of file transfer!" << std::endl; - //client->disconnect(); + std::cout << recipient << " doesn't support any kind of file transfer!" << std::endl; + client->disconnect(); } } } - void handleDisconnected(const boost::optional<ClientError>&) { - std::cerr << "Error!" << std::endl; - exit(-1); + void handleDisconnected(const boost::optional<ClientError>& err) { + if (err) { + std::cout << "Disconnected due to error ( " << err.get().getType() << " )." << std::endl; + exit(-1); + } + else { + std::cout << "Successfully disconnected." << std::endl; + } } void handleFileTransferFinished(const boost::optional<FileTransferError>& error) { - std::cout << "File transfer finished" << std::endl; + std::cout << "File transfer finished." << std::endl; + outgoingFileTransfer.reset(); if (error) { + client->disconnect(); exit(-1); } else { + client->disconnect(); exit(0); } } @@ -137,15 +129,16 @@ int main(int argc, char* argv[]) { return -1; } + //Log::setLogLevel(Log::debug); + JID sender(argv[1]); JID recipient(argv[3]); - Log::setLogLevel(Log::debug); FileSender fileSender(sender, std::string(argv[2]), recipient, boost::filesystem::path(argv[4])); fileSender.start(); { - /*BoostTimer::ref timer(BoostTimer::create(30000, &MainBoostIOServiceThread::getInstance().getIOService())); + Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000); timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop)); - timer->start();*/ + timer->start(); eventLoop.run(); } |