@@ -80,36 +80,15 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
8080 Swift::XMPPParser *m_xmppParser;
8181 Swift::FullPayloadParserFactoryCollection m_collection2;
8282
83- SwiftenPlugin (Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
83+ SwiftenPlugin (Config *config, const std::string &host, int port) : NetworkPlugin() {
8484 this ->config = config;
8585 m_firstPing = true ;
86- m_factories = new Swift::BoostNetworkFactories (loop);
87- m_conn = m_factories->getConnectionFactory ()->createConnection ();
88- m_conn->onDataRead .connect (boost::bind (&SwiftenPlugin::_handleDataRead, this , _1));
89- m_conn->connect (Swift::HostAddressPort (*(Swift::HostAddress::fromString (host)), port));
9086 serializer = new Swift::XMPPSerializer (&collection, Swift::ClientStreamType, false );
9187 m_xmppParser = new Swift::XMPPParser (this , &m_collection2, m_factories->getXMLParserFactory ());
9288 m_xmppParser->parse (" <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>" );
9389
9490 LOG4CXX_INFO (logger, " Starting the plugin." );
95- }
96-
97- // NetworkPlugin uses this method to send the data to networkplugin server
98- void sendData (const std::string &string) {
99- m_conn->write (Swift::createSafeByteArray (string));
100- }
101-
102- // This method has to call handleDataRead with all received data from network plugin server
103- void _handleDataRead (std::shared_ptr<Swift::SafeByteArray> data) {
104- if (m_firstPing) {
105- m_firstPing = false ;
106- NetworkPlugin::PluginConfig cfg;
107- cfg.setRawXML (true );
108- cfg.setNeedRegistration (false );
109- sendConfig (cfg);
110- }
111- std::string d (data->begin (), data->end ());
112- handleDataRead (d);
91+ connect (host, std::to_string (port));
11392 }
11493
11594 void handleStreamStart (const Swift::ProtocolHeader&) {}
@@ -446,10 +425,7 @@ int main (int argc, char* argv[]) {
446425
447426 Logging::initBackendLogging (cfg);
448427
449- Swift::SimpleEventLoop eventLoop;
450- loop_ = &eventLoop;
451- np = new SwiftenPlugin (cfg, &eventLoop, host, port);
452- loop_->run ();
428+ np = new SwiftenPlugin (cfg, host, port);
453429
454430 return 0 ;
455431}
0 commit comments