Changeset - 14ff0a11d657
[Not reviewed]
0 8 0
HanzZ - 14 years ago 2011-10-11 19:27:22
hanzz.k@gmail.com
working service.eventloop=libev config to run libpurple with eventloop
8 files changed with 38 insertions and 16 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -19,90 +19,101 @@ set(glib_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(glib)
 

	
 
set(popt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(popt)
 

	
 
set(event_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(event)
 

	
 
set(Swiften_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(Swiften REQUIRED)
 

	
 
set(Boost_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(Boost COMPONENTS date_time system filesystem regex thread signals REQUIRED)
 
message( STATUS "Found Boost: ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}")
 

	
 
set(Protobuf_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(Protobuf REQUIRED)
 

	
 
set(IRCClientQt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(IRCClientQt)
 

	
 
set(log4cxx_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(log4cxx)
 

	
 
set(event_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
find_package(event)
 

	
 
find_package(Doxygen)
 

	
 
INCLUDE(FindQt4)
 
FIND_PACKAGE(Qt4 COMPONENTS QtCore)
 

	
 
# ADD_DEFINITIONS(${SWIFTEN_CFLAGS})
 
ADD_DEFINITIONS(-DSUPPORT_LEGACY_CAPS)
 
ADD_DEFINITIONS(-DBOOST_FILESYSTEM_VERSION=2)
 

	
 
message("  Supported features")
 
message("-----------------------")
 
if (SQLITE3_FOUND)
 
	ADD_DEFINITIONS(-DWITH_SQLITE)
 
	include_directories(${SQLITE3_INCLUDE_DIR})
 
	message("SQLite3           : yes")
 
else (SQLITE3_FOUND)
 
	set(SQLITE3_LIBRARIES "")
 
	message("SQLite3           : no")
 
endif (SQLITE3_FOUND)
 

	
 
if (MYSQL_FOUND)
 
	ADD_DEFINITIONS(-DWITH_MYSQL)
 
	include_directories(${MYSQL_INCLUDE_DIR})
 
	message("MySQL             : yes")
 
else (MYSQL_FOUND)
 
	set(MYSQL_LIBRARIES "")
 
	message("MySQL             : no (install mysql-devel)")
 
endif (MYSQL_FOUND)
 

	
 
if (PROTOBUF_FOUND)
 
	ADD_DEFINITIONS(-DWITH_PROTOBUF)
 
	include_directories(${PROTOBUF_INCLUDE_DIRS})
 
	message("Network plugins   : yes")
 

	
 
	if(PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR)
 
		message("Libpurple plugin  : yes")
 
		include_directories(${PURPLE_INCLUDE_DIR})
 
		include_directories(${GLIB2_INCLUDE_DIR})
 
	else()
 
		message("Libpurple plugin  : no (install libpurple)")
 
	endif()
 

	
 
	if (HAVE_EVENT)
 
		ADD_DEFINITIONS(-DWITH_LIBEVENT)
 
		include_directories(${EVENT_INCLUDE_DIRS})
 
		message("  libev eventloop : yes")
 
	else()
 
		message("  libev eventloop : no (install libev-devel)")
 
	endif()
 

	
 
	if(IRC_FOUND)
 
		ADD_DEFINITIONS(-DIRC_SHARED)
 
		message("IRC plugin        : yes")
 
		include_directories(${IRC_INCLUDE_DIR})
 
		include(${QT_USE_FILE})
 
	else()
 
		message("IRC plugin        : no (install libircclient-qt and libprotobuf-dev)")
 
	endif()
 

	
 
	message("Frotz plugin      : yes")
 

	
 
else()
 
	message("Network plugins   : no (install libprotobuf-dev)")
 
	message("Libpurple plugin  : no (install libpurple and libprotobuf-dev)")
 
	message("IRC plugin        : no (install libircclient-qt and libprotobuf-dev)")
 
	message("Frotz plugin      : no (install libprotobuf-dev)")
 
endif()
 

	
 
if (LOG4CXX_FOUND)
 
	message("Logging           : yes")
 
	include_directories(${LOG4CXX_INCLUDE_DIR})
 
else()
 
	message(FATAL_ERROR "Logging           : no (install log4cxx-devel)")
 
endif()
backends/libpurple/geventloop.cpp
Show inline comments
 
@@ -218,32 +218,37 @@ static guint event_timeout_add (guint interval, GSourceFunc function, gpointer d
 
	g_hash_table_replace(events, f, closure);
 
	return *f;
 
}
 

	
 
static PurpleEventLoopUiOps libEventLoopOps =
 
{
 
	event_timeout_add,
 
	event_input_remove,
 
	event_input_add,
 
	event_input_remove,
 
	NULL,
 
// #if GLIB_CHECK_VERSION(2,14,0)
 
// 	g_timeout_add_seconds,
 
// #else
 
	NULL,
 
// #endif
 

	
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
#endif /* WITH_LIBEVENT*/
 

	
 
PurpleEventLoopUiOps * getEventLoopUiOps(void){
 
	return &eventLoopOps;
 
PurpleEventLoopUiOps * getEventLoopUiOps(bool libev){
 
#ifdef WITH_LIBEVENT
 
	std::cout << "EPOLL\n";
 
	if (libev) {
 
		event_init();
 
		events = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
 
		return &libEventLoopOps;
 
	}
 
	else {
 
		return &eventLoopOps;
 
	}
 
#endif
 
	return &eventLoopOps;
 
}
backends/libpurple/geventloop.h
Show inline comments
 
@@ -7,27 +7,27 @@
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#ifndef _HI_EVENTLOOP_H
 
#define _HI_EVENTLOOP_H
 

	
 
#include <glib.h>
 
#include "purple.h"
 
#include "eventloop.h"
 

	
 
#define READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR)
 
#define WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
 

	
 
PurpleEventLoopUiOps * getEventLoopUiOps(void);
 
PurpleEventLoopUiOps * getEventLoopUiOps(bool libev);
 

	
 
#endif
backends/libpurple/main.cpp
Show inline comments
 
@@ -1566,49 +1566,52 @@ static void buddyTypingStopped(PurpleAccount *account, const char *who, gpointer
 
		w.erase((int) pos, w.length() - (int) pos);
 
	np->handleBuddyStoppedTyping(np->m_accounts[account], w);
 
}
 

	
 
static void gotAttention(PurpleAccount *account, const char *who, PurpleConversation *conv, guint type) {
 
	std::string w = purple_normalize(account, who);
 
	size_t pos = w.find("/");
 
	if (pos != std::string::npos)
 
		w.erase((int) pos, w.length() - (int) pos);
 
	np->handleAttention(np->m_accounts[account], w, "");
 
}
 

	
 
static bool initPurple(Config &cfg) {
 
	bool ret;
 

	
 
	purple_util_set_user_dir("./");
 
	remove("./accounts.xml");
 
	remove("./blist.xml");
 

	
 
// 	if (m_configuration.logAreas & LOG_AREA_PURPLE)
 
		purple_debug_set_ui_ops(&debugUiOps);
 
		purple_debug_set_verbose(true);
 

	
 
	purple_core_set_ui_ops(&coreUiOps);
 
	purple_eventloop_set_ui_ops(getEventLoopUiOps());
 
	std::map<std::string, std::string> unregistered = cfg.getUnregistered();
 
	if (unregistered.find("service.eventloop") != unregistered.end()) {
 
		purple_eventloop_set_ui_ops(getEventLoopUiOps(unregistered["service.eventloop"] == "libev"));
 
	}
 

	
 
	ret = purple_core_init("spectrum");
 
	if (ret) {
 
		static int blist_handle;
 
		static int conversation_handle;
 

	
 
		purple_set_blist(purple_blist_new());
 
		purple_blist_load();
 

	
 
		purple_prefs_load();
 

	
 
		/* Good default preferences */
 
		/* The combination of these two settings mean that libpurple will never
 
		 * (of its own accord) set all the user accounts idle.
 
		 */
 
		purple_prefs_set_bool("/purple/away/away_when_idle", false);
 
		/*
 
		 * This must be set to something not "none" for idle reporting to work
 
		 * for, e.g., the OSCAR prpl. We don't implement the UI ops, so this is
 
		 * okay for now.
 
		 */
 
		purple_prefs_set_string("/purple/away/idle_reporting", "system");
 

	
 
		/* Disable all logging */
 
@@ -1723,31 +1726,32 @@ int main(int argc, char **argv) {
 
//		}
 
#endif
 
		Config config;
 
		if (!config.load(argv[1])) {
 
			std::cout << "Can't open " << argv[1] << " configuration file.\n";
 
			return 1;
 
		}
 

	
 
		if (CONFIG_STRING(&config, "logging.backend_config").empty()) {
 
			LoggerPtr root = log4cxx::Logger::getRootLogger();
 
			root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n")));
 
		}
 
		else {
 
			log4cxx::helpers::Properties p;
 
			log4cxx::helpers::FileInputStream *istream = new log4cxx::helpers::FileInputStream(CONFIG_STRING(&config, "logging.backend_config"));
 

	
 
			p.load(istream);
 
			p.setProperty("pid", boost::lexical_cast<std::string>(getpid()));
 
			p.setProperty("jid", CONFIG_STRING(&config, "service.jid"));
 
			log4cxx::PropertyConfigurator::configure(p);
 
		}
 

	
 
		initPurple(config);
 

	
 
		SpectrumEventLoop eventLoop;
 
		std::map<std::string, std::string> unregistered = config.getUnregistered();
 
		SpectrumEventLoop eventLoop(unregistered["service.eventloop"] == "libev");
 
		np = new SpectrumNetworkPlugin(&config, &eventLoop, host, port);
 
		eventLoop.run();
 
	}
 

	
 
	g_option_context_free(context);
 
}
backends/libpurple/spectrumeventloop.cpp
Show inline comments
 
@@ -24,60 +24,58 @@
 
#include <iostream>
 

	
 
#ifdef WITH_LIBEVENT
 
#include <event.h>
 
#endif
 

	
 
#include "log4cxx/logger.h"
 

	
 
using namespace log4cxx;
 

	
 
static LoggerPtr logger = Logger::getLogger("SpectrumEventLoop");
 

	
 
using namespace Swift;
 

	
 
static SpectrumEventLoop *loop;
 

	
 
// Fires the event's callback and frees the event
 
static gboolean processEvent(void *data) {
 
	Event *ev = (Event *) data;
 
	LOG4CXX_INFO(logger, "got event in main thread " << ev);
 
	loop->handle(ev);
 
	return FALSE;
 
}
 

	
 
SpectrumEventLoop::SpectrumEventLoop() : m_isRunning(false) {
 
SpectrumEventLoop::SpectrumEventLoop(bool libev) : m_isRunning(false) {
 
	m_loop = NULL;
 
	loop = this;
 
	if (true) {
 
		m_loop = g_main_loop_new(NULL, FALSE);
 
	}
 
#ifdef WITH_LIBEVENT
 
	else {
 
		/*struct event_base *base = (struct event_base *)*/
 
		event_init();
 
	if (!libev) {
 
		m_loop = g_main_loop_new(NULL, FALSE);
 
	}
 
	return;
 
#endif
 
	m_loop = g_main_loop_new(NULL, FALSE);
 
}
 

	
 
SpectrumEventLoop::~SpectrumEventLoop() {
 
	stop();
 
}
 

	
 
void SpectrumEventLoop::run() {
 
	m_isRunning = true;
 
	if (m_loop) {
 
		g_main_loop_run(m_loop);
 
	}
 
#ifdef WITH_LIBEVENT
 
	else {
 
		event_loop(0);
 
	}
 
#endif
 
}
 

	
 
void SpectrumEventLoop::handle(Swift::Event *event) {
 
	handleEvent(*event);
 
	delete event;
 
}
 

	
 
void SpectrumEventLoop::stop() {
backends/libpurple/spectrumeventloop.h
Show inline comments
 
@@ -8,44 +8,44 @@
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#ifndef SPECTRUM_EVENT_LOOP_H
 
#define SPECTRUM_EVENT_LOOP_H
 

	
 
#include <vector>
 
#include "Swiften/EventLoop/EventLoop.h"
 
#include "glib.h"
 

	
 
// Event loop implementation for Spectrum
 
class SpectrumEventLoop : public Swift::EventLoop {
 
	public:
 
		// Creates event loop according to CONFIG().eventloop settings.
 
		SpectrumEventLoop();
 
		SpectrumEventLoop(bool libev);
 
		~SpectrumEventLoop();
 

	
 
		// Executes the eventloop.
 
		void run();
 

	
 
		// Stops tht eventloop.
 
		void stop();
 

	
 
		void handle(Swift::Event *event);
 

	
 
		// Posts new Swift::Event to main thread.
 
		virtual void post(const Swift::Event& event);
 

	
 
	private:
 
		bool m_isRunning;
 
		GMainLoop *m_loop;
 
};
 

	
 
#endif
cmake_modules/eventConfig.cmake
Show inline comments
 
FIND_PATH(EVENT_INCLUDE_DIRS libev/event.h)
 
FIND_PATH(EVENT_INCLUDE_DIRS event.h PATH_SUFFIXES libev)
 

	
 
SET(EVENT_NAMES ${EVENT_NAMES} ev libev)
 
FIND_LIBRARY(EVENT_LIBRARIES NAMES ${EVENT_NAMES} PATH)
 

	
 
IF(EVENT_INCLUDE_DIRS AND EVENT_LIBRARIES)
 
SET(HAVE_EVENT TRUE)
 
file(APPEND src/transport_config.h "#define WITH_LIBEVENT 1\n")
 
ELSE(EVENT_INCLUDE_DIRS AND EVENT_LIBRARIES)
 
SET (EVENT_INCLUDE_DIRS "")
 
SET (EVENT_LIBRARIES "")
 
ENDIF(EVENT_INCLUDE_DIRS AND EVENT_LIBRARIES)
 

	
 
IF(HAVE_EVENT)
 
MESSAGE(STATUS "Found Event: ${EVENT_LIBRARIES}")
 
MESSAGE(STATUS "Found Event: ${EVENT_LIBRARIES} ${EVENT_INCLUDE_DIRS}")
 
ENDIF(HAVE_EVENT)
include/Swiften/Network/DummyNetworkFactories.h
Show inline comments
 
@@ -15,31 +15,35 @@ namespace Swift {
 
		public:
 
			DummyNetworkFactories(EventLoop *eventLoop);
 
			~DummyNetworkFactories();
 

	
 
			virtual TimerFactory* getTimerFactory() const {
 
				return timerFactory;
 
			}
 

	
 
			virtual ConnectionFactory* getConnectionFactory() const {
 
				return connectionFactory;
 
			}
 

	
 
			DomainNameResolver* getDomainNameResolver() const {
 
				return domainNameResolver;
 
			}
 

	
 
			ConnectionServerFactory* getConnectionServerFactory() const {
 
				return connectionServerFactory;
 
			}
 

	
 
			virtual Swift::NATTraverser* getNATTraverser() const {
 
				return 0;
 
			}
 

	
 
			Swift::XMLParserFactory* getXMLParserFactory() const {
 
				return 0;
 
			}
 

	
 
		private:
 
			TimerFactory* timerFactory;
 
			ConnectionFactory* connectionFactory;
 
			DomainNameResolver* domainNameResolver;
 
			ConnectionServerFactory* connectionServerFactory;
 
	};
 
}
0 comments (0 inline, 0 general)