Changeset - bfa4176bac88
[Not reviewed]
0 2 0
HanzZ - 14 years ago 2011-07-19 01:25:26
hanzz.k@gmail.com
Do not create m_convs in getConversation
2 files changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
include/transport/conversationmanager.h
Show inline comments
 
@@ -13,72 +13,74 @@
 
 * 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
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include "Swiften/Swiften.h"
 

	
 
namespace Transport {
 

	
 
class Conversation;
 
class User;
 
class Component;
 

	
 
/// Manages all Conversations of particular User.
 
class ConversationManager {
 
	public:
 
		/// Creates new ConversationManager.
 

	
 
		/// \param user User associated with this ConversationManager.
 
		/// \param component Transport instance associated with this ConversationManager.
 
		ConversationManager(User *user, Component *component);
 

	
 
		/// Destructor.
 
		virtual ~ConversationManager();
 

	
 
		/// Returns user associated with this manager.
 

	
 
		/// \return User
 
		User *getUser() { return m_user; }
 

	
 
		/// Returns component associated with this ConversationManager.
 

	
 
		/// \return component associated with this ConversationManager.
 
		Component *getComponent() { return m_component; }
 

	
 
		/// Returns Conversation by its legacy network name (for example by UIN in case of ICQ).
 

	
 
		/// \param name legacy network name.
 
		/// \return Conversation or NULL.
 
		Conversation *getConversation(const std::string &name) {
 
			if (m_convs.find(name) == m_convs.end())
 
				return NULL;
 
			return m_convs[name];
 
		}
 

	
 
		/// Adds new Conversation to the manager.
 

	
 
		/// \param conv Conversation.
 
		void addConversation(Conversation *conv);
 

	
 
		/// Removes Conversation from the manager.
 

	
 
		/// \param conv Conversation.
 
		void removeConversation(Conversation *conv);
 

	
 
	private:
 
		void handleMessageReceived(Swift::Message::ref message);
 

	
 
		Component *m_component;
 
		User *m_user;
 

	
 
		std::map<std::string, Conversation *> m_convs;
 
		friend class UserManager;
 
};
 

	
 
}
src/networkpluginserver.cpp
Show inline comments
 
@@ -844,82 +844,82 @@ void NetworkPluginServer::handleBuddyAdded(Buddy *buddy, const Swift::RosterItem
 
}
 

	
 
void NetworkPluginServer::handleVCardUpdated(User *user, boost::shared_ptr<Swift::VCard> v) {
 
	pbnetwork::VCard vcard;
 
	vcard.set_username(user->getJID().toBare());
 
	vcard.set_buddyname("");
 
	vcard.set_id(0);
 
	vcard.set_photo(&v->getPhoto()[0], v->getPhoto().size());
 

	
 
	std::string message;
 
	vcard.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_VCARD);
 

	
 
	Backend *c = (Backend *) user->getData();
 
	if (!c) {
 
		return;
 
	}
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::handleVCardRequired(User *user, const std::string &name, unsigned int id) {
 
	pbnetwork::VCard vcard;
 
	vcard.set_username(user->getJID().toBare());
 
	vcard.set_buddyname(name);
 
	vcard.set_id(id);
 

	
 
	std::string message;
 
	vcard.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_VCARD);
 

	
 
	Backend *c = (Backend *) user->getData();
 
	if (!c) {
 
		return;
 
	}
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::sendPing(Backend *c) {
 

	
 
	std::string message;
 
	pbnetwork::WrapperMessage wrap;
 
	wrap.set_type(pbnetwork::WrapperMessage_Type_TYPE_PING);
 
	wrap.SerializeToString(&message);
 

	
 
	send(c->connection, message);
 
	c->pongReceived = false;
 
	LOG4CXX_INFO(logger, "PING to " << c);
 
// 	LOG4CXX_INFO(logger, "PING to " << c);
 
}
 

	
 
NetworkPluginServer::Backend *NetworkPluginServer::getFreeClient() {
 
	NetworkPluginServer::Backend *c = NULL;
 
	bool spawnNew = false;
 
	for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
 
		// This backend is free.
 
		if ((*it)->users.size() < CONFIG_INT(m_config, "service.users_per_backend")) {
 
			// After this user, this backend could be full, so we have to spawn new one...
 
			if ((*it)->users.size() + 1 >= CONFIG_INT(m_config, "service.users_per_backend")) {
 
				spawnNew = true;
 
			}
 

	
 
			if (c == NULL) {
 
				c = *it;
 
			}
 
			else {
 
				if ((*it)->users.size() + 1 != CONFIG_INT(m_config, "service.users_per_backend")) {
 
					spawnNew = false;
 
					break;
 
				}
 
			}
 
		}
 
	}
 

	
 
	if (spawnNew || c == NULL) {
 
		exec_(CONFIG_STRING(m_config, "service.backend").c_str(), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str());
 
	}
 

	
 
	return c;
 
}
 

	
 
}
0 comments (0 inline, 0 general)