Fwd: Problem quitting libpurple core

Vaibhav Chauhan chauhan at umich.edu
Fri Jul 20 15:49:14 EDT 2012


FYI.
Issue my code given below (issue in reconnecting).


---------- Forwarded message ----------
From: Vaibhav Chauhan <chauhan at umich.edu>
Date: Fri, Jul 20, 2012 at 1:28 PM
Subject: Re: Problem quitting libpurple core
To: duncan at berrimans.co.uk


Thanks a ton for your reply.

1. Seems your g_main_loop_run will run many times. I am running it once
only and invoke g_main_loop_run and g_main_loop_unref* *when I am done. Am
I wrong? My g_main_loop_run runs in synchronous way so I start it in new
thread. Please see bold sentences below.
2. Can you please share your timeout_callback implementation.

3.
My code:

bool Connect( csui uiTimeoutInSecs, UtilError *pErr = NULL )
{

if ( !m_bInitialized )
{
 return ValidationError( "Client is not initialzed. Initialize before
connecting.", pErr );
}

if ( m_pAccount )
{
* // WILL COME here while reconnecting*
if ( purple_account_is_disconnected( m_pAccount ) )
 {
purple_account_set_password(m_pAccount, m_pPassword.c_str());
 purple_account_connect(m_pAccount);
if ( !WaitForSuccessfulConnection( uiTimeoutInSecs, pErr ) )
 {
return false;
 }

return true;
 }

if ( m_pAccount->disconnecting )
 return ValidationError( "Account is disconnecting. Make a connection after
a few moments.", pErr );
 }
 std::string strProtocol;
if( !ValidateProtocol( strProtocol, pErr ) )
 return false;

// Create the account
 m_pAccount = purple_account_new( m_pUserName.c_str(), strProtocol.c_str()
);
if( !m_pAccount )
 return ValidationError( "Account cannot be created for user", pErr );

 purple_account_set_password( m_pAccount, m_pPassword.c_str() );
 // It's necessary to enable the account first.
purple_account_set_enabled( m_pAccount, m_pUId.c_str(), TRUE );
 // Now, to connect the account(s), create a status and activate it.
 PurpleSavedStatus *pStatus = purple_savedstatus_new( NULL,
PURPLE_STATUS_AVAILABLE );
 if ( !pStatus )
return ValidationError( "Status for created account is NULL", pErr );

purple_savedstatus_activate( pStatus );
 // Register to libpurple callback signals
RegisterToSignals();


m_pLoop = g_main_loop_new(NULL, FALSE);

//if ( !m_thread.IsInitialized() )
//m_pLoop = g_main_loop_new(NULL, FALSE);
 #ifndef _WIN32
signal(SIGCHLD, SIG_IGN);
 #endif

                // *this runs g_main_loop_run in separate thread. If i
don't use separate thread my g_main_loop_run keeps running and I am not
able to              // proceed to next line*
 m_thread.Init( NULL, 0, StartGLoopAsync, m_pLoop, 0, NULL );

if ( !WaitForSuccessfulConnection( uiTimeoutInSecs, pErr ) )
 {
return false;
 }

return true;
 }

Once this Connect func returns true, I send message. This works fine but
reconnecting doesnt work.


Please respond. Thanks.



On Fri, Jul 20, 2012 at 12:32 PM, <duncan at berrimans.co.uk> wrote:

>   I use
>
> msnaccount = purple_account_new(msn_user, "prpl-msn");
> purple_account_set_password(msnaccount, msn_password);
> purple_accounts_add(msnaccount);
> purple_account_set_enabled(msnaccount, UI_ID, TRUE);
>
> GMainLoop *loop = g_main_loop_new(NULL, FALSE);
> while (!dostop) {
>    g_timeout_add (1000 , timeout_callback , loop);
>    g_main_loop_run(loop);
>
>     msn_online = checkconnected(msnaccount, &msn_retry,msn_password);
>     ... other code send messages etc
>     ... set dostop if required
>
> }
> g_main_loop_unref(loop);
>
> checkconnected function uses purple_account_get_connection and
> purple_connection_get_state to check the connection and status
>
> If its not connected ( purple_account_get_connection  = NULL or
> purple_connection_get_state(gc)) != PURPLE_CONNECTED ) then I do a
> disconnect
>
> purple_account_disconnect(account);
>
> then to reconnect I do
>
> purple_account_set_password(account, password);
> purple_account_connect(account);
>
> It may not be possible to reconnect immediately so I check the return
> status and retry periodically (not every pass!).
>
> Hope that helps
> Duncan
>
>  *From:* Vaibhav Chauhan <chauhan.umichigan at gmail.com>
> *Sent:* Friday, July 20, 2012 5:04 PM
> *To:* devel at pidgin.im
> *Subject:* Problem quitting libpurple core
>
> Hi,
>
> I am working on a libpurple client which does everything fine, other than
> reconnecting.
> I connect -> disconnect using purple_account_disconnect( m_pAccount ); ->
> call connect and am unable to connect.
>
> My connect does following(I am posting main functionalities of code below):
>
> m_pLoop = g_main_loop_new(NULL, FALSE);
>  m_pAccount = purple_account_new( m_pUserName.c_str(),
> strProtocol.c_str() );
> purple_account_set_password( m_pAccount, m_pPassword.c_str() );
> purple_account_set_enabled( m_pAccount, m_pUId.c_str(), TRUE );
> PurpleSavedStatus *pStatus = purple_savedstatus_new( NULL,
> PURPLE_STATUS_AVAILABLE );
> purple_savedstatus_activate( pStatus );
>
>
> I have tried calling:
>
>  g_main_loop_quit( m_pLoop );
> g_main_loop_unref( m_pLoop );
> purple_core_quit(); // I call this when I am done with client and want to
> start a completely fresh client
>
>
> but nothing works.
> purple_core_quit(); keeps running and never stops. What is the way to:
> 1. Quit libpurple client removing all memory gracefully
> 2. Reconnect after disconnecting
>
> Please help. Quite urgent.
>
>
>
>
> Best Regards
> *Vaibhav Chauhan*
>
> --
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.
>
> ------------------------------
> _______________________________________________
> Devel mailing list
> Devel at pidgin.im
> http://pidgin.im/cgi-bin/mailman/listinfo/devel
>
>


-- 
Best Regards
*Vaibhav Chauhan*
Master of Science in Financial Engineering, Class of 2012
*University of Michigan*
*Email: chauhan at umich.edu*
*Mobile:* +1 (734) 635 8603
LinkedIn <http://www.linkedin.com/in/vaibhavchauhan>




-- 
Best Regards
*Vaibhav Chauhan*
Master of Science in Financial Engineering, Class of 2012
*University of Michigan*
*Email: chauhan at umich.edu*
*Mobile:* +1 (734) 635 8603
LinkedIn <http://www.linkedin.com/in/vaibhavchauhan>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pidgin.im/pipermail/devel/attachments/20120720/e62b8cd0/attachment-0002.html>


More information about the Devel mailing list