Changeset - 31de3415d282
[Not reviewed]
0 1 0
HanzZ - 13 years ago 2012-02-17 14:01:01
hanzz.k@gmail.com
Removed big sleep from skype
1 file changed with 27 insertions and 13 deletions:
0 comments (0 inline, 0 general)
backends/skype/main.cpp
Show inline comments
 
@@ -104,24 +104,25 @@ class Skype {
 
};
 

	
 
class SpectrumNetworkPlugin : public NetworkPlugin {
 
	public:
 
		SpectrumNetworkPlugin(Config *config, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
			LOG4CXX_INFO(logger, "Starting the backend.");
 
		}
 

	
 
		~SpectrumNetworkPlugin() {
 
			for (std::map<Skype *, std::string>::iterator it = m_accounts.begin(); it != m_accounts.end(); it++) {
 
				delete (*it).first;
 
			}
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			std::string name = legacyName;
 
			name = name.substr(name.find(".") + 1);
 
			LOG4CXX_INFO(logger,  "Creating account with name '" << name);
 
			LOG4CXX_INFO(logger,  "Creating account with name '" << name << "'");
 

	
 
			Skype *skype = new Skype(user, name, password);
 
			m_sessions[user] = skype;
 
			m_accounts[skype] = user;
 

	
 
			skype->login();
 
@@ -363,42 +364,55 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			close(fd);
 
			
 
			fcntl (fd_output, F_SETFL, O_NONBLOCK);
 

	
 
			free(db);
 

	
 
			sleep(10);
 

	
 
			GError *error = NULL;
 
			DBusObjectPathVTable vtable;
 

	
 
			//Initialise threading
 
			dbus_threads_init_default();
 
			
 
			if (m_connection == NULL)
 
			{
 
				LOG4CXX_INFO(logger, "Creating DBus connection.");
 
				m_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
				if (m_connection == NULL && error != NULL)
 
				{
 
					LOG4CXX_INFO(logger,  m_username << ": DBUS Error: " << error->message);
 
					g_error_free(error);
 
					return;
 
				}
 
			}
 
			
 
			if (m_proxy == NULL)
 
			{
 
				m_proxy = dbus_g_proxy_new_for_name_owner (m_connection,
 
												"com.Skype.API",
 
												"/com/Skype",
 
												"com.Skype.API",
 
												&error);
 
				if (m_proxy == NULL && error != NULL)
 
				{
 
					LOG4CXX_INFO(logger,  m_username << ":" << error->message);
 
					g_error_free(error);
 
				int counter = 0;
 
				while (m_proxy == NULL) {
 
					counter++;
 
					sleep(1);
 
					LOG4CXX_INFO(logger, "Creating DBus proxy for com.Skype.Api.");
 
					m_proxy = dbus_g_proxy_new_for_name_owner (m_connection,
 
													"com.Skype.API",
 
													"/com/Skype",
 
													"com.Skype.API",
 
													&error);
 
					if (m_proxy == NULL && error != NULL)
 
					{
 
						LOG4CXX_INFO(logger,  m_username << ":" << error->message);
 

	
 
						if (counter == 15) {
 
							np->handleDisconnected(m_user, 0, error->message);
 
							close(fd_output);
 
							logout();
 
							g_error_free(error);
 
							break;
 
						}
 
						g_error_free(error);
 
					}
 
				}
 
				
 
				vtable.message_function = &skype_notify_handler;
 
				dbus_connection_register_object_path(dbus_g_connection_get_connection(m_connection), "/com/Skype/Client", &vtable, this);
 
			}
 

	
 
@@ -463,13 +477,13 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
				{
 
					std::string buddy = full_friends_list[i];
 

	
 
					if (buddy[0] == ',') {
 
						buddy.erase(buddy.begin());
 
					}
 
					std::cout << "BUDDY '" << buddy << "'\n";
 
					LOG4CXX_INFO(logger, "Got buddy " << buddy);
 
					std::string st = full_friends_list[i + 5];
 
					
 
					pbnetwork::StatusType status = getStatus(st);
 

	
 
					std::string alias = full_friends_list[i + 6];
 

	
0 comments (0 inline, 0 general)