Make friend_status_message callback stateless.

See #40 for details.
This commit is contained in:
iphydf 2016-08-18 00:37:45 +01:00
parent 6935643f9a
commit bdf5ac37b4
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
7 changed files with 9 additions and 14 deletions

View File

@ -560,7 +560,7 @@ START_TEST(test_few_clients)
tox_friend_get_name(tox3, 0, temp_name, 0);
ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
tox_callback_friend_status_message(tox3, print_status_m_change, &to_compare);
tox_callback_friend_status_message(tox3, print_status_m_change);
succ = tox_self_set_status_message(tox2, (uint8_t *)"Installing Gentoo", sizeof("Installing Gentoo"), &err_n);
ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n);

View File

@ -1240,7 +1240,7 @@ namespace friend {
/**
* This event is triggered when a friend changes their status message.
*/
event status_message {
event status_message const {
/**
* @param friend_number The friend number of the friend whose status message
* changed.

View File

@ -1293,7 +1293,7 @@ int main(int argc, char *argv[])
tox_callback_friend_request(m, print_request, NULL);
tox_callback_friend_message(m, print_message, NULL);
tox_callback_friend_name(m, print_nickchange);
tox_callback_friend_status_message(m, print_statuschange, NULL);
tox_callback_friend_status_message(m, print_statuschange);
tox_callback_group_invite(m, print_invite, NULL);
tox_callback_group_message(m, print_groupmessage, NULL);
tox_callback_file_recv_chunk(m, write_file, NULL);

View File

@ -782,11 +782,9 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t
m->friend_namechange = function;
}
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *),
void *userdata)
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *))
{
m->friend_statusmessagechange = function;
m->friend_statusmessagechange_userdata = userdata;
}
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *), void *userdata)
@ -1959,8 +1957,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void
data_terminated[data_length] = 0;
if (m->friend_statusmessagechange)
m->friend_statusmessagechange(m, i, data_terminated, data_length,
m->friend_statusmessagechange_userdata);
m->friend_statusmessagechange(m, i, data_terminated, data_length, userdata);
set_friend_statusmessage(m, i, data_terminated, data_length);
break;

View File

@ -241,7 +241,6 @@ struct Messenger {
void *friend_message_userdata;
void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void *friend_statusmessagechange_userdata;
void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
void *friend_userstatuschange_userdata;
void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *);
@ -491,8 +490,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t
*
* You are not responsible for freeing newstatus
*/
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *),
void *userdata);
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *));
/* Set the callback for status type changes.
* Function(uint32_t friendnumber, USERSTATUS kind)

View File

@ -761,10 +761,10 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8
return 1;
}
void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *function, void *user_data)
void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *function)
{
Messenger *m = tox;
m_callback_statusmessage(m, function, user_data);
m_callback_statusmessage(m, function);
}
TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)

View File

@ -1327,7 +1327,7 @@ typedef void tox_friend_status_message_cb(Tox *tox, uint32_t friend_number, cons
*
* This event is triggered when a friend changes their status message.
*/
void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback, void *user_data);
void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback);
/**
* Return the friend's user status (away/busy/...). If the friend number is