Files
@ fbb10606458d
Branch filter:
Location: libtransport.git/src/logger.cpp
fbb10606458d
5.5 KiB
text/x-c++hdr
Remove firstSet check
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | /**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* 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
*/
#include "transport/logger.h"
#include "transport/usermanager.h"
#include "transport/user.h"
#include "transport/transport.h"
#include "transport/storagebackend.h"
#include "transport/userregistration.h"
#include "transport/buddy.h"
#include "transport/rostermanager.h"
#include <boost/bind.hpp>
using namespace boost;
namespace Transport {
Logger::Logger(Component *component) {
component->onConnected.connect(boost::bind(&Logger::handleConnected, this));
component->onConnectionError.connect(boost::bind(&Logger::handleConnectionError, this, _1));
component->onXMLIn.connect(boost::bind(&Logger::handleXMLIn, this, _1));
component->onXMLOut.connect(boost::bind(&Logger::handleXMLOut, this, _1));
}
Logger::~Logger(){
}
void Logger::setStorageBackend(StorageBackend *storage) {
// storage->onStorageError.connect(boost::bind(&Logger::handleStorageError, this, _1, _2));
}
void Logger::setUserRegistration(UserRegistration *userRegistration) {
userRegistration->onUserRegistered.connect(boost::bind(&Logger::handleUserRegistered, this, _1));
userRegistration->onUserUnregistered.connect(boost::bind(&Logger::handleUserUnregistered, this, _1));
userRegistration->onUserUpdated.connect(boost::bind(&Logger::handleUserUpdated, this, _1));
}
void Logger::setUserManager(UserManager *userManager) {
userManager->onUserCreated.connect(boost::bind(&Logger::handleUserCreated, this, _1));
userManager->onUserDestroyed.connect(boost::bind(&Logger::handleUserDestroyed, this, _1));
}
void Logger::setRosterManager(RosterManager *rosterManager) {
rosterManager->onBuddySet.connect(boost::bind(&Logger::handleBuddySet, this, _1));
rosterManager->onBuddyUnset.connect(boost::bind(&Logger::handleBuddyUnset, this, _1));
}
void Logger::handleConnected() {
std::cout << "[COMPONENT] Connected to Jabber Server!\n";
}
void Logger::handleConnectionError(const Swift::ComponentError &error) {
std::cout << "[COMPONENT] Connection Error!\n";
switch (error.getType()) {
case Swift::ComponentError::UnknownError: std::cout << "[COMPONENT] Disconnect reason: UnknownError\n"; break;
case Swift::ComponentError::ConnectionError: std::cout << "[COMPONENT] Disconnect reason: ConnectionError\n"; break;
case Swift::ComponentError::ConnectionReadError: std::cout << "[COMPONENT] Disconnect reason: ConnectionReadError\n"; break;
case Swift::ComponentError::ConnectionWriteError: std::cout << "[COMPONENT] Disconnect reason: ConnectionWriteError\n"; break;
case Swift::ComponentError::XMLError: std::cout << "[COMPONENT] Disconnect reason: XMLError\n"; break;
case Swift::ComponentError::AuthenticationFailedError: std::cout << "[COMPONENT] Disconnect reason: AuthenticationFailedError\n"; break;
case Swift::ComponentError::UnexpectedElementError: std::cout << "[COMPONENT] Disconnect reason: UnexpectedElementError\n"; break;
};
}
void Logger::handleXMLIn(const std::string &data) {
std::cout << "[XML IN] " << data << "\n";
}
void Logger::handleXMLOut(const std::string &data) {
std::cout << "[XML OUT] " << data << "\n";
}
void Logger::handleStorageError(const std::string &statement, const std::string &error) {
std::cout << "[SQL ERROR] \"" << error << "\" during statement \"" << statement << "\"\n";
}
void Logger::handleUserRegistered(const UserInfo &user) {
std::cout << "[REGISTRATION] User \"" << user.jid << "\" registered as \"" << user.uin << "\"\n";
}
void Logger::handleUserUnregistered(const UserInfo &user) {
std::cout << "[REGISTRATION] User \"" << user.jid << "\" unregistered \"" << user.uin << "\"\n";
}
void Logger::handleUserUpdated(const UserInfo &user) {
std::cout << "[REGISTRATION] User \"" << user.jid << "\" updated \"" << user.uin << "\"\n";
}
void Logger::handleUserCreated(User *user) {
std::cout << "[USERMANAGER] User \"" << user->getJID().toString() << "\" (UIN: \"" << user->getUserInfo().uin << "\") connected and User class has been created\n";
}
void Logger::handleUserDestroyed(User *user) {
std::cout << "[USERMANAGER] User \"" << user->getJID().toBare().toString() << "\" (UIN: \"" << user->getUserInfo().uin << "\") disconnected and User class is going to be destroyed\n";
}
void Logger::handleBuddySet(Buddy *buddy) {
std::cout << "[ROSTERMANAGER] \"" << buddy->getRosterManager()->getUser()->getJID().toBare().toString() << "\": Buddy \"" << buddy->getSafeName() << "\" (ALIAS: \"" << buddy->getAlias() << "\") has been bound with this user's roster.\n";
}
void Logger::handleBuddyUnset(Buddy *buddy) {
std::cout << "[ROSTERMANAGER] \"" << buddy->getRosterManager()->getUser()->getJID().toBare().toString() << "\": Buddy \"" << buddy->getSafeName() << "\" (ALIAS: \"" << buddy->getAlias() << "\") has been unbound with this user's roster.\n";
}
}
|