summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-11-23 07:09:39 (GMT)
committerTobias Markmann <tm@ayena.de>2016-11-23 11:30:02 (GMT)
commite405ff3561be3d3c0bd79d7d5173923a8828cf02 (patch)
tree9118ef838ebfaec1df90ec24761944b5d833774c /Swiften/Examples
parent8a71b91be885652f37c5aab5e1ecf25af4599fbc (diff)
downloadswift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.zip
swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.tar.bz2
Migrate remaining Swiften/Base/foreach.h use to range-based for loop
Test-Information: Build on macOS 10.12.1 and all tests pass. Change-Id: Iedaa3fa7e7672c77909fd0568bf30e9393cb87e0
Diffstat (limited to 'Swiften/Examples')
-rw-r--r--Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp3
-rw-r--r--Swiften/Examples/SendFile/ReceiveFile.cpp4
2 files changed, 3 insertions, 4 deletions
diff --git a/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp b/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp
index c3983f1..10b0b40 100644
--- a/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp
+++ b/Swiften/Examples/MUCListAndJoin/MUCListAndJoin.cpp
@@ -1,80 +1,79 @@
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <iostream>
#include <memory>
#include <boost/optional.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Client/Client.h>
#include <Swiften/Client/ClientXMLTracer.h>
#include <Swiften/Disco/GetDiscoItemsRequest.h>
#include <Swiften/EventLoop/SimpleEventLoop.h>
#include <Swiften/JID/JID.h>
#include <Swiften/MUC/MUC.h>
#include <Swiften/MUC/MUCManager.h>
#include <Swiften/Network/BoostNetworkFactories.h>
#include <Swiften/Network/Timer.h>
#include <Swiften/Network/TimerFactory.h>
using namespace Swift;
using namespace std;
static SimpleEventLoop eventLoop;
static BoostNetworkFactories networkFactories(&eventLoop);
static std::shared_ptr<Client> client;
static MUC::ref muc;
static JID mucJID;
static JID roomJID;
static void joinMUC() {
cout << "Joining " << roomJID.toString() << endl;
muc = client->getMUCManager()->createMUC(roomJID);
muc->joinAs("SwiftExample");
}
static void handleRoomsItemsResponse(std::shared_ptr<DiscoItems> items, ErrorPayload::ref error) {
if (error) {
cout << "Error fetching list of rooms." << endl;
return;
}
int roomCount = 0;
cout << "List of rooms at " << mucJID.toString() << endl;
- foreach (DiscoItems::Item item, items->getItems()) {
+ for (auto&& item : items->getItems()) {
roomCount++;
cout << "\t" << roomCount << ". " << item.getJID().getNode() << " - " << item.getName() << std::endl;
if (roomCount == 1) {
roomJID = item.getJID();
}
}
cout << endl;
joinMUC();
}
static void handleConnected() {
cout << "Connected." << endl;
// search for MUC rooms
GetDiscoItemsRequest::ref discoItemsRequest = GetDiscoItemsRequest::create(mucJID, client->getIQRouter());
discoItemsRequest->onResponse.connect(&handleRoomsItemsResponse);
cout << "Request list of rooms." << endl;
discoItemsRequest->send();
}
static void handleDisconnected(const boost::optional<ClientError>&) {
cout << "Disconnected." << endl;
}
static void handleIncomingMessage(std::shared_ptr<Message> message) {
if (message->getFrom().toBare() == roomJID) {
cout << "[ " << roomJID << " ] " << message->getFrom().getResource() << ": " << message->getBody().get_value_or("") << endl;
}
}
diff --git a/Swiften/Examples/SendFile/ReceiveFile.cpp b/Swiften/Examples/SendFile/ReceiveFile.cpp
index 0b61987..193c1b7 100644
--- a/Swiften/Examples/SendFile/ReceiveFile.cpp
+++ b/Swiften/Examples/SendFile/ReceiveFile.cpp
@@ -1,89 +1,89 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <iostream>
#include <memory>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Client/Client.h>
#include <Swiften/Client/ClientXMLTracer.h>
#include <Swiften/Disco/ClientDiscoManager.h>
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Elements/Presence.h>
#include <Swiften/EventLoop/SimpleEventLoop.h>
#include <Swiften/FileTransfer/FileTransferManager.h>
#include <Swiften/FileTransfer/FileWriteBytestream.h>
#include <Swiften/FileTransfer/IncomingFileTransferManager.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
#include <Swiften/Jingle/JingleSessionManager.h>
#include <Swiften/Network/BoostNetworkFactories.h>
using namespace Swift;
static SimpleEventLoop eventLoop;
static BoostNetworkFactories networkFactories(&eventLoop);
static int exitCode = 2;
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) {
+ for (const auto& transfer : incomingFileTransfers) {
+ (void)transfer;
//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);
std::shared_ptr<FileWriteBytestream> out = std::make_shared<FileWriteBytestream>("out");
transfer->onFinished.connect(boost::bind(&FileReceiver::handleFileTransferFinished, this, _1, out));
transfer->accept(out);
}