question:multi accounts how to login in the nullclient.c
zjye-yezj
zjye-yezj at 163.com
Sun Mar 1 20:40:38 EST 2009
i modify the main function in nullclient.c , now the two account can not login at the sametime, just one account can login success. what's wrong in my process? may anyone tell me. thanks for all!
int main(int argc, char *argv[])
{
GList *iter;
int i, j, num;
GList *names = NULL;
const char *prpl;
char *name;
char *password;
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
PurpleAccount *account;
PurpleSavedStatus *status;
/* libpurple's built-in DNS resolution forks processes to perform
* blocking lookups without blocking the main process. It does not
* handle SIGCHLD itself, so if the UI does not you quickly get an army
* of zombie subprocesses marching around.
*/
init_libpurple();
purple_debug_set_enabled(TRUE);
printf("libpurple initialized.\n");
iter = purple_plugins_get_protocols();
for (j = 0, i = 0; iter; iter = iter->next) {
PurplePlugin *plugin = iter->data;
PurplePluginInfo *info = plugin->info;
j++;
printf("%d", j);
if (info && info->name) {
printf("\t%d: %s\n", i++, info->name);
names = g_list_append(names, info->id);
}
}
num = 6;
prpl = g_list_nth_data(names, num);//"prpl-msn"
name = "yezhengjun at hotmail.com";
account = purple_account_new(name, prpl);
password = "******";
purple_account_set_password(account, password);
purple_accounts_add(account);
purple_account_set_enabled(account, UI_ID, TRUE);
num = 10;
prpl = g_list_nth_data(names, num);////"prpl-jabber"
name = "yezhengjun at gmail.com";
account = purple_account_new(name, prpl);
password = "******";
purple_account_set_password(account, password);
purple_accounts_add(account);
purple_account_set_enabled(account, UI_ID, TRUE);
/* Now, to connect the account(s), create a status and activate it. */
status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
purple_savedstatus_activate(status);
connect_to_signals_for_demonstration_purposes_only();
g_main_loop_run(loop);
return 0;
}
I used multi thread to login, at can not login at the sametime too, just one account can login success!
anyone can give help?
void * FakeMain(void *arg)
{
PurpleAccount *account;
PurpleSavedStatus *status;
AccountArg iter = *((AccountArg *) arg);
printf("%s-%s-%s\n", iter.name, iter.pwd, iter.protocolid);
/* Create the account */
account = purple_account_new(iter.name, iter.protocolid);
/* Get the password for the account */
purple_account_set_password(account, iter.pwd);
/* It's necessary to enable the account first. */
purple_account_set_enabled(account, UI_ID, TRUE);
/* Now, to connect the account(s), create a status and activate it. */
status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
connect_to_signals_for_demonstration_purposes_only();
purple_savedstatus_activate(status);
return NULL;
}
#define TEST_THREAD_NUM 2
int main(int argc, char *argv[])
{
int i;
GList *names = NULL;
const char *prpl = NULL;
GThread *tid[TEST_THREAD_NUM];
GMutex *mutex = NULL;
GMainLoop *loop = NULL;
AccountArg *account = NULL;
g_thread_init(NULL);
loop = g_main_loop_new(NULL, FALSE);
/* libpurple's built-in DNS resolution forks processes to perform
* blocking lookups without blocking the main process. It does not
* handle SIGCHLD itself, so if the UI does not you quickly get an army
* of zombie subprocesses marching around.
*/
init_libpurple();
//purple_debug_set_enabled(TRUE);
printf("libpurple initialized.\n");
mutex = g_mutex_new();
for (i = 0; i < TEST_THREAD_NUM; i++)
{
g_mutex_lock(mutex);
if(0 == i)
{
account = g_new(AccountArg, 1);
account->name = "yezhengjun at hotmail.com";
account->pwd = "*****";
account->protocolid = "prpl-msn";
}
else
{
account = g_new(AccountArg, 1);
account->name = "yezhengjun at gmail.com";
account->pwd = "******";
account->protocolid = "prpl-jabber";
}
tid[i] = g_thread_create(FakeMain, account, TRUE, NULL);
g_mutex_lock(mutex);
}
for (i = 0; i < TEST_THREAD_NUM; i++)
{
g_thread_join(tid[i]);
}
g_mutex_free(mutex);
g_main_loop_run(loop);
return 0;
}
网易邮箱,中国第一大电子邮件服务商
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pidgin.im/pipermail/devel/attachments/20090302/88a6b8ad/attachment.html>
More information about the Devel
mailing list