summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-03-20 00:05:55 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-03-20 19:13:43 (GMT)
commit3d6694b0c698fff63d11f8bb4aa995c1df882315 (patch)
treea46ccace647f23a65100cf69c951345aa6dea7ab /Slimber
parent3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (diff)
downloadswift-contrib-3d6694b0c698fff63d11f8bb4aa995c1df882315.zip
swift-contrib-3d6694b0c698fff63d11f8bb4aa995c1df882315.tar.bz2
boost::shared_ptr<?>(new ?(...)) -> boost::make_shared<?>(...) transformation where possible.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/FileVCardCollection.cpp3
-rw-r--r--Slimber/Server.cpp2
-rw-r--r--Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp2
3 files changed, 4 insertions, 3 deletions
diff --git a/Slimber/FileVCardCollection.cpp b/Slimber/FileVCardCollection.cpp
index 97ade08..24249d4 100644
--- a/Slimber/FileVCardCollection.cpp
+++ b/Slimber/FileVCardCollection.cpp
@@ -1,43 +1,44 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Slimber/FileVCardCollection.h"
+#include <boost/smart_ptr/make_shared.hpp>
#include <boost/filesystem/fstream.hpp>
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Elements/VCard.h>
#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h>
#include <Swiften/Parser/PayloadParsers/VCardParser.h>
namespace Swift {
FileVCardCollection::FileVCardCollection(boost::filesystem::path dir) : vcardsPath(dir) {
}
boost::shared_ptr<VCard> FileVCardCollection::getOwnVCard() const {
if (boost::filesystem::exists(vcardsPath / std::string("vcard.xml"))) {
ByteArray data;
readByteArrayFromFile(data, boost::filesystem::path(vcardsPath / std::string("vcard.xml")).string());
VCardParser parser;
PayloadParserTester tester(&parser);
tester.parse(byteArrayToString(data));
return boost::dynamic_pointer_cast<VCard>(parser.getPayload());
}
else {
- return boost::shared_ptr<VCard>(new VCard());
+ return boost::make_shared<VCard>();
}
}
void FileVCardCollection::setOwnVCard(boost::shared_ptr<VCard> v) {
boost::filesystem::ofstream file(vcardsPath / std::string("vcard.xml"));
file << VCardSerializer().serializePayload(v);
file.close();
}
}
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index 769217f..b63ca67 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -295,71 +295,71 @@ void Server::handleLinkLocalSessionFinished(boost::shared_ptr<Session> session)
void Server::handleLinkLocalElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<Session> session) {
if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) {
JID fromJID = session->getRemoteJID();
if (!presenceManager->getServiceForJID(fromJID.toBare())) {
return; // TODO: Send error back
}
stanza->setFrom(fromJID);
serverFromClientSession->sendElement(stanza);
}
}
void Server::handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error) {
if (error) {
std::cerr << "Error connecting" << std::endl;
// TODO: Send back queued stanzas
}
else {
boost::shared_ptr<OutgoingLinkLocalSession> outgoingSession(
new OutgoingLinkLocalSession(
selfJID, connector->getService().getJID(), connector->getConnection(),
&payloadParserFactories, &payloadSerializers, &xmlParserFactory));
foreach(const boost::shared_ptr<Element> element, connector->getQueuedElements()) {
outgoingSession->queueElement(element);
}
registerLinkLocalSession(outgoingSession);
}
connectors.erase(std::remove(connectors.begin(), connectors.end(), connector), connectors.end());
}
void Server::registerLinkLocalSession(boost::shared_ptr<Session> session) {
session->onSessionFinished.connect(
boost::bind(&Server::handleLinkLocalSessionFinished, this, session));
session->onElementReceived.connect(
boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session));
linkLocalSessions.push_back(session);
- //tracers.push_back(boost::shared_ptr<SessionTracer>(new SessionTracer(session)));
+ //tracers.push_back(boost::make_shared<SessionTracer>(session));
session->startSession();
}
boost::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) {
foreach(const boost::shared_ptr<Session> session, linkLocalSessions) {
if (session->getRemoteJID() == jid) {
return session;
}
}
return boost::shared_ptr<Session>();
}
boost::shared_ptr<LinkLocalConnector> Server::getLinkLocalConnectorForJID(const JID& jid) {
foreach(const boost::shared_ptr<LinkLocalConnector> connector, connectors) {
if (connector->getService().getJID() == jid) {
return connector;
}
}
return boost::shared_ptr<LinkLocalConnector>();
}
void Server::handleServiceRegistered(const DNSSDServiceID& service) {
selfJID = JID(service.getName());
}
void Server::handleRosterChanged(boost::shared_ptr<RosterPayload> roster) {
if (rosterRequested) {
assert(serverFromClientSession);
boost::shared_ptr<IQ> iq = IQ::createRequest(
IQ::Set, serverFromClientSession->getRemoteJID(),
idGenerator.generateID(), roster);
iq->setFrom(serverFromClientSession->getRemoteJID().toBare());
serverFromClientSession->sendElement(iq);
}
}
diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
index e45861b..c138b2c 100644
--- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
+++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
@@ -10,71 +10,71 @@
#include <map>
#include <Swiften/Elements/Presence.h>
#include <Swiften/Elements/RosterPayload.h>
#include <Swiften/Elements/RosterItemPayload.h>
#include "Slimber/LinkLocalPresenceManager.h"
#include <Swiften/LinkLocal/LinkLocalServiceInfo.h>
#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h>
#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h>
#include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h>
#include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h>
#include <Swiften/EventLoop/DummyEventLoop.h>
using namespace Swift;
class LinkLocalPresenceManagerTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(LinkLocalPresenceManagerTest);
CPPUNIT_TEST(testConstructor);
CPPUNIT_TEST(testServiceAdded);
CPPUNIT_TEST(testServiceRemoved);
CPPUNIT_TEST(testServiceChanged);
CPPUNIT_TEST(testGetRoster);
CPPUNIT_TEST(testGetAllPresence);
CPPUNIT_TEST(testGetRoster_InfoWithNick);
CPPUNIT_TEST(testGetRoster_InfoWithFirstName);
CPPUNIT_TEST(testGetRoster_InfoWithLastName);
CPPUNIT_TEST(testGetRoster_InfoWithFirstAndLastName);
CPPUNIT_TEST(testGetRoster_NoInfo);
CPPUNIT_TEST(testGetServiceForJID);
CPPUNIT_TEST(testGetServiceForJID_NoMatch);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
eventLoop = new DummyEventLoop();
- querier = boost::shared_ptr<FakeDNSSDQuerier>(new FakeDNSSDQuerier("wonderland.lit", eventLoop));
+ querier = boost::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop);
browser = new LinkLocalServiceBrowser(querier);
browser->start();
}
void tearDown() {
browser->stop();
delete browser;
delete eventLoop;
}
void testConstructor() {
addService("alice@wonderland");
addService("rabbit@teaparty");
boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getRoster()->getItems().size()));
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getAllPresence().size()));
}
void testServiceAdded() {
boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
addService("alice@wonderland", "Alice");
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[0]->getItems().size()));
boost::optional<RosterItemPayload> item = rosterChanges[0]->getItem(JID("alice@wonderland"));
CPPUNIT_ASSERT(item);
CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName());
CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription());
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(presenceChanges.size()));
CPPUNIT_ASSERT(StatusShow::Online == presenceChanges[0]->getShow());
CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[0]->getFrom());
}