summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/CLI/DummyMenulet.h34
-rw-r--r--Slimber/CLI/main.cpp12
-rw-r--r--Slimber/Cocoa/CocoaController.mm14
-rw-r--r--Slimber/Cocoa/CocoaMenulet.h34
-rw-r--r--Slimber/Cocoa/CocoaMenulet.mm86
-rw-r--r--Slimber/Cocoa/main.mm8
-rw-r--r--Slimber/FileVCardCollection.cpp30
-rw-r--r--Slimber/FileVCardCollection.h16
-rw-r--r--Slimber/LinkLocalPresenceManager.cpp120
-rw-r--r--Slimber/LinkLocalPresenceManager.h44
-rw-r--r--Slimber/MainController.cpp144
-rw-r--r--Slimber/MainController.h48
-rw-r--r--Slimber/Menulet.h20
-rw-r--r--Slimber/MenuletController.cpp56
-rw-r--r--Slimber/MenuletController.h44
-rw-r--r--Slimber/Qt/QtAboutDialog.cpp44
-rw-r--r--Slimber/Qt/QtAboutDialog.h4
-rw-r--r--Slimber/Qt/QtMenulet.h100
-rw-r--r--Slimber/Qt/main.cpp22
-rw-r--r--Slimber/Server.cpp658
-rw-r--r--Slimber/Server.h194
-rw-r--r--Slimber/ServerError.h42
-rw-r--r--Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp466
-rw-r--r--Slimber/UnitTest/MenuletControllerTest.cpp278
-rw-r--r--Slimber/VCardCollection.h12
25 files changed, 1265 insertions, 1265 deletions
diff --git a/Slimber/CLI/DummyMenulet.h b/Slimber/CLI/DummyMenulet.h
index 22d4b36..4b37df6 100644
--- a/Slimber/CLI/DummyMenulet.h
+++ b/Slimber/CLI/DummyMenulet.h
@@ -9,28 +9,28 @@
#include <Slimber/Menulet.h>
class DummyMenulet : public Menulet {
- public:
- DummyMenulet() {
- }
+ public:
+ DummyMenulet() {
+ }
- void clear() {
- }
+ void clear() {
+ }
- void addItem(const std::string&, const std::string&) {
- }
+ void addItem(const std::string&, const std::string&) {
+ }
- void addAboutItem() {
- }
+ void addAboutItem() {
+ }
- void addRestartItem() {
- }
+ void addRestartItem() {
+ }
- void addExitItem() {
- }
+ void addExitItem() {
+ }
- void addSeparator() {
- }
+ void addSeparator() {
+ }
- void setIcon(const std::string&) {
- }
+ void setIcon(const std::string&) {
+ }
};
diff --git a/Slimber/CLI/main.cpp b/Slimber/CLI/main.cpp
index 9084a60..26f88d0 100644
--- a/Slimber/CLI/main.cpp
+++ b/Slimber/CLI/main.cpp
@@ -12,11 +12,11 @@
using namespace Swift;
int main() {
- SimpleEventLoop eventLoop;
-
- DummyMenulet menulet;
- MainController controller(&menulet, &eventLoop);
+ SimpleEventLoop eventLoop;
- eventLoop.run();
- return 0;
+ DummyMenulet menulet;
+ MainController controller(&menulet, &eventLoop);
+
+ eventLoop.run();
+ return 0;
}
diff --git a/Slimber/Cocoa/CocoaController.mm b/Slimber/Cocoa/CocoaController.mm
index 1d2ef5c..7d17948 100644
--- a/Slimber/Cocoa/CocoaController.mm
+++ b/Slimber/Cocoa/CocoaController.mm
@@ -11,19 +11,19 @@
#include <Slimber/MainController.h>
@implementation CocoaController {
- CocoaMenulet* menulet;
- MainController* main;
+ CocoaMenulet* menulet;
+ MainController* main;
}
- (void) dealloc {
- delete main;
- delete menulet;
- [super dealloc];
+ delete main;
+ delete menulet;
+ [super dealloc];
}
- (void) awakeFromNib {
- menulet = new CocoaMenulet();
- main = new MainController(menulet, eventLoop);
+ menulet = new CocoaMenulet();
+ main = new MainController(menulet, eventLoop);
}
@end
diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h
index c31f15c..0dc06f5 100644
--- a/Slimber/Cocoa/CocoaMenulet.h
+++ b/Slimber/Cocoa/CocoaMenulet.h
@@ -13,21 +13,21 @@
#include <SwifTools/Cocoa/CocoaAction.h>
class CocoaMenulet : public Menulet {
- public:
- CocoaMenulet();
- virtual ~CocoaMenulet();
-
- private:
- virtual void clear();
- virtual void addItem(const std::string& name, const std::string& icon);
- virtual void addSeparator();
- void setIcon(const std::string& icon);
- virtual void addAboutItem();
- virtual void addRestartItem();
- virtual void addExitItem();
-
- private:
- NSStatusItem* statusItem;
- NSMenu* menu;
- CocoaAction* restartAction;
+ public:
+ CocoaMenulet();
+ virtual ~CocoaMenulet();
+
+ private:
+ virtual void clear();
+ virtual void addItem(const std::string& name, const std::string& icon);
+ virtual void addSeparator();
+ void setIcon(const std::string& icon);
+ virtual void addAboutItem();
+ virtual void addRestartItem();
+ virtual void addExitItem();
+
+ private:
+ NSStatusItem* statusItem;
+ NSMenu* menu;
+ CocoaAction* restartAction;
};
diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm
index f62da80..98042d7 100644
--- a/Slimber/Cocoa/CocoaMenulet.mm
+++ b/Slimber/Cocoa/CocoaMenulet.mm
@@ -11,72 +11,72 @@
#include <SwifTools/Cocoa/CocoaUtil.h>
CocoaMenulet::CocoaMenulet() {
- restartAction = [[CocoaAction alloc] initWithFunction:
- new boost::function<void()>(boost::ref(onRestartClicked))];
- menu = [[NSMenu alloc] init];
+ restartAction = [[CocoaAction alloc] initWithFunction:
+ new boost::function<void()>(boost::ref(onRestartClicked))];
+ menu = [[NSMenu alloc] init];
- statusItem = [[[NSStatusBar systemStatusBar]
- statusItemWithLength: NSVariableStatusItemLength] retain];
- [statusItem setHighlightMode: YES];
- [statusItem setEnabled: YES];
- [statusItem setToolTip: @"Slimber"];
- [statusItem setMenu: menu];
+ statusItem = [[[NSStatusBar systemStatusBar]
+ statusItemWithLength: NSVariableStatusItemLength] retain];
+ [statusItem setHighlightMode: YES];
+ [statusItem setEnabled: YES];
+ [statusItem setToolTip: @"Slimber"];
+ [statusItem setMenu: menu];
}
CocoaMenulet::~CocoaMenulet() {
- [statusItem release];
- [menu release];
- [restartAction release];
+ [statusItem release];
+ [menu release];
+ [restartAction release];
}
void CocoaMenulet::setIcon(const std::string& icon) {
- NSString* path = [[NSBundle mainBundle] pathForResource: std2NSString(icon) ofType:@"png"];
- NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
- [statusItem setImage: image];
- [image release];
+ NSString* path = [[NSBundle mainBundle] pathForResource: std2NSString(icon) ofType:@"png"];
+ NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
+ [statusItem setImage: image];
+ [image release];
}
void CocoaMenulet::clear() {
- while ([menu numberOfItems] > 0) {
- [menu removeItemAtIndex: 0];
- }
+ while ([menu numberOfItems] > 0) {
+ [menu removeItemAtIndex: 0];
+ }
}
void CocoaMenulet::addItem(const std::string& name, const std::string& icon) {
- NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: std2NSString(name)
- action: NULL keyEquivalent: @""];
- if (!icon.empty()) {
- NSString* path = [[NSBundle mainBundle] pathForResource: std2NSString(icon) ofType:@"png"];
- NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
- [item setImage: image];
- [image release];
- }
- [menu addItem: item];
- [item release];
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: std2NSString(name)
+ action: NULL keyEquivalent: @""];
+ if (!icon.empty()) {
+ NSString* path = [[NSBundle mainBundle] pathForResource: std2NSString(icon) ofType:@"png"];
+ NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
+ [item setImage: image];
+ [image release];
+ }
+ [menu addItem: item];
+ [item release];
}
void CocoaMenulet::addAboutItem() {
- NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""];
- [item setTarget: [NSApplication sharedApplication]];
- [menu addItem: item];
- [item release];
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""];
+ [item setTarget: [NSApplication sharedApplication]];
+ [menu addItem: item];
+ [item release];
}
void CocoaMenulet::addRestartItem() {
- NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:
- @"Restart" action: @selector(doAction:) keyEquivalent: @""];
- [item setTarget: restartAction];
- [menu addItem: item];
- [item release];
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:
+ @"Restart" action: @selector(doAction:) keyEquivalent: @""];
+ [item setTarget: restartAction];
+ [menu addItem: item];
+ [item release];
}
void CocoaMenulet::addExitItem() {
- NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""];
- [item setTarget: [NSApplication sharedApplication]];
- [menu addItem: item];
- [item release];
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""];
+ [item setTarget: [NSApplication sharedApplication]];
+ [menu addItem: item];
+ [item release];
}
void CocoaMenulet::addSeparator() {
- [menu addItem: [NSMenuItem separatorItem]];
+ [menu addItem: [NSMenuItem separatorItem]];
}
diff --git a/Slimber/Cocoa/main.mm b/Slimber/Cocoa/main.mm
index 41678f1..c5495af 100644
--- a/Slimber/Cocoa/main.mm
+++ b/Slimber/Cocoa/main.mm
@@ -13,8 +13,8 @@
Swift::CocoaEventLoop* eventLoop;
int main(int argc, char *argv[]) {
- eventLoop = new Swift::CocoaEventLoop();
- int result = NSApplicationMain(argc, const_cast<const char **>(argv));
- delete eventLoop;
- return result;
+ eventLoop = new Swift::CocoaEventLoop();
+ int result = NSApplicationMain(argc, const_cast<const char **>(argv));
+ delete eventLoop;
+ return result;
}
diff --git a/Slimber/FileVCardCollection.cpp b/Slimber/FileVCardCollection.cpp
index 33e20c9..af8d57d 100644
--- a/Slimber/FileVCardCollection.cpp
+++ b/Slimber/FileVCardCollection.cpp
@@ -21,24 +21,24 @@ FileVCardCollection::FileVCardCollection(boost::filesystem::path dir) : vcardsPa
}
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::make_shared<VCard>();
- }
+ 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::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();
+ boost::filesystem::ofstream file(vcardsPath / std::string("vcard.xml"));
+ file << VCardSerializer().serializePayload(v);
+ file.close();
}
}
diff --git a/Slimber/FileVCardCollection.h b/Slimber/FileVCardCollection.h
index 40f3e53..c05c4f4 100644
--- a/Slimber/FileVCardCollection.h
+++ b/Slimber/FileVCardCollection.h
@@ -12,14 +12,14 @@
#include <Slimber/VCardCollection.h>
namespace Swift {
- class FileVCardCollection : public VCardCollection {
- public:
- FileVCardCollection(boost::filesystem::path dir);
+ class FileVCardCollection : public VCardCollection {
+ public:
+ FileVCardCollection(boost::filesystem::path dir);
- boost::shared_ptr<VCard> getOwnVCard() const;
- void setOwnVCard(boost::shared_ptr<VCard> vcard);
+ boost::shared_ptr<VCard> getOwnVCard() const;
+ void setOwnVCard(boost::shared_ptr<VCard> vcard);
- private:
- boost::filesystem::path vcardsPath;
- };
+ private:
+ boost::filesystem::path vcardsPath;
+ };
}
diff --git a/Slimber/LinkLocalPresenceManager.cpp b/Slimber/LinkLocalPresenceManager.cpp
index 786f3a8..200e98f 100644
--- a/Slimber/LinkLocalPresenceManager.cpp
+++ b/Slimber/LinkLocalPresenceManager.cpp
@@ -16,54 +16,54 @@
namespace Swift {
LinkLocalPresenceManager::LinkLocalPresenceManager(LinkLocalServiceBrowser* browser) : browser(browser) {
- browser->onServiceAdded.connect(
- boost::bind(&LinkLocalPresenceManager::handleServiceAdded, this, _1));
- browser->onServiceChanged.connect(
- boost::bind(&LinkLocalPresenceManager::handleServiceChanged, this, _1));
- browser->onServiceRemoved.connect(
- boost::bind(&LinkLocalPresenceManager::handleServiceRemoved, this, _1));
+ browser->onServiceAdded.connect(
+ boost::bind(&LinkLocalPresenceManager::handleServiceAdded, this, _1));
+ browser->onServiceChanged.connect(
+ boost::bind(&LinkLocalPresenceManager::handleServiceChanged, this, _1));
+ browser->onServiceRemoved.connect(
+ boost::bind(&LinkLocalPresenceManager::handleServiceRemoved, this, _1));
}
boost::optional<LinkLocalService> LinkLocalPresenceManager::getServiceForJID(const JID& j) const {
- foreach(const LinkLocalService& service, browser->getServices()) {
- if (service.getJID() == j) {
- return service;
- }
- }
- return boost::optional<LinkLocalService>();
+ foreach(const LinkLocalService& service, browser->getServices()) {
+ if (service.getJID() == j) {
+ return service;
+ }
+ }
+ return boost::optional<LinkLocalService>();
}
void LinkLocalPresenceManager::handleServiceAdded(const LinkLocalService& service) {
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->addItem(getRosterItem(service));
- onRosterChanged(roster);
- onPresenceChanged(getPresence(service));
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ roster->addItem(getRosterItem(service));
+ onRosterChanged(roster);
+ onPresenceChanged(getPresence(service));
}
void LinkLocalPresenceManager::handleServiceChanged(const LinkLocalService& service) {
- onPresenceChanged(getPresence(service));
+ onPresenceChanged(getPresence(service));
}
void LinkLocalPresenceManager::handleServiceRemoved(const LinkLocalService& service) {
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->addItem(RosterItemPayload(service.getJID(), "", RosterItemPayload::Remove));
- onRosterChanged(roster);
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ roster->addItem(RosterItemPayload(service.getJID(), "", RosterItemPayload::Remove));
+ onRosterChanged(roster);
}
boost::shared_ptr<RosterPayload> LinkLocalPresenceManager::getRoster() const {
- boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- foreach(const LinkLocalService& service, browser->getServices()) {
- roster->addItem(getRosterItem(service));
- }
- return roster;
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+ foreach(const LinkLocalService& service, browser->getServices()) {
+ roster->addItem(getRosterItem(service));
+ }
+ return roster;
}
std::vector<boost::shared_ptr<Presence> > LinkLocalPresenceManager::getAllPresence() const {
- std::vector<boost::shared_ptr<Presence> > result;
- foreach(const LinkLocalService& service, browser->getServices()) {
- result.push_back(getPresence(service));
- }
- return result;
+ std::vector<boost::shared_ptr<Presence> > result;
+ foreach(const LinkLocalService& service, browser->getServices()) {
+ result.push_back(getPresence(service));
+ }
+ return result;
}
RosterItemPayload LinkLocalPresenceManager::getRosterItem(const LinkLocalService& service) const {
@@ -71,39 +71,39 @@ RosterItemPayload LinkLocalPresenceManager::getRosterItem(const LinkLocalService
}
std::string LinkLocalPresenceManager::getRosterName(const LinkLocalService& service) const {
- LinkLocalServiceInfo info = service.getInfo();
- if (!info.getNick().empty()) {
- return info.getNick();
- }
- else if (!info.getFirstName().empty()) {
- std::string result = info.getFirstName();
- if (!info.getLastName().empty()) {
- result += " " + info.getLastName();
- }
- return result;
- }
- else if (!info.getLastName().empty()) {
- return info.getLastName();
- }
- return "";
+ LinkLocalServiceInfo info = service.getInfo();
+ if (!info.getNick().empty()) {
+ return info.getNick();
+ }
+ else if (!info.getFirstName().empty()) {
+ std::string result = info.getFirstName();
+ if (!info.getLastName().empty()) {
+ result += " " + info.getLastName();
+ }
+ return result;
+ }
+ else if (!info.getLastName().empty()) {
+ return info.getLastName();
+ }
+ return "";
}
boost::shared_ptr<Presence> LinkLocalPresenceManager::getPresence(const LinkLocalService& service) const {
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setFrom(service.getJID());
- switch (service.getInfo().getStatus()) {
- case LinkLocalServiceInfo::Available:
- presence->setShow(StatusShow::Online);
- break;
- case LinkLocalServiceInfo::Away:
- presence->setShow(StatusShow::Away);
- break;
- case LinkLocalServiceInfo::DND:
- presence->setShow(StatusShow::DND);
- break;
- }
- presence->setStatus(service.getInfo().getMessage());
- return presence;
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setFrom(service.getJID());
+ switch (service.getInfo().getStatus()) {
+ case LinkLocalServiceInfo::Available:
+ presence->setShow(StatusShow::Online);
+ break;
+ case LinkLocalServiceInfo::Away:
+ presence->setShow(StatusShow::Away);
+ break;
+ case LinkLocalServiceInfo::DND:
+ presence->setShow(StatusShow::DND);
+ break;
+ }
+ presence->setStatus(service.getInfo().getMessage());
+ return presence;
}
}
diff --git a/Slimber/LinkLocalPresenceManager.h b/Slimber/LinkLocalPresenceManager.h
index 1f27e50..83df624 100644
--- a/Slimber/LinkLocalPresenceManager.h
+++ b/Slimber/LinkLocalPresenceManager.h
@@ -15,33 +15,33 @@
#include <Swiften/JID/JID.h>
namespace Swift {
- class LinkLocalService;
- class LinkLocalServiceBrowser;
- class RosterPayload;
- class Presence;
+ class LinkLocalService;
+ class LinkLocalServiceBrowser;
+ class RosterPayload;
+ class Presence;
- class LinkLocalPresenceManager : public boost::bsignals::trackable {
- public:
- LinkLocalPresenceManager(LinkLocalServiceBrowser*);
+ class LinkLocalPresenceManager : public boost::bsignals::trackable {
+ public:
+ LinkLocalPresenceManager(LinkLocalServiceBrowser*);
- boost::shared_ptr<RosterPayload> getRoster() const;
- std::vector<boost::shared_ptr<Presence> > getAllPresence() const;
+ boost::shared_ptr<RosterPayload> getRoster() const;
+ std::vector<boost::shared_ptr<Presence> > getAllPresence() const;
- boost::optional<LinkLocalService> getServiceForJID(const JID&) const;
+ boost::optional<LinkLocalService> getServiceForJID(const JID&) const;
- boost::signal<void (boost::shared_ptr<RosterPayload>)> onRosterChanged;
- boost::signal<void (boost::shared_ptr<Presence>)> onPresenceChanged;
+ boost::signal<void (boost::shared_ptr<RosterPayload>)> onRosterChanged;
+ boost::signal<void (boost::shared_ptr<Presence>)> onPresenceChanged;
- private:
- void handleServiceAdded(const LinkLocalService&);
- void handleServiceChanged(const LinkLocalService&);
- void handleServiceRemoved(const LinkLocalService&);
+ private:
+ void handleServiceAdded(const LinkLocalService&);
+ void handleServiceChanged(const LinkLocalService&);
+ void handleServiceRemoved(const LinkLocalService&);
- RosterItemPayload getRosterItem(const LinkLocalService& service) const;
- std::string getRosterName(const LinkLocalService& service) const;
- boost::shared_ptr<Presence> getPresence(const LinkLocalService& service) const;
+ RosterItemPayload getRosterItem(const LinkLocalService& service) const;
+ std::string getRosterName(const LinkLocalService& service) const;
+ boost::shared_ptr<Presence> getPresence(const LinkLocalService& service) const;
- private:
- LinkLocalServiceBrowser* browser;
- };
+ private:
+ LinkLocalServiceBrowser* browser;
+ };
}
diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp
index 85c8f4b..90a1b94 100644
--- a/Slimber/MainController.cpp
+++ b/Slimber/MainController.cpp
@@ -26,105 +26,105 @@
using namespace Swift;
MainController::MainController(Menulet* menulet, EventLoop* eventLoop) {
- dnsSDQuerier = PlatformDNSSDQuerierFactory(eventLoop).createQuerier();
- assert(dnsSDQuerier);
+ dnsSDQuerier = PlatformDNSSDQuerierFactory(eventLoop).createQuerier();
+ assert(dnsSDQuerier);
- linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier);
- linkLocalServiceBrowser->onServiceAdded.connect(
- boost::bind(&MainController::handleServicesChanged, this));
- linkLocalServiceBrowser->onServiceRemoved.connect(
- boost::bind(&MainController::handleServicesChanged, this));
- linkLocalServiceBrowser->onServiceChanged.connect(
- boost::bind(&MainController::handleServicesChanged, this));
+ linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier);
+ linkLocalServiceBrowser->onServiceAdded.connect(
+ boost::bind(&MainController::handleServicesChanged, this));
+ linkLocalServiceBrowser->onServiceRemoved.connect(
+ boost::bind(&MainController::handleServicesChanged, this));
+ linkLocalServiceBrowser->onServiceChanged.connect(
+ boost::bind(&MainController::handleServicesChanged, this));
- vCardCollection = new FileVCardCollection(
- PlatformApplicationPathProvider("Slimber").getDataDir());
+ vCardCollection = new FileVCardCollection(
+ PlatformApplicationPathProvider("Slimber").getDataDir());
- server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection, eventLoop);
- server->onStopped.connect(
- boost::bind(&MainController::handleServerStopped, this, _1));
- server->onSelfConnected.connect(
- boost::bind(&MainController::handleSelfConnected, this, _1));
+ server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection, eventLoop);
+ server->onStopped.connect(
+ boost::bind(&MainController::handleServerStopped, this, _1));
+ server->onSelfConnected.connect(
+ boost::bind(&MainController::handleSelfConnected, this, _1));
- menuletController = new MenuletController(menulet);
- menuletController->onRestartRequested.connect(boost::bind(
- &MainController::handleRestartRequested, this));
+ menuletController = new MenuletController(menulet);
+ menuletController->onRestartRequested.connect(boost::bind(
+ &MainController::handleRestartRequested, this));
- start();
+ start();
}
MainController::~MainController() {
- delete server;
- delete menuletController;
- delete vCardCollection;
- linkLocalServiceBrowser->stop();
- delete linkLocalServiceBrowser;
- dnsSDQuerier->stop();
+ delete server;
+ delete menuletController;
+ delete vCardCollection;
+ linkLocalServiceBrowser->stop();
+ delete linkLocalServiceBrowser;
+ dnsSDQuerier->stop();
}
void MainController::start() {
- dnsSDQuerier->start();
- linkLocalServiceBrowser->start();
+ dnsSDQuerier->start();
+ linkLocalServiceBrowser->start();
- handleSelfConnected(false);
- handleServicesChanged();
+ handleSelfConnected(false);
+ handleServicesChanged();
- server->start();
+ server->start();
}
void MainController::stop() {
- server->stop();
- linkLocalServiceBrowser->stop();
- dnsSDQuerier->stop();
+ server->stop();
+ linkLocalServiceBrowser->stop();
+ dnsSDQuerier->stop();
}
void MainController::handleSelfConnected(bool b) {
- if (b) {
- menuletController->setXMPPStatus("You are logged in", MenuletController::Online);
- }
- else {
- menuletController->setXMPPStatus("You are not logged in", MenuletController::Offline);
- }
+ if (b) {
+ menuletController->setXMPPStatus("You are logged in", MenuletController::Online);
+ }
+ else {
+ menuletController->setXMPPStatus("You are not logged in", MenuletController::Offline);
+ }
}
void MainController::handleServicesChanged() {
- std::vector<std::string> names;
- foreach(const LinkLocalService& service, linkLocalServiceBrowser->getServices()) {
- std::string description = service.getDescription();
- if (description != service.getName()) {
- description += " (" + service.getName() + ")";
- }
- names.push_back(description);
- }
- menuletController->setUserNames(names);
+ std::vector<std::string> names;
+ foreach(const LinkLocalService& service, linkLocalServiceBrowser->getServices()) {
+ std::string description = service.getDescription();
+ if (description != service.getName()) {
+ description += " (" + service.getName() + ")";
+ }
+ names.push_back(description);
+ }
+ menuletController->setUserNames(names);
}
void MainController::handleServerStopped(boost::optional<ServerError> error) {
- if (error) {
- std::string message;
- switch (error->getType()) {
- case ServerError::C2SPortConflict:
- message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getClientToServerPort()) + std::string(" in use");
- break;
- case ServerError::C2SError:
- message = std::string("Local connection server error");
- break;
- case ServerError::LinkLocalPortConflict:
- message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getLinkLocalPort()) + std::string(" in use");
- break;
- case ServerError::LinkLocalError:
- message = std::string("External connection server error");
- break;
- }
- menuletController->setXMPPStatus(message, MenuletController::Offline);
- }
- else {
- menuletController->setXMPPStatus("XMPP Server Not Running", MenuletController::Offline);
- }
+ if (error) {
+ std::string message;
+ switch (error->getType()) {
+ case ServerError::C2SPortConflict:
+ message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getClientToServerPort()) + std::string(" in use");
+ break;
+ case ServerError::C2SError:
+ message = std::string("Local connection server error");
+ break;
+ case ServerError::LinkLocalPortConflict:
+ message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getLinkLocalPort()) + std::string(" in use");
+ break;
+ case ServerError::LinkLocalError:
+ message = std::string("External connection server error");
+ break;
+ }
+ menuletController->setXMPPStatus(message, MenuletController::Offline);
+ }
+ else {
+ menuletController->setXMPPStatus("XMPP Server Not Running", MenuletController::Offline);
+ }
}
void MainController::handleRestartRequested() {
- stop();
- start();
+ stop();
+ start();
}
diff --git a/Slimber/MainController.h b/Slimber/MainController.h
index 5f28c31..8f4e981 100644
--- a/Slimber/MainController.h
+++ b/Slimber/MainController.h
@@ -12,34 +12,34 @@
#include <Slimber/ServerError.h>
namespace Swift {
- class DNSSDQuerier;
- class LinkLocalServiceBrowser;
- class VCardCollection;
- class Server;
- class EventLoop;
+ class DNSSDQuerier;
+ class LinkLocalServiceBrowser;
+ class VCardCollection;
+ class Server;
+ class EventLoop;
}
class MenuletController;
class Menulet;
class MainController {
- public:
- MainController(Menulet* menulet, Swift::EventLoop* eventLoop);
- virtual ~MainController();
-
- private:
- void handleSelfConnected(bool b);
- void handleServicesChanged();
- void handleServerStopped(boost::optional<Swift::ServerError> error);
- void handleRestartRequested();
-
- void start();
- void stop();
-
- private:
- boost::shared_ptr<Swift::DNSSDQuerier> dnsSDQuerier;
- Swift::LinkLocalServiceBrowser* linkLocalServiceBrowser;
- Swift::VCardCollection* vCardCollection;
- Swift::Server* server;
- MenuletController* menuletController;
+ public:
+ MainController(Menulet* menulet, Swift::EventLoop* eventLoop);
+ virtual ~MainController();
+
+ private:
+ void handleSelfConnected(bool b);
+ void handleServicesChanged();
+ void handleServerStopped(boost::optional<Swift::ServerError> error);
+ void handleRestartRequested();
+
+ void start();
+ void stop();
+
+ private:
+ boost::shared_ptr<Swift::DNSSDQuerier> dnsSDQuerier;
+ Swift::LinkLocalServiceBrowser* linkLocalServiceBrowser;
+ Swift::VCardCollection* vCardCollection;
+ Swift::Server* server;
+ MenuletController* menuletController;
};
diff --git a/Slimber/Menulet.h b/Slimber/Menulet.h
index cd4b4d9..4f2e33f 100644
--- a/Slimber/Menulet.h
+++ b/Slimber/Menulet.h
@@ -11,16 +11,16 @@
#include <Swiften/Base/boost_bsignals.h>
class Menulet {
- public:
- virtual ~Menulet();
+ public:
+ virtual ~Menulet();
- virtual void clear() = 0;
- virtual void addItem(const std::string& name, const std::string& icon = std::string()) = 0;
- virtual void addAboutItem() = 0;
- virtual void addRestartItem() = 0;
- virtual void addExitItem() = 0;
- virtual void addSeparator() = 0;
- virtual void setIcon(const std::string&) = 0;
+ virtual void clear() = 0;
+ virtual void addItem(const std::string& name, const std::string& icon = std::string()) = 0;
+ virtual void addAboutItem() = 0;
+ virtual void addRestartItem() = 0;
+ virtual void addExitItem() = 0;
+ virtual void addSeparator() = 0;
+ virtual void setIcon(const std::string&) = 0;
- boost::signal<void ()> onRestartClicked;
+ boost::signal<void ()> onRestartClicked;
};
diff --git a/Slimber/MenuletController.cpp b/Slimber/MenuletController.cpp
index c09d35f..5868128 100644
--- a/Slimber/MenuletController.cpp
+++ b/Slimber/MenuletController.cpp
@@ -13,44 +13,44 @@
#include <Slimber/Menulet.h>
-MenuletController::MenuletController(Menulet* menulet) :
- menulet(menulet), xmppStatus(Offline) {
- menulet->onRestartClicked.connect(boost::ref(onRestartRequested));
- update();
+MenuletController::MenuletController(Menulet* menulet) :
+ menulet(menulet), xmppStatus(Offline) {
+ menulet->onRestartClicked.connect(boost::ref(onRestartRequested));
+ update();
}
MenuletController::~MenuletController() {
}
void MenuletController::setXMPPStatus(const std::string& message, Status status) {
- xmppStatus = status;
- xmppStatusMessage = message;
- update();
+ xmppStatus = status;
+ xmppStatusMessage = message;
+ update();
}
void MenuletController::setUserNames(const std::vector<std::string>& users) {
- linkLocalUsers = users;
- update();
+ linkLocalUsers = users;
+ update();
}
void MenuletController::update() {
- menulet->clear();
- if (linkLocalUsers.empty()) {
- menulet->setIcon("UsersOffline");
- menulet->addItem("No online users");
- }
- else {
- menulet->setIcon("UsersOnline");
- menulet->addItem("Online users:");
- foreach(const std::string& user, linkLocalUsers) {
- menulet->addItem(std::string(" ") + user);
- }
- }
- menulet->addSeparator();
- menulet->addItem(xmppStatusMessage, (xmppStatus == Online ? "Online" : "Offline"));
- menulet->addSeparator();
- menulet->addAboutItem();
- menulet->addSeparator();
- menulet->addRestartItem();
- menulet->addExitItem();
+ menulet->clear();
+ if (linkLocalUsers.empty()) {
+ menulet->setIcon("UsersOffline");
+ menulet->addItem("No online users");
+ }
+ else {
+ menulet->setIcon("UsersOnline");
+ menulet->addItem("Online users:");
+ foreach(const std::string& user, linkLocalUsers) {
+ menulet->addItem(std::string(" ") + user);
+ }
+ }
+ menulet->addSeparator();
+ menulet->addItem(xmppStatusMessage, (xmppStatus == Online ? "Online" : "Offline"));
+ menulet->addSeparator();
+ menulet->addAboutItem();
+ menulet->addSeparator();
+ menulet->addRestartItem();
+ menulet->addExitItem();
}
diff --git a/Slimber/MenuletController.h b/Slimber/MenuletController.h
index 46dc41f..210eac2 100644
--- a/Slimber/MenuletController.h
+++ b/Slimber/MenuletController.h
@@ -14,26 +14,26 @@
class Menulet;
class MenuletController {
- public:
- enum Status {
- Online,
- Offline
- };
-
- MenuletController(Menulet*);
- virtual ~MenuletController();
-
- void setXMPPStatus(const std::string& message, Status status);
- void setUserNames(const std::vector<std::string>&);
-
- boost::signal<void ()> onRestartRequested;
-
- private:
- void update();
-
- private:
- Menulet* menulet;
- Status xmppStatus;
- std::string xmppStatusMessage;
- std::vector<std::string> linkLocalUsers;
+ public:
+ enum Status {
+ Online,
+ Offline
+ };
+
+ MenuletController(Menulet*);
+ virtual ~MenuletController();
+
+ void setXMPPStatus(const std::string& message, Status status);
+ void setUserNames(const std::vector<std::string>&);
+
+ boost::signal<void ()> onRestartRequested;
+
+ private:
+ void update();
+
+ private:
+ Menulet* menulet;
+ Status xmppStatus;
+ std::string xmppStatusMessage;
+ std::vector<std::string> linkLocalUsers;
};
diff --git a/Slimber/Qt/QtAboutDialog.cpp b/Slimber/Qt/QtAboutDialog.cpp
index 7fcd2ca..301661e 100644
--- a/Slimber/Qt/QtAboutDialog.cpp
+++ b/Slimber/Qt/QtAboutDialog.cpp
@@ -12,26 +12,26 @@
#include <QVBoxLayout>
QtAboutDialog::QtAboutDialog() {
- setAttribute(Qt::WA_DeleteOnClose);
- setWindowTitle("About Slimber");
-
- QVBoxLayout* layout = new QVBoxLayout(this);
-
- QLabel* iconLabel = new QLabel(this);
- iconLabel->setPixmap(QPixmap(":/icons/Icon-128.png"));
- iconLabel->setAlignment(Qt::AlignHCenter);
- layout->addWidget(iconLabel);
-
- QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this);
- layout->addWidget(appNameLabel);
-
- QLabel* versionLabel = new QLabel(QString("<center><font size='-1'>Version ") + QCoreApplication::applicationVersion() + "</font></center>", this);
- layout->addWidget(versionLabel);
- QString buildString = QString("<center><font size='-1'>Built with: Qt version ") + QT_VERSION_STR;
- buildString += QString("<br/>Running with Qt version ") + qVersion();
- buildString += "</font></center>";
- QLabel* buildLabel = new QLabel(buildString, this);
- layout->addWidget(buildLabel);
-
- setFixedSize(minimumSizeHint());
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle("About Slimber");
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+
+ QLabel* iconLabel = new QLabel(this);
+ iconLabel->setPixmap(QPixmap(":/icons/Icon-128.png"));
+ iconLabel->setAlignment(Qt::AlignHCenter);
+ layout->addWidget(iconLabel);
+
+ QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this);
+ layout->addWidget(appNameLabel);
+
+ QLabel* versionLabel = new QLabel(QString("<center><font size='-1'>Version ") + QCoreApplication::applicationVersion() + "</font></center>", this);
+ layout->addWidget(versionLabel);
+ QString buildString = QString("<center><font size='-1'>Built with: Qt version ") + QT_VERSION_STR;
+ buildString += QString("<br/>Running with Qt version ") + qVersion();
+ buildString += "</font></center>";
+ QLabel* buildLabel = new QLabel(buildString, this);
+ layout->addWidget(buildLabel);
+
+ setFixedSize(minimumSizeHint());
}
diff --git a/Slimber/Qt/QtAboutDialog.h b/Slimber/Qt/QtAboutDialog.h
index d19d209..1f14ebe 100644
--- a/Slimber/Qt/QtAboutDialog.h
+++ b/Slimber/Qt/QtAboutDialog.h
@@ -9,6 +9,6 @@
#include <QDialog>
class QtAboutDialog : public QDialog {
- public:
- QtAboutDialog();
+ public:
+ QtAboutDialog();
};
diff --git a/Slimber/Qt/QtMenulet.h b/Slimber/Qt/QtMenulet.h
index 1aed329..fa17d21 100644
--- a/Slimber/Qt/QtMenulet.h
+++ b/Slimber/Qt/QtMenulet.h
@@ -18,65 +18,65 @@
#include <Slimber/Qt/QtAboutDialog.h>
class QtMenulet : public QObject, public Menulet {
- Q_OBJECT
- public:
- QtMenulet() {
- trayIcon.setIcon(QPixmap(":/icons/UsersOffline.png"));
- trayIcon.setContextMenu(&menu);
- trayIcon.show();
- }
+ Q_OBJECT
+ public:
+ QtMenulet() {
+ trayIcon.setIcon(QPixmap(":/icons/UsersOffline.png"));
+ trayIcon.setContextMenu(&menu);
+ trayIcon.show();
+ }
- void clear() {
- menu.clear();
- }
+ void clear() {
+ menu.clear();
+ }
- void addItem(const std::string& name, const std::string& icon) {
- menu.addAction(getIcon(icon), QString::fromUtf8(name.c_str()));
- }
+ void addItem(const std::string& name, const std::string& icon) {
+ menu.addAction(getIcon(icon), QString::fromUtf8(name.c_str()));
+ }
- void addAboutItem() {
- menu.addAction("About", this, SLOT(showAboutDialog()));
- }
+ void addAboutItem() {
+ menu.addAction("About", this, SLOT(showAboutDialog()));
+ }
- void addRestartItem() {
- menu.addAction("Restart", this, SLOT(restart()));
- }
+ void addRestartItem() {
+ menu.addAction("Restart", this, SLOT(restart()));
+ }
- void addExitItem() {
- menu.addAction("Exit", qApp, SLOT(quit()));
- }
+ void addExitItem() {
+ menu.addAction("Exit", qApp, SLOT(quit()));
+ }
- void addSeparator() {
- menu.addSeparator();
- }
+ void addSeparator() {
+ menu.addSeparator();
+ }
- void setIcon(const std::string& icon) {
- trayIcon.setIcon(getIcon(icon));
- }
+ void setIcon(const std::string& icon) {
+ trayIcon.setIcon(getIcon(icon));
+ }
- private:
- QPixmap getIcon(const std::string& name) {
- return QPixmap(":/icons/" + QString::fromUtf8(name.c_str()) + ".png");
- }
+ private:
+ QPixmap getIcon(const std::string& name) {
+ return QPixmap(":/icons/" + QString::fromUtf8(name.c_str()) + ".png");
+ }
- private slots:
- void showAboutDialog() {
- if (aboutDialog) {
- aboutDialog->raise();
- aboutDialog->activateWindow();
- }
- else {
- aboutDialog = new QtAboutDialog();
- aboutDialog->show();
- }
- }
+ private slots:
+ void showAboutDialog() {
+ if (aboutDialog) {
+ aboutDialog->raise();
+ aboutDialog->activateWindow();
+ }
+ else {
+ aboutDialog = new QtAboutDialog();
+ aboutDialog->show();
+ }
+ }
- void restart() {
- onRestartClicked();
- }
+ void restart() {
+ onRestartClicked();
+ }
- private:
- QMenu menu;
- QSystemTrayIcon trayIcon;
- QPointer<QtAboutDialog> aboutDialog;
+ private:
+ QMenu menu;
+ QSystemTrayIcon trayIcon;
+ QPointer<QtAboutDialog> aboutDialog;
};
diff --git a/Slimber/Qt/main.cpp b/Slimber/Qt/main.cpp
index 69a8b6e..8fbfbb6 100644
--- a/Slimber/Qt/main.cpp
+++ b/Slimber/Qt/main.cpp
@@ -16,21 +16,21 @@
#include <Slimber/Qt/QtMenulet.h>
int main(int argc, char* argv[]) {
- QApplication app(argc, argv);
- Swift::QtEventLoop eventLoop;
+ QApplication app(argc, argv);
+ Swift::QtEventLoop eventLoop;
- QCoreApplication::setApplicationName("Slimber");
- QCoreApplication::setApplicationVersion(QString(buildVersion));
+ QCoreApplication::setApplicationName("Slimber");
+ QCoreApplication::setApplicationVersion(QString(buildVersion));
- if (!QSystemTrayIcon::isSystemTrayAvailable()) {
+ if (!QSystemTrayIcon::isSystemTrayAvailable()) {
QMessageBox::critical(0, QObject::tr("Systray"), QObject::tr("No system tray"));
- return 1;
- }
+ return 1;
+ }
- app.setQuitOnLastWindowClosed(false);
+ app.setQuitOnLastWindowClosed(false);
- QtMenulet menulet;
- MainController controller(&menulet, &eventLoop);
+ QtMenulet menulet;
+ MainController controller(&menulet, &eventLoop);
- return app.exec();
+ return app.exec();
}
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index 79dc22d..c69c75d 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -39,401 +39,401 @@
namespace Swift {
Server::Server(
- int clientConnectionPort,
- int linkLocalConnectionPort,
- LinkLocalServiceBrowser* linkLocalServiceBrowser,
- VCardCollection* vCardCollection,
- EventLoop* eventLoop) :
- linkLocalServiceRegistered(false),
- rosterRequested(false),
- clientConnectionPort(clientConnectionPort),
- linkLocalConnectionPort(linkLocalConnectionPort),
- linkLocalServiceBrowser(linkLocalServiceBrowser),
- vCardCollection(vCardCollection),
- eventLoop(eventLoop),
- presenceManager(NULL),
- stopping(false) {
- linkLocalServiceBrowser->onServiceRegistered.connect(
- boost::bind(&Server::handleServiceRegistered, this, _1));
+ int clientConnectionPort,
+ int linkLocalConnectionPort,
+ LinkLocalServiceBrowser* linkLocalServiceBrowser,
+ VCardCollection* vCardCollection,
+ EventLoop* eventLoop) :
+ linkLocalServiceRegistered(false),
+ rosterRequested(false),
+ clientConnectionPort(clientConnectionPort),
+ linkLocalConnectionPort(linkLocalConnectionPort),
+ linkLocalServiceBrowser(linkLocalServiceBrowser),
+ vCardCollection(vCardCollection),
+ eventLoop(eventLoop),
+ presenceManager(NULL),
+ stopping(false) {
+ linkLocalServiceBrowser->onServiceRegistered.connect(
+ boost::bind(&Server::handleServiceRegistered, this, _1));
}
Server::~Server() {
- stop();
+ stop();
}
void Server::start() {
- assert(!serverFromClientConnectionServer);
- serverFromClientConnectionServer = BoostConnectionServer::create(
- clientConnectionPort, boostIOServiceThread.getIOService(), eventLoop);
- serverFromClientConnectionServerSignalConnections.push_back(
- serverFromClientConnectionServer->onNewConnection.connect(
- boost::bind(&Server::handleNewClientConnection, this, _1)));
- serverFromClientConnectionServerSignalConnections.push_back(
- serverFromClientConnectionServer->onStopped.connect(
- boost::bind(&Server::handleClientConnectionServerStopped, this, _1)));
-
- assert(!serverFromNetworkConnectionServer);
- serverFromNetworkConnectionServer = BoostConnectionServer::create(
- linkLocalConnectionPort, boostIOServiceThread.getIOService(), eventLoop);
- serverFromNetworkConnectionServerSignalConnections.push_back(
- serverFromNetworkConnectionServer->onNewConnection.connect(
- boost::bind(&Server::handleNewLinkLocalConnection, this, _1)));
- serverFromNetworkConnectionServerSignalConnections.push_back(
- serverFromNetworkConnectionServer->onStopped.connect(
- boost::bind(&Server::handleLinkLocalConnectionServerStopped, this, _1)));
-
- assert(!presenceManager);
- presenceManager = new LinkLocalPresenceManager(linkLocalServiceBrowser);
- presenceManager->onRosterChanged.connect(
- boost::bind(&Server::handleRosterChanged, this, _1));
- presenceManager->onPresenceChanged.connect(
- boost::bind(&Server::handlePresenceChanged, this, _1));
-
- serverFromClientConnectionServer->start();
- serverFromNetworkConnectionServer->start();
+ assert(!serverFromClientConnectionServer);
+ serverFromClientConnectionServer = BoostConnectionServer::create(
+ clientConnectionPort, boostIOServiceThread.getIOService(), eventLoop);
+ serverFromClientConnectionServerSignalConnections.push_back(
+ serverFromClientConnectionServer->onNewConnection.connect(
+ boost::bind(&Server::handleNewClientConnection, this, _1)));
+ serverFromClientConnectionServerSignalConnections.push_back(
+ serverFromClientConnectionServer->onStopped.connect(
+ boost::bind(&Server::handleClientConnectionServerStopped, this, _1)));
+
+ assert(!serverFromNetworkConnectionServer);
+ serverFromNetworkConnectionServer = BoostConnectionServer::create(
+ linkLocalConnectionPort, boostIOServiceThread.getIOService(), eventLoop);
+ serverFromNetworkConnectionServerSignalConnections.push_back(
+ serverFromNetworkConnectionServer->onNewConnection.connect(
+ boost::bind(&Server::handleNewLinkLocalConnection, this, _1)));
+ serverFromNetworkConnectionServerSignalConnections.push_back(
+ serverFromNetworkConnectionServer->onStopped.connect(
+ boost::bind(&Server::handleLinkLocalConnectionServerStopped, this, _1)));
+
+ assert(!presenceManager);
+ presenceManager = new LinkLocalPresenceManager(linkLocalServiceBrowser);
+ presenceManager->onRosterChanged.connect(
+ boost::bind(&Server::handleRosterChanged, this, _1));
+ presenceManager->onPresenceChanged.connect(
+ boost::bind(&Server::handlePresenceChanged, this, _1));
+
+ serverFromClientConnectionServer->start();
+ serverFromNetworkConnectionServer->start();
}
void Server::stop() {
- stop(boost::optional<ServerError>());
+ stop(boost::optional<ServerError>());
}
void Server::stop(boost::optional<ServerError> e) {
- if (stopping) {
- return;
- }
-
- stopping = true;
-
- delete presenceManager;
- presenceManager = NULL;
-
- if (serverFromClientSession) {
- serverFromClientSession->finishSession();
- }
- serverFromClientSession.reset();
- foreach(boost::shared_ptr<Session> session, linkLocalSessions) {
- session->finishSession();
- }
- linkLocalSessions.clear();
- foreach(boost::shared_ptr<LinkLocalConnector> connector, connectors) {
- connector->cancel();
- }
- connectors.clear();
- tracers.clear();
-
- if (serverFromNetworkConnectionServer) {
- serverFromNetworkConnectionServer->stop();
- foreach(boost::bsignals::connection& connection, serverFromNetworkConnectionServerSignalConnections) {
- connection.disconnect();
- }
- serverFromNetworkConnectionServerSignalConnections.clear();
- serverFromNetworkConnectionServer.reset();
- }
- if (serverFromClientConnectionServer) {
- serverFromClientConnectionServer->stop();
- foreach(boost::bsignals::connection& connection, serverFromClientConnectionServerSignalConnections) {
- connection.disconnect();
- }
- serverFromClientConnectionServerSignalConnections.clear();
- serverFromClientConnectionServer.reset();
- }
-
- stopping = false;
- onStopped(e);
+ if (stopping) {
+ return;
+ }
+
+ stopping = true;
+
+ delete presenceManager;
+ presenceManager = NULL;
+
+ if (serverFromClientSession) {
+ serverFromClientSession->finishSession();
+ }
+ serverFromClientSession.reset();
+ foreach(boost::shared_ptr<Session> session, linkLocalSessions) {
+ session->finishSession();
+ }
+ linkLocalSessions.clear();
+ foreach(boost::shared_ptr<LinkLocalConnector> connector, connectors) {
+ connector->cancel();
+ }
+ connectors.clear();
+ tracers.clear();
+
+ if (serverFromNetworkConnectionServer) {
+ serverFromNetworkConnectionServer->stop();
+ foreach(boost::bsignals::connection& connection, serverFromNetworkConnectionServerSignalConnections) {
+ connection.disconnect();
+ }
+ serverFromNetworkConnectionServerSignalConnections.clear();
+ serverFromNetworkConnectionServer.reset();
+ }
+ if (serverFromClientConnectionServer) {
+ serverFromClientConnectionServer->stop();
+ foreach(boost::bsignals::connection& connection, serverFromClientConnectionServerSignalConnections) {
+ connection.disconnect();
+ }
+ serverFromClientConnectionServerSignalConnections.clear();
+ serverFromClientConnectionServer.reset();
+ }
+
+ stopping = false;
+ onStopped(e);
}
void Server::handleNewClientConnection(boost::shared_ptr<Connection> connection) {
- if (serverFromClientSession) {
- connection->disconnect();
- }
- serverFromClientSession = boost::shared_ptr<ServerFromClientSession>(
- new ServerFromClientSession(idGenerator.generateID(), connection,
- &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry));
- serverFromClientSession->setAllowSASLEXTERNAL();
- serverFromClientSession->onSessionStarted.connect(
- boost::bind(&Server::handleSessionStarted, this));
- serverFromClientSession->onElementReceived.connect(
- boost::bind(&Server::handleElementReceived, this, _1,
- serverFromClientSession));
- serverFromClientSession->onSessionFinished.connect(
- boost::bind(&Server::handleSessionFinished, this,
- serverFromClientSession));
- //tracers.push_back(boost::shared_ptr<SessionTracer>(
- // new SessionTracer(serverFromClientSession)));
- serverFromClientSession->startSession();
+ if (serverFromClientSession) {
+ connection->disconnect();
+ }
+ serverFromClientSession = boost::shared_ptr<ServerFromClientSession>(
+ new ServerFromClientSession(idGenerator.generateID(), connection,
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry));
+ serverFromClientSession->setAllowSASLEXTERNAL();
+ serverFromClientSession->onSessionStarted.connect(
+ boost::bind(&Server::handleSessionStarted, this));
+ serverFromClientSession->onElementReceived.connect(
+ boost::bind(&Server::handleElementReceived, this, _1,
+ serverFromClientSession));
+ serverFromClientSession->onSessionFinished.connect(
+ boost::bind(&Server::handleSessionFinished, this,
+ serverFromClientSession));
+ //tracers.push_back(boost::shared_ptr<SessionTracer>(
+ // new SessionTracer(serverFromClientSession)));
+ serverFromClientSession->startSession();
}
void Server::handleSessionStarted() {
- onSelfConnected(true);
+ onSelfConnected(true);
}
void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession>) {
- serverFromClientSession.reset();
- unregisterService();
- selfJID = JID();
- rosterRequested = false;
- onSelfConnected(false);
- lastPresence.reset();
+ serverFromClientSession.reset();
+ unregisterService();
+ selfJID = JID();
+ rosterRequested = false;
+ onSelfConnected(false);
+ lastPresence.reset();
}
void Server::unregisterService() {
- if (linkLocalServiceRegistered) {
- linkLocalServiceRegistered = false;
- linkLocalServiceBrowser->unregisterService();
- }
+ if (linkLocalServiceRegistered) {
+ linkLocalServiceRegistered = false;
+ linkLocalServiceBrowser->unregisterService();
+ }
}
void Server::handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session) {
- boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element);
- if (!stanza) {
- return;
- }
-
- stanza->setFrom(session->getRemoteJID());
- if (!stanza->getTo().isValid()) {
- stanza->setTo(session->getLocalJID());
- }
-
- if (boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(stanza)) {
- if (presence->getType() == Presence::Available) {
- if (!linkLocalServiceRegistered) {
- linkLocalServiceRegistered = true;
- linkLocalServiceBrowser->registerService(
- session->getRemoteJID().toBare().toString(),
- linkLocalConnectionPort, getLinkLocalServiceInfo(presence));
- }
- else {
- linkLocalServiceBrowser->updateService(
- getLinkLocalServiceInfo(presence));
- }
- lastPresence = presence;
- }
- else {
- unregisterService();
- }
- }
- else if (!stanza->getTo().isValid() || stanza->getTo() == session->getLocalJID() || stanza->getTo() == session->getRemoteJID().toBare()) {
- if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(stanza)) {
- if (iq->getPayload<RosterPayload>()) {
- if (iq->getType() == IQ::Get) {
- session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), presenceManager->getRoster()));
- rosterRequested = true;
- foreach(const boost::shared_ptr<Presence> presence, presenceManager->getAllPresence()) {
- session->sendElement(presence);
- }
- }
- else {
- session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel));
- }
- }
- if (boost::shared_ptr<VCard> vcard = iq->getPayload<VCard>()) {
- if (iq->getType() == IQ::Get) {
- session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vCardCollection->getOwnVCard()));
- }
- else {
- vCardCollection->setOwnVCard(vcard);
- session->sendElement(IQ::createResult(iq->getFrom(), iq->getID()));
- if (lastPresence) {
- linkLocalServiceBrowser->updateService(getLinkLocalServiceInfo(lastPresence));
- }
- }
- }
- else {
- session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel));
- }
- }
- }
- else {
- JID toJID = stanza->getTo();
- boost::shared_ptr<Session> outgoingSession =
- getLinkLocalSessionForJID(toJID);
- if (outgoingSession) {
- outgoingSession->sendElement(stanza);
- }
- else {
- boost::optional<LinkLocalService> service =
- presenceManager->getServiceForJID(toJID);
- if (service) {
- boost::shared_ptr<LinkLocalConnector> connector =
- getLinkLocalConnectorForJID(toJID);
- if (!connector) {
- connector = boost::shared_ptr<LinkLocalConnector>(
- new LinkLocalConnector(
- *service,
- linkLocalServiceBrowser->getQuerier(),
- BoostConnection::create(boostIOServiceThread.getIOService(), eventLoop)));
- connector->onConnectFinished.connect(
- boost::bind(&Server::handleConnectFinished, this, connector, _1));
- connectors.push_back(connector);
- connector->connect();
- }
- connector->queueElement(element);
- }
- else {
- session->sendElement(IQ::createError(
- stanza->getFrom(), stanza->getID(),
- ErrorPayload::RecipientUnavailable, ErrorPayload::Wait));
- }
- }
- }
+ boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element);
+ if (!stanza) {
+ return;
+ }
+
+ stanza->setFrom(session->getRemoteJID());
+ if (!stanza->getTo().isValid()) {
+ stanza->setTo(session->getLocalJID());
+ }
+
+ if (boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(stanza)) {
+ if (presence->getType() == Presence::Available) {
+ if (!linkLocalServiceRegistered) {
+ linkLocalServiceRegistered = true;
+ linkLocalServiceBrowser->registerService(
+ session->getRemoteJID().toBare().toString(),
+ linkLocalConnectionPort, getLinkLocalServiceInfo(presence));
+ }
+ else {
+ linkLocalServiceBrowser->updateService(
+ getLinkLocalServiceInfo(presence));
+ }
+ lastPresence = presence;
+ }
+ else {
+ unregisterService();
+ }
+ }
+ else if (!stanza->getTo().isValid() || stanza->getTo() == session->getLocalJID() || stanza->getTo() == session->getRemoteJID().toBare()) {
+ if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(stanza)) {
+ if (iq->getPayload<RosterPayload>()) {
+ if (iq->getType() == IQ::Get) {
+ session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), presenceManager->getRoster()));
+ rosterRequested = true;
+ foreach(const boost::shared_ptr<Presence> presence, presenceManager->getAllPresence()) {
+ session->sendElement(presence);
+ }
+ }
+ else {
+ session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel));
+ }
+ }
+ if (boost::shared_ptr<VCard> vcard = iq->getPayload<VCard>()) {
+ if (iq->getType() == IQ::Get) {
+ session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vCardCollection->getOwnVCard()));
+ }
+ else {
+ vCardCollection->setOwnVCard(vcard);
+ session->sendElement(IQ::createResult(iq->getFrom(), iq->getID()));
+ if (lastPresence) {
+ linkLocalServiceBrowser->updateService(getLinkLocalServiceInfo(lastPresence));
+ }
+ }
+ }
+ else {
+ session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel));
+ }
+ }
+ }
+ else {
+ JID toJID = stanza->getTo();
+ boost::shared_ptr<Session> outgoingSession =
+ getLinkLocalSessionForJID(toJID);
+ if (outgoingSession) {
+ outgoingSession->sendElement(stanza);
+ }
+ else {
+ boost::optional<LinkLocalService> service =
+ presenceManager->getServiceForJID(toJID);
+ if (service) {
+ boost::shared_ptr<LinkLocalConnector> connector =
+ getLinkLocalConnectorForJID(toJID);
+ if (!connector) {
+ connector = boost::shared_ptr<LinkLocalConnector>(
+ new LinkLocalConnector(
+ *service,
+ linkLocalServiceBrowser->getQuerier(),
+ BoostConnection::create(boostIOServiceThread.getIOService(), eventLoop)));
+ connector->onConnectFinished.connect(
+ boost::bind(&Server::handleConnectFinished, this, connector, _1));
+ connectors.push_back(connector);
+ connector->connect();
+ }
+ connector->queueElement(element);
+ }
+ else {
+ session->sendElement(IQ::createError(
+ stanza->getFrom(), stanza->getID(),
+ ErrorPayload::RecipientUnavailable, ErrorPayload::Wait));
+ }
+ }
+ }
}
void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection) {
- boost::shared_ptr<IncomingLinkLocalSession> session(
- new IncomingLinkLocalSession(
- selfJID, connection,
- &payloadParserFactories, &payloadSerializers, &xmlParserFactory));
- registerLinkLocalSession(session);
+ boost::shared_ptr<IncomingLinkLocalSession> session(
+ new IncomingLinkLocalSession(
+ selfJID, connection,
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory));
+ registerLinkLocalSession(session);
}
void Server::handleLinkLocalSessionFinished(boost::shared_ptr<Session> session) {
- //std::cout << "Link local session from " << session->getRemoteJID() << " ended" << std::endl;
- linkLocalSessions.erase(
- std::remove(linkLocalSessions.begin(), linkLocalSessions.end(), session),
- linkLocalSessions.end());
+ //std::cout << "Link local session from " << session->getRemoteJID() << " ended" << std::endl;
+ linkLocalSessions.erase(
+ std::remove(linkLocalSessions.begin(), linkLocalSessions.end(), session),
+ linkLocalSessions.end());
}
void Server::handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> 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);
- }
+ 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<ToplevelElement> element, connector->getQueuedElements()) {
- outgoingSession->queueElement(element);
- }
- registerLinkLocalSession(outgoingSession);
- }
- connectors.erase(std::remove(connectors.begin(), connectors.end(), connector), connectors.end());
+ 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<ToplevelElement> 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::make_shared<SessionTracer>(session));
- session->startSession();
+ 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::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>();
+ 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>();
+ 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());
+ 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);
- }
+ 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);
+ }
}
void Server::handlePresenceChanged(boost::shared_ptr<Presence> presence) {
- if (rosterRequested) {
- serverFromClientSession->sendElement(presence);
- }
+ if (rosterRequested) {
+ serverFromClientSession->sendElement(presence);
+ }
}
void Server::handleClientConnectionServerStopped(boost::optional<BoostConnectionServer::Error> e) {
- if (e) {
- if (*e == BoostConnectionServer::Conflict) {
- stop(ServerError(ServerError::C2SPortConflict));
- }
- else {
- stop(ServerError(ServerError::C2SError));
- }
- }
- else {
- stop();
- }
+ if (e) {
+ if (*e == BoostConnectionServer::Conflict) {
+ stop(ServerError(ServerError::C2SPortConflict));
+ }
+ else {
+ stop(ServerError(ServerError::C2SError));
+ }
+ }
+ else {
+ stop();
+ }
}
void Server::handleLinkLocalConnectionServerStopped(boost::optional<BoostConnectionServer::Error> e) {
- if (e) {
- if (*e == BoostConnectionServer::Conflict) {
- stop(ServerError(ServerError::LinkLocalPortConflict));
- }
- else {
- stop(ServerError(ServerError::LinkLocalError));
- }
- }
- else {
- stop();
- }
+ if (e) {
+ if (*e == BoostConnectionServer::Conflict) {
+ stop(ServerError(ServerError::LinkLocalPortConflict));
+ }
+ else {
+ stop(ServerError(ServerError::LinkLocalError));
+ }
+ }
+ else {
+ stop();
+ }
}
LinkLocalServiceInfo Server::getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence) {
- LinkLocalServiceInfo info;
- boost::shared_ptr<VCard> vcard = vCardCollection->getOwnVCard();
- if (!vcard->getFamilyName().empty() || !vcard->getGivenName().empty()) {
- info.setFirstName(vcard->getGivenName());
- info.setLastName(vcard->getFamilyName());
- }
- else if (!vcard->getFullName().empty()) {
- std::pair<std::string,std::string> p = String::getSplittedAtFirst(vcard->getFullName(), ' ');
- info.setFirstName(p.first);
- info.setLastName(p.second);
- }
- if (!vcard->getNickname().empty()) {
- info.setNick(vcard->getNickname());
- }
- if (!vcard->getPreferredEMailAddress().address.empty()) {
- info.setEMail(vcard->getPreferredEMailAddress().address);
- }
- info.setMessage(presence->getStatus());
- switch (presence->getShow()) {
- case StatusShow::Online:
- case StatusShow::None:
- case StatusShow::FFC:
- info.setStatus(LinkLocalServiceInfo::Available);
- break;
- case StatusShow::Away:
- case StatusShow::XA:
- info.setStatus(LinkLocalServiceInfo::Away);
- break;
- case StatusShow::DND:
- info.setStatus(LinkLocalServiceInfo::DND);
- break;
- }
- info.setPort(linkLocalConnectionPort);
- return info;
+ LinkLocalServiceInfo info;
+ boost::shared_ptr<VCard> vcard = vCardCollection->getOwnVCard();
+ if (!vcard->getFamilyName().empty() || !vcard->getGivenName().empty()) {
+ info.setFirstName(vcard->getGivenName());
+ info.setLastName(vcard->getFamilyName());
+ }
+ else if (!vcard->getFullName().empty()) {
+ std::pair<std::string,std::string> p = String::getSplittedAtFirst(vcard->getFullName(), ' ');
+ info.setFirstName(p.first);
+ info.setLastName(p.second);
+ }
+ if (!vcard->getNickname().empty()) {
+ info.setNick(vcard->getNickname());
+ }
+ if (!vcard->getPreferredEMailAddress().address.empty()) {
+ info.setEMail(vcard->getPreferredEMailAddress().address);
+ }
+ info.setMessage(presence->getStatus());
+ switch (presence->getShow()) {
+ case StatusShow::Online:
+ case StatusShow::None:
+ case StatusShow::FFC:
+ info.setStatus(LinkLocalServiceInfo::Available);
+ break;
+ case StatusShow::Away:
+ case StatusShow::XA:
+ info.setStatus(LinkLocalServiceInfo::Away);
+ break;
+ case StatusShow::DND:
+ info.setStatus(LinkLocalServiceInfo::DND);
+ break;
+ }
+ info.setPort(linkLocalConnectionPort);
+ return info;
}
}
diff --git a/Slimber/Server.h b/Slimber/Server.h
index a87381c..7037cdb 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -26,101 +26,101 @@
#include <Slimber/ServerError.h>
namespace Swift {
- class DNSSDServiceID;
-
- class VCardCollection;
- class LinkLocalConnector;
- class LinkLocalServiceBrowser;
- class LinkLocalPresenceManager;
- class BoostConnectionServer;
- class SessionTracer;
- class RosterPayload;
- class Presence;
- class EventLoop;
-
- class Server {
- public:
- Server(
- int clientConnectionPort,
- int linkLocalConnectionPort,
- LinkLocalServiceBrowser* browser,
- VCardCollection* vCardCollection,
- EventLoop* eventLoop);
- ~Server();
-
- void start();
- void stop();
-
- int getLinkLocalPort() const {
- return linkLocalConnectionPort;
- }
-
- int getClientToServerPort() const {
- return clientConnectionPort;
- }
-
- boost::signal<void (bool)> onSelfConnected;
- boost::signal<void (boost::optional<ServerError>)> onStopped;
-
- private:
- void stop(boost::optional<ServerError>);
-
- void handleNewClientConnection(boost::shared_ptr<Connection> c);
- void handleSessionStarted();
- void handleSessionFinished(boost::shared_ptr<ServerFromClientSession>);
- void handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session);
- void handleRosterChanged(boost::shared_ptr<RosterPayload> roster);
- void handlePresenceChanged(boost::shared_ptr<Presence> presence);
- void handleServiceRegistered(const DNSSDServiceID& service);
- void handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection);
- void handleLinkLocalSessionFinished(boost::shared_ptr<Session> session);
- void handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<Session> session);
- void handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error);
- void handleClientConnectionServerStopped(
- boost::optional<BoostConnectionServer::Error>);
- void handleLinkLocalConnectionServerStopped(
- boost::optional<BoostConnectionServer::Error>);
- boost::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid);
- boost::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid);
- void registerLinkLocalSession(boost::shared_ptr<Session> session);
- void unregisterService();
- LinkLocalServiceInfo getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence);
-
- private:
- class DummyUserRegistry : public UserRegistry {
- public:
- DummyUserRegistry() {}
-
- virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const {
- return true;
- }
- };
-
- private:
- IDGenerator idGenerator;
- FullPayloadParserFactoryCollection payloadParserFactories;
- FullPayloadSerializerCollection payloadSerializers;
- BoostIOServiceThread boostIOServiceThread;
- DummyUserRegistry userRegistry;
- PlatformXMLParserFactory xmlParserFactory;
- bool linkLocalServiceRegistered;
- bool rosterRequested;
- int clientConnectionPort;
- int linkLocalConnectionPort;
- LinkLocalServiceBrowser* linkLocalServiceBrowser;
- VCardCollection* vCardCollection;
- EventLoop* eventLoop;
- LinkLocalPresenceManager* presenceManager;
- bool stopping;
- boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer;
- std::vector<boost::bsignals::connection> serverFromClientConnectionServerSignalConnections;
- boost::shared_ptr<ServerFromClientSession> serverFromClientSession;
- boost::shared_ptr<Presence> lastPresence;
- JID selfJID;
- boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer;
- std::vector<boost::bsignals::connection> serverFromNetworkConnectionServerSignalConnections;
- std::vector< boost::shared_ptr<Session> > linkLocalSessions;
- std::vector< boost::shared_ptr<LinkLocalConnector> > connectors;
- std::vector< boost::shared_ptr<SessionTracer> > tracers;
- };
+ class DNSSDServiceID;
+
+ class VCardCollection;
+ class LinkLocalConnector;
+ class LinkLocalServiceBrowser;
+ class LinkLocalPresenceManager;
+ class BoostConnectionServer;
+ class SessionTracer;
+ class RosterPayload;
+ class Presence;
+ class EventLoop;
+
+ class Server {
+ public:
+ Server(
+ int clientConnectionPort,
+ int linkLocalConnectionPort,
+ LinkLocalServiceBrowser* browser,
+ VCardCollection* vCardCollection,
+ EventLoop* eventLoop);
+ ~Server();
+
+ void start();
+ void stop();
+
+ int getLinkLocalPort() const {
+ return linkLocalConnectionPort;
+ }
+
+ int getClientToServerPort() const {
+ return clientConnectionPort;
+ }
+
+ boost::signal<void (bool)> onSelfConnected;
+ boost::signal<void (boost::optional<ServerError>)> onStopped;
+
+ private:
+ void stop(boost::optional<ServerError>);
+
+ void handleNewClientConnection(boost::shared_ptr<Connection> c);
+ void handleSessionStarted();
+ void handleSessionFinished(boost::shared_ptr<ServerFromClientSession>);
+ void handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session);
+ void handleRosterChanged(boost::shared_ptr<RosterPayload> roster);
+ void handlePresenceChanged(boost::shared_ptr<Presence> presence);
+ void handleServiceRegistered(const DNSSDServiceID& service);
+ void handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection);
+ void handleLinkLocalSessionFinished(boost::shared_ptr<Session> session);
+ void handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<Session> session);
+ void handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error);
+ void handleClientConnectionServerStopped(
+ boost::optional<BoostConnectionServer::Error>);
+ void handleLinkLocalConnectionServerStopped(
+ boost::optional<BoostConnectionServer::Error>);
+ boost::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid);
+ boost::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid);
+ void registerLinkLocalSession(boost::shared_ptr<Session> session);
+ void unregisterService();
+ LinkLocalServiceInfo getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence);
+
+ private:
+ class DummyUserRegistry : public UserRegistry {
+ public:
+ DummyUserRegistry() {}
+
+ virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const {
+ return true;
+ }
+ };
+
+ private:
+ IDGenerator idGenerator;
+ FullPayloadParserFactoryCollection payloadParserFactories;
+ FullPayloadSerializerCollection payloadSerializers;
+ BoostIOServiceThread boostIOServiceThread;
+ DummyUserRegistry userRegistry;
+ PlatformXMLParserFactory xmlParserFactory;
+ bool linkLocalServiceRegistered;
+ bool rosterRequested;
+ int clientConnectionPort;
+ int linkLocalConnectionPort;
+ LinkLocalServiceBrowser* linkLocalServiceBrowser;
+ VCardCollection* vCardCollection;
+ EventLoop* eventLoop;
+ LinkLocalPresenceManager* presenceManager;
+ bool stopping;
+ boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer;
+ std::vector<boost::bsignals::connection> serverFromClientConnectionServerSignalConnections;
+ boost::shared_ptr<ServerFromClientSession> serverFromClientSession;
+ boost::shared_ptr<Presence> lastPresence;
+ JID selfJID;
+ boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer;
+ std::vector<boost::bsignals::connection> serverFromNetworkConnectionServerSignalConnections;
+ std::vector< boost::shared_ptr<Session> > linkLocalSessions;
+ std::vector< boost::shared_ptr<LinkLocalConnector> > connectors;
+ std::vector< boost::shared_ptr<SessionTracer> > tracers;
+ };
}
diff --git a/Slimber/ServerError.h b/Slimber/ServerError.h
index b8cb0a5..93b6a3f 100644
--- a/Slimber/ServerError.h
+++ b/Slimber/ServerError.h
@@ -9,29 +9,29 @@
#include <string>
namespace Swift {
- class ServerError {
- public:
- enum Type {
- C2SPortConflict,
- C2SError,
- LinkLocalPortConflict,
- LinkLocalError
- };
+ class ServerError {
+ public:
+ enum Type {
+ C2SPortConflict,
+ C2SError,
+ LinkLocalPortConflict,
+ LinkLocalError
+ };
- ServerError(Type type, const std::string& message = std::string()) :
- type(type), message(message) {
- }
+ ServerError(Type type, const std::string& message = std::string()) :
+ type(type), message(message) {
+ }
- Type getType() const {
- return type;
- }
+ Type getType() const {
+ return type;
+ }
- const std::string& getMessage() const {
- return message;
- }
+ const std::string& getMessage() const {
+ return message;
+ }
- private:
- Type type;
- std::string message;
- };
+ private:
+ Type type;
+ std::string message;
+ };
}
diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
index 2681c1a..45bc2aa 100644
--- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
+++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
@@ -26,239 +26,239 @@
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::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());
- }
-
- void testServiceRemoved() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland");
- removeService("alice@wonderland");
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterChanges.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[1]->getItems().size()));
- boost::optional<RosterItemPayload> item = rosterChanges[1]->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Remove, item->getSubscription());
- }
-
- void testServiceChanged() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland");
- updateServicePresence("alice@wonderland", LinkLocalServiceInfo::Away, "I'm Away");
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size()));
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presenceChanges.size()));
- CPPUNIT_ASSERT(StatusShow::Away == presenceChanges[1]->getShow());
- CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[1]->getFrom());
- CPPUNIT_ASSERT_EQUAL(std::string("I'm Away"), presenceChanges[1]->getStatus());
- }
-
- void testGetAllPresence() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland");
- addService("rabbit@teaparty");
- updateServicePresence("rabbit@teaparty", LinkLocalServiceInfo::Away, "Partying");
-
- std::vector<boost::shared_ptr<Presence> > presences = testling->getAllPresence();
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presences.size()));
- // The order doesn't matter
- CPPUNIT_ASSERT(JID("rabbit@teaparty") == presences[0]->getFrom());
- CPPUNIT_ASSERT(StatusShow::Away == presences[0]->getShow());
- CPPUNIT_ASSERT(JID("alice@wonderland") == presences[1]->getFrom());
- CPPUNIT_ASSERT(StatusShow::Online == presences[1]->getShow());
- }
-
- void testGetRoster() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland", "Alice");
- addService("rabbit@teaparty", "Rabbit");
-
- boost::shared_ptr<RosterPayload> roster = testling->getRoster();
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster->getItems().size()));
- boost::optional<RosterItemPayload> item;
- item = roster->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName());
- CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription());
- item = roster->getItem(JID("rabbit@teaparty"));
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), item->getName());
- CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription());
- }
-
- void testGetRoster_InfoWithNick() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland", "Alice", "Alice In", "Wonderland");
-
- boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName());
- }
-
- void testGetRoster_InfoWithFirstName() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland", "", "Alice In", "");
-
- boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT_EQUAL(std::string("Alice In"), item->getName());
- }
-
- void testGetRoster_InfoWithLastName() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland", "", "", "Wonderland");
-
- boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), item->getName());
- }
-
- void testGetRoster_InfoWithFirstAndLastName() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland", "", "Alice In", "Wonderland");
-
- boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), item->getName());
- }
-
- void testGetRoster_NoInfo() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland");
-
- boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
- CPPUNIT_ASSERT_EQUAL(std::string(""), item->getName());
- }
-
- void testGetServiceForJID() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland");
- addService("rabbit@teaparty");
- addService("queen@garden");
-
- boost::optional<LinkLocalService> service = testling->getServiceForJID(JID("rabbit@teaparty"));
- CPPUNIT_ASSERT(service);
- CPPUNIT_ASSERT_EQUAL(std::string("rabbit@teaparty"), service->getID().getName());
- }
-
- void testGetServiceForJID_NoMatch() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
-
- addService("alice@wonderland");
- addService("queen@garden");
-
- CPPUNIT_ASSERT(!testling->getServiceForJID(JID("rabbit@teaparty")));
- }
-
- private:
- boost::shared_ptr<LinkLocalPresenceManager> createTestling() {
- boost::shared_ptr<LinkLocalPresenceManager> testling(
- new LinkLocalPresenceManager(browser));
- testling->onRosterChanged.connect(boost::bind(
- &LinkLocalPresenceManagerTest::handleRosterChanged, this, _1));
- testling->onPresenceChanged.connect(boost::bind(
- &LinkLocalPresenceManagerTest::handlePresenceChanged, this, _1));
- return testling;
- }
-
- void addService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) {
- DNSSDServiceID service(name, "local.");
- LinkLocalServiceInfo info;
- info.setFirstName(firstName);
- info.setLastName(lastName);
- info.setNick(nickName);
- querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord()));
- querier->addService(service);
- eventLoop->processEvents();
- }
-
- void removeService(const std::string& name) {
- DNSSDServiceID service(name, "local.");
- querier->removeService(DNSSDServiceID(name, "local."));
- eventLoop->processEvents();
- }
-
- void updateServicePresence(const std::string& name, LinkLocalServiceInfo::Status status, const std::string& message) {
- DNSSDServiceID service(name, "local.");
- LinkLocalServiceInfo info;
- info.setStatus(status);
- info.setMessage(message);
- querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord()));
- eventLoop->processEvents();
- }
-
- void handleRosterChanged(boost::shared_ptr<RosterPayload> payload) {
- rosterChanges.push_back(payload);
- }
-
- void handlePresenceChanged(boost::shared_ptr<Presence> presence) {
- presenceChanges.push_back(presence);
- }
-
- private:
- DummyEventLoop* eventLoop;
- boost::shared_ptr<FakeDNSSDQuerier> querier;
- LinkLocalServiceBrowser* browser;
- std::vector< boost::shared_ptr<RosterPayload> > rosterChanges;
- std::vector< boost::shared_ptr<Presence> > presenceChanges;
+ 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::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());
+ }
+
+ void testServiceRemoved() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ removeService("alice@wonderland");
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterChanges.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[1]->getItems().size()));
+ boost::optional<RosterItemPayload> item = rosterChanges[1]->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Remove, item->getSubscription());
+ }
+
+ void testServiceChanged() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ updateServicePresence("alice@wonderland", LinkLocalServiceInfo::Away, "I'm Away");
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size()));
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presenceChanges.size()));
+ CPPUNIT_ASSERT(StatusShow::Away == presenceChanges[1]->getShow());
+ CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[1]->getFrom());
+ CPPUNIT_ASSERT_EQUAL(std::string("I'm Away"), presenceChanges[1]->getStatus());
+ }
+
+ void testGetAllPresence() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ addService("rabbit@teaparty");
+ updateServicePresence("rabbit@teaparty", LinkLocalServiceInfo::Away, "Partying");
+
+ std::vector<boost::shared_ptr<Presence> > presences = testling->getAllPresence();
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presences.size()));
+ // The order doesn't matter
+ CPPUNIT_ASSERT(JID("rabbit@teaparty") == presences[0]->getFrom());
+ CPPUNIT_ASSERT(StatusShow::Away == presences[0]->getShow());
+ CPPUNIT_ASSERT(JID("alice@wonderland") == presences[1]->getFrom());
+ CPPUNIT_ASSERT(StatusShow::Online == presences[1]->getShow());
+ }
+
+ void testGetRoster() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland", "Alice");
+ addService("rabbit@teaparty", "Rabbit");
+
+ boost::shared_ptr<RosterPayload> roster = testling->getRoster();
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster->getItems().size()));
+ boost::optional<RosterItemPayload> item;
+ item = roster->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName());
+ CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription());
+ item = roster->getItem(JID("rabbit@teaparty"));
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), item->getName());
+ CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription());
+ }
+
+ void testGetRoster_InfoWithNick() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland", "Alice", "Alice In", "Wonderland");
+
+ boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName());
+ }
+
+ void testGetRoster_InfoWithFirstName() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland", "", "Alice In", "");
+
+ boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Alice In"), item->getName());
+ }
+
+ void testGetRoster_InfoWithLastName() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland", "", "", "Wonderland");
+
+ boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), item->getName());
+ }
+
+ void testGetRoster_InfoWithFirstAndLastName() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland", "", "Alice In", "Wonderland");
+
+ boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), item->getName());
+ }
+
+ void testGetRoster_NoInfo() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+
+ boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland"));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), item->getName());
+ }
+
+ void testGetServiceForJID() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ addService("rabbit@teaparty");
+ addService("queen@garden");
+
+ boost::optional<LinkLocalService> service = testling->getServiceForJID(JID("rabbit@teaparty"));
+ CPPUNIT_ASSERT(service);
+ CPPUNIT_ASSERT_EQUAL(std::string("rabbit@teaparty"), service->getID().getName());
+ }
+
+ void testGetServiceForJID_NoMatch() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ addService("queen@garden");
+
+ CPPUNIT_ASSERT(!testling->getServiceForJID(JID("rabbit@teaparty")));
+ }
+
+ private:
+ boost::shared_ptr<LinkLocalPresenceManager> createTestling() {
+ boost::shared_ptr<LinkLocalPresenceManager> testling(
+ new LinkLocalPresenceManager(browser));
+ testling->onRosterChanged.connect(boost::bind(
+ &LinkLocalPresenceManagerTest::handleRosterChanged, this, _1));
+ testling->onPresenceChanged.connect(boost::bind(
+ &LinkLocalPresenceManagerTest::handlePresenceChanged, this, _1));
+ return testling;
+ }
+
+ void addService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) {
+ DNSSDServiceID service(name, "local.");
+ LinkLocalServiceInfo info;
+ info.setFirstName(firstName);
+ info.setLastName(lastName);
+ info.setNick(nickName);
+ querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord()));
+ querier->addService(service);
+ eventLoop->processEvents();
+ }
+
+ void removeService(const std::string& name) {
+ DNSSDServiceID service(name, "local.");
+ querier->removeService(DNSSDServiceID(name, "local."));
+ eventLoop->processEvents();
+ }
+
+ void updateServicePresence(const std::string& name, LinkLocalServiceInfo::Status status, const std::string& message) {
+ DNSSDServiceID service(name, "local.");
+ LinkLocalServiceInfo info;
+ info.setStatus(status);
+ info.setMessage(message);
+ querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord()));
+ eventLoop->processEvents();
+ }
+
+ void handleRosterChanged(boost::shared_ptr<RosterPayload> payload) {
+ rosterChanges.push_back(payload);
+ }
+
+ void handlePresenceChanged(boost::shared_ptr<Presence> presence) {
+ presenceChanges.push_back(presence);
+ }
+
+ private:
+ DummyEventLoop* eventLoop;
+ boost::shared_ptr<FakeDNSSDQuerier> querier;
+ LinkLocalServiceBrowser* browser;
+ std::vector< boost::shared_ptr<RosterPayload> > rosterChanges;
+ std::vector< boost::shared_ptr<Presence> > presenceChanges;
};
CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalPresenceManagerTest);
diff --git a/Slimber/UnitTest/MenuletControllerTest.cpp b/Slimber/UnitTest/MenuletControllerTest.cpp
index c379b8b..e3b46ab 100644
--- a/Slimber/UnitTest/MenuletControllerTest.cpp
+++ b/Slimber/UnitTest/MenuletControllerTest.cpp
@@ -11,145 +11,145 @@
#include <Slimber/MenuletController.h>
class MenuletControllerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(MenuletControllerTest);
- CPPUNIT_TEST(testConstructor);
- CPPUNIT_TEST(testUpdate);
- CPPUNIT_TEST(testSetXMPPStatus_Online);
- CPPUNIT_TEST(testSetXMPPStatus_Offline);
- CPPUNIT_TEST(testSetUserNames);
- CPPUNIT_TEST(testSetUserNames_NoUsers);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- menulet = new FakeMenulet();
- }
-
- void tearDown() {
- delete menulet;
- }
-
- void testConstructor() {
- MenuletController testling(menulet);
-
- CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
- size_t i = 0;
- CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("[Offline] "), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]);
- }
-
- void testUpdate() {
- MenuletController testling(menulet);
-
- testling.setXMPPStatus("You are connected", MenuletController::Online);
-
- CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
- size_t i = 0;
- CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]);
- }
-
- void testSetXMPPStatus_Online() {
- MenuletController testling(menulet);
-
- testling.setXMPPStatus("You are connected", MenuletController::Online);
-
- size_t i = 0;
- CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]);
- }
-
-
- void testSetXMPPStatus_Offline() {
- MenuletController testling(menulet);
-
- testling.setXMPPStatus("You are not connected", MenuletController::Offline);
-
- size_t i = 0;
- CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("[Offline] You are not connected"), menulet->items[i++]);
- }
-
- void testSetUserNames() {
- MenuletController testling(menulet);
-
- std::vector<std::string> users;
- users.push_back("Alice In Wonderland");
- users.push_back("The Mad Hatter");
- testling.setUserNames(users);
-
- size_t i = 0;
- CPPUNIT_ASSERT_EQUAL(std::string("Online users:"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string(" Alice In Wonderland"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string(" The Mad Hatter"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- }
-
- void testSetUserNames_NoUsers() {
- MenuletController testling(menulet);
-
- std::vector<std::string> users;
- testling.setUserNames(users);
-
- size_t i = 0;
- CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
- CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
- }
-
- private:
- struct FakeMenulet : public Menulet {
- virtual void clear() {
- items.clear();
- }
-
- virtual void addItem(const std::string& name, const std::string& icon = std::string()) {
- std::string result;
- if (!icon.empty()) {
- result += "[" + icon + "] ";
- }
- result += name;
- items.push_back(result);
- }
-
- virtual void addAboutItem() {
- items.push_back("*About*");
- }
-
- virtual void addRestartItem() {
- items.push_back("*Restart*");
- }
-
- virtual void addExitItem() {
- items.push_back("*Exit*");
- }
-
- virtual void addSeparator() {
- items.push_back("-");
- }
-
- virtual void setIcon(const std::string& i) {
- icon = i;
- }
-
- std::vector<std::string> items;
- std::string icon;
- };
-
- FakeMenulet* menulet;
+ CPPUNIT_TEST_SUITE(MenuletControllerTest);
+ CPPUNIT_TEST(testConstructor);
+ CPPUNIT_TEST(testUpdate);
+ CPPUNIT_TEST(testSetXMPPStatus_Online);
+ CPPUNIT_TEST(testSetXMPPStatus_Offline);
+ CPPUNIT_TEST(testSetUserNames);
+ CPPUNIT_TEST(testSetUserNames_NoUsers);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ menulet = new FakeMenulet();
+ }
+
+ void tearDown() {
+ delete menulet;
+ }
+
+ void testConstructor() {
+ MenuletController testling(menulet);
+
+ CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("[Offline] "), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]);
+ }
+
+ void testUpdate() {
+ MenuletController testling(menulet);
+
+ testling.setXMPPStatus("You are connected", MenuletController::Online);
+
+ CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]);
+ }
+
+ void testSetXMPPStatus_Online() {
+ MenuletController testling(menulet);
+
+ testling.setXMPPStatus("You are connected", MenuletController::Online);
+
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]);
+ }
+
+
+ void testSetXMPPStatus_Offline() {
+ MenuletController testling(menulet);
+
+ testling.setXMPPStatus("You are not connected", MenuletController::Offline);
+
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("[Offline] You are not connected"), menulet->items[i++]);
+ }
+
+ void testSetUserNames() {
+ MenuletController testling(menulet);
+
+ std::vector<std::string> users;
+ users.push_back("Alice In Wonderland");
+ users.push_back("The Mad Hatter");
+ testling.setUserNames(users);
+
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL(std::string("Online users:"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string(" Alice In Wonderland"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string(" The Mad Hatter"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ }
+
+ void testSetUserNames_NoUsers() {
+ MenuletController testling(menulet);
+
+ std::vector<std::string> users;
+ testling.setUserNames(users);
+
+ size_t i = 0;
+ CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
+ CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
+ }
+
+ private:
+ struct FakeMenulet : public Menulet {
+ virtual void clear() {
+ items.clear();
+ }
+
+ virtual void addItem(const std::string& name, const std::string& icon = std::string()) {
+ std::string result;
+ if (!icon.empty()) {
+ result += "[" + icon + "] ";
+ }
+ result += name;
+ items.push_back(result);
+ }
+
+ virtual void addAboutItem() {
+ items.push_back("*About*");
+ }
+
+ virtual void addRestartItem() {
+ items.push_back("*Restart*");
+ }
+
+ virtual void addExitItem() {
+ items.push_back("*Exit*");
+ }
+
+ virtual void addSeparator() {
+ items.push_back("-");
+ }
+
+ virtual void setIcon(const std::string& i) {
+ icon = i;
+ }
+
+ std::vector<std::string> items;
+ std::string icon;
+ };
+
+ FakeMenulet* menulet;
};
CPPUNIT_TEST_SUITE_REGISTRATION(MenuletControllerTest);
diff --git a/Slimber/VCardCollection.h b/Slimber/VCardCollection.h
index 0e7d27f..3295039 100644
--- a/Slimber/VCardCollection.h
+++ b/Slimber/VCardCollection.h
@@ -11,11 +11,11 @@
#include <Swiften/Elements/VCard.h>
namespace Swift {
- class VCardCollection {
- public:
- virtual ~VCardCollection();
+ class VCardCollection {
+ public:
+ virtual ~VCardCollection();
- virtual boost::shared_ptr<VCard> getOwnVCard() const = 0;
- virtual void setOwnVCard(boost::shared_ptr<VCard> vcard) = 0;
- };
+ virtual boost::shared_ptr<VCard> getOwnVCard() const = 0;
+ virtual void setOwnVCard(boost::shared_ptr<VCard> vcard) = 0;
+ };
}