diff options
author | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
commit | cfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch) | |
tree | 18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/Examples/SendFile | |
parent | 1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff) | |
download | swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2 |
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines
in the process.
Changed CheckTabs.py tool to disallow hard tabs in source
files.
Test-Information:
Manually checked 30 random files that the conversion worked
as expected.
Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/Examples/SendFile')
-rw-r--r-- | Swiften/Examples/SendFile/ReceiveFile.cpp | 180 | ||||
-rw-r--r-- | Swiften/Examples/SendFile/SendFile.cpp | 204 |
2 files changed, 192 insertions, 192 deletions
diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp index bfda44f..c6e75e8 100644 --- a/Swiften/Examples/SendFile/ReceiveFile.cpp +++ b/Swiften/Examples/SendFile/ReceiveFile.cpp @@ -36,101 +36,101 @@ static const std::string CLIENT_NAME = "Swiften FT Test"; static const std::string CLIENT_NODE = "http://swift.im"; class FileReceiver { - public: - FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password) { - client = new Swift::Client(jid, password, &networkFactories); - client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this)); - client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1)); - tracer = new ClientXMLTracer(client); - } - - ~FileReceiver() { - delete tracer; - client->onDisconnected.disconnect(boost::bind(&FileReceiver::handleDisconnected, this, _1)); - client->onConnected.disconnect(boost::bind(&FileReceiver::handleConnected, this)); - delete client; - } - - void start() { - client->connect(); - } - - void stop() { - foreach(const IncomingFileTransfer::ref transfer, incomingFileTransfers) { - //transfer->stop(); - } - client->disconnect(); - } - - private: - void handleConnected() { - Log::setLogLevel(Log::debug); - client->getFileTransferManager()->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1)); - - DiscoInfo discoInfo; - discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc")); - discoInfo.addFeature(DiscoInfo::JingleFeature); - discoInfo.addFeature(DiscoInfo::JingleFTFeature); - discoInfo.addFeature(DiscoInfo::Bytestream); - discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature); - discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature); - client->getDiscoManager()->setCapsNode(CLIENT_NODE); - client->getDiscoManager()->setDiscoInfo(discoInfo); - client->getPresenceSender()->sendPresence(Presence::create()); - } - - void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) { - SWIFT_LOG(debug) << "foo" << std::endl; - incomingFileTransfers.push_back(transfer); - boost::shared_ptr<FileWriteBytestream> out = boost::make_shared<FileWriteBytestream>("out"); - transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1, out)); - transfer->accept(out); - } - - void handleDisconnected(const boost::optional<ClientError>&) { - std::cerr << "Error!" << std::endl; - exit(-1); - } - - void handleFileTransferFinished( - const boost::optional<FileTransferError>& error, - boost::shared_ptr<FileWriteBytestream> out) { - std::cout << "File transfer finished" << std::endl; - out->close(); - if (error) { - exit(-1); - } - else { - exit(0); - } - } - - void exit(int code) { - exitCode = code; - stop(); - eventLoop.stop(); - } - - private: - JID jid; - std::string password; - Client* client; - ClientXMLTracer* tracer; - std::vector<IncomingFileTransfer::ref> incomingFileTransfers; + public: + FileReceiver(const JID& jid, const std::string& password) : jid(jid), password(password) { + client = new Swift::Client(jid, password, &networkFactories); + client->onConnected.connect(boost::bind(&FileReceiver::handleConnected, this)); + client->onDisconnected.connect(boost::bind(&FileReceiver::handleDisconnected, this, _1)); + tracer = new ClientXMLTracer(client); + } + + ~FileReceiver() { + delete tracer; + client->onDisconnected.disconnect(boost::bind(&FileReceiver::handleDisconnected, this, _1)); + client->onConnected.disconnect(boost::bind(&FileReceiver::handleConnected, this)); + delete client; + } + + void start() { + client->connect(); + } + + void stop() { + foreach(const IncomingFileTransfer::ref transfer, incomingFileTransfers) { + //transfer->stop(); + } + client->disconnect(); + } + + private: + void handleConnected() { + Log::setLogLevel(Log::debug); + client->getFileTransferManager()->onIncomingFileTransfer.connect(boost::bind(&FileReceiver::handleIncomingFileTransfer, this, _1)); + + DiscoInfo discoInfo; + discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc")); + discoInfo.addFeature(DiscoInfo::JingleFeature); + discoInfo.addFeature(DiscoInfo::JingleFTFeature); + discoInfo.addFeature(DiscoInfo::Bytestream); + discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature); + discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature); + client->getDiscoManager()->setCapsNode(CLIENT_NODE); + client->getDiscoManager()->setDiscoInfo(discoInfo); + client->getPresenceSender()->sendPresence(Presence::create()); + } + + void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) { + SWIFT_LOG(debug) << "foo" << std::endl; + incomingFileTransfers.push_back(transfer); + boost::shared_ptr<FileWriteBytestream> out = boost::make_shared<FileWriteBytestream>("out"); + transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1, out)); + transfer->accept(out); + } + + void handleDisconnected(const boost::optional<ClientError>&) { + std::cerr << "Error!" << std::endl; + exit(-1); + } + + void handleFileTransferFinished( + const boost::optional<FileTransferError>& error, + boost::shared_ptr<FileWriteBytestream> out) { + std::cout << "File transfer finished" << std::endl; + out->close(); + if (error) { + exit(-1); + } + else { + exit(0); + } + } + + void exit(int code) { + exitCode = code; + stop(); + eventLoop.stop(); + } + + private: + JID jid; + std::string password; + Client* client; + ClientXMLTracer* tracer; + std::vector<IncomingFileTransfer::ref> incomingFileTransfers; }; int main(int argc, char* argv[]) { - if (argc != 3) { - std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl; - return -1; - } + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " <jid> <password>" << std::endl; + return -1; + } - JID jid(argv[1]); - FileReceiver fileReceiver(jid, std::string(argv[2])); - fileReceiver.start(); + JID jid(argv[1]); + FileReceiver fileReceiver(jid, std::string(argv[2])); + fileReceiver.start(); - eventLoop.run(); + eventLoop.run(); - return exitCode; + return exitCode; } diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp index 5f2403a..bed6512 100644 --- a/Swiften/Examples/SendFile/SendFile.cpp +++ b/Swiften/Examples/SendFile/SendFile.cpp @@ -38,110 +38,110 @@ static BoostNetworkFactories networkFactories(&eventLoop); 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), 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); - client->getEntityCapsProvider()->onCapsChanged.connect(boost::bind(&FileSender::handleCapsChanged, this, _1)); - } - - ~FileSender() { - delete tracer; - client->onDisconnected.disconnect(boost::bind(&FileSender::handleDisconnected, this, _1)); - client->onConnected.disconnect(boost::bind(&FileSender::handleConnected, this)); - delete client; - } - - void start() { - client->connect(); - } - - private: - void handleConnected() { - std::cout << "Connected. Awaiting presence from receipient." << std::endl; - client->sendPresence(Presence::create()); - } - - void handleCapsChanged(JID jid) { - if (jid.toBare() == recipient) { - // create ReadBytestream from file - boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(file); - - outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream); - - if (outgoingFileTransfer) { - 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 << recipient << " doesn't support any kind of file transfer!" << std::endl; - client->disconnect(); - } - } - } - - 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; - outgoingFileTransfer.reset(); - if (error) { - client->disconnect(); - exit(-1); - } - else { - client->disconnect(); - exit(0); - } - } - - void exit(int code) { - exitCode = code; - eventLoop.stop(); - } - - private: - BoostConnectionServer::ref connectionServer; - OutgoingFileTransfer::ref outgoingFileTransfer; - JID jid; - std::string password; - JID recipient; - boost::filesystem::path file; - Client* client; - ClientXMLTracer* tracer; + 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), 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); + client->getEntityCapsProvider()->onCapsChanged.connect(boost::bind(&FileSender::handleCapsChanged, this, _1)); + } + + ~FileSender() { + delete tracer; + client->onDisconnected.disconnect(boost::bind(&FileSender::handleDisconnected, this, _1)); + client->onConnected.disconnect(boost::bind(&FileSender::handleConnected, this)); + delete client; + } + + void start() { + client->connect(); + } + + private: + void handleConnected() { + std::cout << "Connected. Awaiting presence from receipient." << std::endl; + client->sendPresence(Presence::create()); + } + + void handleCapsChanged(JID jid) { + if (jid.toBare() == recipient) { + // create ReadBytestream from file + boost::shared_ptr<FileReadBytestream> fileStream = boost::make_shared<FileReadBytestream>(file); + + outgoingFileTransfer = client->getFileTransferManager()->createOutgoingFileTransfer(recipient, file, "Some File!", fileStream); + + if (outgoingFileTransfer) { + 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 << recipient << " doesn't support any kind of file transfer!" << std::endl; + client->disconnect(); + } + } + } + + 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; + outgoingFileTransfer.reset(); + if (error) { + client->disconnect(); + exit(-1); + } + else { + client->disconnect(); + exit(0); + } + } + + void exit(int code) { + exitCode = code; + eventLoop.stop(); + } + + private: + BoostConnectionServer::ref connectionServer; + OutgoingFileTransfer::ref outgoingFileTransfer; + JID jid; + std::string password; + JID recipient; + boost::filesystem::path file; + Client* client; + ClientXMLTracer* tracer; }; int main(int argc, char* argv[]) { - if (argc != 5) { - std::cerr << "Usage: " << argv[0] << " <jid> <password> <recipient> <file>" << std::endl; - return -1; - } - - //Log::setLogLevel(Log::debug); - - JID sender(argv[1]); - JID recipient(argv[3]); - FileSender fileSender(sender, std::string(argv[2]), recipient, boost::filesystem::path(argv[4])); - fileSender.start(); - { - Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000); - timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop)); - timer->start(); - - eventLoop.run(); - } - - return exitCode; + if (argc != 5) { + std::cerr << "Usage: " << argv[0] << " <jid> <password> <recipient> <file>" << std::endl; + return -1; + } + + //Log::setLogLevel(Log::debug); + + JID sender(argv[1]); + JID recipient(argv[3]); + FileSender fileSender(sender, std::string(argv[2]), recipient, boost::filesystem::path(argv[4])); + fileSender.start(); + { + Timer::ref timer = networkFactories.getTimerFactory()->createTimer(30000); + timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop)); + timer->start(); + + eventLoop.run(); + } + + return exitCode; } |