Changed libtransport-plugin deps to have logging.h used from libpurple backend

This commit is contained in:
HanzZ 2012-03-21 15:46:25 +01:00
parent 52039dd4df
commit 1f60d0547c
3 changed files with 21 additions and 42 deletions

View file

@ -6,6 +6,8 @@
#include <iostream>
#include "transport/networkplugin.h"
#include "transport/logging.h"
#include "transport/config.h"
#include "geventloop.h"
#include "log4cxx/logger.h"
#include "log4cxx/consoleappender.h"
@ -1648,44 +1650,12 @@ int main(int argc, char **argv) {
return 1;
}
if (KEYFILE_STRING("logging", "backend_config").empty()) {
LoggerPtr root = log4cxx::Logger::getRootLogger();
#ifndef _MSC_VER
root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n")));
#else
root->addAppender(new ConsoleAppender(new PatternLayout(L"%d %-5p %c: %m%n")));
#endif
}
else {
log4cxx::helpers::Properties p;
log4cxx::helpers::FileInputStream *istream = NULL;
try {
istream = new log4cxx::helpers::FileInputStream(KEYFILE_STRING("logging", "backend_config"));
}
catch(log4cxx::helpers::IOException &ex) {
std::cerr << "Can't create FileInputStream logger instance: " << ex.what() << "\n";
}
catch (...) {
std::cerr << "Can't create FileInputStream logger instance\n";
}
if (!istream) {
return 1;
}
p.load(istream);
LogString pid, jid;
log4cxx::helpers::Transcoder::decode(stringOf(getpid()), pid);
log4cxx::helpers::Transcoder::decode(KEYFILE_STRING("service", "jid"), jid);
#ifdef _MSC_VER
p.setProperty(L"pid", pid);
p.setProperty(L"jid", jid);
#else
p.setProperty("pid", pid);
p.setProperty("jid", jid);
#endif
log4cxx::PropertyConfigurator::configure(p);
Config config;
if (!config.load(argv[1])) {
std::cerr << "Can't open " << argv[1] << " configuration file.\n";
return 1;
}
Logging::initBackendLogging(&config);
initPurple();

View file

@ -3,6 +3,8 @@ FILE(GLOB SRC *.cpp *.h)
FILE(GLOB HEADERS ../include/transport/*.h)
set(EXTRA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../../src/memoryusage.cpp)
set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/../../src/logging.cpp)
set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/../../src/config.cpp)
set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/../../include/transport/protocol.pb.cc)
if (NOT WIN32)
@ -18,9 +20,9 @@ if (CMAKE_COMPILER_IS_GNUCXX)
endif()
if (NOT WIN32)
TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES})
TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES})
else()
TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ws2_32.lib)
TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES} ws2_32.lib)
endif()
SET_TARGET_PROPERTIES(transport-plugin PROPERTIES

View file

@ -19,7 +19,6 @@
*/
#include "transport/config.h"
#include "transport/util.h"
#include <fstream>
#ifdef _MSC_VER
#include <direct.h>
@ -31,6 +30,14 @@
using namespace boost::program_options;
namespace Transport {
int getRandomPort(const std::string &s) {
unsigned long r = 0;
BOOST_FOREACH(char c, s) {
r += (int) c;
}
srand(time(NULL) + r);
return 30000 + rand() % 10000;
}
bool Config::load(const std::string &configfile, boost::program_options::options_description &opts, const std::string &jid) {
std::ifstream ifs(configfile.c_str());
@ -126,7 +133,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
else if (opt.string_key == "service.backend_port") {
found_backend_port = true;
if (opt.value[0] == "0") {
opt.value[0] = boost::lexical_cast<std::string>(Util::getRandomPort(_jid.empty() ? jid : _jid));
opt.value[0] = boost::lexical_cast<std::string>(getRandomPort(_jid.empty() ? jid : _jid));
}
}
else if (opt.string_key == "service.working_dir") {
@ -152,7 +159,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
}
if (!found_backend_port) {
std::vector<std::string> value;
std::string p = boost::lexical_cast<std::string>(Util::getRandomPort(_jid.empty() ? jid : _jid));
std::string p = boost::lexical_cast<std::string>(getRandomPort(_jid.empty() ? jid : _jid));
value.push_back(p);
parsed.options.push_back(boost::program_options::basic_option<char>("service.backend_port", value));
}