summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/SluiftComponent.cpp')
-rw-r--r--Sluift/SluiftComponent.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/Sluift/SluiftComponent.cpp b/Sluift/SluiftComponent.cpp
index e1d1738..74728ee 100644
--- a/Sluift/SluiftComponent.cpp
+++ b/Sluift/SluiftComponent.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2014-2016 Isode Limited.
+ * Copyright (c) 2014-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/SluiftComponent.h>
#include <boost/numeric/conversion/cast.hpp>
#include <Swiften/Component/Component.h>
@@ -34,19 +34,22 @@ SluiftComponent::SluiftComponent(
component->onMessageReceived.connect(boost::bind(&SluiftComponent::handleIncomingMessage, this, _1));
component->onPresenceReceived.connect(boost::bind(&SluiftComponent::handleIncomingPresence, this, _1));
}
SluiftComponent::~SluiftComponent() {
delete tracer;
delete component;
}
-void SluiftComponent::connect(const std::string& host, int port) {
+void SluiftComponent::connect(const std::string& host, unsigned short port) {
+ if (component->isActive()) {
+ throw Lua::Exception("Component is already connecting or connected");
+ }
disconnectedError = boost::optional<ComponentError>();
component->connect(host, port);
}
void SluiftComponent::setTraceEnabled(bool b) {
if (b && !tracer) {
tracer = new ComponentXMLTracer(component);
}
else if (!b && tracer) {
@@ -69,19 +72,19 @@ void SluiftComponent::waitConnected(int timeout) {
}
}
bool SluiftComponent::isConnected() const {
return component->isAvailable();
}
void SluiftComponent::disconnect() {
component->disconnect();
- while (component->isAvailable()) {
+ while (component->isActive()) {
eventLoop->runUntilEvents();
}
}
void SluiftComponent::setSoftwareVersion(const std::string& name, const std::string& version, const std::string& /* os */) {
component->setSoftwareVersion(name, version);
}
boost::optional<SluiftComponent::Event> SluiftComponent::getNextEvent(
@@ -96,24 +99,24 @@ boost::optional<SluiftComponent::Event> SluiftComponent::getNextEvent(
pendingEvents.erase(
pendingEvents.begin()
+ boost::numeric_cast<int>(currentIndex));
return event;
}
++currentIndex;
}
// Wait for new events
- while (!watchdog.getTimedOut() && currentIndex >= pendingEvents.size() && component->isAvailable()) {
+ while (!watchdog.getTimedOut() && currentIndex >= pendingEvents.size() && component->isActive()) {
eventLoop->runUntilEvents();
}
// Finish if we're disconnected or timed out
- if (watchdog.getTimedOut() || !component->isAvailable()) {
+ if (watchdog.getTimedOut() || !component->isActive()) {
return boost::optional<Event>();
}
}
}
void SluiftComponent::handleIncomingMessage(std::shared_ptr<Message> stanza) {
pendingEvents.push_back(Event(stanza));
}